shoplazza-ai-dev-cli 0.1.17 → 0.1.19

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.
@@ -1,5 +1,5 @@
1
1
  import { loadConfig, runLogin } from "../cli.mjs";
2
- import { readFileSync } from "fs";
2
+ import { readFileSync, readSync } from "fs";
3
3
  function parseGlobalFlags(args) {
4
4
  const flags = { json: false };
5
5
  const rest = [];
@@ -58,6 +58,30 @@ function parseNamedArgs(args) {
58
58
  named
59
59
  };
60
60
  }
61
+ const STDIN_READ_CHUNK_BYTES = 64 * 1024;
62
+ const STDIN_EAGAIN_WAIT_MS = 5;
63
+ function readAllFd(fd = 0) {
64
+ const chunks = [];
65
+ const buf = Buffer.allocUnsafe(STDIN_READ_CHUNK_BYTES);
66
+ const idle = new Int32Array(new SharedArrayBuffer(4));
67
+ for (;;) {
68
+ let bytesRead;
69
+ try {
70
+ bytesRead = readSync(fd, buf, 0, buf.length, null);
71
+ } catch (err) {
72
+ const code = err.code;
73
+ if (code === "EAGAIN" || code === "EWOULDBLOCK") {
74
+ Atomics.wait(idle, 0, 0, STDIN_EAGAIN_WAIT_MS);
75
+ continue;
76
+ }
77
+ if (code === "EOF") break;
78
+ throw err;
79
+ }
80
+ if (bytesRead === 0) break;
81
+ chunks.push(Buffer.from(buf.subarray(0, bytesRead)));
82
+ }
83
+ return Buffer.concat(chunks).toString("utf-8");
84
+ }
61
85
  function readFileInput(filePath) {
62
86
  if (filePath === "-") {
63
87
  if (process.stdin.isTTY) {
@@ -65,8 +89,7 @@ function readFileInput(filePath) {
65
89
  process.exitCode = 2;
66
90
  throw new Error("missing --file");
67
91
  }
68
- const raw = readFileSync(0, "utf-8");
69
- return JSON.parse(raw);
92
+ return JSON.parse(readAllFd());
70
93
  }
71
94
  const raw = readFileSync(filePath, "utf-8");
72
95
  return JSON.parse(raw);
@@ -344,6 +367,13 @@ async function create$2(client, args, json) {
344
367
  ["Case Set ID", data["case_set_id"] ?? "—"]
345
368
  ]);
346
369
  } else console.log(`ℹ Requirement already exists: ${data["req_id"]} (not modified)`);
370
+ printFeishuSyncWarning(data);
371
+ }
372
+ function printFeishuSyncWarning(data) {
373
+ const failed = (data["feishu_sync"]?.fields ?? []).filter((f) => f.status === "failed");
374
+ if (failed.length === 0) return;
375
+ printError("飞书工单回写失败(需求本身已入库;下次对同一工单执行 create 会自动补写):");
376
+ for (const f of failed) console.error(` - ${f.label ?? ""}(${f.field_key ?? "?"}) reason=${f.reason ?? "?"} err_code=${f.err_code ?? 0} err_msg=${f.err_msg ?? ""} expect=${f.expect ?? ""} actual=${f.actual ?? ""}`);
347
377
  }
348
378
  async function sync$1(client, args, json) {
349
379
  const { positional, named } = parseNamedArgs(args);
@@ -512,22 +542,80 @@ const VALID_USER_KINDS = [
512
542
  "baseline",
513
543
  "custom"
514
544
  ];
515
- async function list$1(client, args, json) {
516
- const { named } = parseNamedArgs(args);
545
+ function buildListParams(named) {
517
546
  const params = {};
518
547
  for (const k of [
519
548
  "q",
520
549
  "module-id",
521
550
  "type",
522
551
  "priority",
552
+ "automation-status",
523
553
  "page",
524
554
  "size"
525
555
  ]) {
526
- const apiKey = k === "module-id" ? "module_id" : k === "type" ? "case_type" : k;
556
+ const apiKey = k === "module-id" ? "module_id" : k === "type" ? "case_type" : k === "automation-status" ? "automation_status" : k;
527
557
  const v = named[k];
528
558
  const val = Array.isArray(v) ? v[v.length - 1] : v;
529
559
  if (typeof val === "string") params[apiKey] = val;
530
560
  }
561
+ return params;
562
+ }
563
+ const LIST_PAGE_CAP = 200;
564
+ async function list$1(client, args, json) {
565
+ const { named } = parseNamedArgs(args);
566
+ const params = buildListParams(named);
567
+ if (named["all"] === "true") {
568
+ delete params["page"];
569
+ delete params["size"];
570
+ const items = [];
571
+ let total = 0;
572
+ for (let page = 1;; page++) {
573
+ const data = await client.get("/api/test/cases", {
574
+ ...params,
575
+ page: String(page),
576
+ size: String(LIST_PAGE_CAP)
577
+ });
578
+ const batch = data.items ?? [];
579
+ items.push(...batch);
580
+ total = data.total;
581
+ if (items.length >= total || batch.length === 0) break;
582
+ }
583
+ const merged = {
584
+ items,
585
+ total
586
+ };
587
+ if (json) {
588
+ printJson(merged);
589
+ return;
590
+ }
591
+ printTable(items, [
592
+ {
593
+ key: "case_id",
594
+ label: "Case ID"
595
+ },
596
+ {
597
+ key: "title",
598
+ label: "Title"
599
+ },
600
+ {
601
+ key: "case_type",
602
+ label: "Type",
603
+ width: 5
604
+ },
605
+ {
606
+ key: "priority",
607
+ label: "Pri",
608
+ width: 4
609
+ },
610
+ {
611
+ key: "automation_status",
612
+ label: "Auto",
613
+ width: 10
614
+ }
615
+ ]);
616
+ printPagination(total);
617
+ return;
618
+ }
531
619
  const data = await client.get("/api/test/cases", params);
532
620
  if (json) {
533
621
  printJson(data);
@@ -697,16 +785,64 @@ async function update(client, args, json) {
697
785
  process.exitCode = 1;
698
786
  }
699
787
  }
788
+ async function batchStatus(client, args, json) {
789
+ const { named } = parseNamedArgs(args);
790
+ const idsRaw = named["ids"];
791
+ const idsVal = Array.isArray(idsRaw) ? idsRaw.join(",") : idsRaw;
792
+ if (typeof idsVal !== "string" || idsVal.trim() === "") {
793
+ printError("Usage: cases batch-status --ids TC-000001,TC-000002 [--include-content]");
794
+ process.exitCode = 2;
795
+ return;
796
+ }
797
+ const body = { case_ids: idsVal.split(",").map((s) => s.trim()).filter((s) => s !== "") };
798
+ if (named["include-content"] !== void 0) body["include_content"] = true;
799
+ const data = await client.post("/api/test/cases:batch-status", body);
800
+ if (json) {
801
+ printJson(data);
802
+ return;
803
+ }
804
+ printTable(data.items, [
805
+ {
806
+ key: "case_id",
807
+ label: "Case ID"
808
+ },
809
+ {
810
+ key: "exists",
811
+ label: "Exists",
812
+ width: 6
813
+ },
814
+ {
815
+ key: "deleted",
816
+ label: "Deleted",
817
+ width: 7
818
+ },
819
+ {
820
+ key: "status",
821
+ label: "Status",
822
+ width: 10
823
+ },
824
+ {
825
+ key: "version",
826
+ label: "Ver",
827
+ width: 4
828
+ },
829
+ {
830
+ key: "title",
831
+ label: "Title"
832
+ }
833
+ ]);
834
+ }
700
835
  async function runCases(client, args, json) {
701
836
  const action = args[0];
702
837
  const subArgs = args.slice(1);
703
838
  switch (action) {
704
839
  case "list": return list$1(client, subArgs, json);
705
840
  case "update": return update(client, subArgs, json);
841
+ case "batch-status": return batchStatus(client, subArgs, json);
706
842
  case "--help":
707
843
  case "-h":
708
844
  case void 0:
709
- console.log(`cases commands:\n list List cases with filters\n update Patch a case by id (pointer semantics: only pass fields to change; --file <path|-> for JSON body)`);
845
+ console.log(`cases commands:\n list List cases with filters (--q --module-id --type --priority --automation-status --page --size; --all to fetch every page)\n update Patch a case by id (pointer semantics: only pass fields to change; --file <path|-> for JSON body)\n batch-status Batch read existence/deleted/status/version by case ids (--ids a,b,c [--include-content])`);
710
846
  return;
711
847
  default:
712
848
  printError(`Unknown cases action: ${action}`);
@@ -920,7 +1056,7 @@ function validatePlanCreateMatrix(planType, src) {
920
1056
  if (!src.reqId || !src.caseIds || src.fromSet) return "type=smoke 必须同时提供 --req-id 与 --case-ids(测试员手选),不接受 --from-set";
921
1057
  return null;
922
1058
  case "regression":
923
- if (!src.fromSet || src.reqId) return "type=regression 只接受 --from-set(全局用例集),可选 --case-ids 建子集回归,不接受 --req-id";
1059
+ if (!src.fromSet || src.reqId) return "type=regression 只接受 --from-set(全局集,或需求规范集配 --case-ids),可选 --case-ids 建子集回归,不接受 --req-id";
924
1060
  return null;
925
1061
  default: return `Invalid type "${planType}"`;
926
1062
  }
@@ -1029,7 +1165,7 @@ async function list(client, args, json) {
1029
1165
  ]);
1030
1166
  printPagination(data.total);
1031
1167
  }
1032
- async function add(client, args, json) {
1168
+ async function add$1(client, args, json) {
1033
1169
  const { positional } = parseNamedArgs(args);
1034
1170
  const [planId, ...caseIDs] = positional;
1035
1171
  if (!planId || caseIDs.length === 0) {
@@ -1061,7 +1197,7 @@ async function runPlans(client, args, json) {
1061
1197
  case "create": return create(client, subArgs, json);
1062
1198
  case "get": return get(client, subArgs, json);
1063
1199
  case "list": return list(client, subArgs, json);
1064
- case "add": return add(client, subArgs, json);
1200
+ case "add": return add$1(client, subArgs, json);
1065
1201
  case "--help":
1066
1202
  case "-h":
1067
1203
  case void 0:
@@ -1108,13 +1244,60 @@ async function runResults(client, args, json) {
1108
1244
  process.exitCode = 2;
1109
1245
  }
1110
1246
  }
1247
+ const ADD_USAGE = "Usage: test kb-mrs add (--set <set_id> | --plan <PLAN-id>) --urls <u1,u2>";
1248
+ function buildKBMRsRequest(named) {
1249
+ const set = typeof named["set"] === "string" ? named["set"] : void 0;
1250
+ const plan = typeof named["plan"] === "string" ? named["plan"] : void 0;
1251
+ const urlsRaw = typeof named["urls"] === "string" ? named["urls"] : void 0;
1252
+ if (set && plan || !set && !plan) return { error: `exactly one of --set or --plan is required\n${ADD_USAGE}` };
1253
+ if (!urlsRaw) return { error: `missing --urls\n${ADD_USAGE}` };
1254
+ const urls = urlsRaw.split(",").map((s) => s.trim()).filter(Boolean);
1255
+ if (urls.length === 0) return { error: `--urls must contain at least one URL\n${ADD_USAGE}` };
1256
+ return {
1257
+ path: plan ? `/api/test/test-plans/${encodeURIComponent(plan)}/kb-mrs` : `/api/test/case-sets/${encodeURIComponent(set)}/kb-mrs`,
1258
+ body: { urls }
1259
+ };
1260
+ }
1261
+ async function add(client, args, json) {
1262
+ const { named } = parseNamedArgs(args);
1263
+ const req = buildKBMRsRequest(named);
1264
+ if ("error" in req) {
1265
+ printError(req.error);
1266
+ process.exitCode = 2;
1267
+ return;
1268
+ }
1269
+ const data = await client.post(req.path, req.body);
1270
+ if (json) {
1271
+ printJson(data);
1272
+ return;
1273
+ }
1274
+ const all = data["kb_mr_urls"] ?? [];
1275
+ printSuccess(`KB MRs recorded: ${data["added"]} added (total ${all.length})`);
1276
+ for (const u of all) console.log(` ${u}`);
1277
+ }
1278
+ async function runKBMRs(client, args, json) {
1279
+ const action = args[0];
1280
+ const subArgs = args.slice(1);
1281
+ switch (action) {
1282
+ case "add": return add(client, subArgs, json);
1283
+ case "--help":
1284
+ case "-h":
1285
+ case void 0:
1286
+ console.log(`kb-mrs commands:\n add Record knowledge-base MR links on a case set (--set) or plan (--plan)\n\n${ADD_USAGE}`);
1287
+ return;
1288
+ default:
1289
+ printError(`Unknown kb-mrs action: ${action}`);
1290
+ process.exitCode = 2;
1291
+ }
1292
+ }
1111
1293
  const RESOURCES = {
1112
1294
  taxonomy: runTaxonomy,
1113
1295
  requirements: runRequirements,
1114
1296
  cases: runCases,
1115
1297
  "case-sets": runCaseSets,
1116
1298
  plans: runPlans,
1117
- results: runResults
1299
+ results: runResults,
1300
+ "kb-mrs": runKBMRs
1118
1301
  };
1119
1302
  const HELP = `Testing platform commands (Scenario A & B).
1120
1303
 
@@ -1125,6 +1308,7 @@ Resources:
1125
1308
  case-sets Case set member management
1126
1309
  plans Test plans & execution
1127
1310
  results Test results (batch)
1311
+ kb-mrs Knowledge-base MR links (case set / plan)
1128
1312
 
1129
1313
  Run: shoplazza-ai-dev-cli test <resource> --help`;
1130
1314
  async function runTest(rawArgs) {
package/dist/cli.mjs CHANGED
@@ -2481,6 +2481,11 @@ async function withInstallLock(lockDir, fn) {
2481
2481
  }
2482
2482
  }
2483
2483
  async function installPlugin(ref, opts) {
2484
+ if (opts.fromDir !== void 0) {
2485
+ if (!existsSync(opts.fromDir)) throw new Error(`--from-dir directory not found: ${opts.fromDir}`);
2486
+ if (!existsSync(join(opts.fromDir, "plugin.json")) && !existsSync(join(opts.fromDir, ".claude-plugin", "plugin.json"))) throw new Error(`--from-dir directory has no plugin root (missing plugin.json or .claude-plugin/plugin.json): ${opts.fromDir}`);
2487
+ return await installFromExtracted(ref, opts.fromDir, opts, void 0);
2488
+ }
2484
2489
  const cfg = loadConfig();
2485
2490
  const { buffer: tarball, commitSha } = await fetchPluginArchive(ref, cfg.portal, cfg.token);
2486
2491
  const tmp = await mkdtemp(join(tmpdir(), "plugin-"));
@@ -2722,6 +2727,13 @@ function componentSubRef$1(c) {
2722
2727
  case "plugin-rule-deps-dir": return `rules/${c.dirname}`;
2723
2728
  }
2724
2729
  }
2730
+ async function resolvePluginVersion(pluginCanonical, pluginName) {
2731
+ for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
2732
+ const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
2733
+ if (manifest.name && manifest.description) return manifest.version || "0.0.0";
2734
+ } catch {}
2735
+ throw new Error(`refusing to register ${pluginName}: no valid plugin.json (with name/description) in canonical store ${pluginCanonical} (partial/corrupt install?)`);
2736
+ }
2725
2737
  async function commitPluginInstall(params) {
2726
2738
  const { ref, scopeNamespace, pluginName, pluginCanonical, extractedDir, components, preflight, statuses, opts, commitSha } = params;
2727
2739
  await rm(pluginCanonical, {
@@ -2807,15 +2819,7 @@ async function commitPluginInstall(params) {
2807
2819
  cwd: opts.cwd
2808
2820
  });
2809
2821
  if (components.skills.length > 0) for (const agent of opts.agents) await ensureForgeHooks(agent);
2810
- let version;
2811
- for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
2812
- const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
2813
- if (manifest.version) {
2814
- version = manifest.version;
2815
- break;
2816
- }
2817
- } catch {}
2818
- if (!version) throw new Error(`refusing to register ${pluginName}: no plugin.json version in canonical store ${pluginCanonical} (partial/corrupt install?)`);
2822
+ const version = await resolvePluginVersion(pluginCanonical, pluginName);
2819
2823
  const warnings = [];
2820
2824
  const warn = (msg) => warnings.push(msg);
2821
2825
  let registrationFailed = false;
@@ -3154,16 +3158,19 @@ async function fetchAuditData(source, skillSlugs, timeoutMs = 3e3) {
3154
3158
  const pendingTelemetry = [];
3155
3159
  function track(data) {
3156
3160
  if (!isTelemetryEnabled()) return;
3157
- if (!portalUrl) portalUrl = loadConfig().portal;
3161
+ const cfg = loadConfig();
3162
+ if (!portalUrl) portalUrl = cfg.portal;
3158
3163
  try {
3159
3164
  const bodyPayload = {};
3160
3165
  for (const [key, value] of Object.entries(data)) if (value !== void 0 && value !== null) bodyPayload[key] = value;
3166
+ const headers = {
3167
+ "Content-Type": "application/json",
3168
+ "User-Agent": "shoplazza-ai-dev-cli"
3169
+ };
3170
+ if (cfg.token) headers.Authorization = `Bearer ${cfg.token}`;
3161
3171
  const p = fetch(`${portalUrl}${TELEMETRY_URL_SUFFIX}`, {
3162
3172
  method: "POST",
3163
- headers: {
3164
- "Content-Type": "application/json",
3165
- "User-Agent": "shoplazza-ai-dev-cli"
3166
- },
3173
+ headers,
3167
3174
  body: JSON.stringify(bodyPayload)
3168
3175
  }).catch(() => {}).then(() => {});
3169
3176
  pendingTelemetry.push(p);
@@ -4265,6 +4272,16 @@ async function runTeamBatchAdd(teamScope, options) {
4265
4272
  }
4266
4273
  await promptForFindSkills(options, targetAgents);
4267
4274
  }
4275
+ function isPluginPortalRef(ref) {
4276
+ return /^(?:@public|@teams\/[^/]+)\/plugins(?:\/.+)?$/.test(ref);
4277
+ }
4278
+ function resolvePluginItemRef(portalRef, pluginOpt) {
4279
+ const pluginsDirRe = /^(?:@public|@teams\/[^/]+)\/plugins$/;
4280
+ const pluginsItemRe = /^(?:@public|@teams\/[^/]+)\/plugins\/[^/]+/;
4281
+ if (pluginsDirRe.test(portalRef) && pluginOpt && pluginOpt.length === 1) return `${portalRef}/${pluginOpt[0]}`;
4282
+ if (pluginsItemRe.test(portalRef)) return portalRef;
4283
+ return null;
4284
+ }
4268
4285
  async function runAdd(args, options = {}) {
4269
4286
  const source = args[0];
4270
4287
  let installTipShown = false;
@@ -4315,6 +4332,11 @@ async function runAdd(args, options = {}) {
4315
4332
  const parsed = parseSource(source);
4316
4333
  const sourceLabel = parsed.type === "local" ? parsed.localPath : parsed.type === "portal" ? parsed.portalRef : parsed.url;
4317
4334
  spinner.stop(`Source: ${sourceLabel}${parsed.ref ? ` @ ${import_picocolors.default.yellow(parsed.ref)}` : ""}${parsed.subpath ? ` (${parsed.subpath})` : ""}${parsed.skillFilter ? ` ${import_picocolors.default.dim("@")}${import_picocolors.default.cyan(parsed.skillFilter)}` : ""}`);
4335
+ const isFromDirAllowed = parsed.type === "portal" && !!parsed.portalRef && isPluginPortalRef(parsed.portalRef);
4336
+ if (options.fromDir && !isFromDirAllowed) {
4337
+ Se(import_picocolors.default.red("--from-dir is only supported for plugin refs (e.g. @public/plugins/<name> or @teams/<scope>/plugins/<name>)"));
4338
+ process.exit(1);
4339
+ }
4318
4340
  const ownerRepoRaw = getOwnerRepo(parsed);
4319
4341
  const repoPrivacyPromise = (() => {
4320
4342
  if (!ownerRepoRaw) return Promise.resolve(null);
@@ -4342,11 +4364,7 @@ async function runAdd(args, options = {}) {
4342
4364
  }
4343
4365
  if (parsed.type === "portal" && parsed.portalRef) {
4344
4366
  const portalRef = parsed.portalRef;
4345
- const pluginsDirRe = /^(?:@public|@teams\/[^/]+)\/plugins$/;
4346
- const pluginsItemRe = /^(?:@public|@teams\/[^/]+)\/plugins\/[^/]+/;
4347
- let resolvedPluginRef = null;
4348
- if (pluginsDirRe.test(portalRef) && options.plugin && options.plugin.length === 1) resolvedPluginRef = `${portalRef}/${options.plugin[0]}`;
4349
- else if (pluginsItemRe.test(portalRef)) resolvedPluginRef = portalRef;
4367
+ const resolvedPluginRef = resolvePluginItemRef(portalRef, options.plugin);
4350
4368
  if (resolvedPluginRef !== null) {
4351
4369
  const isTeam = resolvedPluginRef.startsWith("@teams/");
4352
4370
  const teamMatch = isTeam ? resolvedPluginRef.match(/^@teams\/([^/]+)/) : null;
@@ -4434,7 +4452,8 @@ async function runAdd(args, options = {}) {
4434
4452
  agents: targetAgents,
4435
4453
  cwd: process.cwd(),
4436
4454
  yes: options.yes,
4437
- force: options.force
4455
+ force: options.force,
4456
+ fromDir: options.fromDir
4438
4457
  });
4439
4458
  } catch (err) {
4440
4459
  spinner.stop(import_picocolors.default.red("Plugin installation failed"));
@@ -4543,7 +4562,7 @@ async function runAdd(args, options = {}) {
4543
4562
  spinner.start("Downloading from portal...");
4544
4563
  const cfg = loadConfig();
4545
4564
  const portalUrl = cfg.portal;
4546
- const token = parsed.portalRef.startsWith("@teams/") ? cfg.token : void 0;
4565
+ const token = cfg.token;
4547
4566
  let archive;
4548
4567
  try {
4549
4568
  archive = await fetchSkillArchive(parsed.portalRef, portalUrl, token);
@@ -5227,7 +5246,10 @@ function parseAddOptions(args) {
5227
5246
  }
5228
5247
  i--;
5229
5248
  } else if (arg === "--full-depth") options.fullDepth = true;
5230
- else if (arg === "--team") {
5249
+ else if (arg === "--from-dir") {
5250
+ i++;
5251
+ options.fromDir = args[i];
5252
+ } else if (arg === "--team") {
5231
5253
  i++;
5232
5254
  options.team = args[i];
5233
5255
  } else if (arg === "--dangerously-accept-openclaw-risks") options.dangerouslyAcceptOpenclawRisks = true;
@@ -6865,6 +6887,8 @@ ${BOLD}Add Options:${RESET}
6865
6887
  (no positional source; mutually exclusive with <source>)
6866
6888
  --all Shorthand for --skill '*' --agent '*' -y
6867
6889
  --full-depth Search all subdirectories even when a root SKILL.md exists
6890
+ --from-dir <path> Install a plugin from an already-extracted local directory
6891
+ instead of downloading it from the portal (plugin refs only)
6868
6892
 
6869
6893
  ${BOLD}Remove Options:${RESET}
6870
6894
  -a, --agent <agents> Restrict cleanup to specific agents
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoplazza-ai-dev-cli",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Shoplazza AI Dev CLI: install, publish and manage AI agent skills/rules",
5
5
  "type": "module",
6
6
  "bin": {