From f80845a64ed4173c15cab5015a90d79dd47ed693 Mon Sep 17 00:00:00 2001 From: William Weishuhn Date: Sun, 22 Mar 2026 10:27:19 -0700 Subject: [PATCH] fix: watch now correctly diffs against previous run and shows "no changes" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit findLatestArtifact accepts an excludePath param so watch can skip the artifact it just wrote. When runs are identical, shows "✓ No changes since last run" instead of silently falling through. Co-Authored-By: Claude Opus 4.6 --- src/commands/watch.ts | 16 ++++++++++------ src/storage.ts | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/commands/watch.ts b/src/commands/watch.ts index 43c14a8..0151dcf 100644 --- a/src/commands/watch.ts +++ b/src/commands/watch.ts @@ -23,14 +23,18 @@ async function runWatchOneShot( const outPath = await writeRunArtifact(artifact, outDir); // Find the PREVIOUS run for this target (excluding the one just written) - const latestPath = await findLatestArtifact(outDir, target.targetId); - if (latestPath && latestPath !== outPath) { - const previousRaw = await readArtifact(latestPath); + const previousPath = await findLatestArtifact(outDir, target.targetId, outPath); + if (previousPath) { + const previousRaw = await readArtifact(previousPath); if (previousRaw.artifactType === "run") { - const previous = previousRaw; - const diffResult = diff(previous, artifact); + const diffResult = diff(previousRaw, artifact); - process.stdout.write(formatOutput(diffResult, options.format as "terminal" | "json") + "\n"); + if (diffResult.summary.regressions === 0 && diffResult.summary.recoveries === 0 && diffResult.summary.added === 0 && diffResult.summary.removed === 0) { + process.stdout.write(formatOutput(artifact, options.format as "terminal" | "json") + "\n"); + process.stdout.write(`${c(ANSI.green, "✓ No changes")} since last run\n`); + } else { + process.stdout.write(formatOutput(diffResult, options.format as "terminal" | "json") + "\n"); + } process.stdout.write(`${c(ANSI.dim, `Artifact: ${outPath}`)}\n`); if (options.failOnRegression && diffResult.summary.regressions > 0) { diff --git a/src/storage.ts b/src/storage.ts index 9211cb4..f75d99b 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -28,7 +28,7 @@ export async function writeRunArtifact( return filePath; } -export async function findLatestArtifact(outDir: string, targetId: string): Promise { +export async function findLatestArtifact(outDir: string, targetId: string, excludePath?: string): Promise { const slug = slugify(targetId); const suffix = `--${slug}.json`; try { @@ -36,9 +36,11 @@ export async function findLatestArtifact(outDir: string, targetId: string): Prom const matching = entries .filter(f => f.endsWith(suffix)) .sort() - .reverse(); + .reverse() + .map(f => path.join(outDir, f)) + .filter(f => f !== excludePath); if (matching.length === 0) return null; - return path.join(outDir, matching[0]!); + return matching[0]!; } catch { return null; }