shoplazza-ai-dev-cli 0.1.18 → 0.1.20

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);
@@ -519,22 +542,80 @@ const VALID_USER_KINDS = [
519
542
  "baseline",
520
543
  "custom"
521
544
  ];
522
- async function list$1(client, args, json) {
523
- const { named } = parseNamedArgs(args);
545
+ function buildListParams(named) {
524
546
  const params = {};
525
547
  for (const k of [
526
548
  "q",
527
549
  "module-id",
528
550
  "type",
529
551
  "priority",
552
+ "automation-status",
530
553
  "page",
531
554
  "size"
532
555
  ]) {
533
- 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;
534
557
  const v = named[k];
535
558
  const val = Array.isArray(v) ? v[v.length - 1] : v;
536
559
  if (typeof val === "string") params[apiKey] = val;
537
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
+ }
538
619
  const data = await client.get("/api/test/cases", params);
539
620
  if (json) {
540
621
  printJson(data);
@@ -761,7 +842,7 @@ async function runCases(client, args, json) {
761
842
  case "--help":
762
843
  case "-h":
763
844
  case void 0:
764
- 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)\n batch-status Batch read existence/deleted/status/version by case ids (--ids a,b,c [--include-content])`);
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])`);
765
846
  return;
766
847
  default:
767
848
  printError(`Unknown cases action: ${action}`);
@@ -975,7 +1056,7 @@ function validatePlanCreateMatrix(planType, src) {
975
1056
  if (!src.reqId || !src.caseIds || src.fromSet) return "type=smoke 必须同时提供 --req-id 与 --case-ids(测试员手选),不接受 --from-set";
976
1057
  return null;
977
1058
  case "regression":
978
- 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";
979
1060
  return null;
980
1061
  default: return `Invalid type "${planType}"`;
981
1062
  }
@@ -1028,6 +1109,7 @@ async function get(client, args, json) {
1028
1109
  console.log(`\n Cases (${cases.length}):`);
1029
1110
  for (const c of cases) {
1030
1111
  const marks = [];
1112
+ if (c["status"] === "deprecated") marks.push("已废弃 · 不计入进度");
1031
1113
  if (c["in_source_set"] === false) marks.push("已离开来源集");
1032
1114
  if (c["content_updated"] === true) marks.push(`正文已更新 v${c["case_version_at_add"]}→v${c["current_version"]}`);
1033
1115
  const suffix = marks.length ? ` [${marks.join(" · ")}]` : "";
package/dist/cli.mjs CHANGED
@@ -2521,6 +2521,28 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
2521
2521
  const pluginCanonical = join(storeRoot, "plugins", `${scopeNamespace}__${pluginName}`);
2522
2522
  const components = await classifyExtracted(extractedDir);
2523
2523
  const ignoredComponents = await collectIgnoredTopLevel(extractedDir);
2524
+ if (opts.agents.length > 0 && opts.agents.every((a) => a === "claude-code")) {
2525
+ const unchanged = await findUnchangedInstall({
2526
+ ref,
2527
+ pluginName,
2528
+ extractedDir,
2529
+ pluginCanonical,
2530
+ claudeHome: getAgentHome("claude-code"),
2531
+ commitSha,
2532
+ force: opts.force
2533
+ });
2534
+ if (unchanged) return {
2535
+ pluginRef: ref,
2536
+ pluginCanonical,
2537
+ installedComponents: unchanged.installedComponents,
2538
+ installedEntries: [],
2539
+ forgeOtherReplacements: [],
2540
+ ignoredComponents,
2541
+ warnings: [],
2542
+ registrationFailed: false,
2543
+ unchanged: true
2544
+ };
2545
+ }
2524
2546
  const preflight = buildPreflightList(pluginCanonical, components, opts);
2525
2547
  const foreignConflicts = [];
2526
2548
  const forgeOtherReplacements = [];
@@ -2727,6 +2749,53 @@ function componentSubRef$1(c) {
2727
2749
  case "plugin-rule-deps-dir": return `rules/${c.dirname}`;
2728
2750
  }
2729
2751
  }
2752
+ async function findUnchangedInstall(params) {
2753
+ if (params.force) return null;
2754
+ let version;
2755
+ try {
2756
+ version = await resolvePluginVersion(params.extractedDir, params.pluginName);
2757
+ } catch {
2758
+ return null;
2759
+ }
2760
+ const entry = (await readJsonOrNull(join(params.claudeHome, "plugins", "installed_plugins.json")))?.plugins?.[`${params.pluginName}@${MARKETPLACE}`]?.[0];
2761
+ if (!entry?.installPath || entry.version !== version) return null;
2762
+ if (params.commitSha && entry.gitCommitSha && params.commitSha !== entry.gitCommitSha) return null;
2763
+ const ledger = await readJsonOrNull(join(params.pluginCanonical, ".forge-plugin.json"));
2764
+ if (!ledger || ledger.ref !== params.ref) return null;
2765
+ if (!await cacheDirIntact(params.extractedDir, entry.installPath)) return null;
2766
+ return {
2767
+ version,
2768
+ installPath: entry.installPath,
2769
+ installedComponents: ledger.installed_components ?? []
2770
+ };
2771
+ }
2772
+ const CACHE_SKIPPED_TOP_LEVEL = new Set([
2773
+ ".cursor-plugin",
2774
+ ".codex-plugin",
2775
+ "hooks-cursor.json",
2776
+ "hooks-codex.json"
2777
+ ]);
2778
+ async function cacheDirIntact(extractedDir, installPath) {
2779
+ if (!existsSync(installPath)) return false;
2780
+ let entries;
2781
+ try {
2782
+ entries = await readdir(extractedDir);
2783
+ } catch {
2784
+ return false;
2785
+ }
2786
+ for (const name of entries) {
2787
+ if (CACHE_SKIPPED_TOP_LEVEL.has(name)) continue;
2788
+ if (!existsSync(join(installPath, name))) return false;
2789
+ }
2790
+ return true;
2791
+ }
2792
+ async function readJsonOrNull(path) {
2793
+ try {
2794
+ return JSON.parse(await readFile(path, "utf-8"));
2795
+ } catch {
2796
+ return null;
2797
+ }
2798
+ }
2730
2799
  async function resolvePluginVersion(pluginCanonical, pluginName) {
2731
2800
  for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
2732
2801
  const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
@@ -4459,7 +4528,7 @@ async function runAdd(args, options = {}) {
4459
4528
  spinner.stop(import_picocolors.default.red("Plugin installation failed"));
4460
4529
  throw err;
4461
4530
  }
4462
- spinner.stop(import_picocolors.default.green("Plugin installed"));
4531
+ spinner.stop(pluginResult.unchanged ? import_picocolors.default.green("Plugin already up to date (same version installed, nothing rewritten)") : import_picocolors.default.green("Plugin installed"));
4463
4532
  if (pluginResult.warnings.length > 0) for (const w of pluginResult.warnings) M.warn(w);
4464
4533
  if (pluginResult.registrationFailed) {
4465
4534
  M.error(import_picocolors.default.red("Claude native plugin registration failed"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoplazza-ai-dev-cli",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Shoplazza AI Dev CLI: install, publish and manage AI agent skills/rules",
5
5
  "type": "module",
6
6
  "bin": {