bpmax-cli 0.1.44-beta.20 → 0.1.44-beta.22
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.22",
|
|
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();
|
|
@@ -4394,6 +5386,25 @@ function parseMaybeJsonObject(value, fallback) {
|
|
|
4394
5386
|
}
|
|
4395
5387
|
return fallback;
|
|
4396
5388
|
}
|
|
5389
|
+
function parseNavConfigContent(type, value) {
|
|
5390
|
+
if (isRecord3(value)) {
|
|
5391
|
+
return value;
|
|
5392
|
+
}
|
|
5393
|
+
if (typeof value === "string") {
|
|
5394
|
+
const raw = value.trim();
|
|
5395
|
+
if (!raw) {
|
|
5396
|
+
return {};
|
|
5397
|
+
}
|
|
5398
|
+
try {
|
|
5399
|
+
const parsed = JSON.parse(raw);
|
|
5400
|
+
if (isRecord3(parsed)) {
|
|
5401
|
+
return parsed;
|
|
5402
|
+
}
|
|
5403
|
+
} catch {
|
|
5404
|
+
}
|
|
5405
|
+
}
|
|
5406
|
+
throw new Error(`nav-config ${type} content must be a JSON object or a JSON object string.`);
|
|
5407
|
+
}
|
|
4397
5408
|
function extractListData(value) {
|
|
4398
5409
|
if (Array.isArray(value)) {
|
|
4399
5410
|
return value.filter(isRecord3);
|
|
@@ -4740,7 +5751,7 @@ async function collectApiPlatformAggregate(profile, id) {
|
|
|
4740
5751
|
function extractNavConfigDetail(type, response) {
|
|
4741
5752
|
const records = extractListData(response);
|
|
4742
5753
|
const detail = records.find((item) => item.type === type) || records[0] || {};
|
|
4743
|
-
const content =
|
|
5754
|
+
const content = detail.content === void 0 || detail.content === null ? {} : parseNavConfigContent(type, detail.content);
|
|
4744
5755
|
const contentKey = NAV_CONTENT_KEY_BY_TYPE[type];
|
|
4745
5756
|
const items = Array.isArray(content[contentKey]) ? content[contentKey] : [];
|
|
4746
5757
|
return {
|
|
@@ -4758,7 +5769,7 @@ function extractNavConfigDetail(type, response) {
|
|
|
4758
5769
|
}
|
|
4759
5770
|
function navConfigItemsForType(type, config) {
|
|
4760
5771
|
const contentKey = NAV_CONTENT_KEY_BY_TYPE[type];
|
|
4761
|
-
const content =
|
|
5772
|
+
const content = config.content === void 0 || config.content === null ? {} : parseNavConfigContent(type, config.content);
|
|
4762
5773
|
const hasItems = Array.isArray(config.items);
|
|
4763
5774
|
const hasContentItems = Array.isArray(content[contentKey]);
|
|
4764
5775
|
if (hasItems && hasContentItems && JSON.stringify(config.items) !== JSON.stringify(content[contentKey])) {
|
|
@@ -4808,6 +5819,7 @@ function buildNavConfigSubmitPayload(work, raw, options = {}) {
|
|
|
4808
5819
|
type,
|
|
4809
5820
|
method: hasId ? "PUT" : "POST",
|
|
4810
5821
|
path: hasId ? `/configuration/${payload.id}?is_default_action=1` : "/configuration?is_default_action=1",
|
|
5822
|
+
params: work.workspace ? { $workspace: work.workspace } : void 0,
|
|
4811
5823
|
id: hasId ? payload.id : null,
|
|
4812
5824
|
payload
|
|
4813
5825
|
};
|
|
@@ -4944,9 +5956,9 @@ async function exportRoleDomain(profile, id, outDir) {
|
|
|
4944
5956
|
const { raw, work } = await collectRoleAggregate(profile, id);
|
|
4945
5957
|
const baseHash = hashJson(raw);
|
|
4946
5958
|
const stem = `role-${id}`;
|
|
4947
|
-
const rawFile =
|
|
4948
|
-
const workFile =
|
|
4949
|
-
const metaFile =
|
|
5959
|
+
const rawFile = path5.join(outDir, "raw", `${stem}.json`);
|
|
5960
|
+
const workFile = path5.join(outDir, "work", `${stem}.json`);
|
|
5961
|
+
const metaFile = path5.join(outDir, "meta", `${stem}.meta.json`);
|
|
4950
5962
|
await writeJsonFile(rawFile, raw);
|
|
4951
5963
|
await writeJsonFile(workFile, work);
|
|
4952
5964
|
await writeJsonFile(metaFile, {
|
|
@@ -5280,12 +6292,50 @@ async function submitOperationPlan(profile, capabilityPrefix, operations) {
|
|
|
5280
6292
|
op.path,
|
|
5281
6293
|
{
|
|
5282
6294
|
data: op.method === "DELETE" ? void 0 : op.payload,
|
|
6295
|
+
params: isRecord3(op.params) ? op.params : void 0,
|
|
5283
6296
|
capability: op.method === "POST" ? `${capabilityPrefix}.create` : op.method === "DELETE" ? `${capabilityPrefix}.delete` : `${capabilityPrefix}.submit`
|
|
5284
6297
|
}
|
|
5285
6298
|
));
|
|
5286
6299
|
}
|
|
5287
6300
|
return responses;
|
|
5288
6301
|
}
|
|
6302
|
+
function navConfigComparable(value) {
|
|
6303
|
+
return {
|
|
6304
|
+
type: value.type,
|
|
6305
|
+
name: value.name,
|
|
6306
|
+
content: value.content
|
|
6307
|
+
};
|
|
6308
|
+
}
|
|
6309
|
+
function navConfigItemCount(value) {
|
|
6310
|
+
const type = value.type;
|
|
6311
|
+
if (!NAV_CONFIG_TYPES.includes(type)) {
|
|
6312
|
+
return 0;
|
|
6313
|
+
}
|
|
6314
|
+
const contentKey = NAV_CONTENT_KEY_BY_TYPE[type];
|
|
6315
|
+
const content = isRecord3(value.content) ? value.content : {};
|
|
6316
|
+
return Array.isArray(content[contentKey]) ? content[contentKey].length : 0;
|
|
6317
|
+
}
|
|
6318
|
+
function assertNavConfigReadbackMatchesOperations(submitPayload, readbackRaw) {
|
|
6319
|
+
const operations = Array.isArray(submitPayload.operations) ? submitPayload.operations : [];
|
|
6320
|
+
const readbackConfigs = isRecord3(readbackRaw.configs) ? readbackRaw.configs : {};
|
|
6321
|
+
for (const op of operations) {
|
|
6322
|
+
if (!isRecord3(op) || op.method === "DELETE") {
|
|
6323
|
+
continue;
|
|
6324
|
+
}
|
|
6325
|
+
const type = op.type;
|
|
6326
|
+
if (!NAV_CONFIG_TYPES.includes(type) || !isRecord3(op.payload)) {
|
|
6327
|
+
continue;
|
|
6328
|
+
}
|
|
6329
|
+
const navType = type;
|
|
6330
|
+
const actualConfig = isRecord3(readbackConfigs[navType]) ? readbackConfigs[navType] : {};
|
|
6331
|
+
const actualPayload = navConfigToSubmitRecord(navType, actualConfig);
|
|
6332
|
+
if (hashJson(navConfigComparable(actualPayload)) !== hashJson(navConfigComparable(op.payload))) {
|
|
6333
|
+
throw new Error(
|
|
6334
|
+
`nav-config submit verification failed for ${navType}: readback content does not match submitted payload (expected items=${navConfigItemCount(op.payload)}, actual items=${navConfigItemCount(actualPayload)}). Re-export before retrying; do not continue submitting this payload.`
|
|
6335
|
+
);
|
|
6336
|
+
}
|
|
6337
|
+
}
|
|
6338
|
+
}
|
|
5289
6339
|
async function submitAggregateConfigDomain(profile, domain, id, submit) {
|
|
5290
6340
|
const payload = submit.payload;
|
|
5291
6341
|
if (!isRecord3(payload) || !Array.isArray(payload.operations)) {
|
|
@@ -5299,6 +6349,9 @@ async function submitAggregateConfigDomain(profile, domain, id, submit) {
|
|
|
5299
6349
|
};
|
|
5300
6350
|
}
|
|
5301
6351
|
const current = domain === "api-platform" ? await collectApiPlatformAggregate(profile, id) : await collectNavConfigAggregate(profile, id);
|
|
6352
|
+
if (domain === "nav-config") {
|
|
6353
|
+
assertNavConfigReadbackMatchesOperations(payload, current.raw);
|
|
6354
|
+
}
|
|
5302
6355
|
return {
|
|
5303
6356
|
operation_responses: responses,
|
|
5304
6357
|
readback_hash: hashJson(current.raw)
|
|
@@ -5343,6 +6396,14 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
|
|
|
5343
6396
|
next: `Run again with --confirm "${expectedConfirm}" to create.`
|
|
5344
6397
|
};
|
|
5345
6398
|
}
|
|
6399
|
+
const pluginLint = await runFlowTemplatePluginLint(work, {
|
|
6400
|
+
profile,
|
|
6401
|
+
agent: options.agent || "codex",
|
|
6402
|
+
requireInstalled: true
|
|
6403
|
+
});
|
|
6404
|
+
if (pluginLint?.errors.length) {
|
|
6405
|
+
throw new Error(`flow-template plugin lint failed: ${pluginLint.errors.join("; ")}`);
|
|
6406
|
+
}
|
|
5346
6407
|
const client = createApiClient(profile);
|
|
5347
6408
|
const createResponse = await apiRequest(
|
|
5348
6409
|
client,
|
|
@@ -5603,6 +6664,26 @@ function comparableSubmitPayload(domain, value, options) {
|
|
|
5603
6664
|
const comparable = domain === "form-template" && options.ignoreServerFields ? stripServerFilledFields(value, FORM_TEMPLATE_SERVER_FIELD_KEYS) : value;
|
|
5604
6665
|
return buildDomainSubmitPayload(domain, comparable);
|
|
5605
6666
|
}
|
|
6667
|
+
function diffMismatchCount(diff) {
|
|
6668
|
+
const counts = isRecord3(diff?.counts) ? diff.counts : {};
|
|
6669
|
+
return ["added", "removed", "changed"].reduce((sum, key) => {
|
|
6670
|
+
const value = counts[key];
|
|
6671
|
+
return sum + (typeof value === "number" && Number.isFinite(value) ? value : 0);
|
|
6672
|
+
}, 0);
|
|
6673
|
+
}
|
|
6674
|
+
function verifyFailureReasons(ok, diff, comparisonSkippedReason) {
|
|
6675
|
+
if (ok) {
|
|
6676
|
+
return [];
|
|
6677
|
+
}
|
|
6678
|
+
if (comparisonSkippedReason) {
|
|
6679
|
+
return [comparisonSkippedReason];
|
|
6680
|
+
}
|
|
6681
|
+
const summary = Array.isArray(diff?.summary) ? diff.summary.filter((item) => typeof item === "string") : [];
|
|
6682
|
+
if (summary.length) {
|
|
6683
|
+
return summary.slice(0, 5);
|
|
6684
|
+
}
|
|
6685
|
+
return ["normalized submit payload differs, but no diff summary was produced"];
|
|
6686
|
+
}
|
|
5606
6687
|
async function verifyConfigDomain(config, profile, domain, id, options = {}) {
|
|
5607
6688
|
void config;
|
|
5608
6689
|
assertNotLocalUuidConfigId(domain, id, "verify");
|
|
@@ -5619,16 +6700,28 @@ async function verifyConfigDomain(config, profile, domain, id, options = {}) {
|
|
|
5619
6700
|
const expectedComparable = expected ? comparableSubmitPayload(domain, expected, options) : void 0;
|
|
5620
6701
|
const ok = expected ? JSON.stringify(actualComparable) === JSON.stringify(expectedComparable) : true;
|
|
5621
6702
|
const diff = expected ? diffJsonComparable(domain, expected, actual, (value) => comparableSubmitPayload(domain, value, options)) : void 0;
|
|
6703
|
+
const rawDiff = expected && domain === "form-template" && options.ignoreServerFields ? diffJsonComparable(domain, expected, actual, (value) => buildDomainSubmitPayload(domain, value)) : void 0;
|
|
6704
|
+
const comparisonSkippedReason = expected ? null : "no --expect file provided; verify performed readback only";
|
|
6705
|
+
const serverDefaultDrift = Boolean(ok && rawDiff?.changed === true);
|
|
6706
|
+
const mismatchCount = diffMismatchCount(diff);
|
|
6707
|
+
const reasons = verifyFailureReasons(ok, diff, comparisonSkippedReason);
|
|
5622
6708
|
return {
|
|
5623
6709
|
domain,
|
|
5624
6710
|
id,
|
|
5625
6711
|
ok,
|
|
6712
|
+
structural_ok: true,
|
|
6713
|
+
semantic_ok: ok,
|
|
6714
|
+
server_default_drift: serverDefaultDrift,
|
|
6715
|
+
comparison_skipped_reason: comparisonSkippedReason,
|
|
6716
|
+
mismatch_count: mismatchCount,
|
|
6717
|
+
...!ok ? { reason: reasons[0], reasons } : {},
|
|
5626
6718
|
compare: expected ? "normalized_submit_payload" : "readback_only",
|
|
5627
6719
|
...expected ? {
|
|
5628
6720
|
expected_hash: expectedComparable ? hashJson(expectedComparable) : null,
|
|
5629
6721
|
actual_hash: actualComparable ? hashJson(actualComparable) : null,
|
|
5630
6722
|
actual_config_hash: exported.base_hash,
|
|
5631
6723
|
...domain === "form-template" && options.ignoreServerFields ? { ignored_server_fields: [...FORM_TEMPLATE_SERVER_FIELD_KEYS] } : {},
|
|
6724
|
+
...rawDiff ? { raw_diff: rawDiff } : {},
|
|
5632
6725
|
diff
|
|
5633
6726
|
} : {},
|
|
5634
6727
|
exported
|
|
@@ -5710,12 +6803,12 @@ async function resolveLocalUuidConfigId(options) {
|
|
|
5710
6803
|
if (!tableDir) {
|
|
5711
6804
|
throw new Error(`resolve-id does not support domain ${options.domain}.`);
|
|
5712
6805
|
}
|
|
5713
|
-
const root =
|
|
6806
|
+
const root = path5.resolve(options.repo, tableDir);
|
|
5714
6807
|
async function walk(dir) {
|
|
5715
|
-
const entries = await
|
|
6808
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
5716
6809
|
const result = [];
|
|
5717
6810
|
for (const entry of entries) {
|
|
5718
|
-
const entryPath =
|
|
6811
|
+
const entryPath = path5.join(dir, entry.name);
|
|
5719
6812
|
if (entry.isDirectory()) {
|
|
5720
6813
|
result.push(...await walk(entryPath));
|
|
5721
6814
|
} else if (entry.isFile()) {
|
|
@@ -5728,10 +6821,10 @@ async function resolveLocalUuidConfigId(options) {
|
|
|
5728
6821
|
const matches = [];
|
|
5729
6822
|
for (const filePath of files) {
|
|
5730
6823
|
try {
|
|
5731
|
-
const record = JSON.parse(await
|
|
6824
|
+
const record = JSON.parse(await readFile8(filePath, "utf8"));
|
|
5732
6825
|
if (!isRecord3(record)) continue;
|
|
5733
6826
|
if (String(record.uuid || "").toLowerCase() !== options.uuid.toLowerCase()) continue;
|
|
5734
|
-
const filenameId = numericIdString(
|
|
6827
|
+
const filenameId = numericIdString(path5.basename(filePath, path5.extname(filePath)));
|
|
5735
6828
|
const id = numericIdString(record.id) ?? numericIdString(record.origin_template_id) ?? numericIdString(record.template_id) ?? filenameId ?? null;
|
|
5736
6829
|
matches.push({
|
|
5737
6830
|
domain: options.domain,
|
|
@@ -5749,7 +6842,7 @@ async function resolveLocalUuidConfigId(options) {
|
|
|
5749
6842
|
return {
|
|
5750
6843
|
domain: options.domain,
|
|
5751
6844
|
uuid: options.uuid,
|
|
5752
|
-
repo:
|
|
6845
|
+
repo: path5.resolve(options.repo),
|
|
5753
6846
|
match_count: matches.length,
|
|
5754
6847
|
matches,
|
|
5755
6848
|
resolved_id: matches.length === 1 ? matches[0].id : null,
|
|
@@ -5811,11 +6904,11 @@ async function ensureConfigCapability(profile, capability) {
|
|
|
5811
6904
|
await ensureCapability(createApiClient(profile), profile, capability);
|
|
5812
6905
|
}
|
|
5813
6906
|
async function readJsonFile(file) {
|
|
5814
|
-
return JSON.parse(await
|
|
6907
|
+
return JSON.parse(await readFile8(file, "utf8"));
|
|
5815
6908
|
}
|
|
5816
6909
|
async function writeJsonFile(file, value) {
|
|
5817
|
-
await
|
|
5818
|
-
await
|
|
6910
|
+
await mkdir5(path5.dirname(file), { recursive: true });
|
|
6911
|
+
await writeFile5(file, `${JSON.stringify(value, null, 2)}
|
|
5819
6912
|
`, "utf8");
|
|
5820
6913
|
}
|
|
5821
6914
|
async function exportConfigDomain(config, profile, domain, id, outDir, options = {}) {
|
|
@@ -5825,9 +6918,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
|
|
|
5825
6918
|
const { raw, work: work2 } = await collectApiPlatformAggregate(profile, id);
|
|
5826
6919
|
const baseHash2 = hashJson(raw);
|
|
5827
6920
|
const stem2 = `${domain}-${id.replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
5828
|
-
const rawFile2 =
|
|
5829
|
-
const workFile2 =
|
|
5830
|
-
const metaFile2 =
|
|
6921
|
+
const rawFile2 = path5.join(outDir, "raw", `${stem2}.json`);
|
|
6922
|
+
const workFile2 = path5.join(outDir, "work", `${stem2}.json`);
|
|
6923
|
+
const metaFile2 = path5.join(outDir, "meta", `${stem2}.meta.json`);
|
|
5831
6924
|
await writeJsonFile(rawFile2, raw);
|
|
5832
6925
|
await writeJsonFile(workFile2, work2);
|
|
5833
6926
|
await writeJsonFile(metaFile2, {
|
|
@@ -5849,9 +6942,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
|
|
|
5849
6942
|
const { raw, work: work2 } = await collectNavConfigAggregate(profile, id);
|
|
5850
6943
|
const baseHash2 = hashJson(raw);
|
|
5851
6944
|
const stem2 = `${domain}-${id.replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
5852
|
-
const rawFile2 =
|
|
5853
|
-
const workFile2 =
|
|
5854
|
-
const metaFile2 =
|
|
6945
|
+
const rawFile2 = path5.join(outDir, "raw", `${stem2}.json`);
|
|
6946
|
+
const workFile2 = path5.join(outDir, "work", `${stem2}.json`);
|
|
6947
|
+
const metaFile2 = path5.join(outDir, "meta", `${stem2}.meta.json`);
|
|
5855
6948
|
await writeJsonFile(rawFile2, raw);
|
|
5856
6949
|
await writeJsonFile(workFile2, work2);
|
|
5857
6950
|
await writeJsonFile(metaFile2, {
|
|
@@ -5878,9 +6971,9 @@ async function exportConfigDomain(config, profile, domain, id, outDir, options =
|
|
|
5878
6971
|
validateExpectedType(domain, definition, data);
|
|
5879
6972
|
const baseHash = hashJson(data);
|
|
5880
6973
|
const stem = `${domain}-${id}`;
|
|
5881
|
-
const rawFile =
|
|
5882
|
-
const workFile =
|
|
5883
|
-
const metaFile =
|
|
6974
|
+
const rawFile = path5.join(outDir, "raw", `${stem}.json`);
|
|
6975
|
+
const workFile = path5.join(outDir, "work", `${stem}.json`);
|
|
6976
|
+
const metaFile = path5.join(outDir, "meta", `${stem}.meta.json`);
|
|
5884
6977
|
await writeJsonFile(rawFile, data);
|
|
5885
6978
|
const work = domain === "form-template" && options.workFormat === "structured" && isRecord3(data) ? formTemplateRawToStructured(data) : data;
|
|
5886
6979
|
await writeJsonFile(workFile, work);
|
|
@@ -5920,6 +7013,12 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
5920
7013
|
throw new Error("Config build requires a meta file produced by `bpmax-cli config <domain> export`.");
|
|
5921
7014
|
}
|
|
5922
7015
|
const raw = typeof meta.raw_file === "string" ? await readJsonFile(meta.raw_file) : void 0;
|
|
7016
|
+
if (domain === "flow-template" && isRecord3(work)) {
|
|
7017
|
+
const pluginLint = await runFlowTemplatePluginLint(work, options.pluginLint);
|
|
7018
|
+
if (pluginLint?.errors.length) {
|
|
7019
|
+
throw new Error(`flow-template plugin lint failed: ${pluginLint.errors.join("; ")}`);
|
|
7020
|
+
}
|
|
7021
|
+
}
|
|
5923
7022
|
const payload = buildDomainSubmitPayload(domain, work, options, raw);
|
|
5924
7023
|
if (domain === "flow-template" && options.publishLive) {
|
|
5925
7024
|
payload.publish_live = true;
|
|
@@ -5942,9 +7041,47 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
5942
7041
|
await writeJsonFile(outFile, result);
|
|
5943
7042
|
return { domain, work_file: workFile, submit_file: outFile, payload_keys: Object.keys(payload) };
|
|
5944
7043
|
}
|
|
5945
|
-
async function
|
|
7044
|
+
async function runFlowTemplatePluginLint(flowWork, options = {}) {
|
|
7045
|
+
if (!options.profile) {
|
|
7046
|
+
return void 0;
|
|
7047
|
+
}
|
|
7048
|
+
if (!hasPotentialFlowTemplatePluginExtension(flowWork)) {
|
|
7049
|
+
return void 0;
|
|
7050
|
+
}
|
|
7051
|
+
const agent = options.agent || "codex";
|
|
7052
|
+
const client = createApiClient(options.profile);
|
|
7053
|
+
const platformSkills = await listPluginSkills(client);
|
|
7054
|
+
return lintFlowTemplatePluginExtensions({
|
|
7055
|
+
profile: options.profile,
|
|
7056
|
+
agent,
|
|
7057
|
+
flowWork,
|
|
7058
|
+
platformSkills,
|
|
7059
|
+
requireInstalled: Boolean(options.requireInstalled)
|
|
7060
|
+
});
|
|
7061
|
+
}
|
|
7062
|
+
function hasPotentialFlowTemplatePluginExtension(flowWork) {
|
|
7063
|
+
if (collectFlowTemplatePluginKeys(flowWork).length) {
|
|
7064
|
+
return true;
|
|
7065
|
+
}
|
|
7066
|
+
const data = typeof flowWork.data === "object" && flowWork.data !== null && !Array.isArray(flowWork.data) ? flowWork.data : {};
|
|
7067
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes : [];
|
|
7068
|
+
return nodes.some((node) => {
|
|
7069
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) {
|
|
7070
|
+
return false;
|
|
7071
|
+
}
|
|
7072
|
+
return Object.entries(node).some(([key, value]) => {
|
|
7073
|
+
if (!Array.isArray(value) || !/_(?:triggers|configs|plugins)$/.test(key)) {
|
|
7074
|
+
return false;
|
|
7075
|
+
}
|
|
7076
|
+
return value.some((item) => item && typeof item === "object" && !Array.isArray(item));
|
|
7077
|
+
});
|
|
7078
|
+
});
|
|
7079
|
+
}
|
|
7080
|
+
async function lintConfigWorkFile(file, options = {}) {
|
|
5946
7081
|
const value = await readJsonFile(file);
|
|
5947
7082
|
const errors = [];
|
|
7083
|
+
const warnings = [];
|
|
7084
|
+
let pluginLint;
|
|
5948
7085
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
5949
7086
|
errors.push("Config work file must be a JSON object.");
|
|
5950
7087
|
} else {
|
|
@@ -5971,6 +7108,11 @@ async function lintConfigWorkFile(file) {
|
|
|
5971
7108
|
validateFlowTemplateCodeModeMessages(flowWork, errors);
|
|
5972
7109
|
validateFlowTemplateRuntimeScripts(flowWork, errors);
|
|
5973
7110
|
validateFlowTemplateFeishuChatPlugin(flowWork, errors);
|
|
7111
|
+
pluginLint = await runFlowTemplatePluginLint(flowWork, options.pluginLint);
|
|
7112
|
+
if (pluginLint) {
|
|
7113
|
+
errors.push(...pluginLint.errors);
|
|
7114
|
+
warnings.push(...pluginLint.warnings);
|
|
7115
|
+
}
|
|
5974
7116
|
if (flowWork.mode === "create") {
|
|
5975
7117
|
validateFlowTemplateFormDrivenCreateBaseline(flowWork, errors, { context: "flow-template create" });
|
|
5976
7118
|
} else {
|
|
@@ -5982,6 +7124,8 @@ async function lintConfigWorkFile(file) {
|
|
|
5982
7124
|
file,
|
|
5983
7125
|
ok: errors.length === 0,
|
|
5984
7126
|
errors,
|
|
7127
|
+
warnings,
|
|
7128
|
+
...pluginLint ? { plugin_lints: pluginLint.plugin_lints } : {},
|
|
5985
7129
|
checked_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
5986
7130
|
};
|
|
5987
7131
|
}
|
|
@@ -6314,6 +7458,14 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
6314
7458
|
validateFlowTemplateFeishuChatPlugin(submit.payload);
|
|
6315
7459
|
validateFlowTemplateStandardFlowType(submit.payload);
|
|
6316
7460
|
validateFlowTemplateIdentityStandard(id, submit.payload);
|
|
7461
|
+
const pluginLint = await runFlowTemplatePluginLint(submit.payload, {
|
|
7462
|
+
profile,
|
|
7463
|
+
agent: options.agent || "codex",
|
|
7464
|
+
requireInstalled: true
|
|
7465
|
+
});
|
|
7466
|
+
if (pluginLint?.errors.length) {
|
|
7467
|
+
throw new Error(`flow-template plugin lint failed: ${pluginLint.errors.join("; ")}`);
|
|
7468
|
+
}
|
|
6317
7469
|
}
|
|
6318
7470
|
if (domain === "list-template") {
|
|
6319
7471
|
validateListTemplateActionGate(submit.payload);
|
|
@@ -6572,8 +7724,8 @@ async function runDatasetLifecycleAction(config, profile, action, id, confirm3)
|
|
|
6572
7724
|
}
|
|
6573
7725
|
|
|
6574
7726
|
// src/core/config-workspace.ts
|
|
6575
|
-
import { mkdir as
|
|
6576
|
-
import
|
|
7727
|
+
import { mkdir as mkdir6, readFile as readFile9, writeFile as writeFile6 } from "fs/promises";
|
|
7728
|
+
import path6 from "path";
|
|
6577
7729
|
var DEFAULT_AGENT_GUIDE_FILE = "AGENTS.md";
|
|
6578
7730
|
var CONFIG_DOMAINS2 = [
|
|
6579
7731
|
["form-template", "bpmax-form-template-editor", "\u8868\u5355\u6A21\u677F"],
|
|
@@ -6725,10 +7877,10 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6725
7877
|
);
|
|
6726
7878
|
}
|
|
6727
7879
|
const file = options.file || DEFAULT_AGENT_GUIDE_FILE;
|
|
6728
|
-
if (
|
|
7880
|
+
if (path6.isAbsolute(file) || file.split(/[\\/]+/).includes("..")) {
|
|
6729
7881
|
throw new Error("Agent guide file must be a relative file name inside the target workspace.");
|
|
6730
7882
|
}
|
|
6731
|
-
const targetFile =
|
|
7883
|
+
const targetFile = path6.resolve(options.cwd, file);
|
|
6732
7884
|
const block = renderConfigWorkspaceGuide({
|
|
6733
7885
|
profileName: options.profile.name,
|
|
6734
7886
|
profile: options.profile.config,
|
|
@@ -6738,7 +7890,7 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6738
7890
|
});
|
|
6739
7891
|
let existing = "";
|
|
6740
7892
|
try {
|
|
6741
|
-
existing = await
|
|
7893
|
+
existing = await readFile9(targetFile, "utf8");
|
|
6742
7894
|
} catch (error) {
|
|
6743
7895
|
if (error.code !== "ENOENT") {
|
|
6744
7896
|
throw error;
|
|
@@ -6746,8 +7898,8 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6746
7898
|
}
|
|
6747
7899
|
const content = upsertConfigWorkspaceBlock(existing, options.env, block);
|
|
6748
7900
|
if (!options.dryRun) {
|
|
6749
|
-
await
|
|
6750
|
-
await
|
|
7901
|
+
await mkdir6(path6.dirname(targetFile), { recursive: true });
|
|
7902
|
+
await writeFile6(targetFile, content, "utf8");
|
|
6751
7903
|
}
|
|
6752
7904
|
return {
|
|
6753
7905
|
dry_run: Boolean(options.dryRun),
|
|
@@ -6761,13 +7913,13 @@ async function initConfigWorkspaceGuide(options) {
|
|
|
6761
7913
|
|
|
6762
7914
|
// src/commands/config-env.ts
|
|
6763
7915
|
import { execFile } from "child_process";
|
|
6764
|
-
import { mkdir as
|
|
7916
|
+
import { mkdir as mkdir7, rm as rm3, stat as stat4, writeFile as writeFile7 } from "fs/promises";
|
|
6765
7917
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
6766
7918
|
import { tmpdir as tmpdir2 } from "os";
|
|
6767
|
-
import
|
|
7919
|
+
import path7 from "path";
|
|
6768
7920
|
import { promisify } from "util";
|
|
6769
7921
|
import { password, text } from "@clack/prompts";
|
|
6770
|
-
import
|
|
7922
|
+
import axios6 from "axios";
|
|
6771
7923
|
var execFileAsync = promisify(execFile);
|
|
6772
7924
|
var PLATFORM_SYSCONFIG_BRANCH = "master";
|
|
6773
7925
|
var LATEST_EXEC_MAX_BUFFER = 64 * 1024 * 1024;
|
|
@@ -6903,12 +8055,12 @@ async function gitCloneWithTransientCredentials(gitUrl, workspaceDir, credential
|
|
|
6903
8055
|
const sanitizedGitUrl = stripGitUrlCredentials(gitUrl);
|
|
6904
8056
|
if (!credentials) {
|
|
6905
8057
|
await execFileAsync("git", ["clone", sanitizedGitUrl, workspaceDir], {
|
|
6906
|
-
cwd:
|
|
8058
|
+
cwd: path7.dirname(workspaceDir)
|
|
6907
8059
|
});
|
|
6908
8060
|
return;
|
|
6909
8061
|
}
|
|
6910
|
-
const askpassPath =
|
|
6911
|
-
await
|
|
8062
|
+
const askpassPath = path7.join(tmpdir2(), `bpmax-cli-git-askpass-${randomUUID3()}.sh`);
|
|
8063
|
+
await writeFile7(
|
|
6912
8064
|
askpassPath,
|
|
6913
8065
|
[
|
|
6914
8066
|
"#!/bin/sh",
|
|
@@ -6923,7 +8075,7 @@ async function gitCloneWithTransientCredentials(gitUrl, workspaceDir, credential
|
|
|
6923
8075
|
);
|
|
6924
8076
|
try {
|
|
6925
8077
|
await execFileAsync("git", ["clone", sanitizedGitUrl, workspaceDir], {
|
|
6926
|
-
cwd:
|
|
8078
|
+
cwd: path7.dirname(workspaceDir),
|
|
6927
8079
|
env: {
|
|
6928
8080
|
...process.env,
|
|
6929
8081
|
GIT_ASKPASS: askpassPath,
|
|
@@ -6934,15 +8086,15 @@ async function gitCloneWithTransientCredentials(gitUrl, workspaceDir, credential
|
|
|
6934
8086
|
cwd: workspaceDir
|
|
6935
8087
|
});
|
|
6936
8088
|
} finally {
|
|
6937
|
-
await
|
|
8089
|
+
await rm3(askpassPath, { force: true });
|
|
6938
8090
|
}
|
|
6939
8091
|
}
|
|
6940
8092
|
async function withTransientGitCredentials(credentials, operation) {
|
|
6941
8093
|
if (!credentials) {
|
|
6942
8094
|
return operation(void 0);
|
|
6943
8095
|
}
|
|
6944
|
-
const askpassPath =
|
|
6945
|
-
await
|
|
8096
|
+
const askpassPath = path7.join(tmpdir2(), `bpmax-cli-git-askpass-${randomUUID3()}.sh`);
|
|
8097
|
+
await writeFile7(
|
|
6946
8098
|
askpassPath,
|
|
6947
8099
|
[
|
|
6948
8100
|
"#!/bin/sh",
|
|
@@ -6962,7 +8114,7 @@ async function withTransientGitCredentials(credentials, operation) {
|
|
|
6962
8114
|
GIT_TERMINAL_PROMPT: "0"
|
|
6963
8115
|
});
|
|
6964
8116
|
} finally {
|
|
6965
|
-
await
|
|
8117
|
+
await rm3(askpassPath, { force: true });
|
|
6966
8118
|
}
|
|
6967
8119
|
}
|
|
6968
8120
|
async function runGitWithTransientCredentials(args, workspaceDir, credentials) {
|
|
@@ -7056,7 +8208,7 @@ function hasBlockingDirtyStatus(status, allowedPaths = /* @__PURE__ */ new Set([
|
|
|
7056
8208
|
}
|
|
7057
8209
|
async function pathExists(targetPath) {
|
|
7058
8210
|
try {
|
|
7059
|
-
await
|
|
8211
|
+
await stat4(targetPath);
|
|
7060
8212
|
return true;
|
|
7061
8213
|
} catch (error) {
|
|
7062
8214
|
if (error.code === "ENOENT") {
|
|
@@ -7130,7 +8282,7 @@ function platformStepUrl(environment, step) {
|
|
|
7130
8282
|
}
|
|
7131
8283
|
async function callPlatformSysconfigStep(environment, env, step) {
|
|
7132
8284
|
const url = platformStepUrl(environment, step);
|
|
7133
|
-
const response = await
|
|
8285
|
+
const response = await axios6.get(url, {
|
|
7134
8286
|
params: { env },
|
|
7135
8287
|
auth: environment.username && (environment.password || environment.token) ? {
|
|
7136
8288
|
username: environment.username,
|
|
@@ -7281,10 +8433,10 @@ async function initConfigWorkspaceFromPlatform(env, options) {
|
|
|
7281
8433
|
requiredPlatformField(platformEnv, "pull_url");
|
|
7282
8434
|
requiredPlatformField(platformEnv, "extract_url");
|
|
7283
8435
|
requiredPlatformField(platformEnv, "push_url");
|
|
7284
|
-
const workspaceDir =
|
|
8436
|
+
const workspaceDir = path7.resolve(options.workspaceDir);
|
|
7285
8437
|
const existed = await pathExists(workspaceDir);
|
|
7286
8438
|
if (!existed) {
|
|
7287
|
-
await
|
|
8439
|
+
await mkdir7(path7.dirname(workspaceDir), { recursive: true });
|
|
7288
8440
|
await gitCloneWithTransientCredentials(gitUrl, workspaceDir, credentials);
|
|
7289
8441
|
} else {
|
|
7290
8442
|
await assertExistingGitWorkspace(workspaceDir, gitUrl, options.force);
|
|
@@ -7389,6 +8541,19 @@ async function pullLatestConfigEnvironment(env, options) {
|
|
|
7389
8541
|
|
|
7390
8542
|
// src/commands/config.ts
|
|
7391
8543
|
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8544
|
+
async function resolveFlowTemplatePluginLintOptions(options) {
|
|
8545
|
+
const configData = await loadConfig();
|
|
8546
|
+
const profileName = options.profile || configData.current_profile || "default";
|
|
8547
|
+
const profileConfig = configData.profiles[profileName];
|
|
8548
|
+
if (!options.profile && !profileConfig?.origin) {
|
|
8549
|
+
return void 0;
|
|
8550
|
+
}
|
|
8551
|
+
return {
|
|
8552
|
+
profile: resolveProfile(configData, options.profile),
|
|
8553
|
+
agent: options.agent || "codex",
|
|
8554
|
+
requireInstalled: options.requireInstalled
|
|
8555
|
+
};
|
|
8556
|
+
}
|
|
7392
8557
|
function stringValue(value) {
|
|
7393
8558
|
return typeof value === "string" && value.trim() ? value : void 0;
|
|
7394
8559
|
}
|
|
@@ -7610,7 +8775,7 @@ function registerConfigCommands(program2) {
|
|
|
7610
8775
|
const domainCommand = domain === "workspace" ? workspace.description("Initialize local sysconfig workspaces and manage BPMAX workspace configuration") : config.command(domain).description(`Manage BPMAX ${domain} configuration`);
|
|
7611
8776
|
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
8777
|
if (domain === "flow-template") {
|
|
7613
|
-
createCommand.requiredOption("--work <file>", "Flow-template work JSON file");
|
|
8778
|
+
createCommand.requiredOption("--work <file>", "Flow-template work JSON file").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex");
|
|
7614
8779
|
} else {
|
|
7615
8780
|
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
8781
|
}
|
|
@@ -7622,7 +8787,7 @@ function registerConfigCommands(program2) {
|
|
|
7622
8787
|
resolved,
|
|
7623
8788
|
String(options.work || ""),
|
|
7624
8789
|
options.confirm,
|
|
7625
|
-
{ publishLive: Boolean(options.publishLive) }
|
|
8790
|
+
{ publishLive: Boolean(options.publishLive), agent: options.agent || "codex" }
|
|
7626
8791
|
) : await submitConfigDomain(
|
|
7627
8792
|
configData,
|
|
7628
8793
|
resolved,
|
|
@@ -7663,18 +8828,35 @@ function registerConfigCommands(program2) {
|
|
|
7663
8828
|
await saveConfig(configData);
|
|
7664
8829
|
printResult(options.format, result);
|
|
7665
8830
|
});
|
|
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
|
-
|
|
8831
|
+
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) => {
|
|
8832
|
+
let pluginLint;
|
|
8833
|
+
if (domain === "flow-template") {
|
|
8834
|
+
pluginLint = await resolveFlowTemplatePluginLintOptions({
|
|
8835
|
+
profile: options.profile,
|
|
8836
|
+
agent: options.agent,
|
|
8837
|
+
requireInstalled: true
|
|
8838
|
+
});
|
|
8839
|
+
}
|
|
8840
|
+
const result = await lintConfigWorkFile(options.work, { pluginLint });
|
|
7668
8841
|
if (!result.ok) {
|
|
7669
8842
|
printResult(options.format, result);
|
|
7670
8843
|
throw new Error(`Config lint failed for ${options.work}`);
|
|
7671
8844
|
}
|
|
7672
8845
|
printResult(options.format, result);
|
|
7673
8846
|
});
|
|
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) => {
|
|
8847
|
+
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) => {
|
|
8848
|
+
let pluginLint;
|
|
8849
|
+
if (domain === "flow-template") {
|
|
8850
|
+
pluginLint = await resolveFlowTemplatePluginLintOptions({
|
|
8851
|
+
profile: options.profile,
|
|
8852
|
+
agent: options.agent,
|
|
8853
|
+
requireInstalled: true
|
|
8854
|
+
});
|
|
8855
|
+
}
|
|
7675
8856
|
const result = await buildConfigSubmitPayload(domain, options.work, options.out, options.meta, {
|
|
7676
8857
|
allRecords: Boolean(options.allRecords),
|
|
7677
|
-
publishLive: Boolean(options.publishLive)
|
|
8858
|
+
publishLive: Boolean(options.publishLive),
|
|
8859
|
+
pluginLint
|
|
7678
8860
|
});
|
|
7679
8861
|
printResult(options.format, result);
|
|
7680
8862
|
});
|
|
@@ -7692,7 +8874,7 @@ function registerConfigCommands(program2) {
|
|
|
7692
8874
|
submit_preview: submit || null
|
|
7693
8875
|
});
|
|
7694
8876
|
});
|
|
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) => {
|
|
8877
|
+
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
8878
|
const configData = await loadConfig();
|
|
7697
8879
|
const resolved = resolveProfile(configData, options.profile);
|
|
7698
8880
|
const result = await submitConfigDomain(
|
|
@@ -7702,7 +8884,7 @@ function registerConfigCommands(program2) {
|
|
|
7702
8884
|
options.id,
|
|
7703
8885
|
options.payload,
|
|
7704
8886
|
options.confirm,
|
|
7705
|
-
{ publishLive: Boolean(options.publishLive) }
|
|
8887
|
+
{ publishLive: Boolean(options.publishLive), agent: options.agent || "codex" }
|
|
7706
8888
|
);
|
|
7707
8889
|
await saveConfig(configData);
|
|
7708
8890
|
printResult(options.format, result);
|
|
@@ -7743,6 +8925,23 @@ function registerConfigCommands(program2) {
|
|
|
7743
8925
|
});
|
|
7744
8926
|
});
|
|
7745
8927
|
}
|
|
8928
|
+
if (domain === "form-template") {
|
|
8929
|
+
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) => {
|
|
8930
|
+
const configData = await loadConfig();
|
|
8931
|
+
const resolved = resolveProfile(configData, options.profile);
|
|
8932
|
+
const result = await inspectFormTemplate(
|
|
8933
|
+
configData,
|
|
8934
|
+
resolved,
|
|
8935
|
+
options.id,
|
|
8936
|
+
{
|
|
8937
|
+
field: options.field,
|
|
8938
|
+
outDir: ".codex/tmp/form-template-inspect"
|
|
8939
|
+
}
|
|
8940
|
+
);
|
|
8941
|
+
await saveConfig(configData);
|
|
8942
|
+
printResult(options.format, result);
|
|
8943
|
+
});
|
|
8944
|
+
}
|
|
7746
8945
|
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
8946
|
const configData = await loadConfig();
|
|
7748
8947
|
const resolved = resolveProfile(configData, options.profile);
|
|
@@ -7875,7 +9074,7 @@ function registerFlowCommands(program2) {
|
|
|
7875
9074
|
const client = createApiClient(profile);
|
|
7876
9075
|
if (options.flowType) {
|
|
7877
9076
|
const bindings = await getWorkspaceFlowBindings(client, profile, options);
|
|
7878
|
-
const
|
|
9077
|
+
const path12 = options.flowKey ? "/flow/options" : "/flow/flow_type";
|
|
7879
9078
|
const params = options.flowKey ? {
|
|
7880
9079
|
detail: "1"
|
|
7881
9080
|
} : {
|
|
@@ -7885,7 +9084,7 @@ function registerFlowCommands(program2) {
|
|
|
7885
9084
|
const result2 = await apiRequest(
|
|
7886
9085
|
client,
|
|
7887
9086
|
"GET",
|
|
7888
|
-
|
|
9087
|
+
path12,
|
|
7889
9088
|
{
|
|
7890
9089
|
params
|
|
7891
9090
|
}
|
|
@@ -7996,76 +9195,6 @@ function setupSummary(input) {
|
|
|
7996
9195
|
};
|
|
7997
9196
|
}
|
|
7998
9197
|
|
|
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
9198
|
// src/commands/init.ts
|
|
8070
9199
|
function shellQuote5(value) {
|
|
8071
9200
|
if (/^[A-Za-z0-9_./:@=-]+$/.test(value)) {
|
|
@@ -8212,10 +9341,10 @@ async function parseOptionalJson(input, label) {
|
|
|
8212
9341
|
}
|
|
8213
9342
|
return parseJsonInput(input, label);
|
|
8214
9343
|
}
|
|
8215
|
-
async function memoryRequest(options, method,
|
|
9344
|
+
async function memoryRequest(options, method, path12, capability, data, params) {
|
|
8216
9345
|
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
8217
9346
|
const client = createApiClient(profile);
|
|
8218
|
-
return apiRequest(client, method,
|
|
9347
|
+
return apiRequest(client, method, path12, {
|
|
8219
9348
|
capability,
|
|
8220
9349
|
data: redactAuditValue(data),
|
|
8221
9350
|
params: params ? redactAuditValue(params) : void 0
|
|
@@ -8270,7 +9399,7 @@ function registerMemoryCommands(program2) {
|
|
|
8270
9399
|
}
|
|
8271
9400
|
|
|
8272
9401
|
// src/commands/matrix.ts
|
|
8273
|
-
import { readFile as
|
|
9402
|
+
import { readFile as readFile10 } from "fs/promises";
|
|
8274
9403
|
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
9404
|
var UUID_PATH_PATTERN = /uuid'[^'"\s/]+/i;
|
|
8276
9405
|
async function parseSeedRules(input) {
|
|
@@ -8278,7 +9407,7 @@ async function parseSeedRules(input) {
|
|
|
8278
9407
|
if (source === "") {
|
|
8279
9408
|
throw new Error("--rules file path is empty.");
|
|
8280
9409
|
}
|
|
8281
|
-
const raw = source ? await
|
|
9410
|
+
const raw = source ? await readFile10(source, "utf8") : input;
|
|
8282
9411
|
let parsed;
|
|
8283
9412
|
try {
|
|
8284
9413
|
parsed = JSON.parse(raw);
|
|
@@ -8297,15 +9426,15 @@ async function parseSeedRules(input) {
|
|
|
8297
9426
|
});
|
|
8298
9427
|
return rules;
|
|
8299
9428
|
}
|
|
8300
|
-
function collectUuidPaths(value,
|
|
9429
|
+
function collectUuidPaths(value, path12 = "$") {
|
|
8301
9430
|
if (typeof value === "string") {
|
|
8302
|
-
return UUID_VALUE_PATTERN2.test(value) || UUID_PATH_PATTERN.test(value) ? [
|
|
9431
|
+
return UUID_VALUE_PATTERN2.test(value) || UUID_PATH_PATTERN.test(value) ? [path12] : [];
|
|
8303
9432
|
}
|
|
8304
9433
|
if (Array.isArray(value)) {
|
|
8305
|
-
return value.flatMap((item, index) => collectUuidPaths(item, `${
|
|
9434
|
+
return value.flatMap((item, index) => collectUuidPaths(item, `${path12}[${index}]`));
|
|
8306
9435
|
}
|
|
8307
9436
|
if (typeof value === "object" && value !== null) {
|
|
8308
|
-
return Object.entries(value).flatMap(([key, child]) => collectUuidPaths(child, `${
|
|
9437
|
+
return Object.entries(value).flatMap(([key, child]) => collectUuidPaths(child, `${path12}.${key}`));
|
|
8309
9438
|
}
|
|
8310
9439
|
return [];
|
|
8311
9440
|
}
|
|
@@ -8334,16 +9463,16 @@ function dataArray(value) {
|
|
|
8334
9463
|
if (isRecord6(value) && Array.isArray(value.data)) return value.data;
|
|
8335
9464
|
return [];
|
|
8336
9465
|
}
|
|
8337
|
-
function collectMatrixOwnerPaths(value,
|
|
9466
|
+
function collectMatrixOwnerPaths(value, path12 = "$") {
|
|
8338
9467
|
if (Array.isArray(value)) {
|
|
8339
|
-
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${
|
|
9468
|
+
return value.flatMap((item, index) => collectMatrixOwnerPaths(item, `${path12}[${index}]`));
|
|
8340
9469
|
}
|
|
8341
9470
|
if (!isRecord6(value)) {
|
|
8342
9471
|
return [];
|
|
8343
9472
|
}
|
|
8344
9473
|
const matches = [];
|
|
8345
9474
|
Object.entries(value).forEach(([key, child]) => {
|
|
8346
|
-
const childPath = `${
|
|
9475
|
+
const childPath = `${path12}.${key}`;
|
|
8347
9476
|
if (key.includes("matrix_owner") || typeof child === "string" && child.includes("matrix_owner")) {
|
|
8348
9477
|
matches.push({ path: childPath, value: child });
|
|
8349
9478
|
}
|
|
@@ -8457,6 +9586,72 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
8457
9586
|
});
|
|
8458
9587
|
}
|
|
8459
9588
|
|
|
9589
|
+
// src/commands/plugin.ts
|
|
9590
|
+
function defaultAgent2(options) {
|
|
9591
|
+
return options.agent || process.env.BPMAX_CLI_AGENT || "codex";
|
|
9592
|
+
}
|
|
9593
|
+
function selectSkills(skills, skillName) {
|
|
9594
|
+
if (!skillName) {
|
|
9595
|
+
return skills;
|
|
9596
|
+
}
|
|
9597
|
+
return skills.filter((item) => item.name === skillName);
|
|
9598
|
+
}
|
|
9599
|
+
function registerPluginCommands(program2) {
|
|
9600
|
+
const plugin = program2.command("plugin").description("Manage BPMAX plugins and plugin-scoped Agent skills");
|
|
9601
|
+
const skills = plugin.command("skills").description("Manage plugin-scoped Agent skills");
|
|
9602
|
+
skills.command("list").argument("[plugin]", "Plugin name").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (pluginName, options) => {
|
|
9603
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
9604
|
+
const result = pluginName ? await apiRequest(createApiClient(profile), "GET", `/cli/plugins/${pluginName}/skills`) : await apiRequest(createApiClient(profile), "GET", "/cli/plugins", { params: { include_skills: 1 } });
|
|
9605
|
+
printResult(options.format, result);
|
|
9606
|
+
});
|
|
9607
|
+
skills.command("state").option("--agent <agent>", "Agent adapter", "codex").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
9608
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
9609
|
+
const agent = defaultAgent2(options);
|
|
9610
|
+
printResult(options.format, {
|
|
9611
|
+
agent,
|
|
9612
|
+
profile: profile.name,
|
|
9613
|
+
state: await readPluginSkillState(profile.name, agent)
|
|
9614
|
+
});
|
|
9615
|
+
});
|
|
9616
|
+
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) => {
|
|
9617
|
+
printResult(options.format, await lintPluginSkillZip(options.zip, { expectedName: options.skill }));
|
|
9618
|
+
});
|
|
9619
|
+
async function ensureSkills(pluginName, options) {
|
|
9620
|
+
const profile = resolveProfile(await loadConfig(), options.profile);
|
|
9621
|
+
const client = createApiClient(profile);
|
|
9622
|
+
const agent = defaultAgent2(options);
|
|
9623
|
+
const available = await listPluginSkills(client, pluginName);
|
|
9624
|
+
const selected = selectSkills(available, options.skill);
|
|
9625
|
+
if (!selected.length) {
|
|
9626
|
+
throw new Error(options.skill ? `Plugin skill not found: ${pluginName}/${options.skill}` : `No plugin skills found for ${pluginName}`);
|
|
9627
|
+
}
|
|
9628
|
+
const installed = [];
|
|
9629
|
+
for (const skill of selected) {
|
|
9630
|
+
installed.push(await ensurePluginSkill({
|
|
9631
|
+
client,
|
|
9632
|
+
profile,
|
|
9633
|
+
plugin: pluginName,
|
|
9634
|
+
skill,
|
|
9635
|
+
agent,
|
|
9636
|
+
force: options.force
|
|
9637
|
+
}));
|
|
9638
|
+
}
|
|
9639
|
+
printResult(options.format, {
|
|
9640
|
+
action: options.force ? "updated" : installed.every((item) => item.action === "in_sync") ? "in_sync" : "ensured",
|
|
9641
|
+
agent,
|
|
9642
|
+
plugin: pluginName,
|
|
9643
|
+
skills: installed,
|
|
9644
|
+
next_commands: installed.map((item) => `Use skill ${item.skill} for plugin ${pluginName}.`)
|
|
9645
|
+
});
|
|
9646
|
+
}
|
|
9647
|
+
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(
|
|
9648
|
+
(pluginName, options) => ensureSkills(pluginName, options)
|
|
9649
|
+
);
|
|
9650
|
+
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(
|
|
9651
|
+
(pluginName, options) => ensureSkills(pluginName, { ...options, force: true })
|
|
9652
|
+
);
|
|
9653
|
+
}
|
|
9654
|
+
|
|
8460
9655
|
// src/core/form-schema.ts
|
|
8461
9656
|
var FIELD_KEY_NAMES = [
|
|
8462
9657
|
"key",
|
|
@@ -8546,6 +9741,15 @@ function pickOptions(source) {
|
|
|
8546
9741
|
return options;
|
|
8547
9742
|
}
|
|
8548
9743
|
}
|
|
9744
|
+
for (const containerKey of ["props", "config", "setting", "value"]) {
|
|
9745
|
+
const container = source[containerKey];
|
|
9746
|
+
if (isRecord7(container)) {
|
|
9747
|
+
const nested = pickOptions(container);
|
|
9748
|
+
if (nested?.length) {
|
|
9749
|
+
return nested;
|
|
9750
|
+
}
|
|
9751
|
+
}
|
|
9752
|
+
}
|
|
8549
9753
|
return void 0;
|
|
8550
9754
|
}
|
|
8551
9755
|
function fieldFromRecord(source) {
|
|
@@ -8636,16 +9840,17 @@ function validateComplexSelector(field, value) {
|
|
|
8636
9840
|
return null;
|
|
8637
9841
|
}
|
|
8638
9842
|
const validObject = (item) => isRecord7(item);
|
|
9843
|
+
const hint = complexSelectorHint(field);
|
|
8639
9844
|
if (Array.isArray(value)) {
|
|
8640
|
-
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
|
|
9845
|
+
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values. ${hint}`;
|
|
8641
9846
|
}
|
|
8642
9847
|
if (validObject(value)) {
|
|
8643
9848
|
return null;
|
|
8644
9849
|
}
|
|
8645
|
-
return `${field.key} must be a selector option object or array of option objects, not a scalar value`;
|
|
9850
|
+
return `${field.key} must be a selector option object or array of option objects, not a scalar value. ${hint}`;
|
|
8646
9851
|
}
|
|
8647
9852
|
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);
|
|
9853
|
+
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
9854
|
}
|
|
8650
9855
|
function isEnumSelectType(type) {
|
|
8651
9856
|
return /enum_select/.test(type);
|
|
@@ -8679,7 +9884,7 @@ function validateType(field, value) {
|
|
|
8679
9884
|
const values = Array.isArray(value) ? value.map((item) => String(optionComparableValue(item))) : [String(optionComparableValue(value))];
|
|
8680
9885
|
const invalid = values.filter((item) => !field.options?.includes(item));
|
|
8681
9886
|
if (invalid.length > 0) {
|
|
8682
|
-
return `${field.key} has invalid option value(s): ${invalid.join(", ")}`;
|
|
9887
|
+
return `${field.key} has invalid option value(s): ${invalid.join(", ")}. Legal options: ${field.options.join(" / ")}`;
|
|
8683
9888
|
}
|
|
8684
9889
|
}
|
|
8685
9890
|
if (/(number|int|decimal|float|double|amount)/.test(type) && typeof value !== "number") {
|
|
@@ -8733,6 +9938,70 @@ function validateFormAgainstFields(form, fields) {
|
|
|
8733
9938
|
const errors = validateFormEntries(form, fields);
|
|
8734
9939
|
return { fields, errors };
|
|
8735
9940
|
}
|
|
9941
|
+
function complexSelectorHint(field) {
|
|
9942
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
9943
|
+
if (/es_project_selector|project_selector|project_selector_new|plugin_project_selector|relation_project/.test(type)) {
|
|
9944
|
+
return "Project selector values usually require BPMAX page selection or a platform selector object with id/name; do not pass a free-text scalar.";
|
|
9945
|
+
}
|
|
9946
|
+
if (/user|person|department|group/.test(type)) {
|
|
9947
|
+
return "User/group selector values usually require BPMAX page selection or a platform selector object; do not pass a free-text scalar.";
|
|
9948
|
+
}
|
|
9949
|
+
return "Use BPMAX page selection unless you have the exact platform selector object shape.";
|
|
9950
|
+
}
|
|
9951
|
+
function fieldExpectedShape(field) {
|
|
9952
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
9953
|
+
if (isSubFormField(field)) {
|
|
9954
|
+
const childShape = Object.fromEntries((field.children ?? []).map((child) => [child.key, childExpectedPlaceholder(child)]));
|
|
9955
|
+
return `array of row objects, for example ${JSON.stringify([childShape])}`;
|
|
9956
|
+
}
|
|
9957
|
+
if (isComplexSelectorType(type)) {
|
|
9958
|
+
return "selector object or array of selector objects; page selection is safer for project/user/group selectors";
|
|
9959
|
+
}
|
|
9960
|
+
if (field.options?.length) {
|
|
9961
|
+
return `one of: ${field.options.join(" / ")}`;
|
|
9962
|
+
}
|
|
9963
|
+
if (/(number|int|decimal|float|double|amount)/.test(type)) {
|
|
9964
|
+
return "number";
|
|
9965
|
+
}
|
|
9966
|
+
if (/(boolean|bool|switch|checkbox)/.test(type)) {
|
|
9967
|
+
return "boolean";
|
|
9968
|
+
}
|
|
9969
|
+
if (/(array|multi|multiple)/.test(type)) {
|
|
9970
|
+
return "array";
|
|
9971
|
+
}
|
|
9972
|
+
return "scalar value";
|
|
9973
|
+
}
|
|
9974
|
+
function childExpectedPlaceholder(field) {
|
|
9975
|
+
if (isSubFormField(field)) {
|
|
9976
|
+
return [];
|
|
9977
|
+
}
|
|
9978
|
+
if (field.options?.length) {
|
|
9979
|
+
return field.options[0] ?? "<option>";
|
|
9980
|
+
}
|
|
9981
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
9982
|
+
if (/(number|int|decimal|float|double|amount)/.test(type)) {
|
|
9983
|
+
return 0;
|
|
9984
|
+
}
|
|
9985
|
+
if (/(boolean|bool|switch|checkbox)/.test(type)) {
|
|
9986
|
+
return false;
|
|
9987
|
+
}
|
|
9988
|
+
if (isComplexSelectorType(type)) {
|
|
9989
|
+
return { id: "<platform-id>", name: "<display-name>" };
|
|
9990
|
+
}
|
|
9991
|
+
return "<value>";
|
|
9992
|
+
}
|
|
9993
|
+
function explainFormValidationSchema(fields) {
|
|
9994
|
+
return fields.map((field) => ({
|
|
9995
|
+
key: field.key,
|
|
9996
|
+
...field.label ? { label: field.label } : {},
|
|
9997
|
+
...field.type ? { type: field.type } : {},
|
|
9998
|
+
required: field.required,
|
|
9999
|
+
expected: fieldExpectedShape(field),
|
|
10000
|
+
...isComplexSelectorType(field.type?.toLowerCase() ?? "") ? { handoff_hint: complexSelectorHint(field) } : {},
|
|
10001
|
+
...field.options?.length ? { options: field.options } : {},
|
|
10002
|
+
...field.children?.length ? { children: explainFormValidationSchema(field.children) } : {}
|
|
10003
|
+
}));
|
|
10004
|
+
}
|
|
8736
10005
|
|
|
8737
10006
|
// src/core/form-prompts.ts
|
|
8738
10007
|
import { confirm, isCancel, multiselect, select, text as text3 } from "@clack/prompts";
|
|
@@ -9311,6 +10580,25 @@ function assertHandoffFormCompatible(fields, form) {
|
|
|
9311
10580
|
);
|
|
9312
10581
|
}
|
|
9313
10582
|
}
|
|
10583
|
+
function explainProjectCreateValidation(fields, form) {
|
|
10584
|
+
if (fields.length === 0) {
|
|
10585
|
+
return {
|
|
10586
|
+
ok: false,
|
|
10587
|
+
errors: [
|
|
10588
|
+
"Could not discover the flow create form schema for local validation."
|
|
10589
|
+
],
|
|
10590
|
+
schema: [],
|
|
10591
|
+
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."
|
|
10592
|
+
};
|
|
10593
|
+
}
|
|
10594
|
+
const validation = validateFormAgainstFields(form, fields);
|
|
10595
|
+
return {
|
|
10596
|
+
ok: validation.errors.length === 0,
|
|
10597
|
+
errors: validation.errors,
|
|
10598
|
+
schema: explainFormValidationSchema(fields),
|
|
10599
|
+
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."
|
|
10600
|
+
};
|
|
10601
|
+
}
|
|
9314
10602
|
function isRiskyFormField(field) {
|
|
9315
10603
|
const type = field.type?.toLowerCase() ?? "";
|
|
9316
10604
|
const label = field.label?.toLowerCase() ?? "";
|
|
@@ -9364,9 +10652,9 @@ function contextField(field, reason, options = {}) {
|
|
|
9364
10652
|
function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
9365
10653
|
for (const field of fields) {
|
|
9366
10654
|
const value = form[field.key];
|
|
9367
|
-
const
|
|
10655
|
+
const path12 = options.prefix ? `${options.prefix}.${field.key}` : field.key;
|
|
9368
10656
|
const fieldOptions = {
|
|
9369
|
-
path:
|
|
10657
|
+
path: path12,
|
|
9370
10658
|
rootKey: options.rootKey ?? field.key,
|
|
9371
10659
|
parentKey: options.parentKey
|
|
9372
10660
|
};
|
|
@@ -9607,11 +10895,14 @@ function registerProjectCommands(program2) {
|
|
|
9607
10895
|
});
|
|
9608
10896
|
}
|
|
9609
10897
|
});
|
|
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) => {
|
|
10898
|
+
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
10899
|
const interactiveSource = command.getOptionValueSource("interactive");
|
|
9612
10900
|
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
9613
10901
|
throw new Error("--body and --interactive cannot be used together.");
|
|
9614
10902
|
}
|
|
10903
|
+
if (options.body && options.explainValidation) {
|
|
10904
|
+
throw new Error("--explain-validation cannot be used with --body because --body bypasses form schema discovery.");
|
|
10905
|
+
}
|
|
9615
10906
|
if (options.body && options.unsafeDirectCreate !== true) {
|
|
9616
10907
|
throw new Error(
|
|
9617
10908
|
[
|
|
@@ -9642,6 +10933,16 @@ function registerProjectCommands(program2) {
|
|
|
9642
10933
|
return projectFormTemplate;
|
|
9643
10934
|
};
|
|
9644
10935
|
const usesTemplateProjectName = metaUsesTemplateProjectName(flowDetail);
|
|
10936
|
+
if (options.explainValidation) {
|
|
10937
|
+
projectFormTemplate = await loadProjectFormTemplate();
|
|
10938
|
+
const fields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
10939
|
+
printResult(options.format, {
|
|
10940
|
+
flow_type: flowIdentifiers.flow_type,
|
|
10941
|
+
flow_key: flowIdentifiers.flow_key,
|
|
10942
|
+
...explainProjectCreateValidation(fields, form)
|
|
10943
|
+
});
|
|
10944
|
+
return;
|
|
10945
|
+
}
|
|
9645
10946
|
if (options.handoffOnly) {
|
|
9646
10947
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
9647
10948
|
const handoffFields2 = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
@@ -9767,11 +11068,11 @@ function registerProjectCommands(program2) {
|
|
|
9767
11068
|
|
|
9768
11069
|
// src/commands/recipe.ts
|
|
9769
11070
|
import { spawn as spawn2 } from "child_process";
|
|
9770
|
-
import { fileURLToPath as
|
|
11071
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
9771
11072
|
|
|
9772
11073
|
// src/core/recipes.ts
|
|
9773
|
-
import { access, mkdir as
|
|
9774
|
-
import
|
|
11074
|
+
import { access, mkdir as mkdir8, readdir as readdir3, readFile as readFile11, writeFile as writeFile8 } from "fs/promises";
|
|
11075
|
+
import path8 from "path";
|
|
9775
11076
|
var RECIPE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
9776
11077
|
var TEMPLATE_PATTERN = /{{\s*([a-zA-Z0-9_.-]+)\s*}}/g;
|
|
9777
11078
|
function assertSafeName(kind, value) {
|
|
@@ -9795,12 +11096,12 @@ function resolveRecipeLocation(options) {
|
|
|
9795
11096
|
workspace,
|
|
9796
11097
|
workspaceDirName,
|
|
9797
11098
|
recipeName: options.recipeName,
|
|
9798
|
-
recipeDir:
|
|
11099
|
+
recipeDir: path8.join(profileDir, "recipes", workspaceDirName, options.recipeName)
|
|
9799
11100
|
};
|
|
9800
11101
|
}
|
|
9801
11102
|
function getRecipesDir(options) {
|
|
9802
11103
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
9803
|
-
return
|
|
11104
|
+
return path8.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
9804
11105
|
}
|
|
9805
11106
|
function isRecord10(value) {
|
|
9806
11107
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -9852,13 +11153,13 @@ function parseRecipeDefinition(input) {
|
|
|
9852
11153
|
};
|
|
9853
11154
|
}
|
|
9854
11155
|
async function loadRecipe(recipeDir) {
|
|
9855
|
-
const raw = await
|
|
11156
|
+
const raw = await readFile11(path8.join(recipeDir, "recipe.json"), "utf8");
|
|
9856
11157
|
return parseRecipeDefinition(JSON.parse(raw));
|
|
9857
11158
|
}
|
|
9858
11159
|
async function listRecipes(recipesDir) {
|
|
9859
11160
|
let entries;
|
|
9860
11161
|
try {
|
|
9861
|
-
entries = await
|
|
11162
|
+
entries = await readdir3(recipesDir);
|
|
9862
11163
|
} catch (error) {
|
|
9863
11164
|
if (error.code === "ENOENT") {
|
|
9864
11165
|
return [];
|
|
@@ -9870,7 +11171,7 @@ async function listRecipes(recipesDir) {
|
|
|
9870
11171
|
if (!RECIPE_NAME_PATTERN.test(entry)) {
|
|
9871
11172
|
continue;
|
|
9872
11173
|
}
|
|
9873
|
-
const recipeDir =
|
|
11174
|
+
const recipeDir = path8.join(recipesDir, entry);
|
|
9874
11175
|
try {
|
|
9875
11176
|
const recipe = await loadRecipe(recipeDir);
|
|
9876
11177
|
summaries.push({
|
|
@@ -9936,12 +11237,12 @@ function renderTemplate(template, variables) {
|
|
|
9936
11237
|
}
|
|
9937
11238
|
function resolveRecipeFile(recipeDir, token) {
|
|
9938
11239
|
const relative = token.slice(1);
|
|
9939
|
-
if (!relative || relative.includes("..") ||
|
|
11240
|
+
if (!relative || relative.includes("..") || path8.isAbsolute(relative)) {
|
|
9940
11241
|
throw new Error(`Unsafe recipe file reference: ${token}`);
|
|
9941
11242
|
}
|
|
9942
|
-
const resolved =
|
|
9943
|
-
const root =
|
|
9944
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
11243
|
+
const resolved = path8.resolve(recipeDir, relative);
|
|
11244
|
+
const root = path8.resolve(recipeDir);
|
|
11245
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path8.sep}`)) {
|
|
9945
11246
|
throw new Error(`Recipe file reference escapes recipe directory: ${token}`);
|
|
9946
11247
|
}
|
|
9947
11248
|
return resolved;
|
|
@@ -9951,7 +11252,7 @@ async function renderArgv(options) {
|
|
|
9951
11252
|
const rendered = [];
|
|
9952
11253
|
for (const token of options.recipe.command.argv) {
|
|
9953
11254
|
if (token.startsWith("@")) {
|
|
9954
|
-
const raw = await
|
|
11255
|
+
const raw = await readFile11(resolveRecipeFile(options.recipeDir, token), "utf8");
|
|
9955
11256
|
rendered.push(renderTemplate(raw, options.variables));
|
|
9956
11257
|
} else {
|
|
9957
11258
|
rendered.push(renderTemplate(token, options.variables));
|
|
@@ -9977,7 +11278,7 @@ async function ensureEmptyOrForce(targetDir, force = false) {
|
|
|
9977
11278
|
}
|
|
9978
11279
|
async function writeRecipeScaffold(options) {
|
|
9979
11280
|
await ensureEmptyOrForce(options.location.recipeDir, options.force);
|
|
9980
|
-
await
|
|
11281
|
+
await mkdir8(options.location.recipeDir, { recursive: true });
|
|
9981
11282
|
const title = options.title || options.location.recipeName;
|
|
9982
11283
|
const recipe = {
|
|
9983
11284
|
version: 1,
|
|
@@ -9994,16 +11295,16 @@ async function writeRecipeScaffold(options) {
|
|
|
9994
11295
|
mutating: true
|
|
9995
11296
|
}
|
|
9996
11297
|
};
|
|
9997
|
-
await
|
|
11298
|
+
await writeFile8(path8.join(options.location.recipeDir, "recipe.json"), `${JSON.stringify(recipe, null, 2)}
|
|
9998
11299
|
`, "utf8");
|
|
9999
|
-
await
|
|
10000
|
-
|
|
11300
|
+
await writeFile8(
|
|
11301
|
+
path8.join(options.location.recipeDir, "payload.json"),
|
|
10001
11302
|
`${JSON.stringify({ form: {} }, null, 2)}
|
|
10002
11303
|
`,
|
|
10003
11304
|
"utf8"
|
|
10004
11305
|
);
|
|
10005
|
-
await
|
|
10006
|
-
|
|
11306
|
+
await writeFile8(
|
|
11307
|
+
path8.join(options.location.recipeDir, "README.md"),
|
|
10007
11308
|
[`# ${title}`, "", "Describe the BPMAX flow, field mapping, prerequisites, and verification steps for this recipe.", ""].join("\n"),
|
|
10008
11309
|
"utf8"
|
|
10009
11310
|
);
|
|
@@ -10011,7 +11312,7 @@ async function writeRecipeScaffold(options) {
|
|
|
10011
11312
|
|
|
10012
11313
|
// src/commands/recipe.ts
|
|
10013
11314
|
function currentCliInvocation() {
|
|
10014
|
-
const entry = process.argv[1] ||
|
|
11315
|
+
const entry = process.argv[1] || fileURLToPath3(import.meta.url);
|
|
10015
11316
|
return {
|
|
10016
11317
|
command: process.execPath,
|
|
10017
11318
|
argsPrefix: [entry]
|
|
@@ -10961,8 +12262,8 @@ function registerStepCommands(program2) {
|
|
|
10961
12262
|
}
|
|
10962
12263
|
|
|
10963
12264
|
// src/core/taskbook.ts
|
|
10964
|
-
import { mkdir as
|
|
10965
|
-
import
|
|
12265
|
+
import { mkdir as mkdir9, readFile as readFile12, writeFile as writeFile9 } from "fs/promises";
|
|
12266
|
+
import path9 from "path";
|
|
10966
12267
|
var TaskbookError = class extends Error {
|
|
10967
12268
|
};
|
|
10968
12269
|
var REQUIRED_TASKBOOK_TERMS = [
|
|
@@ -10974,6 +12275,7 @@ var REQUIRED_TASKBOOK_TERMS = [
|
|
|
10974
12275
|
"\u9A8C\u6536\u95E8\u7981",
|
|
10975
12276
|
"\u5BFC\u822A\u5165\u53E3\u7B56\u7565",
|
|
10976
12277
|
"\u5217\u8868 lint",
|
|
12278
|
+
"\u914D\u7F6E Skill / Capability \u4F9D\u636E\u8868",
|
|
10977
12279
|
"\u505C\u673A\u70B9",
|
|
10978
12280
|
"\u5BF9\u8C61\u9501\u91CD\u590D",
|
|
10979
12281
|
"\u53EA\u8BFB\u4EFB\u52A1",
|
|
@@ -11014,6 +12316,145 @@ var PROMPT_REQUIRED_TERMS = [
|
|
|
11014
12316
|
var BPMAX_SKILL_PATTERN = /bpmax-[a-z0-9-]+|form-control-library|bpmax-memory-protocol/;
|
|
11015
12317
|
var FLOW_LOCK_PATTERN = /\bflow:([A-Za-z0-9_-]+)/g;
|
|
11016
12318
|
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;
|
|
12319
|
+
var CONFIG_TASK_RULES = [
|
|
12320
|
+
{
|
|
12321
|
+
domain: "flow-template",
|
|
12322
|
+
skill: "bpmax-flow-template-editor",
|
|
12323
|
+
lockPattern: /(?:flow:flow\d+|new-flow:[A-Za-z0-9_-]+)/,
|
|
12324
|
+
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/],
|
|
12325
|
+
readonlyEvidence: [/bpmax-cli config flow-template export|流程.*回读|readback/i],
|
|
12326
|
+
constraintEvidence: /project_after_create_path|message_template|return ""|matrix_owner|cc_matrix|流程模板约束|flow-template lint/i,
|
|
12327
|
+
mentionPattern: /流程模板|flow-template|flow_template|流程配置|创建流程|编辑流程/
|
|
12328
|
+
},
|
|
12329
|
+
{
|
|
12330
|
+
domain: "form-template",
|
|
12331
|
+
skill: "bpmax-form-template-editor",
|
|
12332
|
+
lockPattern: /form-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12333
|
+
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/],
|
|
12334
|
+
readonlyEvidence: [/bpmax-cli config form-template export|表单.*回读|readback/i],
|
|
12335
|
+
constraintEvidence: /字段 schema|表单顺序|raw\.value|layout|sub_form|form-template inspect|表单模板约束/i,
|
|
12336
|
+
mentionPattern: /表单模板|form-template|form_template|表单字段|子表单|sub_form/
|
|
12337
|
+
},
|
|
12338
|
+
{
|
|
12339
|
+
domain: "list-template",
|
|
12340
|
+
skill: "bpmax-list-template-editor",
|
|
12341
|
+
lockPattern: /list-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12342
|
+
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/],
|
|
12343
|
+
readonlyEvidence: [/bpmax-cli config list-template export|列表.*回读|readback/i],
|
|
12344
|
+
constraintEvidence: /操作列|删除|guard|icon|查询安全|真实列表页|list-template lint/i,
|
|
12345
|
+
mentionPattern: /列表模板|list-template|list_template|列表配置|操作列/
|
|
12346
|
+
},
|
|
12347
|
+
{
|
|
12348
|
+
domain: "filter-template",
|
|
12349
|
+
skill: "bpmax-filter-template-editor",
|
|
12350
|
+
lockPattern: /filter-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12351
|
+
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/],
|
|
12352
|
+
readonlyEvidence: [/bpmax-cli config filter-template export|筛选.*回读|readback/i],
|
|
12353
|
+
constraintEvidence: /筛选字段|筛选器|查询条件|filter-template lint/i,
|
|
12354
|
+
mentionPattern: /筛选模板|筛选器|filter-template|filter_template/
|
|
12355
|
+
},
|
|
12356
|
+
{
|
|
12357
|
+
domain: "project-detail-template",
|
|
12358
|
+
skill: "bpmax-project-detail-template-editor",
|
|
12359
|
+
lockPattern: /project-detail-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12360
|
+
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/],
|
|
12361
|
+
readonlyEvidence: [/bpmax-cli config project-detail-template export|详情.*回读|resolve-default|readback/i],
|
|
12362
|
+
constraintEvidence: /默认详情模板|resolve-default|详情页|project_detail|project-detail-template lint/i,
|
|
12363
|
+
mentionPattern: /详情模板|项目详情|project-detail-template|project_detail/
|
|
12364
|
+
},
|
|
12365
|
+
{
|
|
12366
|
+
domain: "console-template",
|
|
12367
|
+
skill: "bpmax-console-template-editor",
|
|
12368
|
+
lockPattern: /console-template:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12369
|
+
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/],
|
|
12370
|
+
readonlyEvidence: [/bpmax-cli config console-template export|看板.*回读|readback/i],
|
|
12371
|
+
constraintEvidence: /数据看板|图表|指标|console-template lint/i,
|
|
12372
|
+
mentionPattern: /看板模板|数据看板|console-template|console_template/
|
|
12373
|
+
},
|
|
12374
|
+
{
|
|
12375
|
+
domain: "dataset",
|
|
12376
|
+
skill: "bpmax-dataset-template-editor",
|
|
12377
|
+
lockPattern: /dataset:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12378
|
+
writeEvidence: [/bpmax-cli config dataset lint/, /bpmax-cli config dataset build/, /bpmax-cli config dataset submit/, /bpmax-cli config dataset verify/],
|
|
12379
|
+
readonlyEvidence: [/bpmax-cli config dataset export|数据集.*回读|readback/i],
|
|
12380
|
+
constraintEvidence: /字段关联|relationFields|publish|refresh|数据集约束/i,
|
|
12381
|
+
mentionPattern: /数据集(?!字段)|dataset(?!-field)|data_set(?!_field)/
|
|
12382
|
+
},
|
|
12383
|
+
{
|
|
12384
|
+
domain: "dataset-field",
|
|
12385
|
+
skill: "bpmax-dataset-field-template-editor",
|
|
12386
|
+
lockPattern: /dataset-field:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12387
|
+
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/],
|
|
12388
|
+
readonlyEvidence: [/bpmax-cli config dataset-field export|数据集字段.*回读|readback/i],
|
|
12389
|
+
constraintEvidence: /source_table|source_field|source_fk|source mapping|字段映射|来源表|数据集字段约束/i,
|
|
12390
|
+
mentionPattern: /数据集字段|dataset-field|data_set_field/
|
|
12391
|
+
},
|
|
12392
|
+
{
|
|
12393
|
+
domain: "api-platform",
|
|
12394
|
+
skill: "bpmax-api-platform-editor",
|
|
12395
|
+
lockPattern: /api-platform:[A-Za-z0-9_-]+/,
|
|
12396
|
+
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/],
|
|
12397
|
+
readonlyEvidence: [/bpmax-cli config api-platform export|API.*回读|readback/i],
|
|
12398
|
+
constraintEvidence: /实例|代理|绑定|API 平台|api-platform lint/i,
|
|
12399
|
+
mentionPattern: /API 平台|api-platform|系统集成|接口代理/
|
|
12400
|
+
},
|
|
12401
|
+
{
|
|
12402
|
+
domain: "role",
|
|
12403
|
+
skill: "bpmax-role-editor",
|
|
12404
|
+
lockPattern: /role:(?:\d+|new-[A-Za-z0-9_-]+)/,
|
|
12405
|
+
writeEvidence: [/bpmax-cli config role lint/, /bpmax-cli config role build/, /bpmax-cli config role submit/, /bpmax-cli config role verify/],
|
|
12406
|
+
readonlyEvidence: [/bpmax-cli config role export|角色.*回读|readback/i],
|
|
12407
|
+
constraintEvidence: /权限点|成员|角色权限|role lint/i,
|
|
12408
|
+
mentionPattern: /角色|权限|role/
|
|
12409
|
+
},
|
|
12410
|
+
{
|
|
12411
|
+
domain: "nav-config",
|
|
12412
|
+
skill: "bpmax-nav-config-editor",
|
|
12413
|
+
lockPattern: /nav-config:[A-Za-z0-9_-]+/,
|
|
12414
|
+
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|入口.*浏览器|导航.*浏览器/],
|
|
12415
|
+
readonlyEvidence: [/bpmax-cli config nav-config export|导航.*回读|readback/i],
|
|
12416
|
+
constraintEvidence: /入口|导航|PC|H5|快捷入口|浏览器.*打开/i,
|
|
12417
|
+
mentionPattern: /导航|入口|nav-config|菜单|快捷入口/
|
|
12418
|
+
},
|
|
12419
|
+
{
|
|
12420
|
+
domain: "workspace",
|
|
12421
|
+
skill: "bpmax-workspace-editor",
|
|
12422
|
+
lockPattern: /workspace:[A-Za-z0-9_-]+/,
|
|
12423
|
+
writeEvidence: [/bpmax-cli config workspace lint/, /bpmax-cli config workspace build/, /bpmax-cli config workspace submit/, /bpmax-cli config workspace verify/],
|
|
12424
|
+
readonlyEvidence: [/bpmax-cli config workspace export|工作区.*回读|readback/i],
|
|
12425
|
+
constraintEvidence: /workspace key|entry_path|工作区约束|workspace lint/i,
|
|
12426
|
+
mentionPattern: /创建工作区|编辑工作区|工作区配置|config workspace|workspace config/
|
|
12427
|
+
},
|
|
12428
|
+
{
|
|
12429
|
+
domain: "workspace-flow",
|
|
12430
|
+
skill: "bpmax-workspace-editor",
|
|
12431
|
+
lockPattern: /workspace-flow:[A-Za-z0-9_-]+/,
|
|
12432
|
+
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/],
|
|
12433
|
+
readonlyEvidence: [/bpmax-cli config workspace-flow export|工作区流程.*回读|readback/i],
|
|
12434
|
+
constraintEvidence: /全量替换|重新 export|绑定|workspace-flow/i,
|
|
12435
|
+
mentionPattern: /工作区流程|流程绑定|workspace-flow/
|
|
12436
|
+
},
|
|
12437
|
+
{
|
|
12438
|
+
domain: "e2e",
|
|
12439
|
+
skill: "bpmax-e2e-flow-test-operator",
|
|
12440
|
+
lockPattern: /(?:e2e|test-suite):[A-Za-z0-9_-]+/,
|
|
12441
|
+
writeEvidence: [/bpmax-cli test-suite lint|浏览器|真实页面|E2E|截图|测试报告/i],
|
|
12442
|
+
readonlyEvidence: [/浏览器|真实页面|E2E|截图|测试报告/i],
|
|
12443
|
+
constraintEvidence: /真实业务|测试数据|浏览器|截图|test_data|E2E/i,
|
|
12444
|
+
mentionPattern: /E2E|端到端|浏览器测试|测试用例|回归测试/
|
|
12445
|
+
}
|
|
12446
|
+
];
|
|
12447
|
+
function isWriteMode(rowOrText) {
|
|
12448
|
+
const mode = typeof rowOrText === "string" ? rowOrText.match(/subagent_mode\s*[::]\s*([^\n]+)/)?.[1] || "" : rowOrText.subagent_mode || "";
|
|
12449
|
+
return !/\breadonly\b/i.test(mode);
|
|
12450
|
+
}
|
|
12451
|
+
function hasConfigAdaptersEvidence(value) {
|
|
12452
|
+
return /bpmax-cli config adapters --format json/.test(value) && /(capability|能力|adapter|适配|config\.)/i.test(value);
|
|
12453
|
+
}
|
|
12454
|
+
function hasDomainWriteEvidence(domain, evidenceText, patterns) {
|
|
12455
|
+
const shorthand = new RegExp(`bpmax-cli config ${domain} (?:export/)?lint/build/submit/verify`);
|
|
12456
|
+
return shorthand.test(evidenceText) || patterns.every((pattern) => pattern.test(evidenceText));
|
|
12457
|
+
}
|
|
11017
12458
|
function uuidErrors(text5, target) {
|
|
11018
12459
|
const values = [...new Set([...text5.matchAll(UUID_PATTERN)].map((match) => match[0]))];
|
|
11019
12460
|
return values.map(
|
|
@@ -11021,7 +12462,7 @@ function uuidErrors(text5, target) {
|
|
|
11021
12462
|
);
|
|
11022
12463
|
}
|
|
11023
12464
|
async function readTaskbookText(file) {
|
|
11024
|
-
const raw = await
|
|
12465
|
+
const raw = await readFile12(file, "utf8");
|
|
11025
12466
|
try {
|
|
11026
12467
|
const parsed = JSON.parse(raw);
|
|
11027
12468
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
@@ -11094,6 +12535,56 @@ function validateTaskbookNavigationAndListGates(text5, errors) {
|
|
|
11094
12535
|
}
|
|
11095
12536
|
});
|
|
11096
12537
|
}
|
|
12538
|
+
function rowText(row) {
|
|
12539
|
+
return [
|
|
12540
|
+
row.business_goal,
|
|
12541
|
+
row.required_skills,
|
|
12542
|
+
row.object_lock,
|
|
12543
|
+
row.evidence,
|
|
12544
|
+
row.notes,
|
|
12545
|
+
row.parallel_type
|
|
12546
|
+
].filter(Boolean).join(" ");
|
|
12547
|
+
}
|
|
12548
|
+
function validateConfigRuleForTaskRow(row, rule, errors) {
|
|
12549
|
+
const taskId = row.task_id || "<unknown>";
|
|
12550
|
+
const combined = rowText(row);
|
|
12551
|
+
const hasSkill = (row.required_skills || "").includes(rule.skill);
|
|
12552
|
+
const mentionsDomain = rule.mentionPattern.test(combined) || rule.lockPattern.test(row.object_lock || "");
|
|
12553
|
+
if (mentionsDomain && !hasSkill) {
|
|
12554
|
+
errors.push(`${rule.domain} task ${taskId} mentions ${rule.domain} work but missing required skill ${rule.skill}.`);
|
|
12555
|
+
return;
|
|
12556
|
+
}
|
|
12557
|
+
if (!hasSkill) {
|
|
12558
|
+
return;
|
|
12559
|
+
}
|
|
12560
|
+
const writeMode = isWriteMode(row);
|
|
12561
|
+
if (writeMode && !rule.lockPattern.test(row.object_lock || "")) {
|
|
12562
|
+
errors.push(`${rule.domain} task ${taskId} must use object_lock matching ${rule.domain}:<id> or its documented lock pattern.`);
|
|
12563
|
+
}
|
|
12564
|
+
if (!writeMode && !/^readonly:[A-Za-z0-9_-]+/.test(row.object_lock || "") && !rule.lockPattern.test(row.object_lock || "")) {
|
|
12565
|
+
errors.push(`${rule.domain} readonly task ${taskId} must use readonly:<scope> or the ${rule.domain} object lock.`);
|
|
12566
|
+
}
|
|
12567
|
+
const evidenceText = `${row.evidence || ""} ${row.notes || ""}`;
|
|
12568
|
+
const hasRequiredEvidence = writeMode ? hasDomainWriteEvidence(rule.domain, evidenceText, rule.writeEvidence) : rule.readonlyEvidence.some((pattern) => pattern.test(evidenceText));
|
|
12569
|
+
if (!hasRequiredEvidence) {
|
|
12570
|
+
const expected = writeMode ? `bpmax-cli config ${rule.domain} lint/build/submit/verify evidence` : `bpmax-cli config ${rule.domain} export/readback evidence`;
|
|
12571
|
+
errors.push(`${rule.domain} task ${taskId} missing ${expected}.`);
|
|
12572
|
+
}
|
|
12573
|
+
if (!rule.constraintEvidence.test(evidenceText)) {
|
|
12574
|
+
errors.push(`${rule.domain} task ${taskId} missing domain-specific constraints from ${rule.skill}.`);
|
|
12575
|
+
}
|
|
12576
|
+
if (writeMode && !hasConfigAdaptersEvidence(evidenceText)) {
|
|
12577
|
+
errors.push(`${rule.domain} task ${taskId} is write-capable but missing bpmax-cli config adapters --format json capability/adapters evidence.`);
|
|
12578
|
+
}
|
|
12579
|
+
}
|
|
12580
|
+
function validateTaskbookConfigSkillGates(text5, errors) {
|
|
12581
|
+
const rows = extractTaskRows(text5);
|
|
12582
|
+
for (const row of rows) {
|
|
12583
|
+
for (const rule of CONFIG_TASK_RULES) {
|
|
12584
|
+
validateConfigRuleForTaskRow(row, rule, errors);
|
|
12585
|
+
}
|
|
12586
|
+
}
|
|
12587
|
+
}
|
|
11097
12588
|
function validatePromptNavigationAndListGates(text5, errors) {
|
|
11098
12589
|
const strategy = validateNavigationStrategy(text5, errors, "prompt ");
|
|
11099
12590
|
const hasNavSkill = /bpmax-nav-config-editor/.test(text5);
|
|
@@ -11113,6 +12604,39 @@ function validatePromptNavigationAndListGates(text5, errors) {
|
|
|
11113
12604
|
}
|
|
11114
12605
|
}
|
|
11115
12606
|
}
|
|
12607
|
+
function validatePromptConfigSkillGates(text5, errors) {
|
|
12608
|
+
const objectLock = promptObjectLockText(text5);
|
|
12609
|
+
const writeMode = isWriteMode(text5);
|
|
12610
|
+
const actionableText = text5.split(/\r?\n/).filter((line) => !/^\s*(导航入口策略|列表 lint)\s*[::]/.test(line)).join("\n");
|
|
12611
|
+
for (const rule of CONFIG_TASK_RULES) {
|
|
12612
|
+
const hasSkill = text5.includes(rule.skill);
|
|
12613
|
+
const mentionsDomain = rule.mentionPattern.test(actionableText) || rule.lockPattern.test(objectLock);
|
|
12614
|
+
if (mentionsDomain && !hasSkill) {
|
|
12615
|
+
errors.push(`prompt mentions ${rule.domain} work but missing required skill ${rule.skill}.`);
|
|
12616
|
+
continue;
|
|
12617
|
+
}
|
|
12618
|
+
if (!hasSkill) {
|
|
12619
|
+
continue;
|
|
12620
|
+
}
|
|
12621
|
+
if (writeMode && !rule.lockPattern.test(objectLock)) {
|
|
12622
|
+
errors.push(`prompt ${rule.domain} work must include object lock matching ${rule.domain}:<id> or its documented lock pattern.`);
|
|
12623
|
+
}
|
|
12624
|
+
if (!writeMode && !/^readonly:[A-Za-z0-9_-]+/.test(objectLock) && !rule.lockPattern.test(objectLock)) {
|
|
12625
|
+
errors.push(`prompt ${rule.domain} readonly work must include readonly:<scope> or the ${rule.domain} object lock.`);
|
|
12626
|
+
}
|
|
12627
|
+
const hasRequiredEvidence = writeMode ? hasDomainWriteEvidence(rule.domain, text5, rule.writeEvidence) : rule.readonlyEvidence.some((pattern) => pattern.test(text5));
|
|
12628
|
+
if (!hasRequiredEvidence) {
|
|
12629
|
+
const expected = writeMode ? `bpmax-cli config ${rule.domain} lint/build/submit/verify evidence` : `bpmax-cli config ${rule.domain} export/readback evidence`;
|
|
12630
|
+
errors.push(`prompt ${rule.domain} work missing ${expected}.`);
|
|
12631
|
+
}
|
|
12632
|
+
if (!rule.constraintEvidence.test(text5)) {
|
|
12633
|
+
errors.push(`prompt ${rule.domain} work missing domain-specific constraints from ${rule.skill}.`);
|
|
12634
|
+
}
|
|
12635
|
+
if (writeMode && !hasConfigAdaptersEvidence(text5)) {
|
|
12636
|
+
errors.push(`prompt ${rule.domain} write work missing bpmax-cli config adapters --format json capability/adapters evidence.`);
|
|
12637
|
+
}
|
|
12638
|
+
}
|
|
12639
|
+
}
|
|
11116
12640
|
async function lintTaskbook(file, options = {}) {
|
|
11117
12641
|
const text5 = await readTaskbookText(file);
|
|
11118
12642
|
const errors = [
|
|
@@ -11130,6 +12654,7 @@ async function lintTaskbook(file, options = {}) {
|
|
|
11130
12654
|
errors.push(...uuidErrors(text5, "taskbooks"));
|
|
11131
12655
|
errors.push(...missingTermErrors(text5, SUBAGENT_TERMS, "missing subagent rule term"));
|
|
11132
12656
|
validateTaskbookNavigationAndListGates(text5, errors);
|
|
12657
|
+
validateTaskbookConfigSkillGates(text5, errors);
|
|
11133
12658
|
for (const match of text5.matchAll(FLOW_LOCK_PATTERN)) {
|
|
11134
12659
|
const value = match[1] || "";
|
|
11135
12660
|
if (value.startsWith("flow") && /^flow\d+$/.test(value)) {
|
|
@@ -11155,6 +12680,7 @@ async function lintTaskPrompt(file, options = {}) {
|
|
|
11155
12680
|
}
|
|
11156
12681
|
errors.push(...uuidErrors(text5, "task prompts"));
|
|
11157
12682
|
validatePromptNavigationAndListGates(text5, errors);
|
|
12683
|
+
validatePromptConfigSkillGates(text5, errors);
|
|
11158
12684
|
for (const term of options.forbidTerms || []) {
|
|
11159
12685
|
if (term && text5.includes(term)) {
|
|
11160
12686
|
errors.push(`prompt forbidden term present: ${term}`);
|
|
@@ -11202,15 +12728,25 @@ function taskbookTemplate(title = "BPMAX AI \u5B9E\u65BD\u7F16\u6392\u4EFB\u52A1
|
|
|
11202
12728
|
"| 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
12729
|
"| 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
12730
|
"",
|
|
12731
|
+
"## \u914D\u7F6E Skill / Capability \u4F9D\u636E\u8868",
|
|
12732
|
+
"",
|
|
12733
|
+
"| \u914D\u7F6E\u5BF9\u8C61 | required_skills | typed CLI / capability evidence | \u4E13\u9879\u7EA6\u675F |",
|
|
12734
|
+
"|---|---|---|---|",
|
|
12735
|
+
"| \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 |",
|
|
12736
|
+
"| \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 |",
|
|
12737
|
+
"| \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 |",
|
|
12738
|
+
"| \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 |",
|
|
12739
|
+
"",
|
|
11205
12740
|
"## AI \u6700\u5C0F\u4EFB\u52A1\u5355\u5143",
|
|
11206
12741
|
"",
|
|
11207
12742
|
"| task_id | status | phase | parallel_type | subagent_mode | business_goal | required_skills | object_lock | dependencies | owner | evidence | notes |",
|
|
11208
12743
|
"|---|---|---|---|---|---|---|---|---|---|---|---|",
|
|
11209
12744
|
"| 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 |
|
|
12745
|
+
"| 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
12746
|
"",
|
|
11212
12747
|
"- \u6BCF\u4E2A\u4EFB\u52A1\u7684 `business_goal` \u90FD\u5FC5\u987B\u5199\u6E05\u695A\u4E1A\u52A1\u76EE\u6807\u573A\u666F\u3002",
|
|
11213
12748
|
"- \u6BCF\u4E2A\u4EFB\u52A1\u7684 `required_skills` \u90FD\u5FC5\u987B\u5217\u51FA\u5B9E\u9645\u8981\u4F7F\u7528\u7684 BPMAX skill\u3002",
|
|
12749
|
+
"- \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
12750
|
"",
|
|
11215
12751
|
"## \u8FDB\u5EA6 CSV",
|
|
11216
12752
|
"",
|
|
@@ -11252,8 +12788,8 @@ function taskbookTemplate(title = "BPMAX AI \u5B9E\u65BD\u7F16\u6392\u4EFB\u52A1
|
|
|
11252
12788
|
}
|
|
11253
12789
|
async function initTaskbook(outFile, title) {
|
|
11254
12790
|
const content = taskbookTemplate(title);
|
|
11255
|
-
await
|
|
11256
|
-
await
|
|
12791
|
+
await mkdir9(path9.dirname(outFile), { recursive: true });
|
|
12792
|
+
await writeFile9(outFile, content, "utf8");
|
|
11257
12793
|
return { out: outFile, bytes: Buffer.byteLength(content) };
|
|
11258
12794
|
}
|
|
11259
12795
|
function splitMarkdownRow(line) {
|
|
@@ -11342,8 +12878,8 @@ async function initTaskbookProgress(source, outFile) {
|
|
|
11342
12878
|
fields.join(","),
|
|
11343
12879
|
...rows.map((row) => fields.map((field) => csvEscape(field === "status" ? "\u672A\u5F00\u59CB" : row[field] || "")).join(","))
|
|
11344
12880
|
].join("\n") + "\n";
|
|
11345
|
-
await
|
|
11346
|
-
await
|
|
12881
|
+
await mkdir9(path9.dirname(outFile), { recursive: true });
|
|
12882
|
+
await writeFile9(outFile, csv, "utf8");
|
|
11347
12883
|
return { source, out: outFile, task_count: rows.length };
|
|
11348
12884
|
}
|
|
11349
12885
|
|
|
@@ -11385,18 +12921,18 @@ function registerTaskbookCommands(program2) {
|
|
|
11385
12921
|
}
|
|
11386
12922
|
|
|
11387
12923
|
// src/core/test-suite.ts
|
|
11388
|
-
import { createHash as
|
|
12924
|
+
import { createHash as createHash5 } from "crypto";
|
|
11389
12925
|
import {
|
|
11390
12926
|
copyFile,
|
|
11391
|
-
cp as
|
|
11392
|
-
mkdir as
|
|
11393
|
-
readdir as
|
|
11394
|
-
readFile as
|
|
11395
|
-
rm as
|
|
11396
|
-
stat as
|
|
11397
|
-
writeFile as
|
|
12927
|
+
cp as cp3,
|
|
12928
|
+
mkdir as mkdir10,
|
|
12929
|
+
readdir as readdir4,
|
|
12930
|
+
readFile as readFile13,
|
|
12931
|
+
rm as rm4,
|
|
12932
|
+
stat as stat5,
|
|
12933
|
+
writeFile as writeFile10
|
|
11398
12934
|
} from "fs/promises";
|
|
11399
|
-
import
|
|
12935
|
+
import path10 from "path";
|
|
11400
12936
|
var DEFAULT_SUITE_ROOT = ".ai_test/suite";
|
|
11401
12937
|
var DEFAULT_DRAFT_ROOT = ".ai_test/suite_draft";
|
|
11402
12938
|
var DEFAULT_REPORT_ROOT = ".ai_test/report";
|
|
@@ -11479,16 +13015,16 @@ var IDENTITY_MOCK_CASE_RE = /(非处理人|越权|只读|多角色|角色隔离|
|
|
|
11479
13015
|
var IDENTITY_MOCK_VALUE_RE = /(mock|模拟).*(unmock|退出模拟|恢复)|bpmax-user-mock-operator/;
|
|
11480
13016
|
var TestSuiteError = class extends Error {
|
|
11481
13017
|
};
|
|
11482
|
-
async function
|
|
13018
|
+
async function exists3(filePath) {
|
|
11483
13019
|
try {
|
|
11484
|
-
await
|
|
13020
|
+
await stat5(filePath);
|
|
11485
13021
|
return true;
|
|
11486
13022
|
} catch {
|
|
11487
13023
|
return false;
|
|
11488
13024
|
}
|
|
11489
13025
|
}
|
|
11490
13026
|
async function readText(filePath) {
|
|
11491
|
-
return
|
|
13027
|
+
return readFile13(filePath, "utf8");
|
|
11492
13028
|
}
|
|
11493
13029
|
function fail(message) {
|
|
11494
13030
|
throw new TestSuiteError(message);
|
|
@@ -11542,11 +13078,11 @@ function reviewSchemaExplanation() {
|
|
|
11542
13078
|
};
|
|
11543
13079
|
}
|
|
11544
13080
|
function reviewFail(reviewPath, message) {
|
|
11545
|
-
const scenarioId =
|
|
13081
|
+
const scenarioId = path10.basename(path10.dirname(reviewPath));
|
|
11546
13082
|
fail([
|
|
11547
13083
|
message,
|
|
11548
13084
|
`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 ${
|
|
13085
|
+
`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
13086
|
`Minimal review.json example: ${JSON.stringify(reviewSchemaExample(scenarioId))}`
|
|
11551
13087
|
].join("\n"));
|
|
11552
13088
|
}
|
|
@@ -11576,7 +13112,7 @@ function splitCsvLine(line) {
|
|
|
11576
13112
|
return values;
|
|
11577
13113
|
}
|
|
11578
13114
|
async function readCases(filePath) {
|
|
11579
|
-
if (!await
|
|
13115
|
+
if (!await exists3(filePath)) fail(`missing cases.csv: ${filePath}`);
|
|
11580
13116
|
const text5 = (await readText(filePath)).replace(/^\uFEFF/, "");
|
|
11581
13117
|
const lines = text5.split(/\r?\n/).filter((line) => line.length > 0);
|
|
11582
13118
|
if (lines.length === 0) fail(`${filePath}: CSV fields must be exactly ${JSON.stringify(CASE_FIELDS)}`);
|
|
@@ -11628,14 +13164,14 @@ function parseReadmeText(filePath, text5) {
|
|
|
11628
13164
|
return metadata;
|
|
11629
13165
|
}
|
|
11630
13166
|
async function validateReadme(scenarioDir) {
|
|
11631
|
-
const readmePath =
|
|
11632
|
-
if (!await
|
|
13167
|
+
const readmePath = path10.join(scenarioDir, "README.md");
|
|
13168
|
+
if (!await exists3(readmePath)) fail(`missing README.md: ${readmePath}`);
|
|
11633
13169
|
const text5 = await readText(readmePath);
|
|
11634
13170
|
const metadata = parseReadmeText(readmePath, text5);
|
|
11635
13171
|
for (const key of REQUIRED_README_KEYS) {
|
|
11636
13172
|
if (!metadata[key]) fail(`${scenarioDir}: README.md missing \`${key}\``);
|
|
11637
13173
|
}
|
|
11638
|
-
if (metadata.scenario_id !==
|
|
13174
|
+
if (metadata.scenario_id !== path10.basename(scenarioDir)) fail(`${scenarioDir}: scenario_id must match directory name`);
|
|
11639
13175
|
if (!["true", "false"].includes(metadata.core.toLowerCase())) fail(`${scenarioDir}: core must be true or false`);
|
|
11640
13176
|
if (!STATUSES.has(metadata.status)) fail(`${scenarioDir}: status must be one of ${JSON.stringify([...STATUSES].sort())}`);
|
|
11641
13177
|
if (UUID_RE2.test(text5) || ID_AS_ENTRY_RE.test(text5)) {
|
|
@@ -11655,7 +13191,7 @@ async function validateConfigBasis(filePath, caseId, configBasis) {
|
|
|
11655
13191
|
if (!CONFIG_BASIS_REASON_RE.test(configBasis)) fail(`${filePath}:${caseId}: \`config_basis\` must explain why`);
|
|
11656
13192
|
const missing = [];
|
|
11657
13193
|
for (const location of locations) {
|
|
11658
|
-
if (!await
|
|
13194
|
+
if (!await exists3(location)) missing.push(location);
|
|
11659
13195
|
}
|
|
11660
13196
|
if (missing.length > 0) fail(`${filePath}:${caseId}: \`config_basis\` references missing config location(s): ${missing.join(", ")}`);
|
|
11661
13197
|
}
|
|
@@ -11777,13 +13313,13 @@ async function validateCase(filePath, row, seen) {
|
|
|
11777
13313
|
validateBusinessTestData(filePath, caseId, row);
|
|
11778
13314
|
}
|
|
11779
13315
|
async function scenarioDirs(root) {
|
|
11780
|
-
if (!await
|
|
11781
|
-
const items = await
|
|
11782
|
-
return items.filter((item) => item.isDirectory()).map((item) =>
|
|
13316
|
+
if (!await exists3(root)) return [];
|
|
13317
|
+
const items = await readdir4(root, { withFileTypes: true });
|
|
13318
|
+
return items.filter((item) => item.isDirectory()).map((item) => path10.join(root, item.name)).sort();
|
|
11783
13319
|
}
|
|
11784
13320
|
async function validateScenario(scenarioDir) {
|
|
11785
13321
|
const metadata = await validateReadme(scenarioDir);
|
|
11786
|
-
const casesPath =
|
|
13322
|
+
const casesPath = path10.join(scenarioDir, "cases.csv");
|
|
11787
13323
|
const rows = await readCases(casesPath);
|
|
11788
13324
|
if (rows.length === 0) fail(`${casesPath}: at least one case is required`);
|
|
11789
13325
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -11838,7 +13374,7 @@ async function requireLatestProof(proofPath) {
|
|
|
11838
13374
|
}
|
|
11839
13375
|
async function readLatestProof(proofPath) {
|
|
11840
13376
|
if (!proofPath) fail("--latest-proof is required");
|
|
11841
|
-
if (!await
|
|
13377
|
+
if (!await exists3(proofPath)) fail(`latest proof is required before this command: ${proofPath}`);
|
|
11842
13378
|
let proof;
|
|
11843
13379
|
try {
|
|
11844
13380
|
proof = JSON.parse(await readText(proofPath));
|
|
@@ -11858,9 +13394,9 @@ function validateLatestProofObject(proofPath, proof) {
|
|
|
11858
13394
|
}
|
|
11859
13395
|
function scenarioPath(root, scenario) {
|
|
11860
13396
|
if (!SCENARIO_ID_RE.test(scenario)) fail(`invalid scenario id: ${scenario}`);
|
|
11861
|
-
const rootResolved =
|
|
11862
|
-
const candidate =
|
|
11863
|
-
if (!candidate.startsWith(`${rootResolved}${
|
|
13397
|
+
const rootResolved = path10.resolve(root);
|
|
13398
|
+
const candidate = path10.resolve(root, scenario);
|
|
13399
|
+
if (!candidate.startsWith(`${rootResolved}${path10.sep}`) && candidate !== rootResolved) {
|
|
11864
13400
|
fail(`scenario path escapes root: ${candidate}`);
|
|
11865
13401
|
}
|
|
11866
13402
|
return candidate;
|
|
@@ -11868,14 +13404,14 @@ function scenarioPath(root, scenario) {
|
|
|
11868
13404
|
async function fileMap(root) {
|
|
11869
13405
|
const result = /* @__PURE__ */ new Map();
|
|
11870
13406
|
async function walk(dir) {
|
|
11871
|
-
for (const item of await
|
|
11872
|
-
const itemPath =
|
|
11873
|
-
const rel =
|
|
11874
|
-
if (rel.split(
|
|
13407
|
+
for (const item of await readdir4(dir, { withFileTypes: true })) {
|
|
13408
|
+
const itemPath = path10.join(dir, item.name);
|
|
13409
|
+
const rel = path10.relative(root, itemPath);
|
|
13410
|
+
if (rel.split(path10.sep)[0] === COPY_DIFF_DIR) continue;
|
|
11875
13411
|
if (item.isDirectory()) {
|
|
11876
13412
|
await walk(itemPath);
|
|
11877
13413
|
} else if (item.isFile()) {
|
|
11878
|
-
result.set(rel.split(
|
|
13414
|
+
result.set(rel.split(path10.sep).join("/"), itemPath);
|
|
11879
13415
|
}
|
|
11880
13416
|
}
|
|
11881
13417
|
}
|
|
@@ -11883,11 +13419,11 @@ async function fileMap(root) {
|
|
|
11883
13419
|
return result;
|
|
11884
13420
|
}
|
|
11885
13421
|
async function sha256(filePath) {
|
|
11886
|
-
return
|
|
13422
|
+
return createHash5("sha256").update(await readFile13(filePath)).digest("hex");
|
|
11887
13423
|
}
|
|
11888
13424
|
async function readForDiff(filePath) {
|
|
11889
|
-
const buffer = await
|
|
11890
|
-
if (buffer.includes(0)) return [`<binary sha256=${
|
|
13425
|
+
const buffer = await readFile13(filePath);
|
|
13426
|
+
if (buffer.includes(0)) return [`<binary sha256=${createHash5("sha256").update(buffer).digest("hex")}>
|
|
11891
13427
|
`];
|
|
11892
13428
|
return buffer.toString("utf8").split(/(?<=\n)/);
|
|
11893
13429
|
}
|
|
@@ -11946,7 +13482,7 @@ async function buildCopyDiff(src, dst, operation) {
|
|
|
11946
13482
|
return {
|
|
11947
13483
|
manifest: {
|
|
11948
13484
|
operation,
|
|
11949
|
-
scenario_id:
|
|
13485
|
+
scenario_id: path10.basename(src),
|
|
11950
13486
|
source: src,
|
|
11951
13487
|
destination: dst,
|
|
11952
13488
|
generated_at: (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "+00:00"),
|
|
@@ -11959,12 +13495,12 @@ async function buildCopyDiff(src, dst, operation) {
|
|
|
11959
13495
|
};
|
|
11960
13496
|
}
|
|
11961
13497
|
async function writeCopyDiffArtifacts(dst, artifacts) {
|
|
11962
|
-
const diffDir =
|
|
11963
|
-
await
|
|
11964
|
-
await
|
|
11965
|
-
await
|
|
13498
|
+
const diffDir = path10.join(dst, COPY_DIFF_DIR);
|
|
13499
|
+
await mkdir10(diffDir, { recursive: true });
|
|
13500
|
+
await writeFile10(path10.join(diffDir, "last.diff"), artifacts.diff, "utf8");
|
|
13501
|
+
await writeFile10(path10.join(diffDir, "last.json"), `${JSON.stringify(artifacts.manifest, null, 2)}
|
|
11966
13502
|
`, "utf8");
|
|
11967
|
-
return
|
|
13503
|
+
return path10.join(diffDir, "last.diff");
|
|
11968
13504
|
}
|
|
11969
13505
|
function summarizeCopyDiff(artifacts) {
|
|
11970
13506
|
const files = Array.isArray(artifacts.manifest.files) ? artifacts.manifest.files : [];
|
|
@@ -11983,28 +13519,28 @@ function summarizeCopyDiff(artifacts) {
|
|
|
11983
13519
|
};
|
|
11984
13520
|
}
|
|
11985
13521
|
async function copyScenarioTree(src, dst, replace, operation) {
|
|
11986
|
-
if (!await
|
|
13522
|
+
if (!await exists3(src)) fail(`source scenario not found: ${src}`);
|
|
11987
13523
|
let artifacts;
|
|
11988
|
-
if (await
|
|
13524
|
+
if (await exists3(dst)) {
|
|
11989
13525
|
if (!replace) fail(`destination already exists, pass --replace: ${dst}`);
|
|
11990
13526
|
artifacts = await buildCopyDiff(src, dst, operation);
|
|
11991
|
-
await
|
|
13527
|
+
await rm4(dst, { recursive: true, force: true });
|
|
11992
13528
|
}
|
|
11993
|
-
await
|
|
11994
|
-
await
|
|
13529
|
+
await mkdir10(path10.dirname(dst), { recursive: true });
|
|
13530
|
+
await cp3(src, dst, { recursive: true });
|
|
11995
13531
|
return artifacts ? { path: await writeCopyDiffArtifacts(dst, artifacts), summary: summarizeCopyDiff(artifacts) } : {};
|
|
11996
13532
|
}
|
|
11997
13533
|
async function copyDiffPreview(src, dst, operation) {
|
|
11998
|
-
const previewDir =
|
|
11999
|
-
await
|
|
12000
|
-
await
|
|
13534
|
+
const previewDir = path10.join(DEFAULT_TMP_ROOT, `${operation}-${path10.basename(src)}-copy-diff`);
|
|
13535
|
+
await rm4(previewDir, { recursive: true, force: true });
|
|
13536
|
+
await mkdir10(previewDir, { recursive: true });
|
|
12001
13537
|
const artifacts = await buildCopyDiff(src, dst, operation);
|
|
12002
13538
|
return { path: await writeCopyDiffArtifacts(previewDir, artifacts), summary: summarizeCopyDiff(artifacts) };
|
|
12003
13539
|
}
|
|
12004
13540
|
async function draftUpdate(options) {
|
|
12005
13541
|
const src = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
|
|
12006
13542
|
const dst = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
|
|
12007
|
-
if (options.replace && !options.diffReviewed && await
|
|
13543
|
+
if (options.replace && !options.diffReviewed && await exists3(dst)) {
|
|
12008
13544
|
const preview = await copyDiffPreview(src, dst, "draft-update");
|
|
12009
13545
|
return {
|
|
12010
13546
|
copy_diff: preview.path,
|
|
@@ -12017,15 +13553,15 @@ async function draftUpdate(options) {
|
|
|
12017
13553
|
return { destination: dst, copy_diff: copyDiff.path, copy_diff_summary: copyDiff.summary };
|
|
12018
13554
|
}
|
|
12019
13555
|
async function validateReviewGate(scenarioDir) {
|
|
12020
|
-
const reviewPath =
|
|
12021
|
-
if (!await
|
|
13556
|
+
const reviewPath = path10.join(scenarioDir, "review.json");
|
|
13557
|
+
if (!await exists3(reviewPath)) reviewFail(reviewPath, `${scenarioDir}: missing review.json; run multi-subagent SKILL review before promote`);
|
|
12022
13558
|
let review;
|
|
12023
13559
|
try {
|
|
12024
13560
|
review = JSON.parse(await readText(reviewPath));
|
|
12025
13561
|
} catch (error) {
|
|
12026
13562
|
reviewFail(reviewPath, `${reviewPath}: invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
12027
13563
|
}
|
|
12028
|
-
if (review.scenario_id !==
|
|
13564
|
+
if (review.scenario_id !== path10.basename(scenarioDir)) reviewFail(reviewPath, `${reviewPath}: scenario_id must match directory name`);
|
|
12029
13565
|
if (!review.latest_proof || typeof review.latest_proof !== "object" || Array.isArray(review.latest_proof)) reviewFail(reviewPath, `${reviewPath}: latest_proof is required`);
|
|
12030
13566
|
validateLatestProofObject(reviewPath, review.latest_proof);
|
|
12031
13567
|
if (!REVIEW_STATUSES.has(String(review.status))) reviewFail(reviewPath, `${reviewPath}: status must be one of ${JSON.stringify([...REVIEW_STATUSES].sort())}`);
|
|
@@ -12061,7 +13597,7 @@ async function validateConfigConsistencyReview(reviewPath, item) {
|
|
|
12061
13597
|
}
|
|
12062
13598
|
const missing = [];
|
|
12063
13599
|
for (const location of judgment.config_basis_checked) {
|
|
12064
|
-
if (typeof location !== "string" || !await
|
|
13600
|
+
if (typeof location !== "string" || !await exists3(location)) missing.push(String(location));
|
|
12065
13601
|
}
|
|
12066
13602
|
if (missing.length > 0) reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` references missing checked location(s): ${missing.join(", ")}`);
|
|
12067
13603
|
if (!judgment.evidence) reviewFail(reviewPath, `${reviewPath}: config_consistency judgment \`${judgment.case_id}\` missing evidence`);
|
|
@@ -12132,13 +13668,13 @@ function mergeReviewDraft(scenarioId, proof, rows, existing) {
|
|
|
12132
13668
|
}
|
|
12133
13669
|
async function initOrRepairReview(options) {
|
|
12134
13670
|
const scenarioDir = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
|
|
12135
|
-
if (!await
|
|
13671
|
+
if (!await exists3(scenarioDir)) fail(`draft scenario not found: ${scenarioDir}`);
|
|
12136
13672
|
await validateReadme(scenarioDir);
|
|
12137
|
-
const rows = await readCases(
|
|
13673
|
+
const rows = await readCases(path10.join(scenarioDir, "cases.csv"));
|
|
12138
13674
|
const proof = await readLatestProof(options.latestProof);
|
|
12139
|
-
const reviewPath =
|
|
13675
|
+
const reviewPath = path10.join(scenarioDir, "review.json");
|
|
12140
13676
|
let existing;
|
|
12141
|
-
const existed = await
|
|
13677
|
+
const existed = await exists3(reviewPath);
|
|
12142
13678
|
if (existed) {
|
|
12143
13679
|
if (!options.repair) fail(`${reviewPath}: already exists; pass --repair to update missing schema fields`);
|
|
12144
13680
|
try {
|
|
@@ -12147,8 +13683,8 @@ async function initOrRepairReview(options) {
|
|
|
12147
13683
|
existing = {};
|
|
12148
13684
|
}
|
|
12149
13685
|
}
|
|
12150
|
-
const review = mergeReviewDraft(
|
|
12151
|
-
await
|
|
13686
|
+
const review = mergeReviewDraft(path10.basename(scenarioDir), proof, rows, existing);
|
|
13687
|
+
await writeFile10(reviewPath, `${JSON.stringify(review, null, 2)}
|
|
12152
13688
|
`, "utf8");
|
|
12153
13689
|
return {
|
|
12154
13690
|
ok: true,
|
|
@@ -12163,7 +13699,7 @@ async function promoteScenario(options) {
|
|
|
12163
13699
|
await validateReviewGate(src);
|
|
12164
13700
|
if (metadata.status === "draft") fail(`${src}: cannot promote README status draft; set status to active or deprecated`);
|
|
12165
13701
|
const dst = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
|
|
12166
|
-
if (options.replace && !options.diffReviewed && await
|
|
13702
|
+
if (options.replace && !options.diffReviewed && await exists3(dst)) {
|
|
12167
13703
|
const preview = await copyDiffPreview(src, dst, "promote");
|
|
12168
13704
|
return {
|
|
12169
13705
|
copy_diff: preview.path,
|
|
@@ -12182,64 +13718,64 @@ async function nextReportDir(root = DEFAULT_REPORT_ROOT, create = false, today =
|
|
|
12182
13718
|
String(today.getDate()).padStart(2, "0")
|
|
12183
13719
|
].join("");
|
|
12184
13720
|
const dirs = await scenarioDirs(root);
|
|
12185
|
-
const nums = dirs.map((dir) =>
|
|
12186
|
-
const reportDir =
|
|
13721
|
+
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));
|
|
13722
|
+
const reportDir = path10.join(root, `${prefix}-${String(Math.max(0, ...nums) + 1).padStart(3, "0")}`);
|
|
12187
13723
|
if (create) {
|
|
12188
|
-
await
|
|
12189
|
-
await
|
|
12190
|
-
|
|
12191
|
-
["# BPMAX E2E \u6D4B\u8BD5\u62A5\u544A\u6C47\u603B", "", `run_id: ${
|
|
13724
|
+
await mkdir10(path10.join(reportDir, "screenshots"), { recursive: true });
|
|
13725
|
+
await writeFile10(
|
|
13726
|
+
path10.join(reportDir, "summary.md"),
|
|
13727
|
+
["# BPMAX E2E \u6D4B\u8BD5\u62A5\u544A\u6C47\u603B", "", `run_id: ${path10.basename(reportDir)}`, "status: draft", "", "## \u573A\u666F\u62A5\u544A", "", "## \u603B\u7ED3", ""].join("\n"),
|
|
12192
13728
|
"utf8"
|
|
12193
13729
|
);
|
|
12194
13730
|
}
|
|
12195
13731
|
return reportDir;
|
|
12196
13732
|
}
|
|
12197
13733
|
async function lintReport(root = DEFAULT_REPORT_ROOT) {
|
|
12198
|
-
if (!await
|
|
13734
|
+
if (!await exists3(root)) return [`report root not found: ${root}`];
|
|
12199
13735
|
const errors = [];
|
|
12200
13736
|
for (const runDir of await scenarioDirs(root)) {
|
|
12201
|
-
const runName =
|
|
13737
|
+
const runName = path10.basename(runDir);
|
|
12202
13738
|
if (!RUN_RE.test(runName)) {
|
|
12203
13739
|
errors.push(`${runDir}: run directory name must be YYYYMMDD-NNN`);
|
|
12204
13740
|
continue;
|
|
12205
13741
|
}
|
|
12206
|
-
if (!await
|
|
12207
|
-
const files = await
|
|
13742
|
+
if (!await exists3(path10.join(runDir, "summary.md"))) errors.push(`${runDir}: missing summary.md`);
|
|
13743
|
+
const files = await readdir4(runDir);
|
|
12208
13744
|
const scenarioReports = files.filter((file) => file.endsWith(".md") && file !== "summary.md");
|
|
12209
13745
|
if (scenarioReports.length === 0) errors.push(`${runDir}: missing scenario report markdown`);
|
|
12210
13746
|
for (const reportName of scenarioReports) {
|
|
12211
|
-
const reportPath =
|
|
13747
|
+
const reportPath = path10.join(runDir, reportName);
|
|
12212
13748
|
const text5 = await readText(reportPath);
|
|
12213
13749
|
for (const key of REPORT_REQUIRED_KEYS) if (!text5.includes(key)) errors.push(`${reportPath}: missing \`${key}\``);
|
|
12214
13750
|
for (const heading of REPORT_REQUIRED_HEADINGS) if (!text5.includes(heading)) errors.push(`${reportPath}: missing \`${heading}\``);
|
|
12215
13751
|
const imageRefs = [...text5.matchAll(IMAGE_RE)].map((match) => match[1]);
|
|
12216
13752
|
if (imageRefs.length === 0) errors.push(`${reportPath}: missing embedded screenshot image`);
|
|
12217
|
-
const screenshotsDir =
|
|
12218
|
-
if (!await
|
|
13753
|
+
const screenshotsDir = path10.join(runDir, "screenshots");
|
|
13754
|
+
if (!await exists3(screenshotsDir)) errors.push(`${runDir}: missing screenshots directory`);
|
|
12219
13755
|
for (const imageRef of imageRefs) {
|
|
12220
13756
|
if (imageRef.includes("://")) {
|
|
12221
13757
|
errors.push(`${reportPath}: screenshot must be a local file under this run's screenshots directory`);
|
|
12222
13758
|
continue;
|
|
12223
13759
|
}
|
|
12224
|
-
const imagePath =
|
|
12225
|
-
const screenshotsResolved =
|
|
12226
|
-
if (!imagePath.startsWith(`${screenshotsResolved}${
|
|
13760
|
+
const imagePath = path10.resolve(path10.dirname(reportPath), imageRef);
|
|
13761
|
+
const screenshotsResolved = path10.resolve(screenshotsDir);
|
|
13762
|
+
if (!imagePath.startsWith(`${screenshotsResolved}${path10.sep}`)) {
|
|
12227
13763
|
errors.push(`${reportPath}: image reference must stay under this run's screenshots directory: ${imageRef}`);
|
|
12228
13764
|
continue;
|
|
12229
13765
|
}
|
|
12230
|
-
if (!await
|
|
13766
|
+
if (!await exists3(imagePath)) errors.push(`${reportPath}: missing image file: ${imageRef}`);
|
|
12231
13767
|
}
|
|
12232
13768
|
}
|
|
12233
13769
|
}
|
|
12234
13770
|
return errors;
|
|
12235
13771
|
}
|
|
12236
13772
|
async function validateCopyDiffArtifacts(scenarioDir) {
|
|
12237
|
-
const diffDir =
|
|
12238
|
-
if (!await
|
|
12239
|
-
const manifestPath =
|
|
12240
|
-
const diffPath =
|
|
12241
|
-
if (!await
|
|
12242
|
-
if (!await
|
|
13773
|
+
const diffDir = path10.join(scenarioDir, COPY_DIFF_DIR);
|
|
13774
|
+
if (!await exists3(diffDir)) return;
|
|
13775
|
+
const manifestPath = path10.join(diffDir, "last.json");
|
|
13776
|
+
const diffPath = path10.join(diffDir, "last.diff");
|
|
13777
|
+
if (!await exists3(manifestPath)) fail(`${scenarioDir}: ${COPY_DIFF_DIR}/last.json is required when copy diff artifacts exist`);
|
|
13778
|
+
if (!await exists3(diffPath)) fail(`${scenarioDir}: ${COPY_DIFF_DIR}/last.diff is required when copy diff artifacts exist`);
|
|
12243
13779
|
let manifest;
|
|
12244
13780
|
try {
|
|
12245
13781
|
manifest = JSON.parse(await readText(manifestPath));
|
|
@@ -12249,7 +13785,7 @@ async function validateCopyDiffArtifacts(scenarioDir) {
|
|
|
12249
13785
|
for (const key of ["operation", "scenario_id", "source", "destination", "generated_at", "summary", "diff_file", "files"]) {
|
|
12250
13786
|
if (!(key in manifest)) fail(`${manifestPath}: missing \`${key}\``);
|
|
12251
13787
|
}
|
|
12252
|
-
if (manifest.scenario_id !==
|
|
13788
|
+
if (manifest.scenario_id !== path10.basename(scenarioDir)) fail(`${manifestPath}: scenario_id must match directory name`);
|
|
12253
13789
|
if (manifest.diff_file !== "last.diff") fail(`${manifestPath}: diff_file must be last.diff`);
|
|
12254
13790
|
if (!(await readText(diffPath)).trim()) fail(`${diffPath}: copy diff must not be empty`);
|
|
12255
13791
|
}
|
|
@@ -12297,8 +13833,8 @@ function registerTestSuiteCommands(program2) {
|
|
|
12297
13833
|
}
|
|
12298
13834
|
|
|
12299
13835
|
// src/core/update.ts
|
|
12300
|
-
import { access as access2, mkdir as
|
|
12301
|
-
import
|
|
13836
|
+
import { access as access2, mkdir as mkdir11, readFile as readFile14, realpath, writeFile as writeFile11 } from "fs/promises";
|
|
13837
|
+
import path11 from "path";
|
|
12302
13838
|
var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/";
|
|
12303
13839
|
var UPDATE_STATE_FILE = "update-state.json";
|
|
12304
13840
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -12410,11 +13946,11 @@ async function fetchLatestVersion(options = {}) {
|
|
|
12410
13946
|
}
|
|
12411
13947
|
}
|
|
12412
13948
|
function updateStatePath(configDir = getConfigDir()) {
|
|
12413
|
-
return
|
|
13949
|
+
return path11.join(configDir, UPDATE_STATE_FILE);
|
|
12414
13950
|
}
|
|
12415
13951
|
async function readUpdateState(configDir) {
|
|
12416
13952
|
try {
|
|
12417
|
-
const raw = await
|
|
13953
|
+
const raw = await readFile14(updateStatePath(configDir), "utf8");
|
|
12418
13954
|
const parsed = JSON.parse(raw);
|
|
12419
13955
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
12420
13956
|
return null;
|
|
@@ -12425,8 +13961,8 @@ async function readUpdateState(configDir) {
|
|
|
12425
13961
|
}
|
|
12426
13962
|
}
|
|
12427
13963
|
async function writeUpdateState(state, configDir = getConfigDir()) {
|
|
12428
|
-
await
|
|
12429
|
-
await
|
|
13964
|
+
await mkdir11(configDir, { recursive: true });
|
|
13965
|
+
await writeFile11(updateStatePath(configDir), JSON.stringify(state), "utf8");
|
|
12430
13966
|
}
|
|
12431
13967
|
async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
12432
13968
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
@@ -12478,7 +14014,7 @@ async function findNpmPath() {
|
|
|
12478
14014
|
}
|
|
12479
14015
|
function detectInstallMethod(input) {
|
|
12480
14016
|
const resolvedPath = input.executablePath || "";
|
|
12481
|
-
const method = resolvedPath.includes(`node_modules${
|
|
14017
|
+
const method = resolvedPath.includes(`node_modules${path11.sep}`) || resolvedPath.includes("node_modules/") ? "npm" : "manual";
|
|
12482
14018
|
return {
|
|
12483
14019
|
method,
|
|
12484
14020
|
resolvedPath,
|
|
@@ -12834,6 +14370,7 @@ var OPTIONS_WITH_VALUES = /* @__PURE__ */ new Set([
|
|
|
12834
14370
|
"--payload",
|
|
12835
14371
|
"--profile",
|
|
12836
14372
|
"--session-key",
|
|
14373
|
+
"--skill",
|
|
12837
14374
|
"--trace-id",
|
|
12838
14375
|
"--work-format"
|
|
12839
14376
|
]);
|
|
@@ -12947,6 +14484,7 @@ registerEsCommands(program);
|
|
|
12947
14484
|
registerFlowCommands(program);
|
|
12948
14485
|
registerMemoryCommands(program);
|
|
12949
14486
|
registerMatrixCommands(program);
|
|
14487
|
+
registerPluginCommands(program);
|
|
12950
14488
|
registerProjectCommands(program);
|
|
12951
14489
|
registerStepCommands(program);
|
|
12952
14490
|
registerTaskbookCommands(program);
|