Agent skills that give coding agents taste: art direction, reference images and a browser check instead of generic AI pages
JavaScript agent-skillsai-agentsanti-slopclaude-codecodexcursordesign-systemfrontendlanding-pageui-designweb-design
fix(browser): 🐞 preserve profiles owned by other runs
tAshb39320c06f5e
diff --git a/.github/workflows/check-skills.yml b/.github/workflows/check-skills.ymlindex a3ccc92..1f18855 100644--- a/.github/workflows/check-skills.yml+++ b/.github/workflows/check-skills.yml@@ -19,3 +19,5 @@ jobs:node tests/frontmatter.mjs- name: Scripts parserun: for f in skills/taste-skill/scripts/*.mjs skills/taste-skill/scripts/lib/*.mjs skills/taste-skill/assets/*.js; do node --check "$f" || exit 1; done+ - name: Browser profile cleanup regression+ run: node --test tests/profile-cleanup.mjsdiff --git a/skills/taste-skill/scripts/lib/cdp.mjs b/skills/taste-skill/scripts/lib/cdp.mjsindex b3b8e01..5ab666c 100644--- a/skills/taste-skill/scripts/lib/cdp.mjs+++ b/skills/taste-skill/scripts/lib/cdp.mjs@@ -2,7 +2,7 @@// Drives an installed Chrome / Edge / Chromium in headless mode over Node's built-in WebSocket.// Requires Node 22+. No npm install.import { spawn, spawnSync } from 'node:child_process';-import { existsSync, mkdtempSync, rmSync, writeFileSync, readdirSync, statSync, openSync, closeSync } from 'node:fs';+import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';@@ -37,24 +37,6 @@ export function findChrome() {return null;}-// Profiles from runs that were killed before close(): removed once no Chrome holds them (a running-// Chrome keeps the profile's lockfile open) and they are a few minutes old.-function sweepProfiles(base) {- try {- const cutoff = Date.now() - 3 * 60 * 1000;- for (const name of readdirSync(base)) {- if (!name.startsWith('ad-chrome-')) continue;- const p = join(base, name);- try {- if (statSync(p).mtimeMs > cutoff) continue;- const lock = join(p, 'lockfile');- if (existsSync(lock)) closeSync(openSync(lock, 'r+')); // throws while a Chrome holds it- rmSync(p, { recursive: true, force: true });- } catch {}- }- } catch {}-}-export class Browser {static async launch({ width = 1440, height = 900, extraArgs = [] } = {}) {if (typeof WebSocket === 'undefined') {@@ -64,10 +46,8 @@ export class Browser {if (!exe) {throw new Error('No Chrome/Edge/Chromium found. Install one or set CHROME_PATH to its executable.');}- // A throwaway profile per run. Its cache is capped (each run starts cold anyway), profiles left by- // runs that were killed are swept once they are a few hours old, and the profile goes on exit.+ // Own only this run's profile: age and opening a lockfile do not prove another profile is unused.const base = process.env.TASTE_SKILL_TMP || tmpdir();- sweepProfiles(base);const dir = mkdtempSync(join(base, 'ad-chrome-'));// On exit Chrome still holds the profile's files: stop it first, then remove the folder.let pid = 0;diff --git a/tests/profile-cleanup.mjs b/tests/profile-cleanup.mjsnew file mode 100644index 0000000..66e89b9--- /dev/null+++ b/tests/profile-cleanup.mjs@@ -0,0 +1,63 @@+import assert from 'node:assert/strict';+import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, rmSync, utimesSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { spawnSync } from 'node:child_process';+import { fileURLToPath } from 'node:url';+import { test } from 'node:test';++// Run in a child so Browser.launch()'s exit/signal handlers cannot leak into the test runner.+if (process.argv[2] === '--fixture') {+ const { Browser } = await import('../skills/taste-skill/scripts/lib/cdp.mjs');+ globalThis.WebSocket = class {+ constructor() { queueMicrotask(() => this.onopen?.()); }+ send(raw) {+ const { id } = JSON.parse(raw);+ queueMicrotask(() => this.onmessage?.({ data: JSON.stringify({ id, result: {} }) }));+ }+ close() {}+ };+ const base = process.env.TASTE_SKILL_TMP;+ const profiles = ['ad-chrome-open-lock', 'ad-chrome-no-lock'].map(name => join(base, name));+ let lock;+ let browser;+ try {+ for (const profile of profiles) {+ mkdirSync(profile);+ writeFileSync(join(profile, 'sentinel'), 'preserve');+ }+ lock = openSync(join(profiles[0], 'lockfile'), 'w+');+ for (const profile of profiles) {+ const old = new Date(Date.now() - 10 * 60 * 1000);+ utimesSync(profile, old, old);+ }+ browser = await Browser.launch();+ for (const profile of profiles) {+ assert.ok(existsSync(join(profile, 'sentinel')), 'launch deleted another profile');+ }+ } finally {+ if (browser) await browser.close();+ if (lock !== undefined) closeSync(lock);+ }+ assert.equal(existsSync(browser.dir), false, 'close left the owned profile behind');+} else {+ test('launch preserves older foreign profiles and close removes its own', {+ skip: process.platform === 'win32' && 'POSIX fake browser fixture',+ }, () => {+ const base = mkdtempSync(join(tmpdir(), 'taste-profile-test-'));+ try {+ const fakeChrome = join(base, 'fake-chrome');+ // No real browser, network, or existing user profile is accessed.+ writeFileSync(fakeChrome, '#!/bin/sh\nprintf "DevTools listening on ws://fixture\\n" >&2\nexec tail -f /dev/null\n', { mode: 0o755 });+ const result = spawnSync(process.execPath, [fileURLToPath(import.meta.url), '--fixture'], {+ env: { ...process.env, CHROME_PATH: fakeChrome, TASTE_SKILL_TMP: base },+ encoding: 'utf8',+ timeout: 15000,+ });+ assert.equal(result.error, undefined, result.error?.message);+ assert.equal(result.status, 0, result.stdout + result.stderr);+ } finally {+ rmSync(base, { recursive: true, force: true });+ }+ });+}