@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.cjs +62 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +62 -8
- package/dist/index.mjs.map +1 -1
- package/integrations/skills/cappa/SKILL.md +3 -4
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ let _cappa_client = require("@cappa/client");
|
|
|
38
38
|
let _cappa_server = require("@cappa/server");
|
|
39
39
|
let node_crypto = require("node:crypto");
|
|
40
40
|
//#region package.json
|
|
41
|
-
var version = "0.
|
|
41
|
+
var version = "0.16.0";
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/utils/agentSkills.ts
|
|
44
44
|
/**
|
|
@@ -358,6 +358,27 @@ const agentApprove = (names, options) => run$1(options, async () => {
|
|
|
358
358
|
else if (approved.length === 0) (0, _cappa_logger.getLogger)().warn("No screenshots matched");
|
|
359
359
|
else (0, _cappa_logger.getLogger)().success(`Approved ${approved.length} screenshot(s): ${approved.map((s) => s.name).join(", ")}`);
|
|
360
360
|
});
|
|
361
|
+
/**
|
|
362
|
+
* Advice about the config the skill will run against. Read-only: `agent init`
|
|
363
|
+
* installs skill files and never edits `cappa.config.ts`.
|
|
364
|
+
*
|
|
365
|
+
* Without a `webServer` the skill still works, but the agent has to get the
|
|
366
|
+
* app under test running by itself — which is exactly the project-specific
|
|
367
|
+
* guesswork `webServer` exists to remove.
|
|
368
|
+
*/
|
|
369
|
+
const webServerHints = async (cwd) => {
|
|
370
|
+
let config;
|
|
371
|
+
try {
|
|
372
|
+
config = await (0, _cappa_config.getConfig)(void 0, {
|
|
373
|
+
cwd,
|
|
374
|
+
command: "agent"
|
|
375
|
+
});
|
|
376
|
+
} catch {
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
if (config.webServer.length > 0) return [];
|
|
380
|
+
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\" }"];
|
|
381
|
+
};
|
|
361
382
|
const agentInit = (options) => run$1(options, async () => {
|
|
362
383
|
const cwd = process.cwd();
|
|
363
384
|
const root = findProjectRoot(cwd);
|
|
@@ -369,13 +390,15 @@ const agentInit = (options) => run$1(options, async () => {
|
|
|
369
390
|
force: options.force,
|
|
370
391
|
runner: options.runner
|
|
371
392
|
});
|
|
393
|
+
const hints = await webServerHints(cwd);
|
|
372
394
|
if (options.json) {
|
|
373
395
|
printJson({
|
|
374
396
|
root,
|
|
375
397
|
stacks,
|
|
376
398
|
runner,
|
|
377
399
|
files,
|
|
378
|
-
warnings
|
|
400
|
+
warnings,
|
|
401
|
+
hints
|
|
379
402
|
});
|
|
380
403
|
return;
|
|
381
404
|
}
|
|
@@ -390,6 +413,7 @@ const agentInit = (options) => run$1(options, async () => {
|
|
|
390
413
|
}
|
|
391
414
|
logger.log(chalk.default.dim(`commands run as \`${runner}\` (--runner to change)`));
|
|
392
415
|
for (const warning of warnings) logger.warn(warning);
|
|
416
|
+
for (const hint of hints) logger.info(hint);
|
|
393
417
|
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");
|
|
394
418
|
});
|
|
395
419
|
const parseChoice = (choices, what) => (value) => {
|
|
@@ -481,6 +505,20 @@ const toCaptureError = (failure) => {
|
|
|
481
505
|
error: "no screenshot was produced"
|
|
482
506
|
};
|
|
483
507
|
};
|
|
508
|
+
/**
|
|
509
|
+
* Fold errors with the same plugin and message into one, keeping the first
|
|
510
|
+
* task and counting the rest. Order follows each message's first occurrence.
|
|
511
|
+
*/
|
|
512
|
+
const collapseIdenticalErrors = (errors) => {
|
|
513
|
+
const collapsed = /* @__PURE__ */ new Map();
|
|
514
|
+
for (const error of errors) {
|
|
515
|
+
const key = `${error.plugin}\u0000${error.error}`;
|
|
516
|
+
const existing = collapsed.get(key);
|
|
517
|
+
if (existing) existing.count = (existing.count ?? 1) + 1;
|
|
518
|
+
else collapsed.set(key, { ...error });
|
|
519
|
+
}
|
|
520
|
+
return [...collapsed.values()];
|
|
521
|
+
};
|
|
484
522
|
const buildCaptureJsonReport = ({ detail, screenshots, durationMs }) => {
|
|
485
523
|
const failures = detail?.failures ?? [];
|
|
486
524
|
const deleted = detail?.deletedScreenshots ?? [];
|
|
@@ -497,10 +535,10 @@ const buildCaptureJsonReport = ({ detail, screenshots, durationMs }) => {
|
|
|
497
535
|
...s.diffMeta?.percentDifference !== void 0 ? { percentDifference: s.diffMeta.percentDifference } : {}
|
|
498
536
|
};
|
|
499
537
|
});
|
|
500
|
-
const errors = failures.flatMap((failure) => {
|
|
538
|
+
const errors = collapseIdenticalErrors(failures.flatMap((failure) => {
|
|
501
539
|
const error = toCaptureError(failure);
|
|
502
540
|
return error ? [error] : [];
|
|
503
|
-
});
|
|
541
|
+
}));
|
|
504
542
|
return {
|
|
505
543
|
ok: failures.length === 0 && deleted.length === 0,
|
|
506
544
|
...detail ? { runId: detail.id } : {},
|
|
@@ -819,6 +857,11 @@ function formatDuration(ms) {
|
|
|
819
857
|
if (minutes > 0) return `${minutes}m ${remainingSeconds}s`;
|
|
820
858
|
return `${(ms / 1e3).toFixed(2)}s`;
|
|
821
859
|
}
|
|
860
|
+
const errorMessageOf = (error) => {
|
|
861
|
+
if (!error) return;
|
|
862
|
+
if (typeof error === "string") return error;
|
|
863
|
+
return error instanceof Error ? error.message : String(error);
|
|
864
|
+
};
|
|
822
865
|
function generateFailureReportMessage(failedScreenshots, deletedScreenshots) {
|
|
823
866
|
const total = failedScreenshots.length + deletedScreenshots.length;
|
|
824
867
|
if (total === 0) return "";
|
|
@@ -832,14 +875,25 @@ function generateFailureReportMessage(failedScreenshots, deletedScreenshots) {
|
|
|
832
875
|
}
|
|
833
876
|
for (const [pluginName, failures] of byPlugin.entries()) {
|
|
834
877
|
lines.push(`\n${chalk.default.bold(`Plugin: ${pluginName}`)}`);
|
|
878
|
+
const byError = /* @__PURE__ */ new Map();
|
|
835
879
|
for (const failed of failures) {
|
|
880
|
+
const message = errorMessageOf(failed.result.error);
|
|
881
|
+
if (message !== void 0) byError.set(message, [...byError.get(message) ?? [], failed]);
|
|
882
|
+
}
|
|
883
|
+
for (const [message, shared] of byError) {
|
|
884
|
+
if (shared.length < 2) continue;
|
|
885
|
+
const shown = shared.slice(0, 3).map((failed) => failed.taskId);
|
|
886
|
+
const more = shared.length - shown.length;
|
|
887
|
+
lines.push(`\n ${chalk.default.dim("Tasks:")} ${shown.join(", ")}${more > 0 ? ` and ${more} more` : ""}`);
|
|
888
|
+
lines.push(` ${chalk.default.red("Error:")} ${message}`);
|
|
889
|
+
}
|
|
890
|
+
for (const failed of failures) {
|
|
891
|
+
const errorMsg = errorMessageOf(failed.result.error);
|
|
892
|
+
if (errorMsg !== void 0 && (byError.get(errorMsg)?.length ?? 0) > 1) continue;
|
|
836
893
|
lines.push(`\n ${chalk.default.dim("Task ID:")} ${failed.taskId}`);
|
|
837
894
|
const result = failed.result;
|
|
838
895
|
if (result.storyName) lines.push(` ${chalk.default.dim("Story:")} ${result.storyName}`);
|
|
839
|
-
if (
|
|
840
|
-
const errorMsg = typeof result.error === "string" ? result.error : result.error instanceof Error ? result.error.message : String(result.error);
|
|
841
|
-
lines.push(` ${chalk.default.red("Error:")} ${errorMsg}`);
|
|
842
|
-
}
|
|
896
|
+
if (errorMsg !== void 0) lines.push(` ${chalk.default.red("Error:")} ${errorMsg}`);
|
|
843
897
|
if (result.success === false) {
|
|
844
898
|
if (result.isNew) lines.push(` ${chalk.default.yellow("Status:")} New screenshot (no baseline — run 'cappa approve' to accept)`);
|
|
845
899
|
else lines.push(` ${chalk.default.red("Status:")} Failed (comparison failed)`);
|