@cappa/cli 0.15.1 → 0.16.0

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/index.mjs CHANGED
@@ -12,7 +12,7 @@ import { ProtocolMismatchError, createClient } from "@cappa/client";
12
12
  import { createServer, isLoopbackHost } from "@cappa/server";
13
13
  import { randomBytes } from "node:crypto";
14
14
  //#region package.json
15
- var version = "0.15.1";
15
+ var version = "0.16.0";
16
16
  //#endregion
17
17
  //#region ../../node_modules/.pnpm/tsdown@0.23.0_@arethetypeswrong+core@0.18.5_oxc-resolver@11.24.2_tsx@4.23.1_typescript@7.0.2/node_modules/tsdown/esm-shims.js
18
18
  const getFilename = () => fileURLToPath(import.meta.url);
@@ -337,6 +337,27 @@ const agentApprove = (names, options) => run$1(options, async () => {
337
337
  else if (approved.length === 0) getLogger().warn("No screenshots matched");
338
338
  else getLogger().success(`Approved ${approved.length} screenshot(s): ${approved.map((s) => s.name).join(", ")}`);
339
339
  });
340
+ /**
341
+ * Advice about the config the skill will run against. Read-only: `agent init`
342
+ * installs skill files and never edits `cappa.config.ts`.
343
+ *
344
+ * Without a `webServer` the skill still works, but the agent has to get the
345
+ * app under test running by itself — which is exactly the project-specific
346
+ * guesswork `webServer` exists to remove.
347
+ */
348
+ const webServerHints = async (cwd) => {
349
+ let config;
350
+ try {
351
+ config = await getConfig(void 0, {
352
+ cwd,
353
+ command: "agent"
354
+ });
355
+ } catch {
356
+ return [];
357
+ }
358
+ if (config.webServer.length > 0) return [];
359
+ return ["cappa.config.ts has no `webServer`, so the agent has to start whatever the plugins point at itself. Add one and `cappa capture` starts and stops it: webServer: { command: \"pnpm storybook --ci\", url: \"http://localhost:6006\" }"];
360
+ };
340
361
  const agentInit = (options) => run$1(options, async () => {
341
362
  const cwd = process.cwd();
342
363
  const root = findProjectRoot(cwd);
@@ -348,13 +369,15 @@ const agentInit = (options) => run$1(options, async () => {
348
369
  force: options.force,
349
370
  runner: options.runner
350
371
  });
372
+ const hints = await webServerHints(cwd);
351
373
  if (options.json) {
352
374
  printJson({
353
375
  root,
354
376
  stacks,
355
377
  runner,
356
378
  files,
357
- warnings
379
+ warnings,
380
+ hints
358
381
  });
359
382
  return;
360
383
  }
@@ -369,6 +392,7 @@ const agentInit = (options) => run$1(options, async () => {
369
392
  }
370
393
  logger.log(chalk.dim(`commands run as \`${runner}\` (--runner to change)`));
371
394
  for (const warning of warnings) logger.warn(warning);
395
+ for (const hint of hints) logger.info(hint);
372
396
  logger.success(stacks.includes("opencode") ? "Agent integration installed — run /cappa-review in OpenCode, or /cappa in Claude Code" : "Agent skill installed — ask your agent to run a visual review, or use /cappa in Claude Code");
373
397
  });
374
398
  const parseChoice = (choices, what) => (value) => {
@@ -460,6 +484,20 @@ const toCaptureError = (failure) => {
460
484
  error: "no screenshot was produced"
461
485
  };
462
486
  };
487
+ /**
488
+ * Fold errors with the same plugin and message into one, keeping the first
489
+ * task and counting the rest. Order follows each message's first occurrence.
490
+ */
491
+ const collapseIdenticalErrors = (errors) => {
492
+ const collapsed = /* @__PURE__ */ new Map();
493
+ for (const error of errors) {
494
+ const key = `${error.plugin}\u0000${error.error}`;
495
+ const existing = collapsed.get(key);
496
+ if (existing) existing.count = (existing.count ?? 1) + 1;
497
+ else collapsed.set(key, { ...error });
498
+ }
499
+ return [...collapsed.values()];
500
+ };
463
501
  const buildCaptureJsonReport = ({ detail, screenshots, durationMs }) => {
464
502
  const failures = detail?.failures ?? [];
465
503
  const deleted = detail?.deletedScreenshots ?? [];
@@ -476,10 +514,10 @@ const buildCaptureJsonReport = ({ detail, screenshots, durationMs }) => {
476
514
  ...s.diffMeta?.percentDifference !== void 0 ? { percentDifference: s.diffMeta.percentDifference } : {}
477
515
  };
478
516
  });
479
- const errors = failures.flatMap((failure) => {
517
+ const errors = collapseIdenticalErrors(failures.flatMap((failure) => {
480
518
  const error = toCaptureError(failure);
481
519
  return error ? [error] : [];
482
- });
520
+ }));
483
521
  return {
484
522
  ok: failures.length === 0 && deleted.length === 0,
485
523
  ...detail ? { runId: detail.id } : {},
@@ -798,6 +836,11 @@ function formatDuration(ms) {
798
836
  if (minutes > 0) return `${minutes}m ${remainingSeconds}s`;
799
837
  return `${(ms / 1e3).toFixed(2)}s`;
800
838
  }
839
+ const errorMessageOf = (error) => {
840
+ if (!error) return;
841
+ if (typeof error === "string") return error;
842
+ return error instanceof Error ? error.message : String(error);
843
+ };
801
844
  function generateFailureReportMessage(failedScreenshots, deletedScreenshots) {
802
845
  const total = failedScreenshots.length + deletedScreenshots.length;
803
846
  if (total === 0) return "";
@@ -811,14 +854,25 @@ function generateFailureReportMessage(failedScreenshots, deletedScreenshots) {
811
854
  }
812
855
  for (const [pluginName, failures] of byPlugin.entries()) {
813
856
  lines.push(`\n${chalk.bold(`Plugin: ${pluginName}`)}`);
857
+ const byError = /* @__PURE__ */ new Map();
814
858
  for (const failed of failures) {
859
+ const message = errorMessageOf(failed.result.error);
860
+ if (message !== void 0) byError.set(message, [...byError.get(message) ?? [], failed]);
861
+ }
862
+ for (const [message, shared] of byError) {
863
+ if (shared.length < 2) continue;
864
+ const shown = shared.slice(0, 3).map((failed) => failed.taskId);
865
+ const more = shared.length - shown.length;
866
+ lines.push(`\n ${chalk.dim("Tasks:")} ${shown.join(", ")}${more > 0 ? ` and ${more} more` : ""}`);
867
+ lines.push(` ${chalk.red("Error:")} ${message}`);
868
+ }
869
+ for (const failed of failures) {
870
+ const errorMsg = errorMessageOf(failed.result.error);
871
+ if (errorMsg !== void 0 && (byError.get(errorMsg)?.length ?? 0) > 1) continue;
815
872
  lines.push(`\n ${chalk.dim("Task ID:")} ${failed.taskId}`);
816
873
  const result = failed.result;
817
874
  if (result.storyName) lines.push(` ${chalk.dim("Story:")} ${result.storyName}`);
818
- if (result.error) {
819
- const errorMsg = typeof result.error === "string" ? result.error : result.error instanceof Error ? result.error.message : String(result.error);
820
- lines.push(` ${chalk.red("Error:")} ${errorMsg}`);
821
- }
875
+ if (errorMsg !== void 0) lines.push(` ${chalk.red("Error:")} ${errorMsg}`);
822
876
  if (result.success === false) {
823
877
  if (result.isNew) lines.push(` ${chalk.yellow("Status:")} New screenshot (no baseline — run 'cappa approve' to accept)`);
824
878
  else lines.push(` ${chalk.red("Status:")} Failed (comparison failed)`);