shoplazza-ai-dev-cli 0.1.13 → 0.1.15
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/_chunks/test.mjs +176 -18
- package/dist/cli.mjs +71 -8
- package/package.json +3 -2
package/dist/_chunks/test.mjs
CHANGED
|
@@ -285,12 +285,15 @@ function askConfirm(prompt) {
|
|
|
285
285
|
});
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
-
async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
288
|
+
async function syncWithGuard(client, url, payload, json, confirmUnlink, confirm = void 0) {
|
|
289
289
|
try {
|
|
290
290
|
return await client.post(url, payload);
|
|
291
291
|
} catch (err) {
|
|
292
292
|
if (!(err instanceof ApiError) || err.status !== 409 || err.code !== "SYNC_UNLINK_GUARD") throw err;
|
|
293
|
-
const
|
|
293
|
+
const envelope = err.data;
|
|
294
|
+
const detail = envelope?.["error"] && typeof envelope["error"] === "object" ? envelope["error"] : envelope;
|
|
295
|
+
const preview = detail?.["unlink_preview"] ?? [];
|
|
296
|
+
const token = detail?.["unlink_confirm_token"];
|
|
294
297
|
const msg = err.message;
|
|
295
298
|
console.error(`\n⚠ ${msg}`);
|
|
296
299
|
console.error("将被移除的用例:");
|
|
@@ -300,12 +303,12 @@ async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
|
300
303
|
process.exitCode = 1;
|
|
301
304
|
return null;
|
|
302
305
|
}
|
|
303
|
-
if (json || !process.stdin.isTTY) {
|
|
306
|
+
if (!confirm && (json || !process.stdin.isTTY)) {
|
|
304
307
|
console.error("\n非交互模式,不自动重发。请在交互终端使用 --confirm-unlink。");
|
|
305
308
|
process.exitCode = 1;
|
|
306
309
|
return null;
|
|
307
310
|
}
|
|
308
|
-
if (await askConfirm(`确认移除 ${preview.length} 条用例?(y/N) `)
|
|
311
|
+
if (!(confirm ? await confirm() : await askConfirm(`确认移除 ${preview.length} 条用例?(y/N) `) === "y")) {
|
|
309
312
|
console.error("已取消。");
|
|
310
313
|
process.exitCode = 1;
|
|
311
314
|
return null;
|
|
@@ -315,10 +318,12 @@ async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
|
315
318
|
process.exitCode = 1;
|
|
316
319
|
return null;
|
|
317
320
|
}
|
|
321
|
+
if (typeof token !== "string" || !token) throw new ApiError(409, "SYNC_UNLINK_GUARD", "server did not return unlink_confirm_token", err.data);
|
|
318
322
|
const body = {
|
|
319
323
|
...payload,
|
|
320
|
-
|
|
324
|
+
unlink_confirm_token: token
|
|
321
325
|
};
|
|
326
|
+
delete body["force_unlink"];
|
|
322
327
|
return await client.post(url, body);
|
|
323
328
|
}
|
|
324
329
|
}
|
|
@@ -349,7 +354,7 @@ async function create$4(client, args, json) {
|
|
|
349
354
|
if (data["created"]) {
|
|
350
355
|
printSuccess(`Requirement created: ${data["req_id"]}`);
|
|
351
356
|
printKV([["Title", data["title"]], ["Status", data["status"]]]);
|
|
352
|
-
console.log(" (case
|
|
357
|
+
console.log(" (typed case sets are created lazily on first attach or sync)");
|
|
353
358
|
} else console.log(`ℹ Requirement already exists: ${data["req_id"]} (not modified)`);
|
|
354
359
|
}
|
|
355
360
|
async function sync$1(client, args, json) {
|
|
@@ -360,7 +365,18 @@ async function sync$1(client, args, json) {
|
|
|
360
365
|
process.exitCode = 2;
|
|
361
366
|
return;
|
|
362
367
|
}
|
|
363
|
-
const
|
|
368
|
+
const input = readFileInput(requireArg(named, "file", "path"));
|
|
369
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) throw new Error("sync input must be a JSON object");
|
|
370
|
+
const reconcileTypes = asArray(named["reconcile-case-types"]);
|
|
371
|
+
if (reconcileTypes.some((caseType) => !["e2e", "api"].includes(caseType))) {
|
|
372
|
+
printError("--reconcile-case-types must contain only e2e,api");
|
|
373
|
+
process.exitCode = 2;
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const payload = {
|
|
377
|
+
...input,
|
|
378
|
+
...reconcileTypes.length ? { reconcile_case_types: reconcileTypes } : {}
|
|
379
|
+
};
|
|
364
380
|
const confirmUnlink = named["confirm-unlink"] !== void 0;
|
|
365
381
|
const data = await syncWithGuard(client, `/api/test/requirements/${encodeURIComponent(reqId)}/cases:sync`, payload, json, confirmUnlink);
|
|
366
382
|
if (!data) return;
|
|
@@ -379,7 +395,7 @@ async function sync$1(client, args, json) {
|
|
|
379
395
|
["Unlinked", s["unlinked"] ?? 0],
|
|
380
396
|
["Failed", s["failed"] ?? 0]
|
|
381
397
|
]);
|
|
382
|
-
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
398
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${r.error_code ? `[${r.error_code}] ` : ""}${(r.errors ?? []).join(", ")}`);
|
|
383
399
|
}
|
|
384
400
|
async function get$2(client, args, json) {
|
|
385
401
|
const { positional } = parseNamedArgs(args);
|
|
@@ -405,6 +421,31 @@ async function get$2(client, args, json) {
|
|
|
405
421
|
["Created By", detail["created_by_name"] || "—"],
|
|
406
422
|
["Created At", detail["created_at"]]
|
|
407
423
|
]);
|
|
424
|
+
const caseSets = detail["case_sets"] ?? [];
|
|
425
|
+
if (caseSets.length) {
|
|
426
|
+
console.log("\n Typed case sets:");
|
|
427
|
+
printTable(caseSets, [
|
|
428
|
+
{
|
|
429
|
+
key: "id",
|
|
430
|
+
label: "ID",
|
|
431
|
+
width: 6
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
key: "case_type",
|
|
435
|
+
label: "Type",
|
|
436
|
+
width: 5
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
key: "name",
|
|
440
|
+
label: "Name"
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
key: "member_count",
|
|
444
|
+
label: "Cases",
|
|
445
|
+
width: 5
|
|
446
|
+
}
|
|
447
|
+
]);
|
|
448
|
+
}
|
|
408
449
|
const cases = casesData.items;
|
|
409
450
|
if (cases.length) {
|
|
410
451
|
console.log(`\n Cases (${cases.length}):`);
|
|
@@ -431,7 +472,45 @@ async function get$2(client, args, json) {
|
|
|
431
472
|
]);
|
|
432
473
|
} else console.log("\n No cases linked.");
|
|
433
474
|
}
|
|
434
|
-
async function
|
|
475
|
+
async function attachCases(client, args, json) {
|
|
476
|
+
const { positional, named } = parseNamedArgs(args);
|
|
477
|
+
const reqId = positional[0];
|
|
478
|
+
if (!reqId) {
|
|
479
|
+
printError("Usage: test requirements attach-cases <req_id> --case-ids TC-1,TC-2");
|
|
480
|
+
process.exitCode = 2;
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const caseIds = asArray(named["case-ids"]);
|
|
484
|
+
if (!caseIds.length) {
|
|
485
|
+
printError("Provide --case-ids");
|
|
486
|
+
process.exitCode = 2;
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const data = await client.post(`/api/test/requirements/${encodeURIComponent(reqId)}/cases:attach`, { case_ids: caseIds });
|
|
490
|
+
if (json) {
|
|
491
|
+
printJson(data);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
printSuccess(`Attached ${(data.items ?? []).reduce((sum, item) => sum + item.added, 0)} case(s) to ${reqId}`);
|
|
495
|
+
if (data.items?.length) printTable(data.items, [
|
|
496
|
+
{
|
|
497
|
+
key: "case_type",
|
|
498
|
+
label: "Type",
|
|
499
|
+
width: 5
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
key: "set_id",
|
|
503
|
+
label: "Set ID",
|
|
504
|
+
width: 8
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
key: "added",
|
|
508
|
+
label: "Added",
|
|
509
|
+
width: 5
|
|
510
|
+
}
|
|
511
|
+
]);
|
|
512
|
+
}
|
|
513
|
+
async function list$3(client, args, json) {
|
|
435
514
|
const { named } = parseNamedArgs(args);
|
|
436
515
|
const params = {};
|
|
437
516
|
for (const k of [
|
|
@@ -473,11 +552,12 @@ async function runRequirements(client, args, json) {
|
|
|
473
552
|
case "create": return create$4(client, subArgs, json);
|
|
474
553
|
case "get": return get$2(client, subArgs, json);
|
|
475
554
|
case "sync": return sync$1(client, subArgs, json);
|
|
476
|
-
case "
|
|
555
|
+
case "attach-cases": return attachCases(client, subArgs, json);
|
|
556
|
+
case "list": return list$3(client, subArgs, json);
|
|
477
557
|
case "--help":
|
|
478
558
|
case "-h":
|
|
479
559
|
case void 0:
|
|
480
|
-
console.log(`requirements commands:\n create
|
|
560
|
+
console.log(`requirements commands:\n create Create a requirement (typed sets are lazy)\n get Get requirement detail with typed sets and cases\n attach-cases Add cases; the server routes each case to its typed set\n sync Sync cases to requirement ([--reconcile-case-types] [--confirm-unlink])\n list List requirements`);
|
|
481
561
|
return;
|
|
482
562
|
default:
|
|
483
563
|
printError(`Unknown requirements action: ${action}`);
|
|
@@ -572,7 +652,7 @@ async function create$3(client, args, json) {
|
|
|
572
652
|
["Priority", data["priority"] || "—"]
|
|
573
653
|
]);
|
|
574
654
|
}
|
|
575
|
-
async function list$
|
|
655
|
+
async function list$2(client, args, json) {
|
|
576
656
|
const { named } = parseNamedArgs(args);
|
|
577
657
|
const params = {};
|
|
578
658
|
for (const k of [
|
|
@@ -803,7 +883,7 @@ async function runCases(client, args, json) {
|
|
|
803
883
|
const subArgs = args.slice(1);
|
|
804
884
|
switch (action) {
|
|
805
885
|
case "create": return create$3(client, subArgs, json);
|
|
806
|
-
case "list": return list$
|
|
886
|
+
case "list": return list$2(client, subArgs, json);
|
|
807
887
|
case "batch": return batch$1(client, subArgs, json);
|
|
808
888
|
case "delete": return remove$1(client, subArgs, json);
|
|
809
889
|
case "update": return update(client, subArgs, json);
|
|
@@ -827,9 +907,16 @@ async function create$2(client, args, json) {
|
|
|
827
907
|
return;
|
|
828
908
|
}
|
|
829
909
|
const moduleId = requireArg(named, "module", "module_id (integer)");
|
|
910
|
+
const caseType = requireArg(named, "type", "e2e|api");
|
|
911
|
+
if (!["e2e", "api"].includes(caseType)) {
|
|
912
|
+
printError(`Invalid --type "${caseType}": must be e2e|api`);
|
|
913
|
+
process.exitCode = 2;
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
830
916
|
const body = {
|
|
831
917
|
name,
|
|
832
918
|
kind,
|
|
919
|
+
case_type: caseType,
|
|
833
920
|
selection_mode: "manual",
|
|
834
921
|
primary_module_id: parseInt(moduleId, 10)
|
|
835
922
|
};
|
|
@@ -839,7 +926,55 @@ async function create$2(client, args, json) {
|
|
|
839
926
|
return;
|
|
840
927
|
}
|
|
841
928
|
printSuccess(`Case set created: ${data["id"]}`);
|
|
842
|
-
printKV([
|
|
929
|
+
printKV([
|
|
930
|
+
["Name", data["name"]],
|
|
931
|
+
["Kind", data["kind"]],
|
|
932
|
+
["Case Type", data["case_type"]]
|
|
933
|
+
]);
|
|
934
|
+
}
|
|
935
|
+
async function list$1(client, args, json) {
|
|
936
|
+
const { named } = parseNamedArgs(args);
|
|
937
|
+
const params = {};
|
|
938
|
+
if (typeof named["q"] === "string") params["q"] = named["q"];
|
|
939
|
+
if (typeof named["type"] === "string") {
|
|
940
|
+
if (!["e2e", "api"].includes(named["type"])) {
|
|
941
|
+
printError(`Invalid --type "${named["type"]}": must be e2e|api`);
|
|
942
|
+
process.exitCode = 2;
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
params["case_type"] = named["type"];
|
|
946
|
+
}
|
|
947
|
+
const data = await client.get("/api/test/case-sets", params);
|
|
948
|
+
if (json) {
|
|
949
|
+
printJson(data);
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
printTable(data.items, [
|
|
953
|
+
{
|
|
954
|
+
key: "id",
|
|
955
|
+
label: "ID",
|
|
956
|
+
width: 6
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
key: "name",
|
|
960
|
+
label: "Name"
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
key: "case_type",
|
|
964
|
+
label: "Type",
|
|
965
|
+
width: 5
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
key: "kind",
|
|
969
|
+
label: "Kind",
|
|
970
|
+
width: 12
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
key: "member_count",
|
|
974
|
+
label: "Cases",
|
|
975
|
+
width: 5
|
|
976
|
+
}
|
|
977
|
+
]);
|
|
843
978
|
}
|
|
844
979
|
async function members(client, args, json) {
|
|
845
980
|
const { positional, named } = parseNamedArgs(args);
|
|
@@ -880,6 +1015,7 @@ async function get$1(client, args, json) {
|
|
|
880
1015
|
printKV([
|
|
881
1016
|
["Name", data.name],
|
|
882
1017
|
["Kind", data.kind],
|
|
1018
|
+
["Case Type", data.case_type],
|
|
883
1019
|
["Members", data.members?.length ?? 0]
|
|
884
1020
|
]);
|
|
885
1021
|
if (data.members?.length) printTable(data.members, [
|
|
@@ -916,7 +1052,18 @@ async function sync(client, args, json) {
|
|
|
916
1052
|
process.exitCode = 2;
|
|
917
1053
|
return;
|
|
918
1054
|
}
|
|
919
|
-
const
|
|
1055
|
+
const input = readFileInput(requireArg(named, "file", "path"));
|
|
1056
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) throw new Error("sync input must be a JSON object");
|
|
1057
|
+
const reconcileTypes = asArray(named["reconcile-case-types"]);
|
|
1058
|
+
if (reconcileTypes.some((caseType) => !["e2e", "api"].includes(caseType))) {
|
|
1059
|
+
printError("--reconcile-case-types must contain only e2e,api");
|
|
1060
|
+
process.exitCode = 2;
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const payload = {
|
|
1064
|
+
...input,
|
|
1065
|
+
...reconcileTypes.length ? { reconcile_case_types: reconcileTypes } : {}
|
|
1066
|
+
};
|
|
920
1067
|
const confirmUnlink = named["confirm-unlink"] !== void 0;
|
|
921
1068
|
const data = await syncWithGuard(client, `/api/test/case-sets/${setId}/cases:sync`, payload, json, confirmUnlink);
|
|
922
1069
|
if (!data) return;
|
|
@@ -935,20 +1082,21 @@ async function sync(client, args, json) {
|
|
|
935
1082
|
["Unlinked", s["unlinked"] ?? 0],
|
|
936
1083
|
["Failed", s["failed"] ?? 0]
|
|
937
1084
|
]);
|
|
938
|
-
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
1085
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${r.error_code ? `[${r.error_code}] ` : ""}${(r.errors ?? []).join(", ")}`);
|
|
939
1086
|
}
|
|
940
1087
|
async function runCaseSets(client, args, json) {
|
|
941
1088
|
const action = args[0];
|
|
942
1089
|
const subArgs = args.slice(1);
|
|
943
1090
|
switch (action) {
|
|
944
1091
|
case "create": return create$2(client, subArgs, json);
|
|
1092
|
+
case "list": return list$1(client, subArgs, json);
|
|
945
1093
|
case "get": return get$1(client, subArgs, json);
|
|
946
1094
|
case "members": return members(client, subArgs, json);
|
|
947
1095
|
case "sync": return sync(client, subArgs, json);
|
|
948
1096
|
case "--help":
|
|
949
1097
|
case "-h":
|
|
950
1098
|
case void 0:
|
|
951
|
-
console.log(`case-sets commands:\n create Create a case set (--name, --kind
|
|
1099
|
+
console.log(`case-sets commands:\n create Create a typed case set (--name, --kind, --module, --type e2e|api)\n list List case sets ([--type e2e|api])\n get Get case set detail with members\n members Batch add members (--add)\n sync Sync cases to a set (--file <path> [--reconcile-case-types] [--confirm-unlink])`);
|
|
952
1100
|
return;
|
|
953
1101
|
default:
|
|
954
1102
|
printError(`Unknown case-sets action: ${action}`);
|
|
@@ -966,6 +1114,15 @@ async function create$1(client, args, json) {
|
|
|
966
1114
|
const body = { type: planType };
|
|
967
1115
|
if (typeof named["title"] === "string") body["title"] = named["title"];
|
|
968
1116
|
if (typeof named["from-set"] === "string") body["from_case_set"] = Number(named["from-set"]);
|
|
1117
|
+
if (typeof named["from-sets"] === "string") {
|
|
1118
|
+
const ids = named["from-sets"].split(",").map((s) => Number(s.trim())).filter((id) => Number.isInteger(id) && id > 0);
|
|
1119
|
+
if (!ids.length) {
|
|
1120
|
+
printError("--from-sets requires one or more numeric IDs");
|
|
1121
|
+
process.exitCode = 2;
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
body["from_case_sets"] = ids;
|
|
1125
|
+
}
|
|
969
1126
|
if (typeof named["case-ids"] === "string") body["case_ids"] = named["case-ids"].split(",").map((s) => s.trim());
|
|
970
1127
|
if (typeof named["req-id"] === "string") body["req_id"] = named["req-id"];
|
|
971
1128
|
if (typeof named["env"] === "string") {
|
|
@@ -981,10 +1138,11 @@ async function create$1(client, args, json) {
|
|
|
981
1138
|
const sources = [
|
|
982
1139
|
body["case_ids"] ? "case-ids" : null,
|
|
983
1140
|
body["from_case_set"] !== void 0 ? "from-set" : null,
|
|
1141
|
+
body["from_case_sets"] !== void 0 ? "from-sets" : null,
|
|
984
1142
|
body["req_id"] ? "req-id" : null
|
|
985
1143
|
].filter(Boolean);
|
|
986
1144
|
if (sources.length === 0) {
|
|
987
|
-
printError("Must specify one of --case-ids, --from-set, or --req-id");
|
|
1145
|
+
printError("Must specify one of --case-ids, --from-set, --from-sets, or --req-id");
|
|
988
1146
|
process.exitCode = 2;
|
|
989
1147
|
return;
|
|
990
1148
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -1290,8 +1290,10 @@ async function fetchWithAutoAuth(url, accept, bearerToken, portalUrl) {
|
|
|
1290
1290
|
if (token) h.Authorization = `Bearer ${token}`;
|
|
1291
1291
|
return h;
|
|
1292
1292
|
};
|
|
1293
|
-
|
|
1294
|
-
|
|
1293
|
+
const envToken = process.env.SHOPLAZZA_FORGE_TOKEN?.trim();
|
|
1294
|
+
const fromEnv = !!envToken && bearerToken === envToken;
|
|
1295
|
+
const resp = await rawFetch(url, buildHeaders(bearerToken), portalUrl);
|
|
1296
|
+
if (resp.status !== 401 || fromEnv) return resp;
|
|
1295
1297
|
await resp.arrayBuffer().catch(() => void 0);
|
|
1296
1298
|
await runLogin({ force: true });
|
|
1297
1299
|
const refreshed = loadConfig().token;
|
|
@@ -2430,6 +2432,54 @@ async function unregisterCodexPlugin(pluginName) {
|
|
|
2430
2432
|
await writeFile(configPath, toml, "utf-8");
|
|
2431
2433
|
} catch {}
|
|
2432
2434
|
}
|
|
2435
|
+
const STALE_MS = 12e4;
|
|
2436
|
+
const RETRY_MS = 100;
|
|
2437
|
+
const WAIT_TIMEOUT_MS = 12e4;
|
|
2438
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2439
|
+
async function lockAgeMs(lockPath) {
|
|
2440
|
+
try {
|
|
2441
|
+
const s = await stat(lockPath);
|
|
2442
|
+
return Date.now() - s.mtimeMs;
|
|
2443
|
+
} catch {
|
|
2444
|
+
return null;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
async function acquire(lockPath) {
|
|
2448
|
+
const start = Date.now();
|
|
2449
|
+
for (;;) try {
|
|
2450
|
+
await mkdir(lockPath);
|
|
2451
|
+
await writeFile(join(lockPath, "owner.json"), JSON.stringify({
|
|
2452
|
+
pid: process.pid,
|
|
2453
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2454
|
+
}) + "\n").catch(() => {});
|
|
2455
|
+
return;
|
|
2456
|
+
} catch (e) {
|
|
2457
|
+
if (e.code !== "EEXIST") throw e;
|
|
2458
|
+
const age = await lockAgeMs(lockPath);
|
|
2459
|
+
if (age === null) continue;
|
|
2460
|
+
if (age > STALE_MS || Date.now() - start > WAIT_TIMEOUT_MS) {
|
|
2461
|
+
await rm(lockPath, {
|
|
2462
|
+
recursive: true,
|
|
2463
|
+
force: true
|
|
2464
|
+
});
|
|
2465
|
+
continue;
|
|
2466
|
+
}
|
|
2467
|
+
await sleep(RETRY_MS);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
async function withInstallLock(lockDir, fn) {
|
|
2471
|
+
const lockPath = join(lockDir, ".forge-install.lock");
|
|
2472
|
+
await mkdir(lockDir, { recursive: true }).catch(() => {});
|
|
2473
|
+
await acquire(lockPath);
|
|
2474
|
+
try {
|
|
2475
|
+
return await fn();
|
|
2476
|
+
} finally {
|
|
2477
|
+
await rm(lockPath, {
|
|
2478
|
+
recursive: true,
|
|
2479
|
+
force: true
|
|
2480
|
+
}).catch(() => {});
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2433
2483
|
async function installPlugin(ref, opts) {
|
|
2434
2484
|
const cfg = loadConfig();
|
|
2435
2485
|
const { buffer: tarball, commitSha } = await fetchPluginArchive(ref, cfg.portal, cfg.token);
|
|
@@ -2493,7 +2543,7 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2493
2543
|
force: opts.force
|
|
2494
2544
|
})) throw new Error(`aborted: ${foreignConflicts.length} foreign conflicts at plugin entry paths`);
|
|
2495
2545
|
}
|
|
2496
|
-
const { ledger, warnings } = await commitPluginInstall({
|
|
2546
|
+
const { ledger, warnings, registrationFailed } = await withInstallLock(join(getAgentHome("claude-code"), "plugins"), () => commitPluginInstall({
|
|
2497
2547
|
ref,
|
|
2498
2548
|
scopeNamespace,
|
|
2499
2549
|
pluginName,
|
|
@@ -2504,7 +2554,7 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2504
2554
|
statuses,
|
|
2505
2555
|
opts,
|
|
2506
2556
|
commitSha
|
|
2507
|
-
});
|
|
2557
|
+
}));
|
|
2508
2558
|
return {
|
|
2509
2559
|
pluginRef: ref,
|
|
2510
2560
|
pluginCanonical,
|
|
@@ -2517,7 +2567,8 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2517
2567
|
})),
|
|
2518
2568
|
forgeOtherReplacements,
|
|
2519
2569
|
ignoredComponents,
|
|
2520
|
-
warnings
|
|
2570
|
+
warnings,
|
|
2571
|
+
registrationFailed
|
|
2521
2572
|
};
|
|
2522
2573
|
}
|
|
2523
2574
|
function componentLedgerKind(kind) {
|
|
@@ -2756,7 +2807,7 @@ async function commitPluginInstall(params) {
|
|
|
2756
2807
|
cwd: opts.cwd
|
|
2757
2808
|
});
|
|
2758
2809
|
if (components.skills.length > 0) for (const agent of opts.agents) await ensureForgeHooks(agent);
|
|
2759
|
-
let version
|
|
2810
|
+
let version;
|
|
2760
2811
|
for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
|
|
2761
2812
|
const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
2762
2813
|
if (manifest.version) {
|
|
@@ -2764,8 +2815,10 @@ async function commitPluginInstall(params) {
|
|
|
2764
2815
|
break;
|
|
2765
2816
|
}
|
|
2766
2817
|
} catch {}
|
|
2818
|
+
if (!version) throw new Error(`refusing to register ${pluginName}: no plugin.json version in canonical store ${pluginCanonical} (partial/corrupt install?)`);
|
|
2767
2819
|
const warnings = [];
|
|
2768
2820
|
const warn = (msg) => warnings.push(msg);
|
|
2821
|
+
let registrationFailed = false;
|
|
2769
2822
|
if (opts.agents.includes("claude-code") || opts.agents.includes("cursor")) await registerClaudePlugin({
|
|
2770
2823
|
pluginName,
|
|
2771
2824
|
version,
|
|
@@ -2773,7 +2826,10 @@ async function commitPluginInstall(params) {
|
|
|
2773
2826
|
gitSha: commitSha,
|
|
2774
2827
|
scope: opts.scope === "project" ? "project" : "user",
|
|
2775
2828
|
cwd: opts.cwd
|
|
2776
|
-
}).then((ws) => ws.forEach(warn)).catch((e) =>
|
|
2829
|
+
}).then((ws) => ws.forEach(warn)).catch((e) => {
|
|
2830
|
+
registrationFailed = true;
|
|
2831
|
+
warn(`claude-code plugin registration failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
2832
|
+
});
|
|
2777
2833
|
if (opts.agents.includes("codex")) await registerCodexPlugin({
|
|
2778
2834
|
pluginName,
|
|
2779
2835
|
installPath: pluginCanonical,
|
|
@@ -2782,7 +2838,8 @@ async function commitPluginInstall(params) {
|
|
|
2782
2838
|
await ensureForgeCliWrapper().catch((e) => warn(`forge-cli.sh wrapper generation failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2783
2839
|
return {
|
|
2784
2840
|
ledger,
|
|
2785
|
-
warnings
|
|
2841
|
+
warnings,
|
|
2842
|
+
registrationFailed
|
|
2786
2843
|
};
|
|
2787
2844
|
}
|
|
2788
2845
|
async function copyDirRecursive(src, dest, skipDotClaudePlugin, extraSkip) {
|
|
@@ -4385,6 +4442,10 @@ async function runAdd(args, options = {}) {
|
|
|
4385
4442
|
}
|
|
4386
4443
|
spinner.stop(import_picocolors.default.green("Plugin installed"));
|
|
4387
4444
|
if (pluginResult.warnings.length > 0) for (const w of pluginResult.warnings) M.warn(w);
|
|
4445
|
+
if (pluginResult.registrationFailed) {
|
|
4446
|
+
M.error(import_picocolors.default.red("Claude native plugin registration failed"));
|
|
4447
|
+
process.exitCode = 1;
|
|
4448
|
+
}
|
|
4388
4449
|
if (pluginResult.installedEntries.length > 0) {
|
|
4389
4450
|
const grouped = /* @__PURE__ */ new Map();
|
|
4390
4451
|
for (const e of pluginResult.installedEntries) {
|
|
@@ -5054,6 +5115,7 @@ async function runAdd(args, options = {}) {
|
|
|
5054
5115
|
console.log();
|
|
5055
5116
|
M.error(import_picocolors.default.red(`Failed to install ${failed.length}`));
|
|
5056
5117
|
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.skill} → ${r.agent}: ${import_picocolors.default.dim(r.error)}`);
|
|
5118
|
+
process.exitCode = 1;
|
|
5057
5119
|
}
|
|
5058
5120
|
console.log();
|
|
5059
5121
|
Se(import_picocolors.default.green("Done!") + import_picocolors.default.dim(" Review skills before use; they run with full agent permissions."));
|
|
@@ -6253,6 +6315,7 @@ async function removeCommand(skillNames, options) {
|
|
|
6253
6315
|
if (failed.length > 0) {
|
|
6254
6316
|
M.error(import_picocolors.default.red(`Failed to remove ${failed.length} item(s)`));
|
|
6255
6317
|
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.name}: ${r.error}`);
|
|
6318
|
+
process.exitCode = 1;
|
|
6256
6319
|
}
|
|
6257
6320
|
console.log();
|
|
6258
6321
|
Se(import_picocolors.default.green("Done!"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shoplazza-ai-dev-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Shoplazza AI Dev CLI: install, publish and manage AI agent skills/rules",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"format:check": "prettier --check \"src/**/*.ts\" \"scripts/**/*.ts\"",
|
|
23
23
|
"test": "vitest",
|
|
24
24
|
"type-check": "tsc --noEmit",
|
|
25
|
-
"publish:snapshot": "npm version prerelease --preid=snapshot --no-git-tag-version && npm publish --tag snapshot"
|
|
25
|
+
"publish:snapshot": "npm version prerelease --preid=snapshot --no-git-tag-version && npm publish --tag snapshot",
|
|
26
|
+
"publish:latest": "npm ci && npm version patch --no-git-tag-version && npm publish --tag latest"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
28
29
|
"cli",
|