bpmax-cli 0.1.44-beta.20 → 0.1.44-beta.21
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/dist/bin.js
CHANGED
|
@@ -231,8 +231,8 @@ function throwCliGovernanceUnsupportedIfNeeded(error, fallbackPath) {
|
|
|
231
231
|
}
|
|
232
232
|
throw error;
|
|
233
233
|
}
|
|
234
|
-
function normalizePath(
|
|
235
|
-
let normalized =
|
|
234
|
+
function normalizePath(path12) {
|
|
235
|
+
let normalized = path12.split("?")[0] || "/";
|
|
236
236
|
if (!normalized.startsWith("/")) {
|
|
237
237
|
normalized = `/${normalized}`;
|
|
238
238
|
}
|
|
@@ -242,17 +242,17 @@ function normalizePath(path11) {
|
|
|
242
242
|
}
|
|
243
243
|
return normalized.replace(/\/+$/g, "") || "/api";
|
|
244
244
|
}
|
|
245
|
-
function getNumber(value,
|
|
246
|
-
const result = getValue(value,
|
|
245
|
+
function getNumber(value, path12) {
|
|
246
|
+
const result = getValue(value, path12);
|
|
247
247
|
return typeof result === "number" ? result : void 0;
|
|
248
248
|
}
|
|
249
|
-
function getString(value,
|
|
250
|
-
const result = getValue(value,
|
|
249
|
+
function getString(value, path12) {
|
|
250
|
+
const result = getValue(value, path12);
|
|
251
251
|
return typeof result === "string" ? result : void 0;
|
|
252
252
|
}
|
|
253
|
-
function getValue(value,
|
|
253
|
+
function getValue(value, path12) {
|
|
254
254
|
let current = value;
|
|
255
|
-
for (const key of
|
|
255
|
+
for (const key of path12) {
|
|
256
256
|
if (!current || typeof current !== "object" || !(key in current)) {
|
|
257
257
|
return void 0;
|
|
258
258
|
}
|
|
@@ -262,10 +262,10 @@ function getValue(value, path11) {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
// src/core/capabilities.ts
|
|
265
|
-
function capabilityForRequest(method,
|
|
265
|
+
function capabilityForRequest(method, path12) {
|
|
266
266
|
const normalizedMethod = method.toUpperCase();
|
|
267
|
-
const normalizedPath = normalizePath2(
|
|
268
|
-
const pageTemplatePrefix = flowPageTemplateCapabilityPrefix(
|
|
267
|
+
const normalizedPath = normalizePath2(path12);
|
|
268
|
+
const pageTemplatePrefix = flowPageTemplateCapabilityPrefix(path12);
|
|
269
269
|
if (normalizedPath === "/cli/capabilities") {
|
|
270
270
|
return void 0;
|
|
271
271
|
}
|
|
@@ -279,6 +279,12 @@ function capabilityForRequest(method, path11) {
|
|
|
279
279
|
if (normalizedMethod === "GET" && /^\/cli\/memory\/[^/]+$/.test(normalizedPath)) return "memory.get";
|
|
280
280
|
if (normalizedMethod === "PUT" && /^\/cli\/memory\/[^/]+$/.test(normalizedPath)) return "memory.update";
|
|
281
281
|
if (normalizedMethod === "DELETE" && /^\/cli\/memory\/[^/]+$/.test(normalizedPath)) return "memory.delete";
|
|
282
|
+
if (normalizedMethod === "GET" && normalizedPath === "/cli/plugins") return "plugin.skills.list";
|
|
283
|
+
if (normalizedMethod === "GET" && /^\/cli\/plugins\/[^/]+$/.test(normalizedPath)) return "plugin.skills.show";
|
|
284
|
+
if (normalizedMethod === "GET" && /^\/cli\/plugins\/[^/]+\/skills$/.test(normalizedPath)) return "plugin.skills.list";
|
|
285
|
+
if (normalizedMethod === "GET" && /^\/cli\/plugins\/[^/]+\/skills\/[^/]+\/download$/.test(normalizedPath)) return "config.plugin.skill.download";
|
|
286
|
+
const pluginAgentCapability = pluginAgentCapabilityForRequest(normalizedMethod, normalizedPath);
|
|
287
|
+
if (pluginAgentCapability) return pluginAgentCapability;
|
|
282
288
|
if (normalizedMethod === "GET" && normalizedPath === "/user/current") return "user.current";
|
|
283
289
|
if (normalizedMethod === "GET" && normalizedPath === "/workspace/by_key") return "config.workspace_flow.export";
|
|
284
290
|
if (normalizedMethod === "PUT" && normalizedPath === "/workspace/workspace_flow") return "config.workspace_flow.submit";
|
|
@@ -417,8 +423,8 @@ async function updateProfileCapabilities(profileName, cache) {
|
|
|
417
423
|
};
|
|
418
424
|
await saveConfig(config);
|
|
419
425
|
}
|
|
420
|
-
function flowPageTemplateCapabilityPrefix(
|
|
421
|
-
const query =
|
|
426
|
+
function flowPageTemplateCapabilityPrefix(path12) {
|
|
427
|
+
const query = path12.includes("?") ? path12.slice(path12.indexOf("?") + 1) : "";
|
|
422
428
|
const type = new URLSearchParams(query).get("type");
|
|
423
429
|
if (type === "2") {
|
|
424
430
|
return "config.project_detail_template";
|
|
@@ -431,8 +437,8 @@ function flowPageTemplateCapabilityPrefix(path11) {
|
|
|
431
437
|
}
|
|
432
438
|
return "config.list_template";
|
|
433
439
|
}
|
|
434
|
-
function normalizePath2(
|
|
435
|
-
let normalized =
|
|
440
|
+
function normalizePath2(path12) {
|
|
441
|
+
let normalized = path12.split("?")[0] || "/";
|
|
436
442
|
if (!normalized.startsWith("/")) {
|
|
437
443
|
normalized = `/${normalized}`;
|
|
438
444
|
}
|
|
@@ -445,11 +451,25 @@ function normalizePath2(path11) {
|
|
|
445
451
|
}
|
|
446
452
|
return normalized;
|
|
447
453
|
}
|
|
454
|
+
function pluginAgentCapabilityForRequest(method, normalizedPath) {
|
|
455
|
+
const match = normalizedPath.match(/^\/(plugin_[A-Za-z0-9_]+)\/agents(?:\/|$)/);
|
|
456
|
+
if (!match) {
|
|
457
|
+
return void 0;
|
|
458
|
+
}
|
|
459
|
+
const plugin = match[1];
|
|
460
|
+
if (method === "GET") {
|
|
461
|
+
return `config.plugin.${plugin}.agent.export`;
|
|
462
|
+
}
|
|
463
|
+
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
|
464
|
+
return `config.plugin.${plugin}.agent.submit`;
|
|
465
|
+
}
|
|
466
|
+
return void 0;
|
|
467
|
+
}
|
|
448
468
|
|
|
449
469
|
// package.json
|
|
450
470
|
var package_default = {
|
|
451
471
|
name: "bpmax-cli",
|
|
452
|
-
version: "0.1.44-beta.
|
|
472
|
+
version: "0.1.44-beta.21",
|
|
453
473
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
454
474
|
type: "module",
|
|
455
475
|
bin: {
|
|
@@ -496,8 +516,8 @@ var NPM_PACKAGE = "bpmax-cli";
|
|
|
496
516
|
// src/core/terminal.ts
|
|
497
517
|
import { randomUUID } from "crypto";
|
|
498
518
|
import os from "os";
|
|
499
|
-
function isCliControlPath(
|
|
500
|
-
const normalized = normalizeApiPath(
|
|
519
|
+
function isCliControlPath(path12) {
|
|
520
|
+
const normalized = normalizeApiPath(path12);
|
|
501
521
|
return normalized === "/api/cli/capabilities" || normalized === "/api/cli/terminals/register" || normalized === "/api/cli/audit/start" || normalized === "/api/cli/audit/finish" || normalized === "/api/cli/bbs_invocations/start" || normalized === "/api/cli/bbs_invocations/finish";
|
|
502
522
|
}
|
|
503
523
|
function commandSummary(argv = process.argv) {
|
|
@@ -661,8 +681,8 @@ async function updateProfileTerminal(profile, terminalId, status) {
|
|
|
661
681
|
profile.config.terminal_status = status;
|
|
662
682
|
profile.config.terminal_registered_at = config.profiles[profile.name].terminal_registered_at;
|
|
663
683
|
}
|
|
664
|
-
function normalizeApiPath(
|
|
665
|
-
let normalized =
|
|
684
|
+
function normalizeApiPath(path12) {
|
|
685
|
+
let normalized = path12.split("?")[0] || "/";
|
|
666
686
|
if (!normalized.startsWith("/")) {
|
|
667
687
|
normalized = `/${normalized}`;
|
|
668
688
|
}
|
|
@@ -780,14 +800,14 @@ function recordCommandAuditResult(value) {
|
|
|
780
800
|
state.result_summary = redactAuditValue(value);
|
|
781
801
|
}
|
|
782
802
|
}
|
|
783
|
-
var ensureApiPath = (
|
|
784
|
-
if (!
|
|
785
|
-
|
|
803
|
+
var ensureApiPath = (path12) => {
|
|
804
|
+
if (!path12.startsWith("/")) {
|
|
805
|
+
path12 = `/${path12}`;
|
|
786
806
|
}
|
|
787
|
-
if (
|
|
788
|
-
return
|
|
807
|
+
if (path12.startsWith("/api/")) {
|
|
808
|
+
return path12;
|
|
789
809
|
}
|
|
790
|
-
return `/api${
|
|
810
|
+
return `/api${path12}`;
|
|
791
811
|
};
|
|
792
812
|
function normalizeWorkspaceForApi(workspace) {
|
|
793
813
|
const normalized = workspace?.trim();
|
|
@@ -833,10 +853,10 @@ function createApiClient(profile) {
|
|
|
833
853
|
});
|
|
834
854
|
return instance;
|
|
835
855
|
}
|
|
836
|
-
async function apiRequest(client, method,
|
|
856
|
+
async function apiRequest(client, method, path12, options = {}) {
|
|
837
857
|
const profile = clientProfiles.get(client);
|
|
838
|
-
const apiPath2 = ensureApiPath(
|
|
839
|
-
const capability = options.capability ?? capabilityForRequest(method,
|
|
858
|
+
const apiPath2 = ensureApiPath(path12);
|
|
859
|
+
const capability = options.capability ?? capabilityForRequest(method, path12);
|
|
840
860
|
const shouldControl = Boolean(profile?.config.api_key) && !isCliControlPath(apiPath2);
|
|
841
861
|
const reqId = requestId();
|
|
842
862
|
if (profile) {
|
|
@@ -1144,8 +1164,8 @@ async function parseJsonAny(input, label = "JSON input") {
|
|
|
1144
1164
|
function isMutatingMethod(method) {
|
|
1145
1165
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase());
|
|
1146
1166
|
}
|
|
1147
|
-
function normalizeApiPath2(
|
|
1148
|
-
let normalized =
|
|
1167
|
+
function normalizeApiPath2(path12) {
|
|
1168
|
+
let normalized = path12.trim();
|
|
1149
1169
|
const queryIndex = normalized.indexOf("?");
|
|
1150
1170
|
if (queryIndex >= 0) {
|
|
1151
1171
|
normalized = normalized.slice(0, queryIndex);
|
|
@@ -1162,19 +1182,35 @@ function normalizeApiPath2(path11) {
|
|
|
1162
1182
|
}
|
|
1163
1183
|
return normalized;
|
|
1164
1184
|
}
|
|
1165
|
-
function
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1185
|
+
function pluginAgentCapabilityForRawApi(method, path12) {
|
|
1186
|
+
const normalizedMethod = method.toUpperCase();
|
|
1187
|
+
const normalizedPath = normalizeApiPath2(path12);
|
|
1188
|
+
const match = normalizedPath.match(/^\/(plugin_[A-Za-z0-9_]+)\/agents(?:\/|$)/);
|
|
1189
|
+
if (!match) {
|
|
1190
|
+
return void 0;
|
|
1191
|
+
}
|
|
1192
|
+
const plugin = match[1];
|
|
1193
|
+
if (normalizedMethod === "GET") {
|
|
1194
|
+
return `config.plugin.${plugin}.agent.export`;
|
|
1195
|
+
}
|
|
1196
|
+
if (["POST", "PUT", "PATCH", "DELETE"].includes(normalizedMethod)) {
|
|
1197
|
+
return `config.plugin.${plugin}.agent.submit`;
|
|
1198
|
+
}
|
|
1199
|
+
return void 0;
|
|
1200
|
+
}
|
|
1201
|
+
function parseQuery(path12) {
|
|
1202
|
+
const queryIndex = path12.indexOf("?");
|
|
1203
|
+
return new URLSearchParams(queryIndex >= 0 ? path12.slice(queryIndex + 1) : "");
|
|
1168
1204
|
}
|
|
1169
|
-
function isRawConfigPath(method,
|
|
1170
|
-
const normalizedPath = normalizeApiPath2(
|
|
1205
|
+
function isRawConfigPath(method, path12) {
|
|
1206
|
+
const normalizedPath = normalizeApiPath2(path12);
|
|
1171
1207
|
if (/^\/(configuration|form_template|flow_page_template|data_set|data_set_field|api_platform|api_platform_instance|api_proxy|api_proxy_entity_binding|entity|entity_field|role|point|user_role|workspace|group|config_repository)(\/|$)/.test(normalizedPath)) {
|
|
1172
1208
|
return true;
|
|
1173
1209
|
}
|
|
1174
1210
|
if (normalizedPath === "/flow/list/lightweight" || normalizedPath.startsWith("/flow/configuration/")) {
|
|
1175
1211
|
return true;
|
|
1176
1212
|
}
|
|
1177
|
-
if (normalizedPath === "/flow" && method === "GET" && parseQuery(
|
|
1213
|
+
if (normalizedPath === "/flow" && method === "GET" && parseQuery(path12).has("draft")) {
|
|
1178
1214
|
return true;
|
|
1179
1215
|
}
|
|
1180
1216
|
if (normalizedPath.startsWith("/flow/") && !["/flow/flow_type", "/flow/options", "/flow/batch_get"].includes(normalizedPath)) {
|
|
@@ -1185,35 +1221,35 @@ function isRawConfigPath(method, path11) {
|
|
|
1185
1221
|
}
|
|
1186
1222
|
return false;
|
|
1187
1223
|
}
|
|
1188
|
-
function assertRawApiPathAllowed(method,
|
|
1189
|
-
if (isRawConfigPath(method,
|
|
1224
|
+
function assertRawApiPathAllowed(method, path12) {
|
|
1225
|
+
if (isRawConfigPath(method, path12)) {
|
|
1190
1226
|
throw new Error(
|
|
1191
|
-
`Raw API ${method} ${
|
|
1227
|
+
`Raw API ${method} ${path12} is blocked because BPMAX configuration APIs must use typed bpmax-cli config commands. Run bpmax-cli config adapters --format json to check whether the target config domain is supported.`
|
|
1192
1228
|
);
|
|
1193
1229
|
}
|
|
1194
1230
|
if (!isMutatingMethod(method)) {
|
|
1195
1231
|
return;
|
|
1196
1232
|
}
|
|
1197
|
-
const normalizedPath = normalizeApiPath2(
|
|
1233
|
+
const normalizedPath = normalizeApiPath2(path12);
|
|
1198
1234
|
const isProjectPath = normalizedPath === "/project" || normalizedPath.startsWith("/project/");
|
|
1199
1235
|
const isAllowedProjectReadPost = method === "POST" && normalizedPath === "/project/list";
|
|
1200
1236
|
if (!isProjectPath || isAllowedProjectReadPost) {
|
|
1201
1237
|
return;
|
|
1202
1238
|
}
|
|
1203
1239
|
throw new Error(
|
|
1204
|
-
`Raw API ${method} ${
|
|
1240
|
+
`Raw API ${method} ${path12} is blocked because /api/project/<id> falls back to project creation in huanpingtong-server. Do not call /project/es-search or /project/raw-es-search; huanpingtong-server does not expose those as public ES APIs. Use bpmax-cli project create --flow-id <id> --json <json> for project creation, or bpmax-cli project search / project list for project reads.`
|
|
1205
1241
|
);
|
|
1206
1242
|
}
|
|
1207
1243
|
function registerApiCommands(program2) {
|
|
1208
|
-
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method,
|
|
1244
|
+
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method, path12, options) => {
|
|
1209
1245
|
const normalizedMethod = method.toUpperCase();
|
|
1210
|
-
assertRawApiPathAllowed(normalizedMethod,
|
|
1246
|
+
assertRawApiPathAllowed(normalizedMethod, path12);
|
|
1211
1247
|
if (isMutatingMethod(normalizedMethod) && options.confirmMutating !== true) {
|
|
1212
1248
|
printResult(options.format, {
|
|
1213
1249
|
ok: false,
|
|
1214
1250
|
dry_run: true,
|
|
1215
1251
|
method: normalizedMethod,
|
|
1216
|
-
path:
|
|
1252
|
+
path: path12,
|
|
1217
1253
|
warning: "Mutating raw API calls require --confirm-mutating. Prefer typed bpmax-cli commands such as step submit."
|
|
1218
1254
|
});
|
|
1219
1255
|
return;
|
|
@@ -1221,10 +1257,11 @@ function registerApiCommands(program2) {
|
|
|
1221
1257
|
const config = await loadConfig();
|
|
1222
1258
|
const profile = resolveProfile(config, options.profile);
|
|
1223
1259
|
const client = createApiClient(profile);
|
|
1224
|
-
const
|
|
1260
|
+
const capability = pluginAgentCapabilityForRawApi(normalizedMethod, path12) || "api.raw";
|
|
1261
|
+
const result = await apiRequest(client, normalizedMethod, path12, {
|
|
1225
1262
|
params: options.params ? await parseJsonInput(options.params, "--params") : void 0,
|
|
1226
1263
|
data: await parseJsonAny(options.data, "--data"),
|
|
1227
|
-
capability
|
|
1264
|
+
capability
|
|
1228
1265
|
});
|
|
1229
1266
|
printResult(options.format, result);
|
|
1230
1267
|
});
|
|
@@ -1296,18 +1333,18 @@ function lintDeviceAuthorizationUrl(urlValue, expectedOrigin, expectedWorkspace,
|
|
|
1296
1333
|
);
|
|
1297
1334
|
}
|
|
1298
1335
|
}
|
|
1299
|
-
function apiPath(
|
|
1300
|
-
if (
|
|
1301
|
-
return
|
|
1336
|
+
function apiPath(path12) {
|
|
1337
|
+
if (path12.startsWith("/api/")) {
|
|
1338
|
+
return path12;
|
|
1302
1339
|
}
|
|
1303
|
-
return `/api${
|
|
1340
|
+
return `/api${path12.startsWith("/") ? path12 : `/${path12}`}`;
|
|
1304
1341
|
}
|
|
1305
1342
|
function createDeviceRequest(origin) {
|
|
1306
1343
|
const client = axios2.create({ baseURL: origin, withCredentials: false });
|
|
1307
|
-
return async (method,
|
|
1344
|
+
return async (method, path12, options) => {
|
|
1308
1345
|
const response = await client.request({
|
|
1309
1346
|
method,
|
|
1310
|
-
url: apiPath(
|
|
1347
|
+
url: apiPath(path12),
|
|
1311
1348
|
data: options.data
|
|
1312
1349
|
});
|
|
1313
1350
|
const body = response.data;
|
|
@@ -1716,20 +1753,20 @@ function requireNumericId(value, name) {
|
|
|
1716
1753
|
}
|
|
1717
1754
|
return nextValue;
|
|
1718
1755
|
}
|
|
1719
|
-
function withQuery(
|
|
1756
|
+
function withQuery(path12, query) {
|
|
1720
1757
|
const params = new URLSearchParams();
|
|
1721
1758
|
for (const [key, value] of Object.entries(query)) {
|
|
1722
1759
|
if (value !== void 0) {
|
|
1723
1760
|
params.set(key, value);
|
|
1724
1761
|
}
|
|
1725
1762
|
}
|
|
1726
|
-
return `${
|
|
1763
|
+
return `${path12}?${params.toString()}`;
|
|
1727
1764
|
}
|
|
1728
1765
|
function buildBpmaxUrl(profile, kind, params = {}) {
|
|
1729
1766
|
const origin = normalizeOrigin2(profile.config.origin);
|
|
1730
1767
|
const workspace = normalizeWorkspaceForUrl(params.workspace || profile.config.workspace);
|
|
1731
1768
|
const basePath = `/${workspace}`;
|
|
1732
|
-
let
|
|
1769
|
+
let path12 = basePath;
|
|
1733
1770
|
const result = {
|
|
1734
1771
|
kind,
|
|
1735
1772
|
profile: profile.name,
|
|
@@ -1737,15 +1774,15 @@ function buildBpmaxUrl(profile, kind, params = {}) {
|
|
|
1737
1774
|
workspace
|
|
1738
1775
|
};
|
|
1739
1776
|
if (kind === "project-list") {
|
|
1740
|
-
|
|
1777
|
+
path12 = `${basePath}/project`;
|
|
1741
1778
|
} else if (kind === "project-detail") {
|
|
1742
1779
|
const projectId = requireNumericId(params.projectId, "projectId");
|
|
1743
|
-
|
|
1780
|
+
path12 = `${basePath}/project_detail/0/${projectId}`;
|
|
1744
1781
|
result.project_id = projectId;
|
|
1745
1782
|
} else if (kind === "project-step") {
|
|
1746
1783
|
const projectId = requireNumericId(params.projectId, "projectId");
|
|
1747
1784
|
const stepId = requireNumericId(params.stepId, "stepId");
|
|
1748
|
-
|
|
1785
|
+
path12 = withQuery(`${basePath}/projectContinue`, {
|
|
1749
1786
|
id: projectId,
|
|
1750
1787
|
step_id: stepId
|
|
1751
1788
|
});
|
|
@@ -1762,15 +1799,15 @@ function buildBpmaxUrl(profile, kind, params = {}) {
|
|
|
1762
1799
|
...flowKey ? { key: flowKey } : {},
|
|
1763
1800
|
...prefillToken ? { prefill_token: prefillToken } : { init_value: initValue }
|
|
1764
1801
|
};
|
|
1765
|
-
|
|
1802
|
+
path12 = withQuery(`${basePath}/project/create`, query);
|
|
1766
1803
|
result.flow_type = flowType;
|
|
1767
1804
|
result.flow_key = flowKey;
|
|
1768
1805
|
result.mobile_path = withQuery("/pages/projectCreate/projectCreate", query);
|
|
1769
1806
|
}
|
|
1770
|
-
const url = `${origin}${
|
|
1807
|
+
const url = `${origin}${path12}`;
|
|
1771
1808
|
return {
|
|
1772
1809
|
...result,
|
|
1773
|
-
path:
|
|
1810
|
+
path: path12,
|
|
1774
1811
|
url,
|
|
1775
1812
|
...kind === "project-create" ? { pc_url: url } : {}
|
|
1776
1813
|
};
|
|
@@ -1880,6 +1917,7 @@ var knownBpmCommands = {
|
|
|
1880
1917
|
es: /* @__PURE__ */ new Set(["project-search"]),
|
|
1881
1918
|
flow: /* @__PURE__ */ new Set(["list", "options", "get"]),
|
|
1882
1919
|
init: null,
|
|
1920
|
+
plugin: /* @__PURE__ */ new Set(["skills"]),
|
|
1883
1921
|
project: /* @__PURE__ */ new Set(["list", "search", "get", "my-step", "approval-context", "create"]),
|
|
1884
1922
|
recipe: /* @__PURE__ */ new Set(["list", "show", "run", "scaffold"]),
|
|
1885
1923
|
schema: /* @__PURE__ */ new Set(["list", "show"]),
|
|
@@ -2246,10 +2284,51 @@ async function findOpenClawCli() {
|
|
|
2246
2284
|
}
|
|
2247
2285
|
return result.stdout.split(/\r?\n/).find((line) => line.trim())?.trim() || "openclaw";
|
|
2248
2286
|
}
|
|
2249
|
-
async function
|
|
2287
|
+
async function readSkillInstallOwner(destination) {
|
|
2288
|
+
try {
|
|
2289
|
+
const parsed = JSON.parse(await readFile4(path2.join(destination, ".bpmax-skill-install.json"), "utf8"));
|
|
2290
|
+
return parsed?.kind === "plugin" ? parsed : void 0;
|
|
2291
|
+
} catch {
|
|
2292
|
+
return void 0;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
async function assertPluginSkillOwnerCompatible(destination, owner, options = {}) {
|
|
2296
|
+
if (!owner) {
|
|
2297
|
+
return;
|
|
2298
|
+
}
|
|
2299
|
+
if (!await exists(destination)) {
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
const existing = await readSkillInstallOwner(destination);
|
|
2303
|
+
if (!existing) {
|
|
2304
|
+
if (options.allowUnownedExisting) {
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
throw new Error(
|
|
2308
|
+
`Plugin skill ${owner.skill} already exists at ${destination} but has no BPMAX ownership metadata. Refusing to overwrite it; uninstall or move the existing skill first.`
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
if (existing.profile === owner.profile && existing.plugin === owner.plugin && existing.skill === owner.skill) {
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
throw new Error(
|
|
2315
|
+
`Plugin skill ${owner.skill} is already installed for profile ${existing.profile} plugin ${existing.plugin}. Refusing to overwrite it from profile ${owner.profile}; use a separate agent skill root or uninstall the existing plugin skill first.`
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
async function writeSkillInstallOwner(destination, owner) {
|
|
2319
|
+
if (!owner) {
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
await writeFile2(path2.join(destination, ".bpmax-skill-install.json"), JSON.stringify(owner, null, 2), "utf8");
|
|
2323
|
+
}
|
|
2324
|
+
async function installSkillDirectory(skillDir, skillName, agent, options = {}) {
|
|
2250
2325
|
if (agent === "openclaw") {
|
|
2326
|
+
const fallbackRoot = path2.join(homedir2(), ".openclaw", "skills");
|
|
2327
|
+
const destination2 = path2.join(fallbackRoot, skillName);
|
|
2251
2328
|
const executable = await findOpenClawCli();
|
|
2252
2329
|
if (executable) {
|
|
2330
|
+
await assertPluginSkillOwnerCompatible(destination2, options.owner, { allowUnownedExisting: true });
|
|
2331
|
+
await writeSkillInstallOwner(skillDir, options.owner);
|
|
2253
2332
|
const result = await runCommand(executable, ["skills", "install", "--file-path", skillDir], {
|
|
2254
2333
|
timeoutMs: 2 * 60 * 1e3
|
|
2255
2334
|
});
|
|
@@ -2257,18 +2336,20 @@ async function installSkillDirectory(skillDir, skillName, agent) {
|
|
|
2257
2336
|
return skillDir;
|
|
2258
2337
|
}
|
|
2259
2338
|
}
|
|
2260
|
-
const fallbackRoot = path2.join(homedir2(), ".openclaw", "skills");
|
|
2261
|
-
const destination2 = path2.join(fallbackRoot, skillName);
|
|
2262
2339
|
await mkdir2(fallbackRoot, { recursive: true });
|
|
2340
|
+
await assertPluginSkillOwnerCompatible(destination2, options.owner);
|
|
2263
2341
|
await rm(destination2, { recursive: true, force: true });
|
|
2264
2342
|
await cp(skillDir, destination2, { recursive: true });
|
|
2343
|
+
await writeSkillInstallOwner(destination2, options.owner);
|
|
2265
2344
|
return destination2;
|
|
2266
2345
|
}
|
|
2267
2346
|
const root = directoryTargets[agent] || directoryTargets.generic;
|
|
2268
2347
|
const destination = path2.join(root, skillName);
|
|
2269
2348
|
await mkdir2(root, { recursive: true });
|
|
2349
|
+
await assertPluginSkillOwnerCompatible(destination, options.owner);
|
|
2270
2350
|
await rm(destination, { recursive: true, force: true });
|
|
2271
2351
|
await cp(skillDir, destination, { recursive: true });
|
|
2352
|
+
await writeSkillInstallOwner(destination, options.owner);
|
|
2272
2353
|
return destination;
|
|
2273
2354
|
}
|
|
2274
2355
|
function resolveDownloadUrl(profile, url) {
|
|
@@ -2589,8 +2670,8 @@ function registerBbsCommands(program2) {
|
|
|
2589
2670
|
const state = await readBusinessSkillState(profile.name, agent);
|
|
2590
2671
|
const installed = state.skills[skill.key];
|
|
2591
2672
|
if (installed) {
|
|
2592
|
-
const { rm:
|
|
2593
|
-
await
|
|
2673
|
+
const { rm: rm5 } = await import("fs/promises");
|
|
2674
|
+
await rm5(installed.install_path, { recursive: true, force: true });
|
|
2594
2675
|
await updateBusinessSkillState(profile.name, agent, (current) => {
|
|
2595
2676
|
delete current.skills[skill.key];
|
|
2596
2677
|
});
|
|
@@ -2638,9 +2719,820 @@ function registerCapabilitiesCommands(program2) {
|
|
|
2638
2719
|
import { text as text2 } from "@clack/prompts";
|
|
2639
2720
|
|
|
2640
2721
|
// src/core/config-workflow.ts
|
|
2722
|
+
import { createHash as createHash4 } from "crypto";
|
|
2723
|
+
import { mkdir as mkdir5, readdir as readdir2, readFile as readFile8, writeFile as writeFile5 } from "fs/promises";
|
|
2724
|
+
import path5 from "path";
|
|
2725
|
+
|
|
2726
|
+
// src/core/plugin-skills.ts
|
|
2641
2727
|
import { createHash as createHash3 } from "crypto";
|
|
2642
|
-
import { mkdir as
|
|
2728
|
+
import { cp as cp2, mkdir as mkdir4, readdir, readFile as readFile7, rm as rm2, stat as stat3, writeFile as writeFile4 } from "fs/promises";
|
|
2729
|
+
import path4 from "path";
|
|
2730
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
2731
|
+
import axios5 from "axios";
|
|
2732
|
+
import JSZip2 from "jszip";
|
|
2733
|
+
|
|
2734
|
+
// src/core/skills.ts
|
|
2735
|
+
import { mkdir as mkdir3, readFile as readFile6, writeFile as writeFile3 } from "fs/promises";
|
|
2643
2736
|
import path3 from "path";
|
|
2737
|
+
import { fileURLToPath } from "url";
|
|
2738
|
+
var SKILLS_STAMP_FILE = "skills.stamp";
|
|
2739
|
+
var SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1e3;
|
|
2740
|
+
function skillsStampValue(version, agent) {
|
|
2741
|
+
return agent ? `${version}:${agent}` : version;
|
|
2742
|
+
}
|
|
2743
|
+
function stampPath(configDir = getConfigDir()) {
|
|
2744
|
+
return path3.join(configDir, SKILLS_STAMP_FILE);
|
|
2745
|
+
}
|
|
2746
|
+
async function readSkillsStamp(configDir = getConfigDir()) {
|
|
2747
|
+
try {
|
|
2748
|
+
return (await readFile6(stampPath(configDir), "utf8")).trim();
|
|
2749
|
+
} catch {
|
|
2750
|
+
return "";
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
async function writeSkillsStamp(version, configDir = getConfigDir(), agent) {
|
|
2754
|
+
await mkdir3(configDir, { recursive: true });
|
|
2755
|
+
await writeFile3(stampPath(configDir), skillsStampValue(version, agent), "utf8");
|
|
2756
|
+
}
|
|
2757
|
+
async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent) {
|
|
2758
|
+
const target = skillsStampValue(currentVersion, agent);
|
|
2759
|
+
if (process.env.BPMAX_CLI_NO_SKILLS_NOTIFIER) {
|
|
2760
|
+
return { current: target, target, inSync: true };
|
|
2761
|
+
}
|
|
2762
|
+
const current = await readSkillsStamp(configDir);
|
|
2763
|
+
return { current, target, inSync: current === target };
|
|
2764
|
+
}
|
|
2765
|
+
async function resolvePackageRootFrom(entrypointPath) {
|
|
2766
|
+
const entryDir = path3.dirname(entrypointPath);
|
|
2767
|
+
if (path3.basename(entryDir) === "dist") {
|
|
2768
|
+
return path3.dirname(entryDir);
|
|
2769
|
+
}
|
|
2770
|
+
if (path3.basename(entryDir) === "core" && path3.basename(path3.dirname(entryDir)) === "src") {
|
|
2771
|
+
return path3.dirname(path3.dirname(entryDir));
|
|
2772
|
+
}
|
|
2773
|
+
return path3.resolve(entryDir, "..", "..");
|
|
2774
|
+
}
|
|
2775
|
+
async function defaultPackageRoot() {
|
|
2776
|
+
return resolvePackageRootFrom(fileURLToPath(import.meta.url));
|
|
2777
|
+
}
|
|
2778
|
+
async function runSkillsInstall(options = {}) {
|
|
2779
|
+
const runner = options.runner || runCommand;
|
|
2780
|
+
const packageRoot = options.packageRoot || await defaultPackageRoot();
|
|
2781
|
+
const args = [path3.join(packageRoot, "scripts", "install-skills.mjs")];
|
|
2782
|
+
if (options.agent) {
|
|
2783
|
+
args.push("--json", "--agent", options.agent);
|
|
2784
|
+
}
|
|
2785
|
+
return runner(process.execPath, args, {
|
|
2786
|
+
timeoutMs: SKILLS_INSTALL_TIMEOUT_MS
|
|
2787
|
+
});
|
|
2788
|
+
}
|
|
2789
|
+
async function syncSkills(version, options = {}) {
|
|
2790
|
+
if (!options.force) {
|
|
2791
|
+
const status = await checkSkillsSync(version, options.configDir, options.agent);
|
|
2792
|
+
if (status.inSync) {
|
|
2793
|
+
return { action: "in_sync" };
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
const result = await runSkillsInstall({ packageRoot: options.packageRoot, runner: options.runner, agent: options.agent });
|
|
2797
|
+
if (result.exitCode === 0) {
|
|
2798
|
+
await writeSkillsStamp(version, options.configDir, options.agent);
|
|
2799
|
+
return { action: "synced", result };
|
|
2800
|
+
}
|
|
2801
|
+
return { action: "failed", result };
|
|
2802
|
+
}
|
|
2803
|
+
|
|
2804
|
+
// src/core/plugin-skills.ts
|
|
2805
|
+
var allowedTopLevelFiles = /* @__PURE__ */ new Set(["SKILL.md"]);
|
|
2806
|
+
var allowedTopLevelDirs = /* @__PURE__ */ new Set(["references", "scripts", "assets", "agents", "lint"]);
|
|
2807
|
+
var allowedAgentsFiles = /* @__PURE__ */ new Set(["openai.yaml"]);
|
|
2808
|
+
var semverPattern2 = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
2809
|
+
var safeSkillNamePattern = /^bpmax-[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
2810
|
+
var safePathSegmentPattern = /^[A-Za-z0-9_.:-]+$/;
|
|
2811
|
+
function issue2(severity, code, message) {
|
|
2812
|
+
return { severity, code, message };
|
|
2813
|
+
}
|
|
2814
|
+
async function exists2(targetPath) {
|
|
2815
|
+
try {
|
|
2816
|
+
await stat3(targetPath);
|
|
2817
|
+
return true;
|
|
2818
|
+
} catch {
|
|
2819
|
+
return false;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
function parseFrontmatter2(markdown) {
|
|
2823
|
+
const match = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
2824
|
+
if (!match) {
|
|
2825
|
+
return {};
|
|
2826
|
+
}
|
|
2827
|
+
const result = {};
|
|
2828
|
+
match[1].split(/\r?\n/).forEach((line) => {
|
|
2829
|
+
const item = line.match(/^([A-Za-z0-9_.-]+):\s*(.*)$/);
|
|
2830
|
+
if (!item) {
|
|
2831
|
+
return;
|
|
2832
|
+
}
|
|
2833
|
+
result[item[1]] = item[2].trim().replace(/^['"]|['"]$/g, "");
|
|
2834
|
+
});
|
|
2835
|
+
return result;
|
|
2836
|
+
}
|
|
2837
|
+
function completeReport2(report) {
|
|
2838
|
+
const errors = report.issues.filter((item) => item.severity === "error");
|
|
2839
|
+
const warnings = report.issues.filter((item) => item.severity === "warning");
|
|
2840
|
+
return {
|
|
2841
|
+
ok: errors.length === 0,
|
|
2842
|
+
errors,
|
|
2843
|
+
warnings,
|
|
2844
|
+
checks: report.checks,
|
|
2845
|
+
manifest: report.manifest,
|
|
2846
|
+
skill_dir: report.skill_dir
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
async function listCoreSkillNames() {
|
|
2850
|
+
const packageRoot = await resolvePackageRootFrom(fileURLToPath2(import.meta.url));
|
|
2851
|
+
const roots = [path4.join(packageRoot, "skills")];
|
|
2852
|
+
const names = /* @__PURE__ */ new Set();
|
|
2853
|
+
for (const root of roots) {
|
|
2854
|
+
let entries;
|
|
2855
|
+
try {
|
|
2856
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
2857
|
+
} catch {
|
|
2858
|
+
continue;
|
|
2859
|
+
}
|
|
2860
|
+
for (const entry of entries) {
|
|
2861
|
+
if (!entry.isDirectory()) {
|
|
2862
|
+
continue;
|
|
2863
|
+
}
|
|
2864
|
+
if (await exists2(path4.join(root, entry.name, "SKILL.md"))) {
|
|
2865
|
+
names.add(entry.name);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
return names;
|
|
2870
|
+
}
|
|
2871
|
+
async function collectRelativeFiles(root, dir = "") {
|
|
2872
|
+
const absolute = path4.join(root, dir);
|
|
2873
|
+
const entries = await readdir(absolute, { withFileTypes: true });
|
|
2874
|
+
const files = [];
|
|
2875
|
+
for (const entry of entries) {
|
|
2876
|
+
const relative = path4.posix.join(dir.replace(/\\/g, "/"), entry.name);
|
|
2877
|
+
if (entry.isDirectory()) {
|
|
2878
|
+
files.push(...await collectRelativeFiles(root, relative));
|
|
2879
|
+
} else {
|
|
2880
|
+
files.push(relative);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
return files;
|
|
2884
|
+
}
|
|
2885
|
+
function validateAllowedPath(relative) {
|
|
2886
|
+
const normalized = relative.replace(/\\/g, "/");
|
|
2887
|
+
const parts = normalized.split("/");
|
|
2888
|
+
if (normalized.startsWith("/") || path4.isAbsolute(normalized) || parts.some((part) => part === "" || part === "." || part === "..")) {
|
|
2889
|
+
return issue2("error", "unsafe_path", `Plugin skill contains unsafe path: ${relative}`);
|
|
2890
|
+
}
|
|
2891
|
+
if (parts.length === 1) {
|
|
2892
|
+
if (!allowedTopLevelFiles.has(parts[0])) {
|
|
2893
|
+
return issue2("error", "disallowed_top_level_file", `Plugin skill top-level file is not allowed: ${relative}`);
|
|
2894
|
+
}
|
|
2895
|
+
return void 0;
|
|
2896
|
+
}
|
|
2897
|
+
const top = parts[0];
|
|
2898
|
+
if (!allowedTopLevelDirs.has(top)) {
|
|
2899
|
+
return issue2("error", "disallowed_top_level_dir", `Plugin skill top-level directory is not allowed: ${top}`);
|
|
2900
|
+
}
|
|
2901
|
+
if (top === "agents" && (parts.length !== 2 || !allowedAgentsFiles.has(parts[1]))) {
|
|
2902
|
+
return issue2("error", "disallowed_agents_file", `Plugin skill agents/ may only contain openai.yaml: ${relative}`);
|
|
2903
|
+
}
|
|
2904
|
+
if (top === "lint" && (parts.length !== 2 || !parts[1].endsWith(".json"))) {
|
|
2905
|
+
return issue2("error", "disallowed_lint_file", `Plugin skill lint/ may only contain JSON files: ${relative}`);
|
|
2906
|
+
}
|
|
2907
|
+
return void 0;
|
|
2908
|
+
}
|
|
2909
|
+
function validateSafeSkillName(name, issues, context = "Plugin skill") {
|
|
2910
|
+
if (!safeSkillNamePattern.test(name)) {
|
|
2911
|
+
issues.push(issue2("error", "invalid_name", `${context} name must match ${safeSkillNamePattern.source}: ${name}`));
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
function assertSafeStateSegment(value, label) {
|
|
2915
|
+
if (!value || value.includes("/") || value.includes("\\") || value === "." || value === ".." || !safePathSegmentPattern.test(value)) {
|
|
2916
|
+
throw new Error(`Unsafe plugin skill state ${label}: ${value}`);
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
async function assertInstallablePluginSkillName(name) {
|
|
2920
|
+
if (!safeSkillNamePattern.test(name)) {
|
|
2921
|
+
throw new Error(`Plugin skill name must match ${safeSkillNamePattern.source}: ${name}`);
|
|
2922
|
+
}
|
|
2923
|
+
const coreSkillNames = await listCoreSkillNames();
|
|
2924
|
+
if (coreSkillNames.has(name)) {
|
|
2925
|
+
throw new Error(`Plugin skill must not overwrite built-in/core skill: ${name}`);
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
async function installProfilePluginSkillDirectory(skillDir, profileName, agent, skillName) {
|
|
2929
|
+
assertSafeStateSegment(profileName, "profile");
|
|
2930
|
+
assertSafeStateSegment(agent, "agent");
|
|
2931
|
+
if (!safeSkillNamePattern.test(skillName)) {
|
|
2932
|
+
throw new Error(`Plugin skill name must match ${safeSkillNamePattern.source}: ${skillName}`);
|
|
2933
|
+
}
|
|
2934
|
+
const destination = path4.join(getConfigDir(), "plugin-skills", profileName, agent, "installed", skillName);
|
|
2935
|
+
await copySkillDirectory(skillDir, destination);
|
|
2936
|
+
return destination;
|
|
2937
|
+
}
|
|
2938
|
+
function normalizePluginLintManifests(value) {
|
|
2939
|
+
if (!Array.isArray(value)) {
|
|
2940
|
+
return [];
|
|
2941
|
+
}
|
|
2942
|
+
return value.filter((item) => typeof item === "object" && item !== null && !Array.isArray(item)).map((item) => ({
|
|
2943
|
+
domain: typeof item.domain === "string" ? item.domain : "",
|
|
2944
|
+
plugin_key: typeof item.plugin_key === "string" ? item.plugin_key : "",
|
|
2945
|
+
path: typeof item.path === "string" ? item.path.replace(/\\/g, "/") : "",
|
|
2946
|
+
version: typeof item.version === "string" || typeof item.version === "number" ? item.version : void 0,
|
|
2947
|
+
paths: Array.isArray(item.paths) ? item.paths.filter((pathItem) => typeof pathItem === "string" && Boolean(pathItem.trim())).map((pathItem) => pathItem.replace(/\\/g, "/")) : void 0
|
|
2948
|
+
})).filter((item) => item.domain && item.plugin_key && item.path);
|
|
2949
|
+
}
|
|
2950
|
+
function validatePluginLintManifest(item, issues, context) {
|
|
2951
|
+
if (item.domain !== "flow-template-node") {
|
|
2952
|
+
issues.push(issue2("error", "unsupported_lint_domain", `${context} lint domain is not supported: ${item.domain}`));
|
|
2953
|
+
}
|
|
2954
|
+
if (!/^plugin_[A-Za-z0-9_]+$/.test(item.plugin_key)) {
|
|
2955
|
+
issues.push(issue2("error", "invalid_lint_plugin_key", `${context} lint plugin_key must look like plugin_xxx.`));
|
|
2956
|
+
}
|
|
2957
|
+
const normalized = item.path.replace(/\\/g, "/");
|
|
2958
|
+
const parts = normalized.split("/");
|
|
2959
|
+
if (!normalized.startsWith("lint/") || parts.some((part) => part === "" || part === "." || part === "..") || normalized.startsWith("/") || path4.isAbsolute(normalized) || !normalized.endsWith(".json")) {
|
|
2960
|
+
issues.push(issue2("error", "invalid_lint_path", `${context} lint path must be a lint/*.json file.`));
|
|
2961
|
+
}
|
|
2962
|
+
if (item.paths) {
|
|
2963
|
+
item.paths.forEach((scanPath) => {
|
|
2964
|
+
if (!isAllowedPluginConfigScanPath(scanPath)) {
|
|
2965
|
+
issues.push(issue2("error", "invalid_lint_scan_path", `${context} lint scan path is not supported: ${scanPath}`));
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
function isAllowedPluginConfigScanPath(scanPath) {
|
|
2971
|
+
return scanPath === "data.meta.<plugin_key>" || scanPath === "data.nodes[].<plugin_key>" || /^data\.nodes\[\]\.[A-Za-z0-9_]+_(?:triggers|configs|plugins)\[\]$/.test(scanPath);
|
|
2972
|
+
}
|
|
2973
|
+
async function validatePluginLintRuleFiles(skillDir, files, issues) {
|
|
2974
|
+
for (const file of files) {
|
|
2975
|
+
if (!file.startsWith("lint/") || !file.endsWith(".json")) {
|
|
2976
|
+
continue;
|
|
2977
|
+
}
|
|
2978
|
+
try {
|
|
2979
|
+
const parsed = JSON.parse(await readFile7(path4.join(skillDir, file), "utf8"));
|
|
2980
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2981
|
+
issues.push(issue2("error", "invalid_lint_rule_file", `${file} must contain a declarative lint JSON object.`));
|
|
2982
|
+
continue;
|
|
2983
|
+
}
|
|
2984
|
+
if (!Array.isArray(parsed.rules) || !parsed.rules.length) {
|
|
2985
|
+
issues.push(issue2("error", "empty_lint_rules", `${file} must contain a non-empty rules array.`));
|
|
2986
|
+
}
|
|
2987
|
+
} catch (error) {
|
|
2988
|
+
issues.push(issue2("error", "invalid_lint_rule_file", `${file} must be valid JSON.`));
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
async function lintPluginSkillDirectory(skillDir, options = {}) {
|
|
2993
|
+
const issues = [];
|
|
2994
|
+
const checks = [];
|
|
2995
|
+
let skillMarkdown = "";
|
|
2996
|
+
let manifest = {};
|
|
2997
|
+
try {
|
|
2998
|
+
skillMarkdown = await readFile7(path4.join(skillDir, "SKILL.md"), "utf8");
|
|
2999
|
+
manifest = parseFrontmatter2(skillMarkdown);
|
|
3000
|
+
} catch {
|
|
3001
|
+
issues.push(issue2("error", "missing_skill_md", "Plugin skill package must contain top-level SKILL.md."));
|
|
3002
|
+
}
|
|
3003
|
+
const name = manifest.name;
|
|
3004
|
+
const version = manifest.version;
|
|
3005
|
+
if (!name || typeof name !== "string") {
|
|
3006
|
+
issues.push(issue2("error", "missing_name", "SKILL.md frontmatter must contain name."));
|
|
3007
|
+
} else {
|
|
3008
|
+
if (!name.startsWith("bpmax-")) {
|
|
3009
|
+
issues.push(issue2("error", "invalid_name_prefix", "Plugin skill name must start with bpmax-."));
|
|
3010
|
+
}
|
|
3011
|
+
validateSafeSkillName(name, issues);
|
|
3012
|
+
if (options.expectedName && name !== options.expectedName) {
|
|
3013
|
+
issues.push(issue2("error", "name_mismatch", `Plugin skill name ${name} does not match expected ${options.expectedName}.`));
|
|
3014
|
+
}
|
|
3015
|
+
if (!options.allowCoreOverwrite) {
|
|
3016
|
+
const coreSkillNames = await listCoreSkillNames();
|
|
3017
|
+
if (coreSkillNames.has(name)) {
|
|
3018
|
+
issues.push(issue2("error", "core_skill_overwrite", `Plugin skill must not overwrite built-in/core skill: ${name}`));
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
if (!version || typeof version !== "string") {
|
|
3023
|
+
issues.push(issue2("error", "missing_version", "SKILL.md frontmatter must contain version."));
|
|
3024
|
+
} else if (!semverPattern2.test(version)) {
|
|
3025
|
+
issues.push(issue2("error", "invalid_version", "Plugin skill version must be semver, for example 1.0.0."));
|
|
3026
|
+
}
|
|
3027
|
+
try {
|
|
3028
|
+
const files = await collectRelativeFiles(skillDir);
|
|
3029
|
+
const invalid = files.map(validateAllowedPath).filter(Boolean);
|
|
3030
|
+
issues.push(...invalid);
|
|
3031
|
+
await validatePluginLintRuleFiles(skillDir, files, issues);
|
|
3032
|
+
checks.push({ name: "allowed_files", files, invalid: invalid.map((item) => item.message) });
|
|
3033
|
+
} catch (error) {
|
|
3034
|
+
issues.push(issue2("error", "read_failed", error instanceof Error ? error.message : String(error)));
|
|
3035
|
+
}
|
|
3036
|
+
[
|
|
3037
|
+
{ pattern: /\brm\s+-rf\b/, code: "dangerous_rm_rf", message: "Dangerous rm -rf command found." },
|
|
3038
|
+
{ pattern: /\bgit\s+reset\s+--hard\b/, code: "dangerous_git_reset", message: "Dangerous git reset --hard command found." },
|
|
3039
|
+
{ pattern: /\bgit\s+checkout\s+--\b/, code: "dangerous_git_checkout", message: "Dangerous git checkout -- command found." },
|
|
3040
|
+
{ pattern: /authorization\s*:\s*bearer|api[_-]?key\s*[:=]\s*['"][^'"]+/i, code: "secret_literal", message: "Possible literal credential found." },
|
|
3041
|
+
{ 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." }
|
|
3042
|
+
].forEach((rule) => {
|
|
3043
|
+
if (rule.pattern.test(skillMarkdown)) {
|
|
3044
|
+
issues.push(issue2("error", rule.code, rule.message));
|
|
3045
|
+
}
|
|
3046
|
+
});
|
|
3047
|
+
return completeReport2({ checks, issues, manifest, skill_dir: skillDir });
|
|
3048
|
+
}
|
|
3049
|
+
async function lintPluginSkillZip(zipPath, options = {}) {
|
|
3050
|
+
try {
|
|
3051
|
+
const buffer = await readFile7(zipPath);
|
|
3052
|
+
const dir = await zipDirectoryToTemp(buffer, "plugin-skill-lint");
|
|
3053
|
+
return lintPluginSkillDirectory(dir, options);
|
|
3054
|
+
} catch (error) {
|
|
3055
|
+
return completeReport2({
|
|
3056
|
+
checks: [],
|
|
3057
|
+
manifest: {},
|
|
3058
|
+
issues: [issue2("error", "invalid_package", error instanceof Error ? error.message : String(error))]
|
|
3059
|
+
});
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
function pluginSkillStatePath(profileName, agent) {
|
|
3063
|
+
assertSafeStateSegment(profileName, "profile");
|
|
3064
|
+
assertSafeStateSegment(agent, "agent");
|
|
3065
|
+
return path4.join(getConfigDir(), "plugin-skills", profileName, agent, "state.json");
|
|
3066
|
+
}
|
|
3067
|
+
async function readPluginSkillState(profileName, agent) {
|
|
3068
|
+
try {
|
|
3069
|
+
return JSON.parse(await readFile7(pluginSkillStatePath(profileName, agent), "utf8"));
|
|
3070
|
+
} catch {
|
|
3071
|
+
return { plugins: {} };
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
async function writePluginSkillState(profileName, agent, state) {
|
|
3075
|
+
const target = pluginSkillStatePath(profileName, agent);
|
|
3076
|
+
await mkdir4(path4.dirname(target), { recursive: true });
|
|
3077
|
+
await writeFile4(target, JSON.stringify(state, null, 2), "utf8");
|
|
3078
|
+
}
|
|
3079
|
+
async function acquireStateLock2(profileName, agent) {
|
|
3080
|
+
const target = pluginSkillStatePath(profileName, agent);
|
|
3081
|
+
const lockPath = `${target}.lock`;
|
|
3082
|
+
await mkdir4(path4.dirname(target), { recursive: true });
|
|
3083
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
3084
|
+
try {
|
|
3085
|
+
await mkdir4(lockPath);
|
|
3086
|
+
return lockPath;
|
|
3087
|
+
} catch (error) {
|
|
3088
|
+
if (error.code !== "EEXIST") {
|
|
3089
|
+
throw error;
|
|
3090
|
+
}
|
|
3091
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
throw new Error(`Timed out waiting for plugin skill state lock: ${lockPath}`);
|
|
3095
|
+
}
|
|
3096
|
+
async function updatePluginSkillState(profileName, agent, updater) {
|
|
3097
|
+
const lockPath = await acquireStateLock2(profileName, agent);
|
|
3098
|
+
try {
|
|
3099
|
+
const state = await readPluginSkillState(profileName, agent);
|
|
3100
|
+
const next = await updater(state) ?? state;
|
|
3101
|
+
await writePluginSkillState(profileName, agent, next);
|
|
3102
|
+
return next;
|
|
3103
|
+
} finally {
|
|
3104
|
+
await rm2(lockPath, { recursive: true, force: true });
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
function resolveDownloadUrl2(profile, url) {
|
|
3108
|
+
if (/^https?:\/\//i.test(url)) {
|
|
3109
|
+
return url;
|
|
3110
|
+
}
|
|
3111
|
+
return `${profile.config.origin.replace(/\/$/, "")}${url.startsWith("/") ? url : `/${url}`}`;
|
|
3112
|
+
}
|
|
3113
|
+
async function downloadPluginSkillPackage(profile, download) {
|
|
3114
|
+
const buffer = download.content_base64 ? Buffer.from(download.content_base64, "base64") : Buffer.from(
|
|
3115
|
+
(await axios5.get(resolveDownloadUrl2(profile, download.url), {
|
|
3116
|
+
responseType: "arraybuffer"
|
|
3117
|
+
})).data
|
|
3118
|
+
);
|
|
3119
|
+
const sha2562 = createHash3("sha256").update(buffer).digest("hex");
|
|
3120
|
+
if (download.sha256 && sha2562 !== download.sha256) {
|
|
3121
|
+
throw new Error(`Plugin skill checksum mismatch. expected ${download.sha256}, got ${sha2562}`);
|
|
3122
|
+
}
|
|
3123
|
+
return buffer;
|
|
3124
|
+
}
|
|
3125
|
+
async function listPluginSkills(client, plugin) {
|
|
3126
|
+
if (plugin) {
|
|
3127
|
+
const result2 = await apiRequest(
|
|
3128
|
+
client,
|
|
3129
|
+
"GET",
|
|
3130
|
+
`/cli/plugins/${plugin}/skills`
|
|
3131
|
+
);
|
|
3132
|
+
return Array.isArray(result2) ? result2 : result2.skills || [];
|
|
3133
|
+
}
|
|
3134
|
+
const result = await apiRequest(
|
|
3135
|
+
client,
|
|
3136
|
+
"GET",
|
|
3137
|
+
"/cli/plugins",
|
|
3138
|
+
{ params: { include_skills: 1 } }
|
|
3139
|
+
);
|
|
3140
|
+
if (Array.isArray(result)) {
|
|
3141
|
+
return result;
|
|
3142
|
+
}
|
|
3143
|
+
return (result.plugins || []).flatMap((item) => item.skills || []);
|
|
3144
|
+
}
|
|
3145
|
+
async function ensurePluginSkill(options) {
|
|
3146
|
+
await assertInstallablePluginSkillName(options.skill.name);
|
|
3147
|
+
const state = await readPluginSkillState(options.profile.name, options.agent);
|
|
3148
|
+
const installed = state.plugins[options.plugin]?.skills[options.skill.name];
|
|
3149
|
+
if (!options.force && installed?.version === options.skill.version && installed.sha256 === options.skill.sha256) {
|
|
3150
|
+
return {
|
|
3151
|
+
action: "in_sync",
|
|
3152
|
+
skill: options.skill.name,
|
|
3153
|
+
plugin: options.plugin,
|
|
3154
|
+
version: installed.version,
|
|
3155
|
+
install_path: installed.install_path
|
|
3156
|
+
};
|
|
3157
|
+
}
|
|
3158
|
+
const download = await apiRequest(
|
|
3159
|
+
options.client,
|
|
3160
|
+
"GET",
|
|
3161
|
+
`/cli/plugins/${options.plugin}/skills/${options.skill.name}/download`
|
|
3162
|
+
);
|
|
3163
|
+
const buffer = await downloadPluginSkillPackage(options.profile, download);
|
|
3164
|
+
const skillDir = await zipDirectoryToTemp(buffer, `plugin-skill-${options.plugin}-${options.skill.name}`);
|
|
3165
|
+
const lint = await lintPluginSkillDirectory(skillDir, { expectedName: options.skill.name });
|
|
3166
|
+
if (!lint.ok) {
|
|
3167
|
+
throw new Error(`Plugin skill lint failed:
|
|
3168
|
+
- ${lint.errors.map((item) => item.message).join("\n- ")}`);
|
|
3169
|
+
}
|
|
3170
|
+
const lintManifests = normalizePluginLintManifests(download.manifest?.lint || options.skill.lint);
|
|
3171
|
+
const lintManifestIssues = [];
|
|
3172
|
+
lintManifests.forEach((item) => validatePluginLintManifest(item, lintManifestIssues, `Plugin skill ${options.skill.name}`));
|
|
3173
|
+
for (const item of lintManifests) {
|
|
3174
|
+
if (!await exists2(path4.join(skillDir, item.path))) {
|
|
3175
|
+
lintManifestIssues.push(issue2("error", "missing_lint_file", `Plugin skill ${options.skill.name} lint file not found: ${item.path}`));
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
if (lintManifestIssues.length) {
|
|
3179
|
+
throw new Error(`Plugin skill lint manifest failed:
|
|
3180
|
+
- ${lintManifestIssues.map((item) => item.message).join("\n- ")}`);
|
|
3181
|
+
}
|
|
3182
|
+
await installSkillDirectory(skillDir, options.skill.name, options.agent, {
|
|
3183
|
+
owner: {
|
|
3184
|
+
kind: "plugin",
|
|
3185
|
+
profile: options.profile.name,
|
|
3186
|
+
plugin: options.plugin,
|
|
3187
|
+
skill: options.skill.name,
|
|
3188
|
+
version: download.version || options.skill.version,
|
|
3189
|
+
sha256: download.sha256
|
|
3190
|
+
}
|
|
3191
|
+
});
|
|
3192
|
+
const installPath = await installProfilePluginSkillDirectory(
|
|
3193
|
+
skillDir,
|
|
3194
|
+
options.profile.name,
|
|
3195
|
+
options.agent,
|
|
3196
|
+
options.skill.name
|
|
3197
|
+
);
|
|
3198
|
+
await updatePluginSkillState(options.profile.name, options.agent, (current) => {
|
|
3199
|
+
current.plugins[options.plugin] ||= { skills: {} };
|
|
3200
|
+
current.plugins[options.plugin].skills[options.skill.name] = {
|
|
3201
|
+
name: options.skill.name,
|
|
3202
|
+
plugin: options.plugin,
|
|
3203
|
+
version: download.version || options.skill.version,
|
|
3204
|
+
sha256: download.sha256,
|
|
3205
|
+
install_path: installPath,
|
|
3206
|
+
domains: options.skill.domains || [],
|
|
3207
|
+
capabilities: options.skill.capabilities || [],
|
|
3208
|
+
lint: lintManifests,
|
|
3209
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3210
|
+
};
|
|
3211
|
+
});
|
|
3212
|
+
return {
|
|
3213
|
+
action: installed ? "updated" : "installed",
|
|
3214
|
+
skill: options.skill.name,
|
|
3215
|
+
plugin: options.plugin,
|
|
3216
|
+
version: download.version || options.skill.version,
|
|
3217
|
+
install_path: installPath
|
|
3218
|
+
};
|
|
3219
|
+
}
|
|
3220
|
+
function getPathValue(source, pathExpression) {
|
|
3221
|
+
if (!pathExpression || pathExpression === "$" || pathExpression === ".") {
|
|
3222
|
+
return source;
|
|
3223
|
+
}
|
|
3224
|
+
const parts = pathExpression.replace(/^\$\.?/, "").split(".").filter(Boolean);
|
|
3225
|
+
let current = source;
|
|
3226
|
+
for (const part of parts) {
|
|
3227
|
+
if (current === null || typeof current !== "object" || Array.isArray(current)) {
|
|
3228
|
+
return void 0;
|
|
3229
|
+
}
|
|
3230
|
+
current = current[part];
|
|
3231
|
+
}
|
|
3232
|
+
return current;
|
|
3233
|
+
}
|
|
3234
|
+
function isNonEmptyValue(value) {
|
|
3235
|
+
if (typeof value === "string") {
|
|
3236
|
+
return value.trim().length > 0;
|
|
3237
|
+
}
|
|
3238
|
+
if (Array.isArray(value)) {
|
|
3239
|
+
return value.length > 0;
|
|
3240
|
+
}
|
|
3241
|
+
return value !== void 0 && value !== null && value !== "";
|
|
3242
|
+
}
|
|
3243
|
+
function shouldSkipPluginLint(config, skipRules) {
|
|
3244
|
+
if (!Array.isArray(skipRules) || !skipRules.length) {
|
|
3245
|
+
return false;
|
|
3246
|
+
}
|
|
3247
|
+
return skipRules.some((rule) => getPathValue(config, rule.path) === rule.equals);
|
|
3248
|
+
}
|
|
3249
|
+
function evaluatePluginRule(config, rule, location) {
|
|
3250
|
+
const type = String(rule.type || "");
|
|
3251
|
+
const value = getPathValue(config, rule.path);
|
|
3252
|
+
const label = rule.path ? `${location}.${rule.path}` : location;
|
|
3253
|
+
if (rule.optional && (value === void 0 || value === null || value === "")) {
|
|
3254
|
+
return void 0;
|
|
3255
|
+
}
|
|
3256
|
+
if (type === "object") {
|
|
3257
|
+
const target = rule.path ? value : config;
|
|
3258
|
+
if (target === null || typeof target !== "object" || Array.isArray(target)) {
|
|
3259
|
+
return rule.message || `${label} must be an object.`;
|
|
3260
|
+
}
|
|
3261
|
+
return void 0;
|
|
3262
|
+
}
|
|
3263
|
+
if (type === "requiredAny") {
|
|
3264
|
+
const paths = Array.isArray(rule.paths) ? rule.paths : [];
|
|
3265
|
+
if (!paths.some((item) => isNonEmptyValue(getPathValue(config, item)))) {
|
|
3266
|
+
return rule.message || `${location} requires at least one of: ${paths.join(", ")}.`;
|
|
3267
|
+
}
|
|
3268
|
+
return void 0;
|
|
3269
|
+
}
|
|
3270
|
+
if (type === "nonEmptyString") {
|
|
3271
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
3272
|
+
return rule.message || `${label} must be a non-empty string.`;
|
|
3273
|
+
}
|
|
3274
|
+
return void 0;
|
|
3275
|
+
}
|
|
3276
|
+
if (type === "nonEmptyArray") {
|
|
3277
|
+
if (!Array.isArray(value) || !value.length) {
|
|
3278
|
+
return rule.message || `${label} must be a non-empty array.`;
|
|
3279
|
+
}
|
|
3280
|
+
return void 0;
|
|
3281
|
+
}
|
|
3282
|
+
if (type === "positiveNumber") {
|
|
3283
|
+
const numericValue = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : Number.NaN;
|
|
3284
|
+
if (!Number.isFinite(numericValue) || numericValue <= 0) {
|
|
3285
|
+
return rule.message || `${label} must be a positive number.`;
|
|
3286
|
+
}
|
|
3287
|
+
return void 0;
|
|
3288
|
+
}
|
|
3289
|
+
if (type === "enum") {
|
|
3290
|
+
const values = Array.isArray(rule.values) ? rule.values : [];
|
|
3291
|
+
if (!values.includes(value)) {
|
|
3292
|
+
return rule.message || `${label} must be one of ${values.map((item) => String(item)).join(", ")}.`;
|
|
3293
|
+
}
|
|
3294
|
+
return void 0;
|
|
3295
|
+
}
|
|
3296
|
+
return `${location} has unsupported plugin lint rule type: ${type || "(missing)"}.`;
|
|
3297
|
+
}
|
|
3298
|
+
function collectFlowTemplatePluginConfigs(flowWork, pluginKey, lintManifests = []) {
|
|
3299
|
+
const scanPaths = new Set(lintManifests.flatMap((item) => item.paths || []));
|
|
3300
|
+
if (scanPaths.size) {
|
|
3301
|
+
const occurrences = [];
|
|
3302
|
+
scanPaths.forEach((scanPath) => {
|
|
3303
|
+
occurrences.push(...collectFlowTemplatePluginConfigsByPath(flowWork, scanPath, pluginKey));
|
|
3304
|
+
});
|
|
3305
|
+
return occurrences;
|
|
3306
|
+
}
|
|
3307
|
+
return collectDefaultFlowTemplatePluginConfigs(flowWork, pluginKey);
|
|
3308
|
+
}
|
|
3309
|
+
function collectDefaultFlowTemplatePluginConfigs(flowWork, pluginKey) {
|
|
3310
|
+
const data = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
3311
|
+
const meta = typeof data.meta === "object" && data.meta !== null && !Array.isArray(data.meta) ? data.meta : {};
|
|
3312
|
+
const occurrences = [];
|
|
3313
|
+
if (Object.prototype.hasOwnProperty.call(meta, pluginKey)) {
|
|
3314
|
+
occurrences.push({ location: `data.meta.${pluginKey}`, config: meta[pluginKey] });
|
|
3315
|
+
}
|
|
3316
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes : [];
|
|
3317
|
+
nodes.forEach((node, index) => {
|
|
3318
|
+
if (node && typeof node === "object" && !Array.isArray(node) && Object.prototype.hasOwnProperty.call(node, pluginKey)) {
|
|
3319
|
+
const nodeRecord = node;
|
|
3320
|
+
const nodeName = typeof nodeRecord.name === "string" && nodeRecord.name.trim() ? nodeRecord.name.trim() : `nodes[${index}]`;
|
|
3321
|
+
occurrences.push({ location: `${nodeName}.${pluginKey}`, config: nodeRecord[pluginKey] });
|
|
3322
|
+
}
|
|
3323
|
+
});
|
|
3324
|
+
return occurrences;
|
|
3325
|
+
}
|
|
3326
|
+
function collectFlowTemplatePluginConfigsByPath(flowWork, scanPath, pluginKey) {
|
|
3327
|
+
if (scanPath === "data.meta.<plugin_key>") {
|
|
3328
|
+
const data2 = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
3329
|
+
const meta = typeof data2.meta === "object" && data2.meta !== null && !Array.isArray(data2.meta) ? data2.meta : {};
|
|
3330
|
+
return Object.prototype.hasOwnProperty.call(meta, pluginKey) ? [{ location: `data.meta.${pluginKey}`, config: meta[pluginKey] }] : [];
|
|
3331
|
+
}
|
|
3332
|
+
if (scanPath === "data.nodes[].<plugin_key>") {
|
|
3333
|
+
const data2 = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
3334
|
+
const nodes2 = Array.isArray(data2.nodes) ? data2.nodes : [];
|
|
3335
|
+
const occurrences2 = [];
|
|
3336
|
+
nodes2.forEach((node, nodeIndex) => {
|
|
3337
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) {
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3340
|
+
const nodeRecord = node;
|
|
3341
|
+
if (!Object.prototype.hasOwnProperty.call(nodeRecord, pluginKey)) {
|
|
3342
|
+
return;
|
|
3343
|
+
}
|
|
3344
|
+
const nodeName = typeof nodeRecord.name === "string" && nodeRecord.name.trim() ? nodeRecord.name.trim() : `nodes[${nodeIndex}]`;
|
|
3345
|
+
occurrences2.push({ location: `${nodeName}.${pluginKey}`, config: nodeRecord[pluginKey] });
|
|
3346
|
+
});
|
|
3347
|
+
return occurrences2;
|
|
3348
|
+
}
|
|
3349
|
+
const match = scanPath.match(/^data\.nodes\[\]\.([A-Za-z0-9_]+)\[\]$/);
|
|
3350
|
+
if (!match) {
|
|
3351
|
+
return [];
|
|
3352
|
+
}
|
|
3353
|
+
const field = match[1];
|
|
3354
|
+
const data = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
3355
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes : [];
|
|
3356
|
+
const occurrences = [];
|
|
3357
|
+
nodes.forEach((node, nodeIndex) => {
|
|
3358
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) {
|
|
3359
|
+
return;
|
|
3360
|
+
}
|
|
3361
|
+
const nodeRecord = node;
|
|
3362
|
+
const values = nodeRecord[field];
|
|
3363
|
+
if (!Array.isArray(values)) {
|
|
3364
|
+
return;
|
|
3365
|
+
}
|
|
3366
|
+
const nodeName = typeof nodeRecord.name === "string" && nodeRecord.name.trim() ? nodeRecord.name.trim() : `nodes[${nodeIndex}]`;
|
|
3367
|
+
values.forEach((value, valueIndex) => {
|
|
3368
|
+
occurrences.push({
|
|
3369
|
+
location: `${nodeName}.${field}[${valueIndex}]`,
|
|
3370
|
+
config: value
|
|
3371
|
+
});
|
|
3372
|
+
});
|
|
3373
|
+
});
|
|
3374
|
+
return occurrences;
|
|
3375
|
+
}
|
|
3376
|
+
function collectFlowTemplatePluginKeys(flowWork) {
|
|
3377
|
+
const data = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
3378
|
+
const meta = typeof data.meta === "object" && data.meta !== null && !Array.isArray(data.meta) ? data.meta : {};
|
|
3379
|
+
const keys = /* @__PURE__ */ new Set();
|
|
3380
|
+
Object.keys(meta).forEach((key) => {
|
|
3381
|
+
if (/^plugin_[A-Za-z0-9_]+$/.test(key)) {
|
|
3382
|
+
keys.add(key);
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3385
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes : [];
|
|
3386
|
+
nodes.forEach((node) => {
|
|
3387
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) {
|
|
3388
|
+
return;
|
|
3389
|
+
}
|
|
3390
|
+
Object.keys(node).forEach((key) => {
|
|
3391
|
+
if (/^plugin_[A-Za-z0-9_]+$/.test(key)) {
|
|
3392
|
+
keys.add(key);
|
|
3393
|
+
}
|
|
3394
|
+
});
|
|
3395
|
+
});
|
|
3396
|
+
return [...keys];
|
|
3397
|
+
}
|
|
3398
|
+
async function readPluginLintRuleFile(skillInstallPath, lintManifest) {
|
|
3399
|
+
const fullPath = path4.join(skillInstallPath, lintManifest.path);
|
|
3400
|
+
const value = JSON.parse(await readFile7(fullPath, "utf8"));
|
|
3401
|
+
if (value.domain && value.domain !== lintManifest.domain) {
|
|
3402
|
+
throw new Error(`Plugin lint rule domain mismatch for ${lintManifest.path}.`);
|
|
3403
|
+
}
|
|
3404
|
+
if (value.plugin_key && value.plugin_key !== lintManifest.plugin_key) {
|
|
3405
|
+
throw new Error(`Plugin lint rule plugin_key mismatch for ${lintManifest.path}.`);
|
|
3406
|
+
}
|
|
3407
|
+
return value;
|
|
3408
|
+
}
|
|
3409
|
+
async function lintFlowTemplatePluginExtensions(options) {
|
|
3410
|
+
const errors = [];
|
|
3411
|
+
const warnings = [];
|
|
3412
|
+
const pluginLints = [];
|
|
3413
|
+
const platformSkills = options.platformSkills || [];
|
|
3414
|
+
const state = await readPluginSkillState(options.profile.name, options.agent);
|
|
3415
|
+
const platformLintDeclarations = platformSkills.flatMap(
|
|
3416
|
+
(skill) => normalizePluginLintManifests(skill.lint).map((lint) => ({
|
|
3417
|
+
plugin: skill.plugin || "",
|
|
3418
|
+
skill: skill.name,
|
|
3419
|
+
lint
|
|
3420
|
+
}))
|
|
3421
|
+
).filter((item) => item.plugin && item.lint.domain === "flow-template-node");
|
|
3422
|
+
const installedLintDeclarations = Object.values(state.plugins).flatMap(
|
|
3423
|
+
(pluginState) => Object.values(pluginState.skills).flatMap(
|
|
3424
|
+
(skill) => normalizePluginLintManifests(skill.lint).map((lint) => ({
|
|
3425
|
+
plugin: skill.plugin,
|
|
3426
|
+
skill: skill.name,
|
|
3427
|
+
installPath: skill.install_path,
|
|
3428
|
+
lint
|
|
3429
|
+
}))
|
|
3430
|
+
)
|
|
3431
|
+
).filter((item) => item.lint.domain === "flow-template-node");
|
|
3432
|
+
const usedPluginKeys = new Set(collectFlowTemplatePluginKeys(options.flowWork));
|
|
3433
|
+
if (!usedPluginKeys.size && !platformLintDeclarations.length && !installedLintDeclarations.length) {
|
|
3434
|
+
return {
|
|
3435
|
+
ok: true,
|
|
3436
|
+
errors: [],
|
|
3437
|
+
warnings: [],
|
|
3438
|
+
plugin_lints: []
|
|
3439
|
+
};
|
|
3440
|
+
}
|
|
3441
|
+
const allPluginKeys = /* @__PURE__ */ new Set([
|
|
3442
|
+
...platformLintDeclarations.map((item) => item.lint.plugin_key),
|
|
3443
|
+
...installedLintDeclarations.map((item) => item.lint.plugin_key)
|
|
3444
|
+
]);
|
|
3445
|
+
for (const pluginKey of allPluginKeys) {
|
|
3446
|
+
const declarations = [
|
|
3447
|
+
...platformLintDeclarations.filter((item) => item.lint.plugin_key === pluginKey).map((item) => item.lint),
|
|
3448
|
+
...installedLintDeclarations.filter((item) => item.lint.plugin_key === pluginKey).map((item) => item.lint)
|
|
3449
|
+
];
|
|
3450
|
+
if (!usedPluginKeys.has(pluginKey) && !declarations.some((item) => item.paths?.length)) {
|
|
3451
|
+
continue;
|
|
3452
|
+
}
|
|
3453
|
+
const occurrences = collectFlowTemplatePluginConfigs(options.flowWork, pluginKey, declarations);
|
|
3454
|
+
if (!occurrences.length) {
|
|
3455
|
+
continue;
|
|
3456
|
+
}
|
|
3457
|
+
const installed = installedLintDeclarations.filter((item) => item.lint.plugin_key === pluginKey);
|
|
3458
|
+
if (!installed.length) {
|
|
3459
|
+
const platform = platformLintDeclarations.find((item) => item.lint.plugin_key === pluginKey);
|
|
3460
|
+
const plugin = platform?.plugin || pluginKey;
|
|
3461
|
+
const message = `Plugin lint for ${pluginKey} is declared but not installed. Run: bpmax-cli plugin skills ensure ${plugin} --profile ${options.profile.name} --agent ${options.agent} --format json`;
|
|
3462
|
+
if (options.requireInstalled) {
|
|
3463
|
+
errors.push(message);
|
|
3464
|
+
} else {
|
|
3465
|
+
warnings.push(message);
|
|
3466
|
+
}
|
|
3467
|
+
pluginLints.push({
|
|
3468
|
+
plugin,
|
|
3469
|
+
skill: platform?.skill,
|
|
3470
|
+
plugin_key: pluginKey,
|
|
3471
|
+
domain: "flow-template-node",
|
|
3472
|
+
checked_locations: occurrences.map((item) => item.location),
|
|
3473
|
+
errors: options.requireInstalled ? [message] : [],
|
|
3474
|
+
warnings: options.requireInstalled ? [] : [message]
|
|
3475
|
+
});
|
|
3476
|
+
continue;
|
|
3477
|
+
}
|
|
3478
|
+
for (const declaration of installed) {
|
|
3479
|
+
const lintErrors = [];
|
|
3480
|
+
const lintWarnings = [];
|
|
3481
|
+
let ruleFile;
|
|
3482
|
+
try {
|
|
3483
|
+
ruleFile = await readPluginLintRuleFile(declaration.installPath, declaration.lint);
|
|
3484
|
+
} catch (error) {
|
|
3485
|
+
lintErrors.push(error instanceof Error ? error.message : String(error));
|
|
3486
|
+
ruleFile = {};
|
|
3487
|
+
}
|
|
3488
|
+
for (const occurrence of occurrences) {
|
|
3489
|
+
if (shouldSkipPluginLint(occurrence.config, ruleFile.skipWhen)) {
|
|
3490
|
+
continue;
|
|
3491
|
+
}
|
|
3492
|
+
const rules = Array.isArray(ruleFile.rules) ? ruleFile.rules : [];
|
|
3493
|
+
if (!rules.length) {
|
|
3494
|
+
const message = `${occurrence.location} has no plugin lint rules.`;
|
|
3495
|
+
if (options.requireInstalled) {
|
|
3496
|
+
lintErrors.push(message);
|
|
3497
|
+
} else {
|
|
3498
|
+
lintWarnings.push(message);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
for (const rule of rules) {
|
|
3502
|
+
const error = evaluatePluginRule(occurrence.config, rule, occurrence.location);
|
|
3503
|
+
if (error) {
|
|
3504
|
+
lintErrors.push(error);
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
errors.push(...lintErrors);
|
|
3509
|
+
warnings.push(...lintWarnings);
|
|
3510
|
+
pluginLints.push({
|
|
3511
|
+
plugin: declaration.plugin,
|
|
3512
|
+
skill: declaration.skill,
|
|
3513
|
+
plugin_key: pluginKey,
|
|
3514
|
+
domain: declaration.lint.domain,
|
|
3515
|
+
rule_path: declaration.lint.path,
|
|
3516
|
+
checked_locations: occurrences.map((item) => item.location),
|
|
3517
|
+
errors: lintErrors,
|
|
3518
|
+
warnings: lintWarnings
|
|
3519
|
+
});
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
return {
|
|
3523
|
+
ok: errors.length === 0,
|
|
3524
|
+
errors,
|
|
3525
|
+
warnings,
|
|
3526
|
+
plugin_lints: pluginLints
|
|
3527
|
+
};
|
|
3528
|
+
}
|
|
3529
|
+
async function copySkillDirectory(sourceDir, destinationDir) {
|
|
3530
|
+
await rm2(destinationDir, { recursive: true, force: true });
|
|
3531
|
+
await mkdir4(path4.dirname(destinationDir), { recursive: true });
|
|
3532
|
+
await cp2(sourceDir, destinationDir, { recursive: true });
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
// src/core/config-workflow.ts
|
|
2644
3536
|
var NAV_CONFIG_TYPES = ["navmenu", "shortcut", "navmenu_mobile", "shortcut_mobile"];
|
|
2645
3537
|
var NAV_CONTENT_KEY_BY_TYPE = {
|
|
2646
3538
|
navmenu: "navConfig",
|
|
@@ -2907,7 +3799,7 @@ function configAdapterMatrix() {
|
|
|
2907
3799
|
});
|
|
2908
3800
|
}
|
|
2909
3801
|
function hashJson(value) {
|
|
2910
|
-
return
|
|
3802
|
+
return createHash4("sha256").update(JSON.stringify(value)).digest("hex");
|
|
2911
3803
|
}
|
|
2912
3804
|
function isRecord3(value) {
|
|
2913
3805
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -3026,9 +3918,9 @@ function summarizeOperationPlan(payload) {
|
|
|
3026
3918
|
return "submit operation";
|
|
3027
3919
|
}
|
|
3028
3920
|
const method = typeof operation.method === "string" ? operation.method : "REQUEST";
|
|
3029
|
-
const
|
|
3921
|
+
const path12 = typeof operation.path === "string" ? operation.path : "";
|
|
3030
3922
|
const type = typeof operation.type === "string" ? ` ${operation.type}` : "";
|
|
3031
|
-
return `submit${type}: ${method}${
|
|
3923
|
+
return `submit${type}: ${method}${path12 ? ` ${path12}` : ""}`;
|
|
3032
3924
|
}),
|
|
3033
3925
|
...skipped.slice(0, Math.max(0, 20 - operations.length)).map((operation) => {
|
|
3034
3926
|
if (!isRecord3(operation)) {
|
|
@@ -4117,6 +5009,106 @@ function stripServerFilledFields(value, keys) {
|
|
|
4117
5009
|
}
|
|
4118
5010
|
return result;
|
|
4119
5011
|
}
|
|
5012
|
+
function fieldIdentity(value) {
|
|
5013
|
+
if (!isRecord3(value)) {
|
|
5014
|
+
return null;
|
|
5015
|
+
}
|
|
5016
|
+
for (const key of ["field", "key", "prop"]) {
|
|
5017
|
+
const identity = value[key];
|
|
5018
|
+
if (typeof identity === "string" && identity.trim()) {
|
|
5019
|
+
return identity.trim();
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
return null;
|
|
5023
|
+
}
|
|
5024
|
+
function flattenFieldOrder(value, order = []) {
|
|
5025
|
+
if (Array.isArray(value)) {
|
|
5026
|
+
for (const item of value) {
|
|
5027
|
+
flattenFieldOrder(item, order);
|
|
5028
|
+
}
|
|
5029
|
+
return order;
|
|
5030
|
+
}
|
|
5031
|
+
const identity = fieldIdentity(value);
|
|
5032
|
+
if (identity) {
|
|
5033
|
+
order.push(identity);
|
|
5034
|
+
}
|
|
5035
|
+
return order;
|
|
5036
|
+
}
|
|
5037
|
+
function extractLayoutOrder(value) {
|
|
5038
|
+
const candidates = [
|
|
5039
|
+
isRecord3(value) ? value.layout : void 0,
|
|
5040
|
+
isRecord3(value) && isRecord3(value.option) ? value.option.layout : void 0,
|
|
5041
|
+
isRecord3(value) && isRecord3(value.option) ? value.option.form_layout : void 0
|
|
5042
|
+
];
|
|
5043
|
+
for (const candidate of candidates) {
|
|
5044
|
+
const order = flattenFieldOrder(candidate);
|
|
5045
|
+
if (order.length) {
|
|
5046
|
+
return order;
|
|
5047
|
+
}
|
|
5048
|
+
if (Array.isArray(candidate)) {
|
|
5049
|
+
const strings = candidate.flatMap((row) => Array.isArray(row) ? row : [row]).filter((item) => typeof item === "string" && item.trim().length > 0);
|
|
5050
|
+
if (strings.length) {
|
|
5051
|
+
return strings;
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
}
|
|
5055
|
+
return [];
|
|
5056
|
+
}
|
|
5057
|
+
function findFormTemplateValueItem(template, field) {
|
|
5058
|
+
const values = Array.isArray(template.value) ? template.value : [];
|
|
5059
|
+
return values.find((item) => fieldIdentity(item) === field) ?? null;
|
|
5060
|
+
}
|
|
5061
|
+
function extractEmbeddedSubformOrder(template, field) {
|
|
5062
|
+
const item = findFormTemplateValueItem(template, field);
|
|
5063
|
+
if (!item || !isRecord3(item.value)) {
|
|
5064
|
+
return [];
|
|
5065
|
+
}
|
|
5066
|
+
const rows = item.value.value;
|
|
5067
|
+
if (Array.isArray(rows) && Array.isArray(rows[0])) {
|
|
5068
|
+
return flattenFieldOrder(rows[0]);
|
|
5069
|
+
}
|
|
5070
|
+
return flattenFieldOrder(rows);
|
|
5071
|
+
}
|
|
5072
|
+
function ordersMismatch(orders) {
|
|
5073
|
+
const comparable = orders.filter((order) => order.length > 0);
|
|
5074
|
+
if (comparable.length <= 1) {
|
|
5075
|
+
return false;
|
|
5076
|
+
}
|
|
5077
|
+
const first = JSON.stringify(comparable[0]);
|
|
5078
|
+
return comparable.some((order) => JSON.stringify(order) !== first);
|
|
5079
|
+
}
|
|
5080
|
+
async function inspectFormTemplate(config, profile, id, options = {}) {
|
|
5081
|
+
const exported = await exportConfigDomain(
|
|
5082
|
+
config,
|
|
5083
|
+
profile,
|
|
5084
|
+
"form-template",
|
|
5085
|
+
id,
|
|
5086
|
+
options.outDir || ".codex/tmp/form-template-inspect"
|
|
5087
|
+
);
|
|
5088
|
+
const raw = await readJsonFile(String(exported.raw_file));
|
|
5089
|
+
const template = isRecord3(raw) ? raw : {};
|
|
5090
|
+
const ruleOrder = flattenFieldOrder(template.rule);
|
|
5091
|
+
const layoutOrder = extractLayoutOrder(template);
|
|
5092
|
+
const valueOrder = flattenFieldOrder(template.value);
|
|
5093
|
+
const result = {
|
|
5094
|
+
domain: "form-template",
|
|
5095
|
+
id,
|
|
5096
|
+
field: options.field ?? null,
|
|
5097
|
+
rule_order: ruleOrder,
|
|
5098
|
+
layout_order: layoutOrder,
|
|
5099
|
+
value_order: valueOrder,
|
|
5100
|
+
order_mismatch: ordersMismatch([ruleOrder, layoutOrder, valueOrder]),
|
|
5101
|
+
exported
|
|
5102
|
+
};
|
|
5103
|
+
if (options.field) {
|
|
5104
|
+
const embeddedSubformOrder = extractEmbeddedSubformOrder(template, options.field);
|
|
5105
|
+
result.embedded_subform_order = embeddedSubformOrder;
|
|
5106
|
+
result.field_order_mismatch = ordersMismatch([embeddedSubformOrder]);
|
|
5107
|
+
result.field_found = Boolean(findFormTemplateValueItem(template, options.field));
|
|
5108
|
+
result.next_action = embeddedSubformOrder.length > 0 ? "Compare this embedded_subform_order with the runtime create page saved value and project detail rendering before accepting sub_form order fixes." : "No embedded sub_form order was discovered for this field; verify the field key and inspect raw.value manually.";
|
|
5109
|
+
}
|
|
5110
|
+
return result;
|
|
5111
|
+
}
|
|
4120
5112
|
function normalizeRemovedFields(value) {
|
|
4121
5113
|
if (!Array.isArray(value)) {
|
|
4122
5114
|
return /* @__PURE__ */ new Set();
|
|
@@ -4944,9 +5936,9 @@ async function exportRoleDomain(profile, id, outDir) {
|
|
|
4944
5936
|
const { raw, work } = await collectRoleAggregate(profile, id);
|
|
4945
5937
|
const baseHash = hashJson(raw);
|
|
4946
5938
|
const stem = `role-${id}`;
|
|
4947
|
-
const rawFile =
|
|
4948
|
-
const workFile =
|
|
4949
|
-
const metaFile =
|
|
5939
|
+
const rawFile = path5.join(outDir, "raw", `${stem}.json`);
|
|
5940
|
+
const workFile = path5.join(outDir, "work", `${stem}.json`);
|
|
5941
|
+
const metaFile = path5.join(outDir, "meta", `${stem}.meta.json`);
|
|
4950
5942
|
await writeJsonFile(rawFile, raw);
|
|
4951
5943
|
await writeJsonFile(workFile, work);
|
|
4952
5944
|
await writeJsonFile(metaFile, {
|
|
@@ -5343,6 +6335,14 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
|
|
|
5343
6335
|
next: `Run again with --confirm "${expectedConfirm}" to create.`
|
|
5344
6336
|
};
|
|
5345
6337
|
}
|
|
6338
|
+
const pluginLint = await runFlowTemplatePluginLint(work, {
|
|
6339
|
+
profile,
|
|
6340
|
+
agent: options.agent || "codex",
|
|
6341
|
+
requireInstalled: true
|
|
6342
|
+
});
|
|
6343
|
+
if (pluginLint?.errors.length) {
|
|
6344
|
+
throw new Error(`flow-template plugin lint failed: ${pluginLint.errors.join("; ")}`);
|
|
6345
|
+
}
|
|
5346
6346
|
const client = createApiClient(profile);
|
|
5347
6347
|
const createResponse = await apiRequest(
|
|
5348
6348
|
client,
|
|
@@ -5603,6 +6603,26 @@ function comparableSubmitPayload(domain, value, options) {
|
|
|
5603
6603
|
const comparable = domain === "form-template" && options.ignoreServerFields ? stripServerFilledFields(value, FORM_TEMPLATE_SERVER_FIELD_KEYS) : value;
|
|
5604
6604
|
return buildDomainSubmitPayload(domain, comparable);
|
|
5605
6605
|
}
|
|
6606
|
+
function diffMismatchCount(diff) {
|
|
6607
|
+
const counts = isRecord3(diff?.counts) ? diff.counts : {};
|
|
6608
|
+
return ["added", "removed", "changed"].reduce((sum, key) => {
|
|
6609
|
+
const value = counts[key];
|
|
6610
|
+
return sum + (typeof value === "number" && Number.isFinite(value) ? value : 0);
|
|
6611
|
+
}, 0);
|
|
6612
|
+
}
|
|
6613
|
+
function verifyFailureReasons(ok, diff, comparisonSkippedReason) {
|
|
6614
|
+
if (ok) {
|
|
6615
|
+
return [];
|
|
6616
|
+
}
|
|
6617
|
+
if (comparisonSkippedReason) {
|
|
6618
|
+
return [comparisonSkippedReason];
|
|
6619
|
+
}
|
|
6620
|
+
const summary = Array.isArray(diff?.summary) ? diff.summary.filter((item) => typeof item === "string") : [];
|
|
6621
|
+
if (summary.length) {
|
|
6622
|
+
return summary.slice(0, 5);
|
|
6623
|
+
}
|
|
6624
|
+
return ["normalized submit payload differs, but no diff summary was produced"];
|
|
6625
|
+
}
|
|
5606
6626
|
async function verifyConfigDomain(config, profile, domain, id, options = {}) {
|
|
5607
6627
|
void config;
|
|
5608
6628
|
assertNotLocalUuidConfigId(domain, id, "verify");
|
|
@@ -5619,16 +6639,28 @@ async function verifyConfigDomain(config, profile, domain, id, options = {}) {
|
|
|
5619
6639
|
const expectedComparable = expected ? comparableSubmitPayload(domain, expected, options) : void 0;
|
|
5620
6640
|
const ok = expected ? JSON.stringify(actualComparable) === JSON.stringify(expectedComparable) : true;
|
|
5621
6641
|
const diff = expected ? diffJsonComparable(domain, expected, actual, (value) => comparableSubmitPayload(domain, value, options)) : void 0;
|
|
6642
|
+
const rawDiff = expected && domain === "form-template" && options.ignoreServerFields ? diffJsonComparable(domain, expected, actual, (value) => buildDomainSubmitPayload(domain, value)) : void 0;
|
|
6643
|
+
const comparisonSkippedReason = expected ? null : "no --expect file provided; verify performed readback only";
|
|
6644
|
+
const serverDefaultDrift = Boolean(ok && rawDiff?.changed === true);
|
|
6645
|
+
const mismatchCount = diffMismatchCount(diff);
|
|
6646
|
+
const reasons = verifyFailureReasons(ok, diff, comparisonSkippedReason);
|
|
5622
6647
|
return {
|
|
5623
6648
|
domain,
|
|
5624
6649
|
id,
|
|
5625
6650
|
ok,
|
|
6651
|
+
structural_ok: true,
|
|
6652
|
+
semantic_ok: ok,
|
|
6653
|
+
server_default_drift: serverDefaultDrift,
|
|
6654
|
+
comparison_skipped_reason: comparisonSkippedReason,
|
|
6655
|
+
mismatch_count: mismatchCount,
|
|
6656
|
+
...!ok ? { reason: reasons[0], reasons } : {},
|
|
5626
6657
|
compare: expected ? "normalized_submit_payload" : "readback_only",
|
|
5627
6658
|
...expected ? {
|
|
5628
6659
|
expected_hash: expectedComparable ? hashJson(expectedComparable) : null,
|
|
5629
6660
|
actual_hash: actualComparable ? hashJson(actualComparable) : null,
|
|
5630
6661
|
actual_config_hash: exported.base_hash,
|
|
5631
6662
|
...domain === "form-template" && options.ignoreServerFields ? { ignored_server_fields: [...FORM_TEMPLATE_SERVER_FIELD_KEYS] } : {},
|
|
6663
|
+
...rawDiff ? { raw_diff: rawDiff } : {},
|
|
5632
6664
|
diff
|
|
5633
6665
|
} : {},
|
|
5634
6666
|
exported
|
|
@@ -5710,12 +6742,12 @@ async function resolveLocalUuidConfigId(options) {
|
|
|
5710
6742
|
if (!tableDir) {
|
|
5711
6743
|
throw new Error(`resolve-id does not support domain ${options.domain}.`);
|
|
5712
6744
|
}
|
|
5713
|
-
const root =
|
|
6745
|
+
const root = path5.resolve(options.repo, tableDir);
|
|
5714
6746
|
async function walk(dir) {
|
|
5715
|
-
const entries = await
|
|
6747
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
5716
6748
|
const result = [];
|
|
5717
6749
|
for (const entry of entries) {
|
|
5718
|
-
const entryPath =
|
|
6750
|
+
const entryPath = path5.join(dir, entry.name);
|
|
5719
6751
|
if (entry.isDirectory()) {
|
|
5720
6752
|
result.push(...await walk(entryPath));
|
|
5721
6753
|
} else if (entry.isFile()) {
|
|
@@ -5728,10 +6760,10 @@ async function resolveLocalUuidConfigId(options) {
|
|
|
5728
6760
|
const matches = [];
|
|
5729
6761
|
for (const filePath of files) {
|
|
5730
6762
|
try {
|
|
5731
|
-
const record = JSON.parse(await
|
|
6763
|
+
const record = JSON.parse(await readFile8(filePath, "utf8"));
|
|
5732
6764
|
if (!isRecord3(record)) continue;
|
|
5733
6765
|
if (String(record.uuid || "").toLowerCase() !== options.uuid.toLowerCase()) continue;
|
|
5734
|
-
const filenameId = numericIdString(
|
|
6766
|
+
const filenameId = numericIdString(path5.basename(filePath, path5.extname(filePath)));
|
|
5735
6767
|
const id = numericIdString(record.id) ?? numericIdString(record.origin_template_id) ?? numericIdString(record.template_id) ?? filenameId ?? null;
|
|
5736
6768
|
matches.push({
|
|
5737
6769
|
domain: options.domain,
|
|
@@ -5749,7 +6781,7 @@ async function resolveLocalUuidConfigId(options) {
|
|
|
5749
6781
|
return {
|
|
5750
6782
|
domain: options.domain,
|
|
5751
6783
|
uuid: options.uuid,
|
|
5752
|
-
repo:
|
|
6784
|
+
repo: path5.resolve(options.repo),
|
|
5753
6785
|
match_count: matches.length,
|
|
5754
6786
|
matches,
|
|
5755
6787
|
resolved_id: matches.length === 1 ? matches[0].id : null,
|
|
@@ -5811,11 +6843,11 @@ async function ensureConfigCapability(profile, capability) {
|
|
|
5811
6843
|
await ensureCapability(createApiClient(profile), profile, capability);
|
|
5812
6844
|
}
|
|
5813
6845
|
async function readJsonFile(file) {
|
|
5814
|
-
return JSON.parse(await
|
|
6846
|
+
return JSON.parse(await readFile8(file, "utf8"));
|
|
5815
6847
|
}
|
|
5816
6848
|
async function writeJsonFile(file, value) {
|
|
5817
|
-
await
|
|
5818
|
-
await
|
|
6849
|
+
await mkdir5(path5.dirname(file), { recursive: true });
|
|
6850
|
+
await writeFile5(file, `${JSON.stringify(value, null, 2)}
|
|
5819
6851
|
`, "utf8");
|
|
5820
6852
|
}
|
|
5821
6853
|
async function exportConfigDomain(config, profile, domain, id, outDir, options = {}) {
|
|
@@ -5825,9 +6857,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
|
|
|
5825
6857
|
const { raw, work: work2 } = await collectApiPlatformAggregate(profile, id);
|
|
5826
6858
|
const baseHash2 = hashJson(raw);
|
|
5827
6859
|
const stem2 = `${domain}-${id.replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
5828
|
-
const rawFile2 =
|
|
5829
|
-
const workFile2 =
|
|
5830
|
-
const metaFile2 =
|
|
6860
|
+
const rawFile2 = path5.join(outDir, "raw", `${stem2}.json`);
|
|
6861
|
+
const workFile2 = path5.join(outDir, "work", `${stem2}.json`);
|
|
6862
|
+
const metaFile2 = path5.join(outDir, "meta", `${stem2}.meta.json`);
|
|
5831
6863
|
await writeJsonFile(rawFile2, raw);
|
|
5832
6864
|
await writeJsonFile(workFile2, work2);
|
|
5833
6865
|
await writeJsonFile(metaFile2, {
|
|
@@ -5849,9 +6881,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
|
|
|
5849
6881
|
const { raw, work: work2 } = await collectNavConfigAggregate(profile, id);
|
|
5850
6882
|
const baseHash2 = hashJson(raw);
|
|
5851
6883
|
const stem2 = `${domain}-${id.replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
5852
|
-
const rawFile2 =
|
|
5853
|
-
const workFile2 =
|
|
5854
|
-
const metaFile2 =
|
|
6884
|
+
const rawFile2 = path5.join(outDir, "raw", `${stem2}.json`);
|
|
6885
|
+
const workFile2 = path5.join(outDir, "work", `${stem2}.json`);
|
|
6886
|
+
const metaFile2 = path5.join(outDir, "meta", `${stem2}.meta.json`);
|
|
5855
6887
|
await writeJsonFile(rawFile2, raw);
|
|
5856
6888
|
await writeJsonFile(workFile2, work2);
|
|
5857
6889
|
await writeJsonFile(metaFile2, {
|
|
@@ -5878,9 +6910,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
|
|
|
5878
6910
|
validateExpectedType(domain, definition, data);
|
|
5879
6911
|
const baseHash = hashJson(data);
|
|
5880
6912
|
const stem = `${domain}-${id}`;
|
|
5881
|
-
const rawFile =
|
|
5882
|
-
const workFile =
|
|
5883
|
-
const metaFile =
|
|
6913
|
+
const rawFile = path5.join(outDir, "raw", `${stem}.json`);
|
|
6914
|
+
const workFile = path5.join(outDir, "work", `${stem}.json`);
|
|
6915
|
+
const metaFile = path5.join(outDir, "meta", `${stem}.meta.json`);
|
|
5884
6916
|
await writeJsonFile(rawFile, data);
|
|
5885
6917
|
const work = domain === "form-template" && options.workFormat === "structured" && isRecord3(data) ? formTemplateRawToStructured(data) : data;
|
|
5886
6918
|
await writeJsonFile(workFile, work);
|
|
@@ -5920,6 +6952,12 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
5920
6952
|
throw new Error("Config build requires a meta file produced by `bpmax-cli config <domain> export`.");
|
|
5921
6953
|
}
|
|
5922
6954
|
const raw = typeof meta.raw_file === "string" ? await readJsonFile(meta.raw_file) : void 0;
|
|
6955
|
+
if (domain === "flow-template" && isRecord3(work)) {
|
|
6956
|
+
const pluginLint = await runFlowTemplatePluginLint(work, options.pluginLint);
|
|
6957
|
+
if (pluginLint?.errors.length) {
|
|
6958
|
+
throw new Error(`flow-template plugin lint failed: ${pluginLint.errors.join("; ")}`);
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
5923
6961
|
const payload = buildDomainSubmitPayload(domain, work, options, raw);
|
|
5924
6962
|
if (domain === "flow-template" && options.publishLive) {
|
|
5925
6963
|
payload.publish_live = true;
|
|
@@ -5942,9 +6980,47 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
5942
6980
|
await writeJsonFile(outFile, result);
|
|
5943
6981
|
return { domain, work_file: workFile, submit_file: outFile, payload_keys: Object.keys(payload) };
|
|
5944
6982
|
}
|
|
5945
|
-
async function
|
|
6983
|
+
async function runFlowTemplatePluginLint(flowWork, options = {}) {
|
|
6984
|
+
if (!options.profile) {
|
|
6985
|
+
return void 0;
|
|
6986
|
+
}
|
|
6987
|
+
if (!hasPotentialFlowTemplatePluginExtension(flowWork)) {
|
|
6988
|
+
return void 0;
|
|
6989
|
+
}
|
|
6990
|
+
const agent = options.agent || "codex";
|
|
6991
|
+
const client = createApiClient(options.profile);
|
|
6992
|
+
const platformSkills = await listPluginSkills(client);
|
|
6993
|
+
return lintFlowTemplatePluginExtensions({
|
|
6994
|
+
profile: options.profile,
|
|
6995
|
+
agent,
|
|
6996
|
+
flowWork,
|
|
6997
|
+
platformSkills,
|
|
6998
|
+
requireInstalled: Boolean(options.requireInstalled)
|
|
6999
|
+
});
|
|
7000
|
+
}
|
|
7001
|
+
function hasPotentialFlowTemplatePluginExtension(flowWork) {
|
|
7002
|
+
if (collectFlowTemplatePluginKeys(flowWork).length) {
|
|
7003
|
+
return true;
|
|
7004
|
+
}
|
|
7005
|
+
const data = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
7006
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes : [];
|
|
7007
|
+
return nodes.some((node) => {
|
|
7008
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) {
|
|
7009
|
+
return false;
|
|
7010
|
+
}
|
|
7011
|
+
return Object.entries(node).some(([key, value]) => {
|
|
7012
|
+
if (!Array.isArray(value) || !/_(?:triggers|configs|plugins)$/.test(key)) {
|
|
7013
|
+
return false;
|
|
7014
|
+
}
|
|
7015
|
+
return value.some((item) => item && typeof item === "object" && !Array.isArray(item));
|
|
7016
|
+
});
|
|
7017
|
+
});
|
|
7018
|
+
}
|
|
7019
|
+
async function lintConfigWorkFile(file, options = {}) {
|
|
5946
7020
|
const value = await readJsonFile(file);
|
|
5947
7021
|
const errors = [];
|
|
7022
|
+
const warnings = [];
|
|
7023
|
+
let pluginLint;
|
|
5948
7024
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
5949
7025
|
errors.push("Config work file must be a JSON object.");
|
|
5950
7026
|
} else {
|
|
@@ -5971,6 +7047,11 @@ async function lintConfigWorkFile(file) {
|
|
|
5971
7047
|
validateFlowTemplateCodeModeMessages(flowWork, errors);
|
|
5972
7048
|
validateFlowTemplateRuntimeScripts(flowWork, errors);
|
|
5973
7049
|
validateFlowTemplateFeishuChatPlugin(flowWork, errors);
|
|
7050
|
+
pluginLint = await runFlowTemplatePluginLint(flowWork, options.pluginLint);
|
|
7051
|
+
if (pluginLint) {
|
|
7052
|
+
errors.push(...pluginLint.errors);
|
|
7053
|
+
warnings.push(...pluginLint.warnings);
|
|
7054
|
+
}
|
|
5974
7055
|
if (flowWork.mode === "create") {
|
|
5975
7056
|
validateFlowTemplateFormDrivenCreateBaseline(flowWork, errors, { context: "flow-template create" });
|
|
5976
7057
|
} else {
|
|
@@ -5982,6 +7063,8 @@ async function lintConfigWorkFile(file) {
|
|
|
5982
7063
|
file,
|
|
5983
7064
|
ok: errors.length === 0,
|
|
5984
7065
|
errors,
|
|
7066
|
+
warnings,
|
|
7067
|
+
...pluginLint ? { plugin_lints: pluginLint.plugin_lints } : {},
|
|
5985
7068
|
checked_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
5986
7069
|
};
|
|
5987
7070
|
}
|
|
@@ -6314,6 +7397,14 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
6314
7397
|
validateFlowTemplateFeishuChatPlugin(submit.payload);
|
|
6315
7398
|
validateFlowTemplateStandardFlowType(submit.payload);
|
|
6316
7399
|
validateFlowTemplateIdentityStandard(id, submit.payload);
|
|
7400
|
+
const pluginLint = await runFlowTemplatePluginLint(submit.payload, {
|
|
7401
|
+
profile,
|
|
7402
|
+
agent: options.agent || "codex",
|
|
7403
|
+
requireInstalled: true
|
|
7404
|
+
});
|
|
7405
|
+
if (pluginLint?.errors.length) {
|
|
7406
|
+
throw new Error(`flow-template plugin lint failed: ${pluginLint.errors.join("; ")}`);
|
|
7407
|
+
}
|
|
6317
7408
|
}
|
|
6318
7409
|
if (domain === "list-template") {
|
|
6319
7410
|
validateListTemplateActionGate(submit.payload);
|
|
@@ -6572,8 +7663,8 @@ async function runDatasetLifecycleAction(config, profile, action, id, confirm3)
|
|
|
6572
7663
|
}
|
|
6573
7664
|
|
|
6574
7665
|
// src/core/config-workspace.ts
|
|
6575
|
-
import { mkdir as
|
|
6576
|
-
import
|
|
7666
|
+
import { mkdir as mkdir6, readFile as readFile9, writeFile as writeFile6 } from "fs/promises";
|
|
7667
|
+
import path6 from "path";
|
|
6577
7668
|
var DEFAULT_AGENT_GUIDE_FILE = "AGENTS.md";
|
|
6578
7669
|
var CONFIG_DOMAINS2 = [
|
|
6579
7670
|
["form-template", "bpmax-form-template-editor", "\u8868\u5355\u6A21\u677F"],
|
|
@@ -6725,10 +7816,10 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6725
7816
|
);
|
|
6726
7817
|
}
|
|
6727
7818
|
const file = options.file || DEFAULT_AGENT_GUIDE_FILE;
|
|
6728
|
-
if (
|
|
7819
|
+
if (path6.isAbsolute(file) || file.split(/[\\/]+/).includes("..")) {
|
|
6729
7820
|
throw new Error("Agent guide file must be a relative file name inside the target workspace.");
|
|
6730
7821
|
}
|
|
6731
|
-
const targetFile =
|
|
7822
|
+
const targetFile = path6.resolve(options.cwd, file);
|
|
6732
7823
|
const block = renderConfigWorkspaceGuide({
|
|
6733
7824
|
profileName: options.profile.name,
|
|
6734
7825
|
profile: options.profile.config,
|
|
@@ -6738,7 +7829,7 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6738
7829
|
});
|
|
6739
7830
|
let existing = "";
|
|
6740
7831
|
try {
|
|
6741
|
-
existing = await
|
|
7832
|
+
existing = await readFile9(targetFile, "utf8");
|
|
6742
7833
|
} catch (error) {
|
|
6743
7834
|
if (error.code !== "ENOENT") {
|
|
6744
7835
|
throw error;
|
|
@@ -6746,8 +7837,8 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6746
7837
|
}
|
|
6747
7838
|
const content = upsertConfigWorkspaceBlock(existing, options.env, block);
|
|
6748
7839
|
if (!options.dryRun) {
|
|
6749
|
-
await
|
|
6750
|
-
await
|
|
7840
|
+
await mkdir6(path6.dirname(targetFile), { recursive: true });
|
|
7841
|
+
await writeFile6(targetFile, content, "utf8");
|
|
6751
7842
|
}
|
|
6752
7843
|
return {
|
|
6753
7844
|
dry_run: Boolean(options.dryRun),
|
|
@@ -6761,13 +7852,13 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6761
7852
|
|
|
6762
7853
|
// src/commands/config-env.ts
|
|
6763
7854
|
import { execFile } from "child_process";
|
|
6764
|
-
import { mkdir as
|
|
7855
|
+
import { mkdir as mkdir7, rm as rm3, stat as stat4, writeFile as writeFile7 } from "fs/promises";
|
|
6765
7856
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
6766
7857
|
import { tmpdir as tmpdir2 } from "os";
|
|
6767
|
-
import
|
|
7858
|
+
import path7 from "path";
|
|
6768
7859
|
import { promisify } from "util";
|
|
6769
7860
|
import { password, text } from "@clack/prompts";
|
|
6770
|
-
import
|
|
7861
|
+
import axios6 from "axios";
|
|
6771
7862
|
var execFileAsync = promisify(execFile);
|
|
6772
7863
|
var PLATFORM_SYSCONFIG_BRANCH = "master";
|
|
6773
7864
|
var LATEST_EXEC_MAX_BUFFER = 64 * 1024 * 1024;
|
|
@@ -6903,12 +7994,12 @@ async function gitCloneWithTransientCredentials(gitUrl, workspaceDir, credential
|
|
|
6903
7994
|
const sanitizedGitUrl = stripGitUrlCredentials(gitUrl);
|
|
6904
7995
|
if (!credentials) {
|
|
6905
7996
|
await execFileAsync("git", ["clone", sanitizedGitUrl, workspaceDir], {
|
|
6906
|
-
cwd:
|
|
7997
|
+
cwd: path7.dirname(workspaceDir)
|
|
6907
7998
|
});
|
|
6908
7999
|
return;
|
|
6909
8000
|
}
|
|
6910
|
-
const askpassPath =
|
|
6911
|
-
await
|
|
8001
|
+
const askpassPath = path7.join(tmpdir2(), `bpmax-cli-git-askpass-${randomUUID3()}.sh`);
|
|
8002
|
+
await writeFile7(
|
|
6912
8003
|
askpassPath,
|
|
6913
8004
|
[
|
|
6914
8005
|
"#!/bin/sh",
|
|
@@ -6923,7 +8014,7 @@ async function gitCloneWithTransientCredentials(gitUrl, workspaceDir, credential
|
|
|
6923
8014
|
);
|
|
6924
8015
|
try {
|
|
6925
8016
|
await execFileAsync("git", ["clone", sanitizedGitUrl, workspaceDir], {
|
|
6926
|
-
cwd:
|
|
8017
|
+
cwd: path7.dirname(workspaceDir),
|
|
6927
8018
|
env: {
|
|
6928
8019
|
...process.env,
|
|
6929
8020
|
GIT_ASKPASS: askpassPath,
|
|
@@ -6934,15 +8025,15 @@ async function gitCloneWithTransientCredentials(gitUrl, workspaceDir, credential
|
|
|
6934
8025
|
cwd: workspaceDir
|
|
6935
8026
|
});
|
|
6936
8027
|
} finally {
|
|
6937
|
-
await
|
|
8028
|
+
await rm3(askpassPath, { force: true });
|
|
6938
8029
|
}
|
|
6939
8030
|
}
|
|
6940
8031
|
async function withTransientGitCredentials(credentials, operation) {
|
|
6941
8032
|
if (!credentials) {
|
|
6942
8033
|
return operation(void 0);
|
|
6943
8034
|
}
|
|
6944
|
-
const askpassPath =
|
|
6945
|
-
await
|
|
8035
|
+
const askpassPath = path7.join(tmpdir2(), `bpmax-cli-git-askpass-${randomUUID3()}.sh`);
|
|
8036
|
+
await writeFile7(
|
|
6946
8037
|
askpassPath,
|
|
6947
8038
|
[
|
|
6948
8039
|
"#!/bin/sh",
|
|
@@ -6962,7 +8053,7 @@ async function withTransientGitCredentials(credentials, operation) {
|
|
|
6962
8053
|
GIT_TERMINAL_PROMPT: "0"
|
|
6963
8054
|
});
|
|
6964
8055
|
} finally {
|
|
6965
|
-
await
|
|
8056
|
+
await rm3(askpassPath, { force: true });
|
|
6966
8057
|
}
|
|
6967
8058
|
}
|
|
6968
8059
|
async function runGitWithTransientCredentials(args, workspaceDir, credentials) {
|
|
@@ -7056,7 +8147,7 @@ function hasBlockingDirtyStatus(status, allowedPaths = /* @__PURE__ */ new Set([
|
|
|
7056
8147
|
}
|
|
7057
8148
|
async function pathExists(targetPath) {
|
|
7058
8149
|
try {
|
|
7059
|
-
await
|
|
8150
|
+
await stat4(targetPath);
|
|
7060
8151
|
return true;
|
|
7061
8152
|
} catch (error) {
|
|
7062
8153
|
if (error.code === "ENOENT") {
|
|
@@ -7130,7 +8221,7 @@ function platformStepUrl(environment, step) {
|
|
|
7130
8221
|
}
|
|
7131
8222
|
async function callPlatformSysconfigStep(environment, env, step) {
|
|
7132
8223
|
const url = platformStepUrl(environment, step);
|
|
7133
|
-
const response = await
|
|
8224
|
+
const response = await axios6.get(url, {
|
|
7134
8225
|
params: { env },
|
|
7135
8226
|
auth: environment.username && (environment.password || environment.token) ? {
|
|
7136
8227
|
username: environment.username,
|
|
@@ -7281,10 +8372,10 @@ async function initConfigWorkspaceFromPlatform(env, options) {
|
|
|
7281
8372
|
requiredPlatformField(platformEnv, "pull_url");
|
|
7282
8373
|
requiredPlatformField(platformEnv, "extract_url");
|
|
7283
8374
|
requiredPlatformField(platformEnv, "push_url");
|
|
7284
|
-
const workspaceDir =
|
|
8375
|
+
const workspaceDir = path7.resolve(options.workspaceDir);
|
|
7285
8376
|
const existed = await pathExists(workspaceDir);
|
|
7286
8377
|
if (!existed) {
|
|
7287
|
-
await
|
|
8378
|
+
await mkdir7(path7.dirname(workspaceDir), { recursive: true });
|
|
7288
8379
|
await gitCloneWithTransientCredentials(gitUrl, workspaceDir, credentials);
|
|
7289
8380
|
} else {
|
|
7290
8381
|
await assertExistingGitWorkspace(workspaceDir, gitUrl, options.force);
|
|
@@ -7389,6 +8480,19 @@ async function pullLatestConfigEnvironment(env, options) {
|
|
|
7389
8480
|
|
|
7390
8481
|
// src/commands/config.ts
|
|
7391
8482
|
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8483
|
+
async function resolveFlowTemplatePluginLintOptions(options) {
|
|
8484
|
+
const configData = await loadConfig();
|
|
8485
|
+
const profileName = options.profile || configData.current_profile || "default";
|
|
8486
|
+
const profileConfig = configData.profiles[profileName];
|
|
8487
|
+
if (!options.profile && !profileConfig?.origin) {
|
|
8488
|
+
return void 0;
|
|
8489
|
+
}
|
|
8490
|
+
return {
|
|
8491
|
+
profile: resolveProfile(configData, options.profile),
|
|
8492
|
+
agent: options.agent || "codex",
|
|
8493
|
+
requireInstalled: options.requireInstalled
|
|
8494
|
+
};
|
|
8495
|
+
}
|
|
7392
8496
|
function stringValue(value) {
|
|
7393
8497
|
return typeof value === "string" && value.trim() ? value : void 0;
|
|
7394
8498
|
}
|
|
@@ -7610,7 +8714,7 @@ function registerConfigCommands(program2) {
|
|
|
7610
8714
|
const domainCommand = domain === "workspace" ? workspace.description("Initialize local sysconfig workspaces and manage BPMAX workspace configuration") : config.command(domain).description(`Manage BPMAX ${domain} configuration`);
|
|
7611
8715
|
const createCommand = domainCommand.command("create").description(domain === "flow-template" ? "Create a new main flow template through the typed adapter" : `Create a ${domain} config object through a verified typed adapter; dry-run unless --confirm is exact`).option("--profile <profile>", "Profile name").option("--confirm <text>", "Exact confirmation text").option("--publish-live", "For flow-template, publish the created flow to live after saving draft").option("--format <format>", "Output format", "pretty");
|
|
7612
8716
|
if (domain === "flow-template") {
|
|
7613
|
-
createCommand.requiredOption("--work <file>", "Flow-template work JSON file");
|
|
8717
|
+
createCommand.requiredOption("--work <file>", "Flow-template work JSON file").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex");
|
|
7614
8718
|
} else {
|
|
7615
8719
|
createCommand.requiredOption("--id <id>", "Create operation id used in payload metadata, for example create:<domain>").requiredOption("--payload <file>", "Create submit payload JSON file produced by build");
|
|
7616
8720
|
}
|
|
@@ -7622,7 +8726,7 @@ function registerConfigCommands(program2) {
|
|
|
7622
8726
|
resolved,
|
|
7623
8727
|
String(options.work || ""),
|
|
7624
8728
|
options.confirm,
|
|
7625
|
-
{ publishLive: Boolean(options.publishLive) }
|
|
8729
|
+
{ publishLive: Boolean(options.publishLive), agent: options.agent || "codex" }
|
|
7626
8730
|
) : await submitConfigDomain(
|
|
7627
8731
|
configData,
|
|
7628
8732
|
resolved,
|
|
@@ -7663,18 +8767,35 @@ function registerConfigCommands(program2) {
|
|
|
7663
8767
|
await saveConfig(configData);
|
|
7664
8768
|
printResult(options.format, result);
|
|
7665
8769
|
});
|
|
7666
|
-
domainCommand.command("lint").description(`Lint a ${domain} work file`).requiredOption("--work <file>", "Work JSON file").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
7667
|
-
|
|
8770
|
+
domainCommand.command("lint").description(`Lint a ${domain} work file`).requiredOption("--work <file>", "Work JSON file").option("--profile <profile>", "Profile name for plugin lint discovery").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
8771
|
+
let pluginLint;
|
|
8772
|
+
if (domain === "flow-template") {
|
|
8773
|
+
pluginLint = await resolveFlowTemplatePluginLintOptions({
|
|
8774
|
+
profile: options.profile,
|
|
8775
|
+
agent: options.agent,
|
|
8776
|
+
requireInstalled: true
|
|
8777
|
+
});
|
|
8778
|
+
}
|
|
8779
|
+
const result = await lintConfigWorkFile(options.work, { pluginLint });
|
|
7668
8780
|
if (!result.ok) {
|
|
7669
8781
|
printResult(options.format, result);
|
|
7670
8782
|
throw new Error(`Config lint failed for ${options.work}`);
|
|
7671
8783
|
}
|
|
7672
8784
|
printResult(options.format, result);
|
|
7673
8785
|
});
|
|
7674
|
-
domainCommand.command("build").description(`Build a submit payload for ${domain} when a verified domain adapter is available`).requiredOption("--work <file>", "Work JSON file").requiredOption("--out <file>", "Submit payload output file").option("--meta <file>", "Export meta JSON file").option("--all-records", "For aggregate domains, submit every record instead of only changed records").option("--publish-live", "For flow-template, build a live publish payload instead of draft save").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
8786
|
+
domainCommand.command("build").description(`Build a submit payload for ${domain} when a verified domain adapter is available`).requiredOption("--work <file>", "Work JSON file").requiredOption("--out <file>", "Submit payload output file").option("--meta <file>", "Export meta JSON file").option("--all-records", "For aggregate domains, submit every record instead of only changed records").option("--publish-live", "For flow-template, build a live publish payload instead of draft save").option("--profile <profile>", "Profile name for plugin lint discovery").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
8787
|
+
let pluginLint;
|
|
8788
|
+
if (domain === "flow-template") {
|
|
8789
|
+
pluginLint = await resolveFlowTemplatePluginLintOptions({
|
|
8790
|
+
profile: options.profile,
|
|
8791
|
+
agent: options.agent,
|
|
8792
|
+
requireInstalled: true
|
|
8793
|
+
});
|
|
8794
|
+
}
|
|
7675
8795
|
const result = await buildConfigSubmitPayload(domain, options.work, options.out, options.meta, {
|
|
7676
8796
|
allRecords: Boolean(options.allRecords),
|
|
7677
|
-
publishLive: Boolean(options.publishLive)
|
|
8797
|
+
publishLive: Boolean(options.publishLive),
|
|
8798
|
+
pluginLint
|
|
7678
8799
|
});
|
|
7679
8800
|
printResult(options.format, result);
|
|
7680
8801
|
});
|
|
@@ -7692,7 +8813,7 @@ function registerConfigCommands(program2) {
|
|
|
7692
8813
|
submit_preview: submit || null
|
|
7693
8814
|
});
|
|
7694
8815
|
});
|
|
7695
|
-
domainCommand.command("submit").description(`Submit a ${domain} payload when a verified domain adapter is available; dry-run unless --confirm is exact`).requiredOption("--id <id>", "Remote config id").requiredOption("--payload <file>", "Submit payload JSON file produced by build").option("--profile <profile>", "Profile name").option("--confirm <text>", "Exact confirmation text").option("--publish-live", "For flow-template, submit this payload as a live publish").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
8816
|
+
domainCommand.command("submit").description(`Submit a ${domain} payload when a verified domain adapter is available; dry-run unless --confirm is exact`).requiredOption("--id <id>", "Remote config id").requiredOption("--payload <file>", "Submit payload JSON file produced by build").option("--profile <profile>", "Profile name").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--confirm <text>", "Exact confirmation text").option("--publish-live", "For flow-template, submit this payload as a live publish").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
7696
8817
|
const configData = await loadConfig();
|
|
7697
8818
|
const resolved = resolveProfile(configData, options.profile);
|
|
7698
8819
|
const result = await submitConfigDomain(
|
|
@@ -7702,7 +8823,7 @@ function registerConfigCommands(program2) {
|
|
|
7702
8823
|
options.id,
|
|
7703
8824
|
options.payload,
|
|
7704
8825
|
options.confirm,
|
|
7705
|
-
{ publishLive: Boolean(options.publishLive) }
|
|
8826
|
+
{ publishLive: Boolean(options.publishLive), agent: options.agent || "codex" }
|
|
7706
8827
|
);
|
|
7707
8828
|
await saveConfig(configData);
|
|
7708
8829
|
printResult(options.format, result);
|
|
@@ -7743,6 +8864,23 @@ function registerConfigCommands(program2) {
|
|
|
7743
8864
|
});
|
|
7744
8865
|
});
|
|
7745
8866
|
}
|
|
8867
|
+
if (domain === "form-template") {
|
|
8868
|
+
domainCommand.command("inspect").description("Inspect form-template raw/rule/layout/value order, especially embedded sub_form field order").requiredOption("--id <id>", "Remote form-template id").option("--field <field>", "Specific sub_form field key to inspect").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
8869
|
+
const configData = await loadConfig();
|
|
8870
|
+
const resolved = resolveProfile(configData, options.profile);
|
|
8871
|
+
const result = await inspectFormTemplate(
|
|
8872
|
+
configData,
|
|
8873
|
+
resolved,
|
|
8874
|
+
options.id,
|
|
8875
|
+
{
|
|
8876
|
+
field: options.field,
|
|
8877
|
+
outDir: ".codex/tmp/form-template-inspect"
|
|
8878
|
+
}
|
|
8879
|
+
);
|
|
8880
|
+
await saveConfig(configData);
|
|
8881
|
+
printResult(options.format, result);
|
|
8882
|
+
});
|
|
8883
|
+
}
|
|
7746
8884
|
domainCommand.command("verify").description(`Read back a ${domain} config and optionally compare with an expected JSON file`).requiredOption("--id <id>", "Remote config id").option("--expect <file>", "Expected JSON file").option("--ignore-server-fields", "For form-template verify, ignore platform-filled system fields such as form_rule_id/template_id/visibility").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
7747
8885
|
const configData = await loadConfig();
|
|
7748
8886
|
const resolved = resolveProfile(configData, options.profile);
|
|
@@ -7875,7 +9013,7 @@ function registerFlowCommands(program2) {
|
|
|
7875
9013
|
const client = createApiClient(profile);
|
|
7876
9014
|
if (options.flowType) {
|
|
7877
9015
|
const bindings = await getWorkspaceFlowBindings(client, profile, options);
|
|
7878
|
-
const
|
|
9016
|
+
const path12 = options.flowKey ? "/flow/options" : "/flow/flow_type";
|
|
7879
9017
|
const params = options.flowKey ? {
|
|
7880
9018
|
detail: "1"
|
|
7881
9019
|
} : {
|
|
@@ -7885,7 +9023,7 @@ function registerFlowCommands(program2) {
|
|
|
7885
9023
|
const result2 = await apiRequest(
|
|
7886
9024
|
client,
|
|
7887
9025
|
"GET",
|
|
7888
|
-
|
|
9026
|
+
path12,
|
|
7889
9027
|
{
|
|
7890
9028
|
params
|
|
7891
9029
|
}
|
|
@@ -7996,76 +9134,6 @@ function setupSummary(input) {
|
|
|
7996
9134
|
};
|
|
7997
9135
|
}
|
|
7998
9136
|
|
|
7999
|
-
// src/core/skills.ts
|
|
8000
|
-
import { mkdir as mkdir6, readFile as readFile8, writeFile as writeFile6 } from "fs/promises";
|
|
8001
|
-
import path6 from "path";
|
|
8002
|
-
import { fileURLToPath } from "url";
|
|
8003
|
-
var SKILLS_STAMP_FILE = "skills.stamp";
|
|
8004
|
-
var SKILLS_INSTALL_TIMEOUT_MS = 2 * 60 * 1e3;
|
|
8005
|
-
function skillsStampValue(version, agent) {
|
|
8006
|
-
return agent ? `${version}:${agent}` : version;
|
|
8007
|
-
}
|
|
8008
|
-
function stampPath(configDir = getConfigDir()) {
|
|
8009
|
-
return path6.join(configDir, SKILLS_STAMP_FILE);
|
|
8010
|
-
}
|
|
8011
|
-
async function readSkillsStamp(configDir = getConfigDir()) {
|
|
8012
|
-
try {
|
|
8013
|
-
return (await readFile8(stampPath(configDir), "utf8")).trim();
|
|
8014
|
-
} catch {
|
|
8015
|
-
return "";
|
|
8016
|
-
}
|
|
8017
|
-
}
|
|
8018
|
-
async function writeSkillsStamp(version, configDir = getConfigDir(), agent) {
|
|
8019
|
-
await mkdir6(configDir, { recursive: true });
|
|
8020
|
-
await writeFile6(stampPath(configDir), skillsStampValue(version, agent), "utf8");
|
|
8021
|
-
}
|
|
8022
|
-
async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent) {
|
|
8023
|
-
const target = skillsStampValue(currentVersion, agent);
|
|
8024
|
-
if (process.env.BPMAX_CLI_NO_SKILLS_NOTIFIER) {
|
|
8025
|
-
return { current: target, target, inSync: true };
|
|
8026
|
-
}
|
|
8027
|
-
const current = await readSkillsStamp(configDir);
|
|
8028
|
-
return { current, target, inSync: current === target };
|
|
8029
|
-
}
|
|
8030
|
-
async function resolvePackageRootFrom(entrypointPath) {
|
|
8031
|
-
const entryDir = path6.dirname(entrypointPath);
|
|
8032
|
-
if (path6.basename(entryDir) === "dist") {
|
|
8033
|
-
return path6.dirname(entryDir);
|
|
8034
|
-
}
|
|
8035
|
-
if (path6.basename(entryDir) === "core" && path6.basename(path6.dirname(entryDir)) === "src") {
|
|
8036
|
-
return path6.dirname(path6.dirname(entryDir));
|
|
8037
|
-
}
|
|
8038
|
-
return path6.resolve(entryDir, "..", "..");
|
|
8039
|
-
}
|
|
8040
|
-
async function defaultPackageRoot() {
|
|
8041
|
-
return resolvePackageRootFrom(fileURLToPath(import.meta.url));
|
|
8042
|
-
}
|
|
8043
|
-
async function runSkillsInstall(options = {}) {
|
|
8044
|
-
const runner = options.runner || runCommand;
|
|
8045
|
-
const packageRoot = options.packageRoot || await defaultPackageRoot();
|
|
8046
|
-
const args = [path6.join(packageRoot, "scripts", "install-skills.mjs")];
|
|
8047
|
-
if (options.agent) {
|
|
8048
|
-
args.push("--json", "--agent", options.agent);
|
|
8049
|
-
}
|
|
8050
|
-
return runner(process.execPath, args, {
|
|
8051
|
-
timeoutMs: SKILLS_INSTALL_TIMEOUT_MS
|
|
8052
|
-
});
|
|
8053
|
-
}
|
|
8054
|
-
async function syncSkills(version, options = {}) {
|
|
8055
|
-
if (!options.force) {
|
|
8056
|
-
const status = await checkSkillsSync(version, options.configDir, options.agent);
|
|
8057
|
-
if (status.inSync) {
|
|
8058
|
-
return { action: "in_sync" };
|
|
8059
|
-
}
|
|
8060
|
-
}
|
|
8061
|
-
const result = await runSkillsInstall({ packageRoot: options.packageRoot, runner: options.runner, agent: options.agent });
|
|
8062
|
-
if (result.exitCode === 0) {
|
|
8063
|
-
await writeSkillsStamp(version, options.configDir, options.agent);
|
|
8064
|
-
return { action: "synced", result };
|
|
8065
|
-
}
|
|
8066
|
-
return { action: "failed", result };
|
|
8067
|
-
}
|
|
8068
|
-
|
|
8069
9137
|
// src/commands/init.ts
|
|
8070
9138
|
function shellQuote5(value) {
|
|
8071
9139
|
if (/^[A-Za-z0-9_./:@=-]+$/.test(value)) {
|
|
@@ -8212,10 +9280,10 @@ async function parseOptionalJson(input, label) {
|
|
|
8212
9280
|
}
|
|
8213
9281
|
return parseJsonInput(input, label);
|
|
8214
9282
|
}
|
|
8215
|
-
async function memoryRequest(options, method,
|
|
9283
|
+
async function memoryRequest(options, method, path12, capability, data, params) {
|
|
8216
9284
|
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
8217
9285
|
const client = createApiClient(profile);
|
|
8218
|
-
return apiRequest(client, method,
|
|
9286
|
+
return apiRequest(client, method, path12, {
|
|
8219
9287
|
capability,
|
|
8220
9288
|
data: redactAuditValue(data),
|
|
8221
9289
|
params: params ? redactAuditValue(params) : void 0
|
|
@@ -8270,7 +9338,7 @@ function registerMemoryCommands(program2) {
|
|
|
8270
9338
|
}
|
|
8271
9339
|
|
|
8272
9340
|
// src/commands/matrix.ts
|
|
8273
|
-
import { readFile as
|
|
9341
|
+
import { readFile as readFile10 } from "fs/promises";
|
|
8274
9342
|
var UUID_VALUE_PATTERN2 = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/i;
|
|
8275
9343
|
var UUID_PATH_PATTERN = /uuid'[^'"\s/]+/i;
|
|
8276
9344
|
async function parseSeedRules(input) {
|
|
@@ -8278,7 +9346,7 @@ async function parseSeedRules(input) {
|
|
|
8278
9346
|
if (source === "") {
|
|
8279
9347
|
throw new Error("--rules file path is empty.");
|
|
8280
9348
|
}
|
|
8281
|
-
const raw = source ? await
|
|
9349
|
+
const raw = source ? await readFile10(source, "utf8") : input;
|
|
8282
9350
|
let parsed;
|
|
8283
9351
|
try {
|
|
8284
9352
|
parsed = JSON.parse(raw);
|
|
@@ -8297,15 +9365,15 @@ async function parseSeedRules(input) {
|
|
|
8297
9365
|
});
|
|
8298
9366
|
return rules;
|
|
8299
9367
|
}
|
|
8300
|
-
function collectUuidPaths(value,
|
|
9368
|
+
function collectUuidPaths(value, path12 = "$") {
|
|
8301
9369
|
if (typeof value === "string") {
|
|
8302
|
-
return UUID_VALUE_PATTERN2.test(value) || UUID_PATH_PATTERN.test(value) ? [
|
|
9370
|
+
return UUID_VALUE_PATTERN2.test(value) || UUID_PATH_PATTERN.test(value) ? [path12] : [];
|
|
8303
9371
|
}
|
|
8304
9372
|
if (Array.isArray(value)) {
|
|
8305
|
-
return value.flatMap((item, index) => collectUuidPaths(item, `${
|
|
9373
|
+
return value.flatMap((item, index) => collectUuidPaths(item, `${path12}[${index}]`));
|
|
8306
9374
|
}
|
|
8307
9375
|
if (typeof value === "object" && value !== null) {
|
|
8308
|
-
return Object.entries(value).flatMap(([key, child]) => collectUuidPaths(child, `${
|
|
9376
|
+
return Object.entries(value).flatMap(([key, child]) => collectUuidPaths(child, `${path12}.${key}`));
|
|
8309
9377
|
}
|
|
8310
9378
|
return [];
|
|
8311
9379
|
}
|
|
@@ -8334,16 +9402,16 @@ function dataArray(value) {
|
|
|
8334
9402
|
if (isRecord6(value) && Array.isArray(value.data)) return value.data;
|
|
8335
9403
|
return [];
|
|
8336
9404
|
}
|
|
8337
|
-
function collectMatrixOwnerPaths(value,
|
|
9405
|
+
function collectMatrixOwnerPaths(value, path12 = "$") {
|
|
8338
9406
|
if (Array.isArray(value)) {
|
|
8339
|
-
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${
|
|
9407
|
+
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${path12}[${index}]`));
|
|
8340
9408
|
}
|
|
8341
9409
|
if (!isRecord6(value)) {
|
|
8342
9410
|
return [];
|
|
8343
9411
|
}
|
|
8344
9412
|
const matches = [];
|
|
8345
9413
|
Object.entries(value).forEach(([key, child]) => {
|
|
8346
|
-
const childPath = `${
|
|
9414
|
+
const childPath = `${path12}.${key}`;
|
|
8347
9415
|
if (key.includes("matrix_owner") || typeof child === "string" && child.includes("matrix_owner")) {
|
|
8348
9416
|
matches.push({ path: childPath, value: child });
|
|
8349
9417
|
}
|
|
@@ -8457,6 +9525,72 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
8457
9525
|
});
|
|
8458
9526
|
}
|
|
8459
9527
|
|
|
9528
|
+
// src/commands/plugin.ts
|
|
9529
|
+
function defaultAgent2(options) {
|
|
9530
|
+
return options.agent || process.env.BPMAX_CLI_AGENT || "codex";
|
|
9531
|
+
}
|
|
9532
|
+
function selectSkills(skills, skillName) {
|
|
9533
|
+
if (!skillName) {
|
|
9534
|
+
return skills;
|
|
9535
|
+
}
|
|
9536
|
+
return skills.filter((item) => item.name === skillName);
|
|
9537
|
+
}
|
|
9538
|
+
function registerPluginCommands(program2) {
|
|
9539
|
+
const plugin = program2.command("plugin").description("Manage BPMAX plugins and plugin-scoped Agent skills");
|
|
9540
|
+
const skills = plugin.command("skills").description("Manage plugin-scoped Agent skills");
|
|
9541
|
+
skills.command("list").argument("[plugin]", "Plugin name").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (pluginName, options) => {
|
|
9542
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
9543
|
+
const result = pluginName ? await apiRequest(createApiClient(profile), "GET", `/cli/plugins/${pluginName}/skills`) : await apiRequest(createApiClient(profile), "GET", "/cli/plugins", { params: { include_skills: 1 } });
|
|
9544
|
+
printResult(options.format, result);
|
|
9545
|
+
});
|
|
9546
|
+
skills.command("state").option("--agent <agent>", "Agent adapter", "codex").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
9547
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
9548
|
+
const agent = defaultAgent2(options);
|
|
9549
|
+
printResult(options.format, {
|
|
9550
|
+
agent,
|
|
9551
|
+
profile: profile.name,
|
|
9552
|
+
state: await readPluginSkillState(profile.name, agent)
|
|
9553
|
+
});
|
|
9554
|
+
});
|
|
9555
|
+
skills.command("lint").requiredOption("--zip <path>", "Plugin skill zip path").option("--skill <skill>", "Expected skill name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
9556
|
+
printResult(options.format, await lintPluginSkillZip(options.zip, { expectedName: options.skill }));
|
|
9557
|
+
});
|
|
9558
|
+
async function ensureSkills(pluginName, options) {
|
|
9559
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
9560
|
+
const client = createApiClient(profile);
|
|
9561
|
+
const agent = defaultAgent2(options);
|
|
9562
|
+
const available = await listPluginSkills(client, pluginName);
|
|
9563
|
+
const selected = selectSkills(available, options.skill);
|
|
9564
|
+
if (!selected.length) {
|
|
9565
|
+
throw new Error(options.skill ? `Plugin skill not found: ${pluginName}/${options.skill}` : `No plugin skills found for ${pluginName}`);
|
|
9566
|
+
}
|
|
9567
|
+
const installed = [];
|
|
9568
|
+
for (const skill of selected) {
|
|
9569
|
+
installed.push(await ensurePluginSkill({
|
|
9570
|
+
client,
|
|
9571
|
+
profile,
|
|
9572
|
+
plugin: pluginName,
|
|
9573
|
+
skill,
|
|
9574
|
+
agent,
|
|
9575
|
+
force: options.force
|
|
9576
|
+
}));
|
|
9577
|
+
}
|
|
9578
|
+
printResult(options.format, {
|
|
9579
|
+
action: options.force ? "updated" : installed.every((item) => item.action === "in_sync") ? "in_sync" : "ensured",
|
|
9580
|
+
agent,
|
|
9581
|
+
plugin: pluginName,
|
|
9582
|
+
skills: installed,
|
|
9583
|
+
next_commands: installed.map((item) => `Use skill ${item.skill} for plugin ${pluginName}.`)
|
|
9584
|
+
});
|
|
9585
|
+
}
|
|
9586
|
+
skills.command("ensure <plugin>").option("--skill <skill>", "Install only one declared plugin skill").option("--agent <agent>", "Agent adapter", "codex").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(
|
|
9587
|
+
(pluginName, options) => ensureSkills(pluginName, options)
|
|
9588
|
+
);
|
|
9589
|
+
skills.command("update <plugin>").option("--skill <skill>", "Update only one declared plugin skill").option("--agent <agent>", "Agent adapter", "codex").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(
|
|
9590
|
+
(pluginName, options) => ensureSkills(pluginName, { ...options, force: true })
|
|
9591
|
+
);
|
|
9592
|
+
}
|
|
9593
|
+
|
|
8460
9594
|
// src/core/form-schema.ts
|
|
8461
9595
|
var FIELD_KEY_NAMES = [
|
|
8462
9596
|
"key",
|
|
@@ -8546,6 +9680,15 @@ function pickOptions(source) {
|
|
|
8546
9680
|
return options;
|
|
8547
9681
|
}
|
|
8548
9682
|
}
|
|
9683
|
+
for (const containerKey of ["props", "config", "setting", "value"]) {
|
|
9684
|
+
const container = source[containerKey];
|
|
9685
|
+
if (isRecord7(container)) {
|
|
9686
|
+
const nested = pickOptions(container);
|
|
9687
|
+
if (nested?.length) {
|
|
9688
|
+
return nested;
|
|
9689
|
+
}
|
|
9690
|
+
}
|
|
9691
|
+
}
|
|
8549
9692
|
return void 0;
|
|
8550
9693
|
}
|
|
8551
9694
|
function fieldFromRecord(source) {
|
|
@@ -8636,16 +9779,17 @@ function validateComplexSelector(field, value) {
|
|
|
8636
9779
|
return null;
|
|
8637
9780
|
}
|
|
8638
9781
|
const validObject = (item) => isRecord7(item);
|
|
9782
|
+
const hint = complexSelectorHint(field);
|
|
8639
9783
|
if (Array.isArray(value)) {
|
|
8640
|
-
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
|
|
9784
|
+
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values. ${hint}`;
|
|
8641
9785
|
}
|
|
8642
9786
|
if (validObject(value)) {
|
|
8643
9787
|
return null;
|
|
8644
9788
|
}
|
|
8645
|
-
return `${field.key} must be a selector option object or array of option objects, not a scalar value`;
|
|
9789
|
+
return `${field.key} must be a selector option object or array of option objects, not a scalar value. ${hint}`;
|
|
8646
9790
|
}
|
|
8647
9791
|
function isComplexSelectorType(type) {
|
|
8648
|
-
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);
|
|
9792
|
+
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|project_selector_new|es_project_selector|person_selector|user_group_selector)/.test(type);
|
|
8649
9793
|
}
|
|
8650
9794
|
function isEnumSelectType(type) {
|
|
8651
9795
|
return /enum_select/.test(type);
|
|
@@ -8679,7 +9823,7 @@ function validateType(field, value) {
|
|
|
8679
9823
|
const values = Array.isArray(value) ? value.map((item) => String(optionComparableValue(item))) : [String(optionComparableValue(value))];
|
|
8680
9824
|
const invalid = values.filter((item) => !field.options?.includes(item));
|
|
8681
9825
|
if (invalid.length > 0) {
|
|
8682
|
-
return `${field.key} has invalid option value(s): ${invalid.join(", ")}`;
|
|
9826
|
+
return `${field.key} has invalid option value(s): ${invalid.join(", ")}. Legal options: ${field.options.join(" / ")}`;
|
|
8683
9827
|
}
|
|
8684
9828
|
}
|
|
8685
9829
|
if (/(number|int|decimal|float|double|amount)/.test(type) && typeof value !== "number") {
|
|
@@ -8733,6 +9877,70 @@ function validateFormAgainstFields(form, fields) {
|
|
|
8733
9877
|
const errors = validateFormEntries(form, fields);
|
|
8734
9878
|
return { fields, errors };
|
|
8735
9879
|
}
|
|
9880
|
+
function complexSelectorHint(field) {
|
|
9881
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
9882
|
+
if (/es_project_selector|project_selector|project_selector_new|plugin_project_selector|relation_project/.test(type)) {
|
|
9883
|
+
return "Project selector values usually require BPMAX page selection or a platform selector object with id/name; do not pass a free-text scalar.";
|
|
9884
|
+
}
|
|
9885
|
+
if (/user|person|department|group/.test(type)) {
|
|
9886
|
+
return "User/group selector values usually require BPMAX page selection or a platform selector object; do not pass a free-text scalar.";
|
|
9887
|
+
}
|
|
9888
|
+
return "Use BPMAX page selection unless you have the exact platform selector object shape.";
|
|
9889
|
+
}
|
|
9890
|
+
function fieldExpectedShape(field) {
|
|
9891
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
9892
|
+
if (isSubFormField(field)) {
|
|
9893
|
+
const childShape = Object.fromEntries((field.children ?? []).map((child) => [child.key, childExpectedPlaceholder(child)]));
|
|
9894
|
+
return `array of row objects, for example ${JSON.stringify([childShape])}`;
|
|
9895
|
+
}
|
|
9896
|
+
if (isComplexSelectorType(type)) {
|
|
9897
|
+
return "selector object or array of selector objects; page selection is safer for project/user/group selectors";
|
|
9898
|
+
}
|
|
9899
|
+
if (field.options?.length) {
|
|
9900
|
+
return `one of: ${field.options.join(" / ")}`;
|
|
9901
|
+
}
|
|
9902
|
+
if (/(number|int|decimal|float|double|amount)/.test(type)) {
|
|
9903
|
+
return "number";
|
|
9904
|
+
}
|
|
9905
|
+
if (/(boolean|bool|switch|checkbox)/.test(type)) {
|
|
9906
|
+
return "boolean";
|
|
9907
|
+
}
|
|
9908
|
+
if (/(array|multi|multiple)/.test(type)) {
|
|
9909
|
+
return "array";
|
|
9910
|
+
}
|
|
9911
|
+
return "scalar value";
|
|
9912
|
+
}
|
|
9913
|
+
function childExpectedPlaceholder(field) {
|
|
9914
|
+
if (isSubFormField(field)) {
|
|
9915
|
+
return [];
|
|
9916
|
+
}
|
|
9917
|
+
if (field.options?.length) {
|
|
9918
|
+
return field.options[0] ?? "<option>";
|
|
9919
|
+
}
|
|
9920
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
9921
|
+
if (/(number|int|decimal|float|double|amount)/.test(type)) {
|
|
9922
|
+
return 0;
|
|
9923
|
+
}
|
|
9924
|
+
if (/(boolean|bool|switch|checkbox)/.test(type)) {
|
|
9925
|
+
return false;
|
|
9926
|
+
}
|
|
9927
|
+
if (isComplexSelectorType(type)) {
|
|
9928
|
+
return { id: "<platform-id>", name: "<display-name>" };
|
|
9929
|
+
}
|
|
9930
|
+
return "<value>";
|
|
9931
|
+
}
|
|
9932
|
+
function explainFormValidationSchema(fields) {
|
|
9933
|
+
return fields.map((field) => ({
|
|
9934
|
+
key: field.key,
|
|
9935
|
+
...field.label ? { label: field.label } : {},
|
|
9936
|
+
...field.type ? { type: field.type } : {},
|
|
9937
|
+
required: field.required,
|
|
9938
|
+
expected: fieldExpectedShape(field),
|
|
9939
|
+
...isComplexSelectorType(field.type?.toLowerCase() ?? "") ? { handoff_hint: complexSelectorHint(field) } : {},
|
|
9940
|
+
...field.options?.length ? { options: field.options } : {},
|
|
9941
|
+
...field.children?.length ? { children: explainFormValidationSchema(field.children) } : {}
|
|
9942
|
+
}));
|
|
9943
|
+
}
|
|
8736
9944
|
|
|
8737
9945
|
// src/core/form-prompts.ts
|
|
8738
9946
|
import { confirm, isCancel, multiselect, select, text as text3 } from "@clack/prompts";
|
|
@@ -9311,6 +10519,25 @@ function assertHandoffFormCompatible(fields, form) {
|
|
|
9311
10519
|
);
|
|
9312
10520
|
}
|
|
9313
10521
|
}
|
|
10522
|
+
function explainProjectCreateValidation(fields, form) {
|
|
10523
|
+
if (fields.length === 0) {
|
|
10524
|
+
return {
|
|
10525
|
+
ok: false,
|
|
10526
|
+
errors: [
|
|
10527
|
+
"Could not discover the flow create form schema for local validation."
|
|
10528
|
+
],
|
|
10529
|
+
schema: [],
|
|
10530
|
+
next_action: "Confirm the flow has a published create form/template, or open the BPMAX page and use browser handoff instead of guessing the payload."
|
|
10531
|
+
};
|
|
10532
|
+
}
|
|
10533
|
+
const validation = validateFormAgainstFields(form, fields);
|
|
10534
|
+
return {
|
|
10535
|
+
ok: validation.errors.length === 0,
|
|
10536
|
+
errors: validation.errors,
|
|
10537
|
+
schema: explainFormValidationSchema(fields),
|
|
10538
|
+
next_action: validation.errors.length > 0 ? "Correct scalar/select values from the schema. For project/user/group selectors, prefer BPMAX page handoff instead of inventing raw values." : "The provided form payload matches the discovered create-form schema."
|
|
10539
|
+
};
|
|
10540
|
+
}
|
|
9314
10541
|
function isRiskyFormField(field) {
|
|
9315
10542
|
const type = field.type?.toLowerCase() ?? "";
|
|
9316
10543
|
const label = field.label?.toLowerCase() ?? "";
|
|
@@ -9364,9 +10591,9 @@ function contextField(field, reason, options = {}) {
|
|
|
9364
10591
|
function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
9365
10592
|
for (const field of fields) {
|
|
9366
10593
|
const value = form[field.key];
|
|
9367
|
-
const
|
|
10594
|
+
const path12 = options.prefix ? `${options.prefix}.${field.key}` : field.key;
|
|
9368
10595
|
const fieldOptions = {
|
|
9369
|
-
path:
|
|
10596
|
+
path: path12,
|
|
9370
10597
|
rootKey: options.rootKey ?? field.key,
|
|
9371
10598
|
parentKey: options.parentKey
|
|
9372
10599
|
};
|
|
@@ -9607,11 +10834,14 @@ function registerProjectCommands(program2) {
|
|
|
9607
10834
|
});
|
|
9608
10835
|
}
|
|
9609
10836
|
});
|
|
9610
|
-
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("--unsafe-direct-create", "Allow raw --body direct project creation without form-template safety checks").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("--handoff-only", "Return a prefilled BPMAX create-page handoff URL without prompting or direct project creation").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
|
|
10837
|
+
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("--unsafe-direct-create", "Allow raw --body direct project creation without form-template safety checks").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("--handoff-only", "Return a prefilled BPMAX create-page handoff URL without prompting or direct project creation").option("--explain-validation", "Print discovered create-form validation schema and errors without creating a project").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
|
|
9611
10838
|
const interactiveSource = command.getOptionValueSource("interactive");
|
|
9612
10839
|
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
9613
10840
|
throw new Error("--body and --interactive cannot be used together.");
|
|
9614
10841
|
}
|
|
10842
|
+
if (options.body && options.explainValidation) {
|
|
10843
|
+
throw new Error("--explain-validation cannot be used with --body because --body bypasses form schema discovery.");
|
|
10844
|
+
}
|
|
9615
10845
|
if (options.body && options.unsafeDirectCreate !== true) {
|
|
9616
10846
|
throw new Error(
|
|
9617
10847
|
[
|
|
@@ -9642,6 +10872,16 @@ function registerProjectCommands(program2) {
|
|
|
9642
10872
|
return projectFormTemplate;
|
|
9643
10873
|
};
|
|
9644
10874
|
const usesTemplateProjectName = metaUsesTemplateProjectName(flowDetail);
|
|
10875
|
+
if (options.explainValidation) {
|
|
10876
|
+
projectFormTemplate = await loadProjectFormTemplate();
|
|
10877
|
+
const fields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
10878
|
+
printResult(options.format, {
|
|
10879
|
+
flow_type: flowIdentifiers.flow_type,
|
|
10880
|
+
flow_key: flowIdentifiers.flow_key,
|
|
10881
|
+
...explainProjectCreateValidation(fields, form)
|
|
10882
|
+
});
|
|
10883
|
+
return;
|
|
10884
|
+
}
|
|
9645
10885
|
if (options.handoffOnly) {
|
|
9646
10886
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
9647
10887
|
const handoffFields2 = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
@@ -9767,11 +11007,11 @@ function registerProjectCommands(program2) {
|
|
|
9767
11007
|
|
|
9768
11008
|
// src/commands/recipe.ts
|
|
9769
11009
|
import { spawn as spawn2 } from "child_process";
|
|
9770
|
-
import { fileURLToPath as
|
|
11010
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
9771
11011
|
|
|
9772
11012
|
// src/core/recipes.ts
|
|
9773
|
-
import { access, mkdir as
|
|
9774
|
-
import
|
|
11013
|
+
import { access, mkdir as mkdir8, readdir as readdir3, readFile as readFile11, writeFile as writeFile8 } from "fs/promises";
|
|
11014
|
+
import path8 from "path";
|
|
9775
11015
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
9776
11016
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
9777
11017
|
function assertSafeName(kind, value) {
|
|
@@ -9795,12 +11035,12 @@ function resolveRecipeLocation(options) {
|
|
|
9795
11035
|
workspace,
|
|
9796
11036
|
workspaceDirName,
|
|
9797
11037
|
recipeName: options.recipeName,
|
|
9798
|
-
recipeDir:
|
|
11038
|
+
recipeDir: path8.join(profileDir, "recipes", workspaceDirName, options.recipeName)
|
|
9799
11039
|
};
|
|
9800
11040
|
}
|
|
9801
11041
|
function getRecipesDir(options) {
|
|
9802
11042
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
9803
|
-
return
|
|
11043
|
+
return path8.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
9804
11044
|
}
|
|
9805
11045
|
function isRecord10(value) {
|
|
9806
11046
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -9852,13 +11092,13 @@ function parseRecipeDefinition(input) {
|
|
|
9852
11092
|
};
|
|
9853
11093
|
}
|
|
9854
11094
|
async function loadRecipe(recipeDir) {
|
|
9855
|
-
const raw = await
|
|
11095
|
+
const raw = await readFile11(path8.join(recipeDir, "recipe.json"), "utf8");
|
|
9856
11096
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
9857
11097
|
}
|
|
9858
11098
|
async function listRecipes(recipesDir) {
|
|
9859
11099
|
let entries;
|
|
9860
11100
|
try {
|
|
9861
|
-
entries = await
|
|
11101
|
+
entries = await readdir3(recipesDir);
|
|
9862
11102
|
} catch (error) {
|
|
9863
11103
|
if (error.code === "ENOENT") {
|
|
9864
11104
|
return [];
|
|
@@ -9870,7 +11110,7 @@ async function listRecipes(recipesDir) {
|
|
|
9870
11110
|
if (!RECIPE_NAME_PATTERN.test(entry)) {
|
|
9871
11111
|
continue;
|
|
9872
11112
|
}
|
|
9873
|
-
const recipeDir =
|
|
11113
|
+
const recipeDir = path8.join(recipesDir, entry);
|
|
9874
11114
|
try {
|
|
9875
11115
|
const recipe = await loadRecipe(recipeDir);
|
|
9876
11116
|
summaries.push({
|
|
@@ -9936,12 +11176,12 @@ function renderTemplate(template, variables) {
|
|
|
9936
11176
|
}
|
|
9937
11177
|
function resolveRecipeFile(recipeDir, token) {
|
|
9938
11178
|
const relative = token.slice(1);
|
|
9939
|
-
if (!relative || relative.includes("..") ||
|
|
11179
|
+
if (!relative || relative.includes("..") || path8.isAbsolute(relative)) {
|
|
9940
11180
|
throw new Error(`Unsafe recipe file reference: ${token}`);
|
|
9941
11181
|
}
|
|
9942
|
-
const resolved =
|
|
9943
|
-
const root =
|
|
9944
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
11182
|
+
const resolved = path8.resolve(recipeDir, relative);
|
|
11183
|
+
const root = path8.resolve(recipeDir);
|
|
11184
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path8.sep}`)) {
|
|
9945
11185
|
throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
|
|
9946
11186
|
}
|
|
9947
11187
|
return resolved;
|
|
@@ -9951,7 +11191,7 @@ async function renderArgv(options) {
|
|
|
9951
11191
|
const rendered = [];
|
|
9952
11192
|
for (const token of options.recipe.command.argv) {
|
|
9953
11193
|
if (token.startsWith("@")) {
|
|
9954
|
-
const raw = await
|
|
11194
|
+
const raw = await readFile11(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
9955
11195
|
rendered.push(renderTemplate(raw, options.variables));
|
|
9956
11196
|
} else {
|
|
9957
11197
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -9977,7 +11217,7 @@ async function ensureEmptyOrForce(targetDir, force = false) {
|
|
|
9977
11217
|
}
|
|
9978
11218
|
async function writeRecipeScaffold(options) {
|
|
9979
11219
|
await ensureEmptyOrForce(options.location.recipeDir, options.force);
|
|
9980
|
-
await
|
|
11220
|
+
await mkdir8(options.location.recipeDir, { recursive: true });
|
|
9981
11221
|
const title = options.title || options.location.recipeName;
|
|
9982
11222
|
const recipe = {
|
|
9983
11223
|
version: 1,
|
|
@@ -9994,16 +11234,16 @@ async function writeRecipeScaffold(options) {
|
|
|
9994
11234
|
mutating: true
|
|
9995
11235
|
}
|
|
9996
11236
|
};
|
|
9997
|
-
await
|
|
11237
|
+
await writeFile8(path8.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
|
|
9998
11238
|
`, "utf8");
|
|
9999
|
-
await
|
|
10000
|
-
|
|
11239
|
+
await writeFile8(
|
|
11240
|
+
path8.join(options.location.recipeDir, "payload.json"),
|
|
10001
11241
|
`${JSON.stringify({ form: {} }, null, 2)}
|
|
10002
11242
|
`,
|
|
10003
11243
|
"utf8"
|
|
10004
11244
|
);
|
|
10005
|
-
await
|
|
10006
|
-
|
|
11245
|
+
await writeFile8(
|
|
11246
|
+
path8.join(options.location.recipeDir, "README.md"),
|
|
10007
11247
|
[`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
|
|
10008
11248
|
"utf8"
|
|
10009
11249
|
);
|
|
@@ -10011,7 +11251,7 @@ async function writeRecipeScaffold(options) {
|
|
|
10011
11251
|
|
|
10012
11252
|
// src/commands/recipe.ts
|
|
10013
11253
|
function currentCliInvocation() {
|
|
10014
|
-
const entry = process.argv[1] ||
|
|
11254
|
+
const entry = process.argv[1] || fileURLToPath3(import.meta.url);
|
|
10015
11255
|
return {
|
|
10016
11256
|
command: process.execPath,
|
|
10017
11257
|
argsPrefix: [entry]
|
|
@@ -10961,8 +12201,8 @@ function registerStepCommands(program2) {
|
|
|
10961
12201
|
}
|
|
10962
12202
|
|
|
10963
12203
|
// src/core/taskbook.ts
|
|
10964
|
-
import { mkdir as
|
|
10965
|
-
import
|
|
12204
|
+
import { mkdir as mkdir9, readFile as readFile12, writeFile as writeFile9 } from "fs/promises";
|
|
12205
|
+
import path9 from "path";
|
|
10966
12206
|
var TaskbookError = class extends Error {
|
|
10967
12207
|
};
|
|
10968
12208
|
var REQUIRED_TASKBOOK_TERMS = [
|
|
@@ -10974,6 +12214,7 @@ var REQUIRED_TASKBOOK_TERMS = [
|
|
|
10974
12214
|
"\u9A8C\u6536\u95E8\u7981",
|
|
10975
12215
|
"\u5BFC\u822A\u5165\u53E3\u7B56\u7565",
|
|
10976
12216
|
"\u5217\u8868 lint",
|
|
12217
|
+
"\u914D\u7F6E Skill / Capability \u4F9D\u636E\u8868",
|
|
10977
12218
|
"\u505C\u673A\u70B9",
|
|
10978
12219
|
"\u5BF9\u8C61\u9501\u91CD\u590D",
|
|
10979
12220
|
"\u53EA\u8BFB\u4EFB\u52A1",
|
|
@@ -11014,6 +12255,145 @@ var PROMPT_REQUIRED_TERMS = [
|
|
|
11014
12255
|
var BPMAX_SKILL_PATTERN = /bpmax-[a-z0-9-]+|form-control-library|bpmax-memory-protocol/;
|
|
11015
12256
|
var FLOW_LOCK_PATTERN = /\bflow:([A-Za-z0-9_-]+)/g;
|
|
11016
12257
|
var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/gi;
|
|
12258
|
+
var CONFIG_TASK_RULES = [
|
|
12259
|
+
{
|
|
12260
|
+
domain: "flow-template",
|
|
12261
|
+
skill: "bpmax-flow-template-editor",
|
|
12262
|
+
lockPattern: /(?:flow:flow\d+|new-flow:[A-Za-z0-9_-]+)/,
|
|
12263
|
+
writeEvidence: [/bpmax-cli config flow-template lint/, /bpmax-cli config flow-template build/, /bpmax-cli config flow-template submit/, /bpmax-cli config flow-template verify/],
|
|
12264
|
+
readonlyEvidence: [/bpmax-cli config flow-template export|流程.*回读|readback/i],
|
|
12265
|
+
constraintEvidence: /project_after_create_path|message_template|return ""|matrix_owner|cc_matrix|流程模板约束|flow-template lint/i,
|
|
12266
|
+
mentionPattern: /流程模板|flow-template|flow_template|流程配置|创建流程|编辑流程/
|
|
12267
|
+
},
|
|
12268
|
+
{
|
|
12269
|
+
domain: "form-template",
|
|
12270
|
+
skill: "bpmax-form-template-editor",
|
|
12271
|
+
lockPattern: /form-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12272
|
+
writeEvidence: [/bpmax-cli config form-template lint/, /bpmax-cli config form-template build/, /bpmax-cli config form-template submit/, /bpmax-cli config form-template verify/],
|
|
12273
|
+
readonlyEvidence: [/bpmax-cli config form-template export|表单.*回读|readback/i],
|
|
12274
|
+
constraintEvidence: /字段 schema|表单顺序|raw\.value|layout|sub_form|form-template inspect|表单模板约束/i,
|
|
12275
|
+
mentionPattern: /表单模板|form-template|form_template|表单字段|子表单|sub_form/
|
|
12276
|
+
},
|
|
12277
|
+
{
|
|
12278
|
+
domain: "list-template",
|
|
12279
|
+
skill: "bpmax-list-template-editor",
|
|
12280
|
+
lockPattern: /list-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12281
|
+
writeEvidence: [/bpmax-cli config list-template lint/, /bpmax-cli config list-template build/, /bpmax-cli config list-template submit/, /bpmax-cli config list-template verify/],
|
|
12282
|
+
readonlyEvidence: [/bpmax-cli config list-template export|列表.*回读|readback/i],
|
|
12283
|
+
constraintEvidence: /操作列|删除|guard|icon|查询安全|真实列表页|list-template lint/i,
|
|
12284
|
+
mentionPattern: /列表模板|list-template|list_template|列表配置|操作列/
|
|
12285
|
+
},
|
|
12286
|
+
{
|
|
12287
|
+
domain: "filter-template",
|
|
12288
|
+
skill: "bpmax-filter-template-editor",
|
|
12289
|
+
lockPattern: /filter-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12290
|
+
writeEvidence: [/bpmax-cli config filter-template lint/, /bpmax-cli config filter-template build/, /bpmax-cli config filter-template submit/, /bpmax-cli config filter-template verify/],
|
|
12291
|
+
readonlyEvidence: [/bpmax-cli config filter-template export|筛选.*回读|readback/i],
|
|
12292
|
+
constraintEvidence: /筛选字段|筛选器|查询条件|filter-template lint/i,
|
|
12293
|
+
mentionPattern: /筛选模板|筛选器|filter-template|filter_template/
|
|
12294
|
+
},
|
|
12295
|
+
{
|
|
12296
|
+
domain: "project-detail-template",
|
|
12297
|
+
skill: "bpmax-project-detail-template-editor",
|
|
12298
|
+
lockPattern: /project-detail-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12299
|
+
writeEvidence: [/bpmax-cli config project-detail-template lint/, /bpmax-cli config project-detail-template build/, /bpmax-cli config project-detail-template submit/, /bpmax-cli config project-detail-template verify/],
|
|
12300
|
+
readonlyEvidence: [/bpmax-cli config project-detail-template export|详情.*回读|resolve-default|readback/i],
|
|
12301
|
+
constraintEvidence: /默认详情模板|resolve-default|详情页|project_detail|project-detail-template lint/i,
|
|
12302
|
+
mentionPattern: /详情模板|项目详情|project-detail-template|project_detail/
|
|
12303
|
+
},
|
|
12304
|
+
{
|
|
12305
|
+
domain: "console-template",
|
|
12306
|
+
skill: "bpmax-console-template-editor",
|
|
12307
|
+
lockPattern: /console-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12308
|
+
writeEvidence: [/bpmax-cli config console-template lint/, /bpmax-cli config console-template build/, /bpmax-cli config console-template submit/, /bpmax-cli config console-template verify/],
|
|
12309
|
+
readonlyEvidence: [/bpmax-cli config console-template export|看板.*回读|readback/i],
|
|
12310
|
+
constraintEvidence: /数据看板|图表|指标|console-template lint/i,
|
|
12311
|
+
mentionPattern: /看板模板|数据看板|console-template|console_template/
|
|
12312
|
+
},
|
|
12313
|
+
{
|
|
12314
|
+
domain: "dataset",
|
|
12315
|
+
skill: "bpmax-dataset-template-editor",
|
|
12316
|
+
lockPattern: /dataset:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12317
|
+
writeEvidence: [/bpmax-cli config dataset lint/, /bpmax-cli config dataset build/, /bpmax-cli config dataset submit/, /bpmax-cli config dataset verify/],
|
|
12318
|
+
readonlyEvidence: [/bpmax-cli config dataset export|数据集.*回读|readback/i],
|
|
12319
|
+
constraintEvidence: /字段关联|relationFields|publish|refresh|数据集约束/i,
|
|
12320
|
+
mentionPattern: /数据集(?!字段)|dataset(?!-field)|data_set(?!_field)/
|
|
12321
|
+
},
|
|
12322
|
+
{
|
|
12323
|
+
domain: "dataset-field",
|
|
12324
|
+
skill: "bpmax-dataset-field-template-editor",
|
|
12325
|
+
lockPattern: /dataset-field:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12326
|
+
writeEvidence: [/bpmax-cli config dataset-field lint/, /bpmax-cli config dataset-field build/, /bpmax-cli config dataset-field submit/, /bpmax-cli config dataset-field verify/],
|
|
12327
|
+
readonlyEvidence: [/bpmax-cli config dataset-field export|数据集字段.*回读|readback/i],
|
|
12328
|
+
constraintEvidence: /source_table|source_field|source_fk|source mapping|字段映射|来源表|数据集字段约束/i,
|
|
12329
|
+
mentionPattern: /数据集字段|dataset-field|data_set_field/
|
|
12330
|
+
},
|
|
12331
|
+
{
|
|
12332
|
+
domain: "api-platform",
|
|
12333
|
+
skill: "bpmax-api-platform-editor",
|
|
12334
|
+
lockPattern: /api-platform:[A-Za-z0-9_-]+/,
|
|
12335
|
+
writeEvidence: [/bpmax-cli config api-platform lint/, /bpmax-cli config api-platform build/, /bpmax-cli config api-platform submit/, /bpmax-cli config api-platform verify/],
|
|
12336
|
+
readonlyEvidence: [/bpmax-cli config api-platform export|API.*回读|readback/i],
|
|
12337
|
+
constraintEvidence: /实例|代理|绑定|API 平台|api-platform lint/i,
|
|
12338
|
+
mentionPattern: /API 平台|api-platform|系统集成|接口代理/
|
|
12339
|
+
},
|
|
12340
|
+
{
|
|
12341
|
+
domain: "role",
|
|
12342
|
+
skill: "bpmax-role-editor",
|
|
12343
|
+
lockPattern: /role:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12344
|
+
writeEvidence: [/bpmax-cli config role lint/, /bpmax-cli config role build/, /bpmax-cli config role submit/, /bpmax-cli config role verify/],
|
|
12345
|
+
readonlyEvidence: [/bpmax-cli config role export|角色.*回读|readback/i],
|
|
12346
|
+
constraintEvidence: /权限点|成员|角色权限|role lint/i,
|
|
12347
|
+
mentionPattern: /角色|权限|role/
|
|
12348
|
+
},
|
|
12349
|
+
{
|
|
12350
|
+
domain: "nav-config",
|
|
12351
|
+
skill: "bpmax-nav-config-editor",
|
|
12352
|
+
lockPattern: /nav-config:[A-Za-z0-9_-]+/,
|
|
12353
|
+
writeEvidence: [/bpmax-cli config nav-config lint/, /bpmax-cli config nav-config build/, /bpmax-cli config nav-config submit/, /bpmax-cli config nav-config verify|入口.*浏览器|导航.*浏览器/],
|
|
12354
|
+
readonlyEvidence: [/bpmax-cli config nav-config export|导航.*回读|readback/i],
|
|
12355
|
+
constraintEvidence: /入口|导航|PC|H5|快捷入口|浏览器.*打开/i,
|
|
12356
|
+
mentionPattern: /导航|入口|nav-config|菜单|快捷入口/
|
|
12357
|
+
},
|
|
12358
|
+
{
|
|
12359
|
+
domain: "workspace",
|
|
12360
|
+
skill: "bpmax-workspace-editor",
|
|
12361
|
+
lockPattern: /workspace:[A-Za-z0-9_-]+/,
|
|
12362
|
+
writeEvidence: [/bpmax-cli config workspace lint/, /bpmax-cli config workspace build/, /bpmax-cli config workspace submit/, /bpmax-cli config workspace verify/],
|
|
12363
|
+
readonlyEvidence: [/bpmax-cli config workspace export|工作区.*回读|readback/i],
|
|
12364
|
+
constraintEvidence: /workspace key|entry_path|工作区约束|workspace lint/i,
|
|
12365
|
+
mentionPattern: /创建工作区|编辑工作区|工作区配置|config workspace|workspace config/
|
|
12366
|
+
},
|
|
12367
|
+
{
|
|
12368
|
+
domain: "workspace-flow",
|
|
12369
|
+
skill: "bpmax-workspace-editor",
|
|
12370
|
+
lockPattern: /workspace-flow:[A-Za-z0-9_-]+/,
|
|
12371
|
+
writeEvidence: [/bpmax-cli config workspace-flow lint/, /bpmax-cli config workspace-flow build/, /bpmax-cli config workspace-flow submit/, /bpmax-cli config workspace-flow verify/],
|
|
12372
|
+
readonlyEvidence: [/bpmax-cli config workspace-flow export|工作区流程.*回读|readback/i],
|
|
12373
|
+
constraintEvidence: /全量替换|重新 export|绑定|workspace-flow/i,
|
|
12374
|
+
mentionPattern: /工作区流程|流程绑定|workspace-flow/
|
|
12375
|
+
},
|
|
12376
|
+
{
|
|
12377
|
+
domain: "e2e",
|
|
12378
|
+
skill: "bpmax-e2e-flow-test-operator",
|
|
12379
|
+
lockPattern: /(?:e2e|test-suite):[A-Za-z0-9_-]+/,
|
|
12380
|
+
writeEvidence: [/bpmax-cli test-suite lint|浏览器|真实页面|E2E|截图|测试报告/i],
|
|
12381
|
+
readonlyEvidence: [/浏览器|真实页面|E2E|截图|测试报告/i],
|
|
12382
|
+
constraintEvidence: /真实业务|测试数据|浏览器|截图|test_data|E2E/i,
|
|
12383
|
+
mentionPattern: /E2E|端到端|浏览器测试|测试用例|回归测试/
|
|
12384
|
+
}
|
|
12385
|
+
];
|
|
12386
|
+
function isWriteMode(rowOrText) {
|
|
12387
|
+
const mode = typeof rowOrText === "string" ? rowOrText.match(/subagent_mode\s*[::]\s*([^\n]+)/)?.[1] || "" : rowOrText.subagent_mode || "";
|
|
12388
|
+
return !/\breadonly\b/i.test(mode);
|
|
12389
|
+
}
|
|
12390
|
+
function hasConfigAdaptersEvidence(value) {
|
|
12391
|
+
return /bpmax-cli config adapters --format json/.test(value) && /(capability|能力|adapter|适配|config\.)/i.test(value);
|
|
12392
|
+
}
|
|
12393
|
+
function hasDomainWriteEvidence(domain, evidenceText, patterns) {
|
|
12394
|
+
const shorthand = new RegExp(`bpmax-cli config ${domain} (?:export/)?lint/build/submit/verify`);
|
|
12395
|
+
return shorthand.test(evidenceText) || patterns.every((pattern) => pattern.test(evidenceText));
|
|
12396
|
+
}
|
|
11017
12397
|
function uuidErrors(text5, target) {
|
|
11018
12398
|
const values = [...new Set([...text5.matchAll(UUID_PATTERN)].map((match) => match[0]))];
|
|
11019
12399
|
return values.map(
|
|
@@ -11021,7 +12401,7 @@ function uuidErrors(text5, target) {
|
|
|
11021
12401
|
);
|
|
11022
12402
|
}
|
|
11023
12403
|
async function readTaskbookText(file) {
|
|
11024
|
-
const raw = await
|
|
12404
|
+
const raw = await readFile12(file, "utf8");
|
|
11025
12405
|
try {
|
|
11026
12406
|
const parsed = JSON.parse(raw);
|
|
11027
12407
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
@@ -11094,6 +12474,56 @@ function validateTaskbookNavigationAndListGates(text5, errors) {
|
|
|
11094
12474
|
}
|
|
11095
12475
|
});
|
|
11096
12476
|
}
|
|
12477
|
+
function rowText(row) {
|
|
12478
|
+
return [
|
|
12479
|
+
row.business_goal,
|
|
12480
|
+
row.required_skills,
|
|
12481
|
+
row.object_lock,
|
|
12482
|
+
row.evidence,
|
|
12483
|
+
row.notes,
|
|
12484
|
+
row.parallel_type
|
|
12485
|
+
].filter(Boolean).join(" ");
|
|
12486
|
+
}
|
|
12487
|
+
function validateConfigRuleForTaskRow(row, rule, errors) {
|
|
12488
|
+
const taskId = row.task_id || "<unknown>";
|
|
12489
|
+
const combined = rowText(row);
|
|
12490
|
+
const hasSkill = (row.required_skills || "").includes(rule.skill);
|
|
12491
|
+
const mentionsDomain = rule.mentionPattern.test(combined) || rule.lockPattern.test(row.object_lock || "");
|
|
12492
|
+
if (mentionsDomain && !hasSkill) {
|
|
12493
|
+
errors.push(`${rule.domain} task ${taskId} mentions ${rule.domain} work but missing required skill ${rule.skill}.`);
|
|
12494
|
+
return;
|
|
12495
|
+
}
|
|
12496
|
+
if (!hasSkill) {
|
|
12497
|
+
return;
|
|
12498
|
+
}
|
|
12499
|
+
const writeMode = isWriteMode(row);
|
|
12500
|
+
if (writeMode && !rule.lockPattern.test(row.object_lock || "")) {
|
|
12501
|
+
errors.push(`${rule.domain} task ${taskId} must use object_lock matching ${rule.domain}:<id> or its documented lock pattern.`);
|
|
12502
|
+
}
|
|
12503
|
+
if (!writeMode && !/^readonly:[A-Za-z0-9_-]+/.test(row.object_lock || "") && !rule.lockPattern.test(row.object_lock || "")) {
|
|
12504
|
+
errors.push(`${rule.domain} readonly task ${taskId} must use readonly:<scope> or the ${rule.domain} object lock.`);
|
|
12505
|
+
}
|
|
12506
|
+
const evidenceText = `${row.evidence || ""} ${row.notes || ""}`;
|
|
12507
|
+
const hasRequiredEvidence = writeMode ? hasDomainWriteEvidence(rule.domain, evidenceText, rule.writeEvidence) : rule.readonlyEvidence.some((pattern) => pattern.test(evidenceText));
|
|
12508
|
+
if (!hasRequiredEvidence) {
|
|
12509
|
+
const expected = writeMode ? `bpmax-cli config ${rule.domain} lint/build/submit/verify evidence` : `bpmax-cli config ${rule.domain} export/readback evidence`;
|
|
12510
|
+
errors.push(`${rule.domain} task ${taskId} missing ${expected}.`);
|
|
12511
|
+
}
|
|
12512
|
+
if (!rule.constraintEvidence.test(evidenceText)) {
|
|
12513
|
+
errors.push(`${rule.domain} task ${taskId} missing domain-specific constraints from ${rule.skill}.`);
|
|
12514
|
+
}
|
|
12515
|
+
if (writeMode && !hasConfigAdaptersEvidence(evidenceText)) {
|
|
12516
|
+
errors.push(`${rule.domain} task ${taskId} is write-capable but missing bpmax-cli config adapters --format json capability/adapters evidence.`);
|
|
12517
|
+
}
|
|
12518
|
+
}
|
|
12519
|
+
function validateTaskbookConfigSkillGates(text5, errors) {
|
|
12520
|
+
const rows = extractTaskRows(text5);
|
|
12521
|
+
for (const row of rows) {
|
|
12522
|
+
for (const rule of CONFIG_TASK_RULES) {
|
|
12523
|
+
validateConfigRuleForTaskRow(row, rule, errors);
|
|
12524
|
+
}
|
|
12525
|
+
}
|
|
12526
|
+
}
|
|
11097
12527
|
function validatePromptNavigationAndListGates(text5, errors) {
|
|
11098
12528
|
const strategy = validateNavigationStrategy(text5, errors, "prompt ");
|
|
11099
12529
|
const hasNavSkill = /bpmax-nav-config-editor/.test(text5);
|
|
@@ -11113,6 +12543,39 @@ function validatePromptNavigationAndListGates(text5, errors) {
|
|
|
11113
12543
|
}
|
|
11114
12544
|
}
|
|
11115
12545
|
}
|
|
12546
|
+
function validatePromptConfigSkillGates(text5, errors) {
|
|
12547
|
+
const objectLock = promptObjectLockText(text5);
|
|
12548
|
+
const writeMode = isWriteMode(text5);
|
|
12549
|
+
const actionableText = text5.split(/\r?\n/).filter((line) => !/^\s*(导航入口策略|列表 lint)\s*[::]/.test(line)).join("\n");
|
|
12550
|
+
for (const rule of CONFIG_TASK_RULES) {
|
|
12551
|
+
const hasSkill = text5.includes(rule.skill);
|
|
12552
|
+
const mentionsDomain = rule.mentionPattern.test(actionableText) || rule.lockPattern.test(objectLock);
|
|
12553
|
+
if (mentionsDomain && !hasSkill) {
|
|
12554
|
+
errors.push(`prompt mentions ${rule.domain} work but missing required skill ${rule.skill}.`);
|
|
12555
|
+
continue;
|
|
12556
|
+
}
|
|
12557
|
+
if (!hasSkill) {
|
|
12558
|
+
continue;
|
|
12559
|
+
}
|
|
12560
|
+
if (writeMode && !rule.lockPattern.test(objectLock)) {
|
|
12561
|
+
errors.push(`prompt ${rule.domain} work must include object lock matching ${rule.domain}:<id> or its documented lock pattern.`);
|
|
12562
|
+
}
|
|
12563
|
+
if (!writeMode && !/^readonly:[A-Za-z0-9_-]+/.test(objectLock) && !rule.lockPattern.test(objectLock)) {
|
|
12564
|
+
errors.push(`prompt ${rule.domain} readonly work must include readonly:<scope> or the ${rule.domain} object lock.`);
|
|
12565
|
+
}
|
|
12566
|
+
const hasRequiredEvidence = writeMode ? hasDomainWriteEvidence(rule.domain, text5, rule.writeEvidence) : rule.readonlyEvidence.some((pattern) => pattern.test(text5));
|
|
12567
|
+
if (!hasRequiredEvidence) {
|
|
12568
|
+
const expected = writeMode ? `bpmax-cli config ${rule.domain} lint/build/submit/verify evidence` : `bpmax-cli config ${rule.domain} export/readback evidence`;
|
|
12569
|
+
errors.push(`prompt ${rule.domain} work missing ${expected}.`);
|
|
12570
|
+
}
|
|
12571
|
+
if (!rule.constraintEvidence.test(text5)) {
|
|
12572
|
+
errors.push(`prompt ${rule.domain} work missing domain-specific constraints from ${rule.skill}.`);
|
|
12573
|
+
}
|
|
12574
|
+
if (writeMode && !hasConfigAdaptersEvidence(text5)) {
|
|
12575
|
+
errors.push(`prompt ${rule.domain} write work missing bpmax-cli config adapters --format json capability/adapters evidence.`);
|
|
12576
|
+
}
|
|
12577
|
+
}
|
|
12578
|
+
}
|
|
11116
12579
|
async function lintTaskbook(file, options = {}) {
|
|
11117
12580
|
const text5 = await readTaskbookText(file);
|
|
11118
12581
|
const errors = [
|
|
@@ -11130,6 +12593,7 @@ async function lintTaskbook(file, options = {}) {
|
|
|
11130
12593
|
errors.push(...uuidErrors(text5, "taskbooks"));
|
|
11131
12594
|
errors.push(...missingTermErrors(text5, SUBAGENT_TERMS, "missing subagent rule term"));
|
|
11132
12595
|
validateTaskbookNavigationAndListGates(text5, errors);
|
|
12596
|
+
validateTaskbookConfigSkillGates(text5, errors);
|
|
11133
12597
|
for (const match of text5.matchAll(FLOW_LOCK_PATTERN)) {
|
|
11134
12598
|
const value = match[1] || "";
|
|
11135
12599
|
if (value.startsWith("flow") && /^flow\d+$/.test(value)) {
|
|
@@ -11155,6 +12619,7 @@ async function lintTaskPrompt(file, options = {}) {
|
|
|
11155
12619
|
}
|
|
11156
12620
|
errors.push(...uuidErrors(text5, "task prompts"));
|
|
11157
12621
|
validatePromptNavigationAndListGates(text5, errors);
|
|
12622
|
+
validatePromptConfigSkillGates(text5, errors);
|
|
11158
12623
|
for (const term of options.forbidTerms || []) {
|
|
11159
12624
|
if (term && text5.includes(term)) {
|
|
11160
12625
|
errors.push(`prompt forbidden term present: ${term}`);
|
|
@@ -11202,15 +12667,25 @@ function taskbookTemplate(title = "BPMAX AI \u5B9E\u65BD\u7F16\u6392\u4EFB\u52A1
|
|
|
11202
12667
|
"| new-flow:<\u6D41\u7A0B\u540D\u79F0> | \u65B0\u6D41\u7A0B\u521B\u5EFA\u524D\u903B\u8F91\u9501 | \u521B\u5EFA\u524D\u6392\u4ED6 | \u5F53\u6210\u771F\u5B9E flow_type \u4F7F\u7528 |",
|
|
11203
12668
|
"| flow:<BPMAX\u751F\u6210\u7684\u771F\u5B9Eflow_type> | \u6D41\u7A0B | \u914D\u7F6E\u548C\u53D1\u5E03 | \u5176\u4ED6\u4EFB\u52A1\u540C\u65F6\u4FDD\u5B58\u53D1\u5E03 |",
|
|
11204
12669
|
"",
|
|
12670
|
+
"## \u914D\u7F6E Skill / Capability \u4F9D\u636E\u8868",
|
|
12671
|
+
"",
|
|
12672
|
+
"| \u914D\u7F6E\u5BF9\u8C61 | required_skills | typed CLI / capability evidence | \u4E13\u9879\u7EA6\u675F |",
|
|
12673
|
+
"|---|---|---|---|",
|
|
12674
|
+
"| \u6D41\u7A0B\u6A21\u677F | bpmax-flow-template-editor | bpmax-cli config flow-template export/lint/build/submit/verify\uFF1B\u5199\u4EFB\u52A1\u5148\u8DD1 bpmax-cli config adapters --format json \u6838\u5BF9 capability/adapter | project_after_create_path\u3001message_template\u3001matrix_owner\u3001\u6D41\u7A0B\u6A21\u677F\u7EA6\u675F |",
|
|
12675
|
+
"| \u8868\u5355\u6A21\u677F | bpmax-form-template-editor | bpmax-cli config form-template export/lint/build/submit/verify\uFF1B\u5199\u4EFB\u52A1\u5148\u8DD1 bpmax-cli config adapters --format json \u6838\u5BF9 capability/adapter | \u5B57\u6BB5 schema\u3001\u8868\u5355\u987A\u5E8F\u3001raw.value\u3001layout\u3001sub_form\u3001form-template inspect |",
|
|
12676
|
+
"| \u5217\u8868\u6A21\u677F | bpmax-list-template-editor | bpmax-cli config list-template lint/build/submit/verify\uFF1B\u5199\u4EFB\u52A1\u5148\u8DD1 bpmax-cli config adapters --format json \u6838\u5BF9 capability/adapter | \u64CD\u4F5C\u5217\u3001\u8BE6\u60C5\u52A8\u4F5C\u3001\u5220\u9664 guard\u3001icon\u3001\u67E5\u8BE2\u5B89\u5168\u3001\u771F\u5B9E\u5217\u8868\u9875 |",
|
|
12677
|
+
"| \u5BFC\u822A\u914D\u7F6E | bpmax-nav-config-editor | bpmax-cli config nav-config lint/build/submit/verify\uFF1B\u5199\u4EFB\u52A1\u5148\u8DD1 bpmax-cli config adapters --format json \u6838\u5BF9 capability/adapter | PC/H5 \u5BFC\u822A\u3001\u5FEB\u6377\u5165\u53E3\u3001\u6D4F\u89C8\u5668\u6253\u5F00\u9A8C\u8BC1 |",
|
|
12678
|
+
"",
|
|
11205
12679
|
"## AI \u6700\u5C0F\u4EFB\u52A1\u5355\u5143",
|
|
11206
12680
|
"",
|
|
11207
12681
|
"| task_id | status | phase | parallel_type | subagent_mode | business_goal | required_skills | object_lock | dependencies | owner | evidence | notes |",
|
|
11208
12682
|
"|---|---|---|---|---|---|---|---|---|---|---|---|",
|
|
11209
12683
|
"| T00 | \u672A\u5F00\u59CB | 0 | \u5355\u7EBF | none | \u786E\u8BA4\u7EBF\u4E0A\u57FA\u7EBF\u548C\u8303\u56F4 | bpmax-e2e-flow-config-orchestrator | global:baseline | | \u4E3B\u7EBF\u7A0B | | |",
|
|
11210
|
-
"| T01 | \u672A\u5F00\u59CB | 1 | \u53EA\u8BFB\u5E76\u884C | readonly | \u8C03\u7814\u76EE\u6807\u6D41\u7A0B\u548C\u8868\u5355 | bpmax-flow-template-editor,bpmax-form-template-editor | readonly:flow | T00 | \u5F85\u5206\u914D |
|
|
12684
|
+
"| T01 | \u672A\u5F00\u59CB | 1 | \u53EA\u8BFB\u5E76\u884C | readonly | \u8C03\u7814\u76EE\u6807\u6D41\u7A0B\u548C\u8868\u5355 | bpmax-flow-template-editor,bpmax-form-template-editor | readonly:flow | T00 | \u5F85\u5206\u914D | bpmax-cli config flow-template export\uFF1Bbpmax-cli config form-template export\uFF1B\u6D41\u7A0B\u56DE\u8BFB\uFF1B\u8868\u5355\u56DE\u8BFB | \u68C0\u67E5 project_after_create_path\u3001message_template\u3001\u5B57\u6BB5 schema\u3001\u8868\u5355\u987A\u5E8F\u3001raw.value\u3001layout\u3001sub_form |",
|
|
11211
12685
|
"",
|
|
11212
12686
|
"- \u6BCF\u4E2A\u4EFB\u52A1\u7684 `business_goal` \u90FD\u5FC5\u987B\u5199\u6E05\u695A\u4E1A\u52A1\u76EE\u6807\u573A\u666F\u3002",
|
|
11213
12687
|
"- \u6BCF\u4E2A\u4EFB\u52A1\u7684 `required_skills` \u90FD\u5FC5\u987B\u5217\u51FA\u5B9E\u9645\u8981\u4F7F\u7528\u7684 BPMAX skill\u3002",
|
|
12688
|
+
"- \u6BCF\u4E2A\u5199\u4EFB\u52A1\u7684 `evidence` \u6216 `notes` \u5FC5\u987B\u5305\u542B `bpmax-cli config adapters --format json` \u7684 capability/adapter \u68C0\u67E5\uFF0C\u4EE5\u53CA\u5BF9\u5E94 typed CLI lint/build/submit/verify\u3002",
|
|
11214
12689
|
"",
|
|
11215
12690
|
"## \u8FDB\u5EA6 CSV",
|
|
11216
12691
|
"",
|
|
@@ -11252,8 +12727,8 @@ function taskbookTemplate(title = "BPMAX AI \u5B9E\u65BD\u7F16\u6392\u4EFB\u52A1
|
|
|
11252
12727
|
}
|
|
11253
12728
|
async function initTaskbook(outFile, title) {
|
|
11254
12729
|
const content = taskbookTemplate(title);
|
|
11255
|
-
await
|
|
11256
|
-
await
|
|
12730
|
+
await mkdir9(path9.dirname(outFile), { recursive: true });
|
|
12731
|
+
await writeFile9(outFile, content, "utf8");
|
|
11257
12732
|
return { out: outFile, bytes: Buffer.byteLength(content) };
|
|
11258
12733
|
}
|
|
11259
12734
|
function splitMarkdownRow(line) {
|
|
@@ -11342,8 +12817,8 @@ async function initTaskbookProgress(source, outFile) {
|
|
|
11342
12817
|
fields.join(","),
|
|
11343
12818
|
...rows.map((row) => fields.map((field) => csvEscape(field === "status" ? "\u672A\u5F00\u59CB" : row[field] || "")).join(","))
|
|
11344
12819
|
].join("\n") + "\n";
|
|
11345
|
-
await
|
|
11346
|
-
await
|
|
12820
|
+
await mkdir9(path9.dirname(outFile), { recursive: true });
|
|
12821
|
+
await writeFile9(outFile, csv, "utf8");
|
|
11347
12822
|
return { source, out: outFile, task_count: rows.length };
|
|
11348
12823
|
}
|
|
11349
12824
|
|
|
@@ -11385,18 +12860,18 @@ function registerTaskbookCommands(program2) {
|
|
|
11385
12860
|
}
|
|
11386
12861
|
|
|
11387
12862
|
// src/core/test-suite.ts
|
|
11388
|
-
import { createHash as
|
|
12863
|
+
import { createHash as createHash5 } from "crypto";
|
|
11389
12864
|
import {
|
|
11390
12865
|
copyFile,
|
|
11391
|
-
cp as
|
|
11392
|
-
mkdir as
|
|
11393
|
-
readdir as
|
|
11394
|
-
readFile as
|
|
11395
|
-
rm as
|
|
11396
|
-
stat as
|
|
11397
|
-
writeFile as
|
|
12866
|
+
cp as cp3,
|
|
12867
|
+
mkdir as mkdir10,
|
|
12868
|
+
readdir as readdir4,
|
|
12869
|
+
readFile as readFile13,
|
|
12870
|
+
rm as rm4,
|
|
12871
|
+
stat as stat5,
|
|
12872
|
+
writeFile as writeFile10
|
|
11398
12873
|
} from "fs/promises";
|
|
11399
|
-
import
|
|
12874
|
+
import path10 from "path";
|
|
11400
12875
|
var DEFAULT_SUITE_ROOT = ".ai_test/suite";
|
|
11401
12876
|
var DEFAULT_DRAFT_ROOT = ".ai_test/suite_draft";
|
|
11402
12877
|
var DEFAULT_REPORT_ROOT = ".ai_test/report";
|
|
@@ -11479,16 +12954,16 @@ var IDENTITY_MOCK_CASE_RE = /(非处理人|越权|只读|多角色|角色隔离|
|
|
|
11479
12954
|
var IDENTITY_MOCK_VALUE_RE = /(mock|模拟).*(unmock|退出模拟|恢复)|bpmax-user-mock-operator/;
|
|
11480
12955
|
var TestSuiteError = class extends Error {
|
|
11481
12956
|
};
|
|
11482
|
-
async function
|
|
12957
|
+
async function exists3(filePath) {
|
|
11483
12958
|
try {
|
|
11484
|
-
await
|
|
12959
|
+
await stat5(filePath);
|
|
11485
12960
|
return true;
|
|
11486
12961
|
} catch {
|
|
11487
12962
|
return false;
|
|
11488
12963
|
}
|
|
11489
12964
|
}
|
|
11490
12965
|
async function readText(filePath) {
|
|
11491
|
-
return
|
|
12966
|
+
return readFile13(filePath, "utf8");
|
|
11492
12967
|
}
|
|
11493
12968
|
function fail(message) {
|
|
11494
12969
|
throw new TestSuiteError(message);
|
|
@@ -11542,11 +13017,11 @@ function reviewSchemaExplanation() {
|
|
|
11542
13017
|
};
|
|
11543
13018
|
}
|
|
11544
13019
|
function reviewFail(reviewPath, message) {
|
|
11545
|
-
const scenarioId =
|
|
13020
|
+
const scenarioId = path10.basename(path10.dirname(reviewPath));
|
|
11546
13021
|
fail([
|
|
11547
13022
|
message,
|
|
11548
13023
|
`Run \`bpmax-cli test-suite review explain --format json\` for the full schema.`,
|
|
11549
|
-
`Run \`bpmax-cli test-suite review repair --scenario ${scenarioId} --draft-root ${
|
|
13024
|
+
`Run \`bpmax-cli test-suite review repair --scenario ${scenarioId} --draft-root ${path10.dirname(path10.dirname(reviewPath))} --latest-proof <proof.json> --format json\` to fill missing fields.`,
|
|
11550
13025
|
`Minimal review.json example: ${JSON.stringify(reviewSchemaExample(scenarioId))}`
|
|
11551
13026
|
].join("\n"));
|
|
11552
13027
|
}
|
|
@@ -11576,7 +13051,7 @@ function splitCsvLine(line) {
|
|
|
11576
13051
|
return values;
|
|
11577
13052
|
}
|
|
11578
13053
|
async function readCases(filePath) {
|
|
11579
|
-
if (!await
|
|
13054
|
+
if (!await exists3(filePath)) fail(`missing cases.csv: ${filePath}`);
|
|
11580
13055
|
const text5 = (await readText(filePath)).replace(/^\uFEFF/, "");
|
|
11581
13056
|
const lines = text5.split(/\r?\n/).filter((line) => line.length > 0);
|
|
11582
13057
|
if (lines.length === 0) fail(`${filePath}: CSV fields must be exactly ${JSON.stringify(CASE_FIELDS)}`);
|
|
@@ -11628,14 +13103,14 @@ function parseReadmeText(filePath, text5) {
|
|
|
11628
13103
|
return metadata;
|
|
11629
13104
|
}
|
|
11630
13105
|
async function validateReadme(scenarioDir) {
|
|
11631
|
-
const readmePath =
|
|
11632
|
-
if (!await
|
|
13106
|
+
const readmePath = path10.join(scenarioDir, "README.md");
|
|
13107
|
+
if (!await exists3(readmePath)) fail(`missing README.md: ${readmePath}`);
|
|
11633
13108
|
const text5 = await readText(readmePath);
|
|
11634
13109
|
const metadata = parseReadmeText(readmePath, text5);
|
|
11635
13110
|
for (const key of REQUIRED_README_KEYS) {
|
|
11636
13111
|
if (!metadata[key]) fail(`${scenarioDir}: README.md missing \`${key}\``);
|
|
11637
13112
|
}
|
|
11638
|
-
if (metadata.scenario_id !==
|
|
13113
|
+
if (metadata.scenario_id !== path10.basename(scenarioDir)) fail(`${scenarioDir}: scenario_id must match directory name`);
|
|
11639
13114
|
if (!["true", "false"].includes(metadata.core.toLowerCase())) fail(`${scenarioDir}: core must be true or false`);
|
|
11640
13115
|
if (!STATUSES.has(metadata.status)) fail(`${scenarioDir}: status must be one of ${JSON.stringify([...STATUSES].sort())}`);
|
|
11641
13116
|
if (UUID_RE2.test(text5) || ID_AS_ENTRY_RE.test(text5)) {
|
|
@@ -11655,7 +13130,7 @@ async function validateConfigBasis(filePath, caseId, configBasis) {
|
|
|
11655
13130
|
if (!CONFIG_BASIS_REASON_RE.test(configBasis)) fail(`${filePath}:${caseId}: \`config_basis\` must explain why`);
|
|
11656
13131
|
const missing = [];
|
|
11657
13132
|
for (const location of locations) {
|
|
11658
|
-
if (!await
|
|
13133
|
+
if (!await exists3(location)) missing.push(location);
|
|
11659
13134
|
}
|
|
11660
13135
|
if (missing.length > 0) fail(`${filePath}:${caseId}: \`config_basis\` references missing config location(s): ${missing.join(", ")}`);
|
|
11661
13136
|
}
|
|
@@ -11777,13 +13252,13 @@ async function validateCase(filePath, row, seen) {
|
|
|
11777
13252
|
validateBusinessTestData(filePath, caseId, row);
|
|
11778
13253
|
}
|
|
11779
13254
|
async function scenarioDirs(root) {
|
|
11780
|
-
if (!await
|
|
11781
|
-
const items = await
|
|
11782
|
-
return items.filter((item) => item.isDirectory()).map((item) =>
|
|
13255
|
+
if (!await exists3(root)) return [];
|
|
13256
|
+
const items = await readdir4(root, { withFileTypes: true });
|
|
13257
|
+
return items.filter((item) => item.isDirectory()).map((item) => path10.join(root, item.name)).sort();
|
|
11783
13258
|
}
|
|
11784
13259
|
async function validateScenario(scenarioDir) {
|
|
11785
13260
|
const metadata = await validateReadme(scenarioDir);
|
|
11786
|
-
const casesPath =
|
|
13261
|
+
const casesPath = path10.join(scenarioDir, "cases.csv");
|
|
11787
13262
|
const rows = await readCases(casesPath);
|
|
11788
13263
|
if (rows.length === 0) fail(`${casesPath}: at least one case is required`);
|
|
11789
13264
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -11838,7 +13313,7 @@ async function requireLatestProof(proofPath) {
|
|
|
11838
13313
|
}
|
|
11839
13314
|
async function readLatestProof(proofPath) {
|
|
11840
13315
|
if (!proofPath) fail("--latest-proof is required");
|
|
11841
|
-
if (!await
|
|
13316
|
+
if (!await exists3(proofPath)) fail(`latest proof is required before this command: ${proofPath}`);
|
|
11842
13317
|
let proof;
|
|
11843
13318
|
try {
|
|
11844
13319
|
proof = JSON.parse(await readText(proofPath));
|
|
@@ -11858,9 +13333,9 @@ function validateLatestProofObject(proofPath, proof) {
|
|
|
11858
13333
|
}
|
|
11859
13334
|
function scenarioPath(root, scenario) {
|
|
11860
13335
|
if (!SCENARIO_ID_RE.test(scenario)) fail(`invalid scenario id: ${scenario}`);
|
|
11861
|
-
const rootResolved =
|
|
11862
|
-
const candidate =
|
|
11863
|
-
if (!candidate.startsWith(`${rootResolved}${
|
|
13336
|
+
const rootResolved = path10.resolve(root);
|
|
13337
|
+
const candidate = path10.resolve(root, scenario);
|
|
13338
|
+
if (!candidate.startsWith(`${rootResolved}${path10.sep}`) && candidate !== rootResolved) {
|
|
11864
13339
|
fail(`scenario path escapes root: ${candidate}`);
|
|
11865
13340
|
}
|
|
11866
13341
|
return candidate;
|
|
@@ -11868,14 +13343,14 @@ function scenarioPath(root, scenario) {
|
|
|
11868
13343
|
async function fileMap(root) {
|
|
11869
13344
|
const result = /* @__PURE__ */ new Map();
|
|
11870
13345
|
async function walk(dir) {
|
|
11871
|
-
for (const item of await
|
|
11872
|
-
const itemPath =
|
|
11873
|
-
const rel =
|
|
11874
|
-
if (rel.split(
|
|
13346
|
+
for (const item of await readdir4(dir, { withFileTypes: true })) {
|
|
13347
|
+
const itemPath = path10.join(dir, item.name);
|
|
13348
|
+
const rel = path10.relative(root, itemPath);
|
|
13349
|
+
if (rel.split(path10.sep)[0] === COPY_DIFF_DIR) continue;
|
|
11875
13350
|
if (item.isDirectory()) {
|
|
11876
13351
|
await walk(itemPath);
|
|
11877
13352
|
} else if (item.isFile()) {
|
|
11878
|
-
result.set(rel.split(
|
|
13353
|
+
result.set(rel.split(path10.sep).join("/"), itemPath);
|
|
11879
13354
|
}
|
|
11880
13355
|
}
|
|
11881
13356
|
}
|
|
@@ -11883,11 +13358,11 @@ async function fileMap(root) {
|
|
|
11883
13358
|
return result;
|
|
11884
13359
|
}
|
|
11885
13360
|
async function sha256(filePath) {
|
|
11886
|
-
return
|
|
13361
|
+
return createHash5("sha256").update(await readFile13(filePath)).digest("hex");
|
|
11887
13362
|
}
|
|
11888
13363
|
async function readForDiff(filePath) {
|
|
11889
|
-
const buffer = await
|
|
11890
|
-
if (buffer.includes(0)) return [`<binary sha256=${
|
|
13364
|
+
const buffer = await readFile13(filePath);
|
|
13365
|
+
if (buffer.includes(0)) return [`<binary sha256=${createHash5("sha256").update(buffer).digest("hex")}>
|
|
11891
13366
|
`];
|
|
11892
13367
|
return buffer.toString("utf8").split(/(?<=\n)/);
|
|
11893
13368
|
}
|
|
@@ -11946,7 +13421,7 @@ async function buildCopyDiff(src, dst, operation) {
|
|
|
11946
13421
|
return {
|
|
11947
13422
|
manifest: {
|
|
11948
13423
|
operation,
|
|
11949
|
-
scenario_id:
|
|
13424
|
+
scenario_id: path10.basename(src),
|
|
11950
13425
|
source: src,
|
|
11951
13426
|
destination: dst,
|
|
11952
13427
|
generated_at: (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "+00:00"),
|
|
@@ -11959,12 +13434,12 @@ async function buildCopyDiff(src, dst, operation) {
|
|
|
11959
13434
|
};
|
|
11960
13435
|
}
|
|
11961
13436
|
async function writeCopyDiffArtifacts(dst, artifacts) {
|
|
11962
|
-
const diffDir =
|
|
11963
|
-
await
|
|
11964
|
-
await
|
|
11965
|
-
await
|
|
13437
|
+
const diffDir = path10.join(dst, COPY_DIFF_DIR);
|
|
13438
|
+
await mkdir10(diffDir, { recursive: true });
|
|
13439
|
+
await writeFile10(path10.join(diffDir, "last.diff"), artifacts.diff, "utf8");
|
|
13440
|
+
await writeFile10(path10.join(diffDir, "last.json"), `${JSON.stringify(artifacts.manifest, null, 2)}
|
|
11966
13441
|
`, "utf8");
|
|
11967
|
-
return
|
|
13442
|
+
return path10.join(diffDir, "last.diff");
|
|
11968
13443
|
}
|
|
11969
13444
|
function summarizeCopyDiff(artifacts) {
|
|
11970
13445
|
const files = Array.isArray(artifacts.manifest.files) ? artifacts.manifest.files : [];
|
|
@@ -11983,28 +13458,28 @@ function summarizeCopyDiff(artifacts) {
|
|
|
11983
13458
|
};
|
|
11984
13459
|
}
|
|
11985
13460
|
async function copyScenarioTree(src, dst, replace, operation) {
|
|
11986
|
-
if (!await
|
|
13461
|
+
if (!await exists3(src)) fail(`source scenario not found: ${src}`);
|
|
11987
13462
|
let artifacts;
|
|
11988
|
-
if (await
|
|
13463
|
+
if (await exists3(dst)) {
|
|
11989
13464
|
if (!replace) fail(`destination already exists, pass --replace: ${dst}`);
|
|
11990
13465
|
artifacts = await buildCopyDiff(src, dst, operation);
|
|
11991
|
-
await
|
|
13466
|
+
await rm4(dst, { recursive: true, force: true });
|
|
11992
13467
|
}
|
|
11993
|
-
await
|
|
11994
|
-
await
|
|
13468
|
+
await mkdir10(path10.dirname(dst), { recursive: true });
|
|
13469
|
+
await cp3(src, dst, { recursive: true });
|
|
11995
13470
|
return artifacts ? { path: await writeCopyDiffArtifacts(dst, artifacts), summary: summarizeCopyDiff(artifacts) } : {};
|
|
11996
13471
|
}
|
|
11997
13472
|
async function copyDiffPreview(src, dst, operation) {
|
|
11998
|
-
const previewDir =
|
|
11999
|
-
await
|
|
12000
|
-
await
|
|
13473
|
+
const previewDir = path10.join(DEFAULT_TMP_ROOT, `${operation}-${path10.basename(src)}-copy-diff`);
|
|
13474
|
+
await rm4(previewDir, { recursive: true, force: true });
|
|
13475
|
+
await mkdir10(previewDir, { recursive: true });
|
|
12001
13476
|
const artifacts = await buildCopyDiff(src, dst, operation);
|
|
12002
13477
|
return { path: await writeCopyDiffArtifacts(previewDir, artifacts), summary: summarizeCopyDiff(artifacts) };
|
|
12003
13478
|
}
|
|
12004
13479
|
async function draftUpdate(options) {
|
|
12005
13480
|
const src = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
|
|
12006
13481
|
const dst = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
|
|
12007
|
-
if (options.replace && !options.diffReviewed && await
|
|
13482
|
+
if (options.replace && !options.diffReviewed && await exists3(dst)) {
|
|
12008
13483
|
const preview = await copyDiffPreview(src, dst, "draft-update");
|
|
12009
13484
|
return {
|
|
12010
13485
|
copy_diff: preview.path,
|
|
@@ -12017,15 +13492,15 @@ async function draftUpdate(options) {
|
|
|
12017
13492
|
return { destination: dst, copy_diff: copyDiff.path, copy_diff_summary: copyDiff.summary };
|
|
12018
13493
|
}
|
|
12019
13494
|
async function validateReviewGate(scenarioDir) {
|
|
12020
|
-
const reviewPath =
|
|
12021
|
-
if (!await
|
|
13495
|
+
const reviewPath = path10.join(scenarioDir, "review.json");
|
|
13496
|
+
if (!await exists3(reviewPath)) reviewFail(reviewPath, `${scenarioDir}: missing review.json; run multi-subagent SKILL review before promote`);
|
|
12022
13497
|
let review;
|
|
12023
13498
|
try {
|
|
12024
13499
|
review = JSON.parse(await readText(reviewPath));
|
|
12025
13500
|
} catch (error) {
|
|
12026
13501
|
reviewFail(reviewPath, `${reviewPath}: invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
12027
13502
|
}
|
|
12028
|
-
if (review.scenario_id !==
|
|
13503
|
+
if (review.scenario_id !== path10.basename(scenarioDir)) reviewFail(reviewPath, `${reviewPath}: scenario_id must match directory name`);
|
|
12029
13504
|
if (!review.latest_proof || typeof review.latest_proof !== "object" || Array.isArray(review.latest_proof)) reviewFail(reviewPath, `${reviewPath}: latest_proof is required`);
|
|
12030
13505
|
validateLatestProofObject(reviewPath, review.latest_proof);
|
|
12031
13506
|
if (!REVIEW_STATUSES.has(String(review.status))) reviewFail(reviewPath, `${reviewPath}: status must be one of ${JSON.stringify([...REVIEW_STATUSES].sort())}`);
|
|
@@ -12061,7 +13536,7 @@ async function validateConfigConsistencyReview(reviewPath, item) {
|
|
|
12061
13536
|
}
|
|
12062
13537
|
const missing = [];
|
|
12063
13538
|
for (const location of judgment.config_basis_checked) {
|
|
12064
|
-
if (typeof location !== "string" || !await
|
|
13539
|
+
if (typeof location !== "string" || !await exists3(location)) missing.push(String(location));
|
|
12065
13540
|
}
|
|
12066
13541
|
if (missing.length > 0) reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` references missing checked location(s): ${missing.join(", ")}`);
|
|
12067
13542
|
if (!judgment.evidence) reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` missing evidence`);
|
|
@@ -12132,13 +13607,13 @@ function mergeReviewDraft(scenarioId, proof, rows, existing) {
|
|
|
12132
13607
|
}
|
|
12133
13608
|
async function initOrRepairReview(options) {
|
|
12134
13609
|
const scenarioDir = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
|
|
12135
|
-
if (!await
|
|
13610
|
+
if (!await exists3(scenarioDir)) fail(`draft scenario not found: ${scenarioDir}`);
|
|
12136
13611
|
await validateReadme(scenarioDir);
|
|
12137
|
-
const rows = await readCases(
|
|
13612
|
+
const rows = await readCases(path10.join(scenarioDir, "cases.csv"));
|
|
12138
13613
|
const proof = await readLatestProof(options.latestProof);
|
|
12139
|
-
const reviewPath =
|
|
13614
|
+
const reviewPath = path10.join(scenarioDir, "review.json");
|
|
12140
13615
|
let existing;
|
|
12141
|
-
const existed = await
|
|
13616
|
+
const existed = await exists3(reviewPath);
|
|
12142
13617
|
if (existed) {
|
|
12143
13618
|
if (!options.repair) fail(`${reviewPath}: already exists; pass --repair to update missing schema fields`);
|
|
12144
13619
|
try {
|
|
@@ -12147,8 +13622,8 @@ async function initOrRepairReview(options) {
|
|
|
12147
13622
|
existing = {};
|
|
12148
13623
|
}
|
|
12149
13624
|
}
|
|
12150
|
-
const review = mergeReviewDraft(
|
|
12151
|
-
await
|
|
13625
|
+
const review = mergeReviewDraft(path10.basename(scenarioDir), proof, rows, existing);
|
|
13626
|
+
await writeFile10(reviewPath, `${JSON.stringify(review, null, 2)}
|
|
12152
13627
|
`, "utf8");
|
|
12153
13628
|
return {
|
|
12154
13629
|
ok: true,
|
|
@@ -12163,7 +13638,7 @@ async function promoteScenario(options) {
|
|
|
12163
13638
|
await validateReviewGate(src);
|
|
12164
13639
|
if (metadata.status === "draft") fail(`${src}: cannot promote README status draft; set status to active or deprecated`);
|
|
12165
13640
|
const dst = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
|
|
12166
|
-
if (options.replace && !options.diffReviewed && await
|
|
13641
|
+
if (options.replace && !options.diffReviewed && await exists3(dst)) {
|
|
12167
13642
|
const preview = await copyDiffPreview(src, dst, "promote");
|
|
12168
13643
|
return {
|
|
12169
13644
|
copy_diff: preview.path,
|
|
@@ -12182,64 +13657,64 @@ async function nextReportDir(root = DEFAULT_REPORT_ROOT, create = false, today =
|
|
|
12182
13657
|
String(today.getDate()).padStart(2, "0")
|
|
12183
13658
|
].join("");
|
|
12184
13659
|
const dirs = await scenarioDirs(root);
|
|
12185
|
-
const nums = dirs.map((dir) =>
|
|
12186
|
-
const reportDir =
|
|
13660
|
+
const nums = dirs.map((dir) => path10.basename(dir)).filter((name) => name.startsWith(prefix)).map((name) => RUN_RE.exec(name)?.[1]).filter((value) => Boolean(value)).map((value) => Number(value));
|
|
13661
|
+
const reportDir = path10.join(root, `${prefix}-${String(Math.max(0, ...nums) + 1).padStart(3, "0")}`);
|
|
12187
13662
|
if (create) {
|
|
12188
|
-
await
|
|
12189
|
-
await
|
|
12190
|
-
|
|
12191
|
-
["# BPMAX E2E \u6D4B\u8BD5\u62A5\u544A\u6C47\u603B", "", `run_id: ${
|
|
13663
|
+
await mkdir10(path10.join(reportDir, "screenshots"), { recursive: true });
|
|
13664
|
+
await writeFile10(
|
|
13665
|
+
path10.join(reportDir, "summary.md"),
|
|
13666
|
+
["# BPMAX E2E \u6D4B\u8BD5\u62A5\u544A\u6C47\u603B", "", `run_id: ${path10.basename(reportDir)}`, "status: draft", "", "## \u573A\u666F\u62A5\u544A", "", "## \u603B\u7ED3", ""].join("\n"),
|
|
12192
13667
|
"utf8"
|
|
12193
13668
|
);
|
|
12194
13669
|
}
|
|
12195
13670
|
return reportDir;
|
|
12196
13671
|
}
|
|
12197
13672
|
async function lintReport(root = DEFAULT_REPORT_ROOT) {
|
|
12198
|
-
if (!await
|
|
13673
|
+
if (!await exists3(root)) return [`report root not found: ${root}`];
|
|
12199
13674
|
const errors = [];
|
|
12200
13675
|
for (const runDir of await scenarioDirs(root)) {
|
|
12201
|
-
const runName =
|
|
13676
|
+
const runName = path10.basename(runDir);
|
|
12202
13677
|
if (!RUN_RE.test(runName)) {
|
|
12203
13678
|
errors.push(`${runDir}: run directory name must be YYYYMMDD-NNN`);
|
|
12204
13679
|
continue;
|
|
12205
13680
|
}
|
|
12206
|
-
if (!await
|
|
12207
|
-
const files = await
|
|
13681
|
+
if (!await exists3(path10.join(runDir, "summary.md"))) errors.push(`${runDir}: missing summary.md`);
|
|
13682
|
+
const files = await readdir4(runDir);
|
|
12208
13683
|
const scenarioReports = files.filter((file) => file.endsWith(".md") && file !== "summary.md");
|
|
12209
13684
|
if (scenarioReports.length === 0) errors.push(`${runDir}: missing scenario report markdown`);
|
|
12210
13685
|
for (const reportName of scenarioReports) {
|
|
12211
|
-
const reportPath =
|
|
13686
|
+
const reportPath = path10.join(runDir, reportName);
|
|
12212
13687
|
const text5 = await readText(reportPath);
|
|
12213
13688
|
for (const key of REPORT_REQUIRED_KEYS) if (!text5.includes(key)) errors.push(`${reportPath}: missing \`${key}\``);
|
|
12214
13689
|
for (const heading of REPORT_REQUIRED_HEADINGS) if (!text5.includes(heading)) errors.push(`${reportPath}: missing \`${heading}\``);
|
|
12215
13690
|
const imageRefs = [...text5.matchAll(IMAGE_RE)].map((match) => match[1]);
|
|
12216
13691
|
if (imageRefs.length === 0) errors.push(`${reportPath}: missing embedded screenshot image`);
|
|
12217
|
-
const screenshotsDir =
|
|
12218
|
-
if (!await
|
|
13692
|
+
const screenshotsDir = path10.join(runDir, "screenshots");
|
|
13693
|
+
if (!await exists3(screenshotsDir)) errors.push(`${runDir}: missing screenshots directory`);
|
|
12219
13694
|
for (const imageRef of imageRefs) {
|
|
12220
13695
|
if (imageRef.includes("://")) {
|
|
12221
13696
|
errors.push(`${reportPath}: screenshot must be a local file under this run's screenshots directory`);
|
|
12222
13697
|
continue;
|
|
12223
13698
|
}
|
|
12224
|
-
const imagePath =
|
|
12225
|
-
const screenshotsResolved =
|
|
12226
|
-
if (!imagePath.startsWith(`${screenshotsResolved}${
|
|
13699
|
+
const imagePath = path10.resolve(path10.dirname(reportPath), imageRef);
|
|
13700
|
+
const screenshotsResolved = path10.resolve(screenshotsDir);
|
|
13701
|
+
if (!imagePath.startsWith(`${screenshotsResolved}${path10.sep}`)) {
|
|
12227
13702
|
errors.push(`${reportPath}: image reference must stay under this run's screenshots directory: ${imageRef}`);
|
|
12228
13703
|
continue;
|
|
12229
13704
|
}
|
|
12230
|
-
if (!await
|
|
13705
|
+
if (!await exists3(imagePath)) errors.push(`${reportPath}: missing image file: ${imageRef}`);
|
|
12231
13706
|
}
|
|
12232
13707
|
}
|
|
12233
13708
|
}
|
|
12234
13709
|
return errors;
|
|
12235
13710
|
}
|
|
12236
13711
|
async function validateCopyDiffArtifacts(scenarioDir) {
|
|
12237
|
-
const diffDir =
|
|
12238
|
-
if (!await
|
|
12239
|
-
const manifestPath =
|
|
12240
|
-
const diffPath =
|
|
12241
|
-
if (!await
|
|
12242
|
-
if (!await
|
|
13712
|
+
const diffDir = path10.join(scenarioDir, COPY_DIFF_DIR);
|
|
13713
|
+
if (!await exists3(diffDir)) return;
|
|
13714
|
+
const manifestPath = path10.join(diffDir, "last.json");
|
|
13715
|
+
const diffPath = path10.join(diffDir, "last.diff");
|
|
13716
|
+
if (!await exists3(manifestPath)) fail(`${scenarioDir}: ${COPY_DIFF_DIR}/last.json is required when copy diff artifacts exist`);
|
|
13717
|
+
if (!await exists3(diffPath)) fail(`${scenarioDir}: ${COPY_DIFF_DIR}/last.diff is required when copy diff artifacts exist`);
|
|
12243
13718
|
let manifest;
|
|
12244
13719
|
try {
|
|
12245
13720
|
manifest = JSON.parse(await readText(manifestPath));
|
|
@@ -12249,7 +13724,7 @@ async function validateCopyDiffArtifacts(scenarioDir) {
|
|
|
12249
13724
|
for (const key of ["operation", "scenario_id", "source", "destination", "generated_at", "summary", "diff_file", "files"]) {
|
|
12250
13725
|
if (!(key in manifest)) fail(`${manifestPath}: missing \`${key}\``);
|
|
12251
13726
|
}
|
|
12252
|
-
if (manifest.scenario_id !==
|
|
13727
|
+
if (manifest.scenario_id !== path10.basename(scenarioDir)) fail(`${manifestPath}: scenario_id must match directory name`);
|
|
12253
13728
|
if (manifest.diff_file !== "last.diff") fail(`${manifestPath}: diff_file must be last.diff`);
|
|
12254
13729
|
if (!(await readText(diffPath)).trim()) fail(`${diffPath}: copy diff must not be empty`);
|
|
12255
13730
|
}
|
|
@@ -12297,8 +13772,8 @@ function registerTestSuiteCommands(program2) {
|
|
|
12297
13772
|
}
|
|
12298
13773
|
|
|
12299
13774
|
// src/core/update.ts
|
|
12300
|
-
import { access as access2, mkdir as
|
|
12301
|
-
import
|
|
13775
|
+
import { access as access2, mkdir as mkdir11, readFile as readFile14, realpath, writeFile as writeFile11 } from "fs/promises";
|
|
13776
|
+
import path11 from "path";
|
|
12302
13777
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
12303
13778
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
12304
13779
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -12410,11 +13885,11 @@ async function fetchLatestVersion(options = {}) {
|
|
|
12410
13885
|
}
|
|
12411
13886
|
}
|
|
12412
13887
|
function updateStatePath(configDir = getConfigDir()) {
|
|
12413
|
-
return
|
|
13888
|
+
return path11.join(configDir, UPDATE_STATE_FILE);
|
|
12414
13889
|
}
|
|
12415
13890
|
async function readUpdateState(configDir) {
|
|
12416
13891
|
try {
|
|
12417
|
-
const raw = await
|
|
13892
|
+
const raw = await readFile14(updateStatePath(configDir), "utf8");
|
|
12418
13893
|
const parsed = JSON.parse(raw);
|
|
12419
13894
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
12420
13895
|
return null;
|
|
@@ -12425,8 +13900,8 @@ async function readUpdateState(configDir) {
|
|
|
12425
13900
|
}
|
|
12426
13901
|
}
|
|
12427
13902
|
async function writeUpdateState(state, configDir = getConfigDir()) {
|
|
12428
|
-
await
|
|
12429
|
-
await
|
|
13903
|
+
await mkdir11(configDir, { recursive: true });
|
|
13904
|
+
await writeFile11(updateStatePath(configDir), JSON.stringify(state), "utf8");
|
|
12430
13905
|
}
|
|
12431
13906
|
async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
12432
13907
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
@@ -12478,7 +13953,7 @@ async function findNpmPath() {
|
|
|
12478
13953
|
}
|
|
12479
13954
|
function detectInstallMethod(input) {
|
|
12480
13955
|
const resolvedPath = input.executablePath || "";
|
|
12481
|
-
const method = resolvedPath.includes(`node_modules${
|
|
13956
|
+
const method = resolvedPath.includes(`node_modules${path11.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
|
|
12482
13957
|
return {
|
|
12483
13958
|
method,
|
|
12484
13959
|
resolvedPath,
|
|
@@ -12834,6 +14309,7 @@ var OPTIONS_WITH_VALUES = /* @__PURE__ */ new Set([
|
|
|
12834
14309
|
"--payload",
|
|
12835
14310
|
"--profile",
|
|
12836
14311
|
"--session-key",
|
|
14312
|
+
"--skill",
|
|
12837
14313
|
"--trace-id",
|
|
12838
14314
|
"--work-format"
|
|
12839
14315
|
]);
|
|
@@ -12947,6 +14423,7 @@ registerEsCommands(program);
|
|
|
12947
14423
|
registerFlowCommands(program);
|
|
12948
14424
|
registerMemoryCommands(program);
|
|
12949
14425
|
registerMatrixCommands(program);
|
|
14426
|
+
registerPluginCommands(program);
|
|
12950
14427
|
registerProjectCommands(program);
|
|
12951
14428
|
registerStepCommands(program);
|
|
12952
14429
|
registerTaskbookCommands(program);
|