Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/upstream-state/hallmark/hallmark
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52328cb3129135499e4e178d4864ee90029dea2b
407fa689f4a276f2fd389208d271d0fef08f5058
4 changes: 2 additions & 2 deletions skills/hallmark/references/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Stamp: `/* Hallmark · component: <type> · genre: <genre> · theme: <theme> ·

## App screens

A dashboard, an admin, a settings page, a tool: a screen someone works in rather than reads. Signals: the prompt says app, dashboard, admin, console, settings or tool; the target sits behind a sign-in; the screen is tables, forms and controls. The bar is earned familiarity: the tool disappears into the task, and someone fluent in the category trusts it at once. The marketing rules step aside: no shape from `macrostructures.md`, no hero or fold, no screen word budget, no section rhythm, no stand-in photographs, no reveal on load. `sloplint --scope app` skips their gates (1, 6, 8, 9, 32, 42, 44, 46b, 58, 59, 66, 68, 77 to 79 and 81 to 83, and F8, F15 and F20) and reads control heights on the app range. Everything else binds, the Floor first: tokens, contrast, focus, states, no eyebrow, no tracked-caps label on a table head, no invented figure.
A dashboard, an admin, a settings page, a tool: a screen someone works in rather than reads. Signals: the prompt says app, dashboard, admin, console, settings or tool; the target sits behind a sign-in; the screen is tables, forms and controls. The bar is earned familiarity: the tool disappears into the task, and someone fluent in the category trusts it at once. The marketing rules step aside: no shape from `macrostructures.md`, no hero or fold, no screen word budget, no section rhythm, no stand-in photographs, no reveal on load. `sloplint --scope app` skips their gates (1, 6, 8, 9, 32, 42, 44, 46b, 58, 59, 66, 68, 77 to 79, 81 to 83 and 85, and F8, F15 and F20) and reads control heights on the app range. Everything else binds, the Floor first: tokens, contrast, focus, states, no eyebrow, no tracked-caps label on a table head, no invented figure.

What takes their place:

- **The theme lends its palette, its faces, its radius and its surfaces,** never its layout, navigation or ornament. One family is often right, and a familiar sans or a system face is allowed here; the type scale is fixed, at a ratio of 1.125 to 1.2, with no fluid heads and no display face on labels, buttons or data (`theme.mjs scaffold --scope app` writes that scale and a stamp without the page's fields).
- **The theme lends its palette, its faces, its radius and its surfaces,** never its layout, navigation or ornament. One family is often right, and a familiar sans or a system face is allowed here; the type scale is fixed, at a ratio of 1.125 to 1.2, with no fluid heads and no display face on labels, buttons or data (`theme.mjs scaffold <slug> --scope app` writes that scale and a stamp without the page's fields).
- **Colour is restrained.** The accent marks the primary action, the current selection and state, nothing else; a second neutral carries sidebars, toolbars and panels.
- **The shell is the project's own.** A new one is a top bar; a sidebar is earned by more than about seven destinations, never reached for by reflex, and it collapses to a menu under 60rem. Standard patterns (tabs, breadcrumbs, a command palette) beat invented ones, and a modal is the last answer, after inline editing and disclosure.
- **Density is the design.** Controls 32 to 40px with a 44px hit target, one container recipe, tables before cards (a table may run wider than any prose measure), and `craft.md` § 9 for controls, inputs, tables and stat rows.
Expand Down
41 changes: 40 additions & 1 deletion skills/hallmark/scripts/fixtures/imagegen/imagegen.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createHash } from 'node:crypto';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync, realpathSync, readFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { spawnSync } from 'node:child_process';

const script = fileURLToPath(new URL('../../imagegen.mjs', import.meta.url));
Expand Down Expand Up @@ -48,6 +48,45 @@ for (const explicit of [false, true]) {
}
const resolvePath = (path) => realpathSync(path);

for (const [label, response] of [
['partial batch', [{ b64_json: png.toString('base64') }]],
['missing payload', [{ b64_json: png.toString('base64') }, {}]],
['excess batch', Array.from({ length: 3 }, () => ({ b64_json: png.toString('base64') }))],
]) {
test('reject ' + label + ' before overwriting output', () => {
withCache(2, true, ({ paths, metadata }) => {
const before = [metadata, ...paths].map((file) => readFileSync(file));
const preload = join(dirname(metadata), 'response.mjs');
writeFileSync(preload, `globalThis.fetch = async () => ({ ok: true, json: async () => (${JSON.stringify({ data: response })}) });`);
const result = spawnSync(process.execPath, ['--import', pathToFileURL(preload).href, script, prompt, '--n', '2', '--force', '--out', join(dirname(metadata), 'chosen.png'), '--json'], {
cwd: dirname(metadata), env: { ...process.env, TOGETHER_API_KEY: 'offline-test-key' }, encoding: 'utf8', timeout: 5000,
});
assert.equal(result.error, undefined);
assert.equal(result.status, 1, result.stdout);
assert.equal(JSON.parse(result.stdout).error, 'image-count');
assert.deepEqual([metadata, ...paths].map((file) => readFileSync(file)), before);
});
});
}

test('complete generated batch writes every requested image', () => {
withCache(2, true, ({ paths, metadata }) => {
const preload = join(dirname(metadata), 'response.mjs');
const generated = Buffer.from('offline image bytes');
writeFileSync(preload, `globalThis.fetch = async () => ({ ok: true, json: async () => ({ data: Array.from({ length: 2 }, () => ({ b64_json: '${generated.toString('base64')}' })) }) });`);
const result = spawnSync(process.execPath, ['--import', pathToFileURL(preload).href, script, prompt, '--n', '2', '--force', '--out', join(dirname(metadata), 'chosen.png'), '--json'], {
cwd: dirname(metadata), env: { ...process.env, TOGETHER_API_KEY: 'offline-test-key' }, encoding: 'utf8', timeout: 5000,
});
assert.equal(result.error, undefined);
assert.equal(result.status, 0, result.stderr);
const report = JSON.parse(result.stdout);
assert.equal(report.cached, false);
assert.equal(report.paths.length, 2);
for (const file of paths) assert.deepEqual(readFileSync(file), generated);
assert.equal(JSON.parse(readFileSync(metadata, 'utf8')).files.length, 2);
});
});

test('single-image cache continues to use unnumbered output', () => {
withCache(1, true, ({ run, paths }) => {
const { code, report } = run();
Expand Down
1 change: 1 addition & 0 deletions skills/hallmark/scripts/imagegen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ try {
const data = await res.json();
const images = (data?.data ?? []).map((d) => d?.b64_json).filter(Boolean);
if (!images.length) out({ error: "no-image", message: "image API returned no b64_json payload" }, 1);
if (images.length !== n) out({ error: "image-count", message: `image API returned ${images.length} images; requested ${n}. No files were written.` }, 1);

mkdirSync(cacheDir, { recursive: true });
const paths = [];
Expand Down
13 changes: 13 additions & 0 deletions skills/hallmark/scripts/refcheck.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,19 @@ const FIX = join(ROOT, 'scripts', 'fixtures');
}
} finally { rmSync(tmp, { recursive: true, force: true }); }
}
{
const tmp = mkdtempSync(join(tmpdir(), 'hallmark-dot-'));
try {
const theme = join(tmp, '.vitepress');
mkdirSync(join(theme, '.cache'), { recursive: true });
writeFileSync(join(theme, 'style.css'), 'p { color: var(--color-text); }');
writeFileSync(join(theme, '.cache', 'style.css'), 'p { color: var(--color-text); }');
const run = spawnSync(process.execPath, [join(ROOT, 'scripts', 'sloplint.mjs'), theme, '--scope', 'component', '--json'], { encoding: 'utf8', timeout: 5000 });
let report = null;
try { report = JSON.parse(run.stdout); } catch {}
if (!report || report.summary.files !== 1) add('error', SKILL, 1, 'fixture', 'a dot folder named on the command line must be linted, while dot folders inside it stay skipped');
} finally { rmSync(tmp, { recursive: true, force: true }); }
}
const lintJson = (t) => { const r = spawnSync(process.execPath, [join(ROOT, 'scripts', 'sloplint.mjs'), t, '--json'], { encoding: 'utf8' }); try { return JSON.parse(r.stdout); } catch { return null; } };
const gatesOf = (j) => new Set(j.findings.map((x) => String(x.gate)));
const expectations = [
Expand Down
2 changes: 1 addition & 1 deletion skills/hallmark/scripts/sloplint-render.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { join, dirname, basename, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

const WIDTHS = [320, 375, 414, 768, 1024, 1280, 1920];
const WIDTHS = [320, 375, 414, 768, 1024, 1280, 1440, 1920];
const CHROMES = ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium', '/usr/bin/google-chrome', '/usr/bin/google-chrome-stable', '/usr/bin/chromium', '/usr/bin/chromium-browser', '/snap/bin/chromium', 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'];
const isUrl = (t) => /^https?:\/\//.test(t);
const slugOf = (t) => isUrl(t) ? t.replace(/^https?:\/\//, '').replace(/[^\w.-]+/g, '-').replace(/-+$/, '') : basename(t, '.html');
Expand Down
2 changes: 1 addition & 1 deletion skills/hallmark/scripts/sloplint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function collectFiles(paths) {
try { st = statSync(abs); real = realpathSync(abs); } catch { console.error(`sloplint: cannot read ${p}`); if (top) process.exit(2); return; }
if (st.isDirectory()) {
const base = basename(abs);
if (base === 'node_modules' || base.startsWith('.') || (!top && BUILD_DIRS.has(base))) return;
if (base === 'node_modules' || (!top && (base.startsWith('.') || BUILD_DIRS.has(base)))) return;
}
if (seen.has(real)) return;
seen.add(real);
Expand Down
14 changes: 10 additions & 4 deletions skills/hallmark/scripts/theme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const args = process.argv.slice(2);
const cmd = args[0];
const flag = (k, d = null) => { const i = args.indexOf('--' + k); const v = i >= 0 ? args[i + 1] : undefined; return v !== undefined && !String(v).startsWith('--') ? v : d; };
const has = (k) => args.includes('--' + k);
const VALUED = new Set(['genre', 'prompt', 'brief', 'log', 'n', 'reroll', 'dealt', 'dir', 'axes', 'face', 'hue', 'entry', 'redesign', 'theme', 'orient', 'save', 'avoid', 'material', 'seed', 'job']);
const VALUED = new Set(['genre', 'prompt', 'brief', 'log', 'n', 'reroll', 'dealt', 'dir', 'axes', 'face', 'hue', 'entry', 'redesign', 'scope', 'theme', 'orient', 'save', 'avoid', 'material', 'seed', 'job']);
const positional = () => { const out = []; for (let i = 1; i < args.length; i++) { const a = args[i]; if (a.startsWith('--')) { if (VALUED.has(a.slice(2))) i++; continue; } out.push(a); } return out; };
const GENRES = ['editorial', 'modern-minimal', 'atmospheric', 'playful'];
// A theme slug names a file in references/themes, so it is a plain name, never a path.
Expand Down Expand Up @@ -193,7 +193,10 @@ function draw() {
const near = (opts, n, k, extra = []) => { const bad = new Set([...recent(k, n), ...extra]); const ok = opts.filter((o) => ![...bad].some((b) => b && b.includes(low(o)))); return ok.length ? ok : opts; };
const take = (opts, m = 1) => { const pool = [...new Set(opts)]; const out = []; while (out.length < m && pool.length) out.push(pool.splice(Math.floor(rand() * pool.length), 1)[0]); return out; };
const shapes = take(near(DRAW.shapes[material], 3, 'shape', pictured), 1);
const jobName = low(flag('job', '')).replace(/download|app/, 'try').replace(/software|saas/, 'sign up').replace(/newsletter|waitlist/, 'subscribe').replace(/watch|read/, 'listen');
// Synonyms match the whole job: "app" is try, "application" is not.
const JOB_SYNONYMS = { download: 'try', app: 'try', software: 'sign up', saas: 'sign up', newsletter: 'subscribe', waitlist: 'subscribe', watch: 'listen', read: 'listen' };
const rawJob = low(flag('job', '')).trim();
const jobName = JOB_SYNONYMS[rawJob] || rawJob;
const job = DRAW.jobs[jobName] || null;
const [hero] = take(near(job ? [...job.heroes, ...job.heroes, ...DRAW.heroes[material].filter((h) => !/settled|stage/i.test(h) || job.heroes.includes(h))] : DRAW.heroes[material], 1, 'hero', pictured));
const [nav] = take(near(DRAW.navs, 3, 'nav'));
Expand All @@ -209,7 +212,8 @@ function draw() {
console.log(`draw ${seed} (fresh each build; --seed ${seed} repeats it)${pictured.length ? ` · clear of the theme picture's ${pictured.join(' and ')}` : ''}`);
console.log(`shape: ${shapes[0]} · hero: ${hero} · nav: ${nav} · footer: ${footer}`);
console.log(`${job ? '' : `first section after the hero: ${opener} · `}leave out this time: ${skip.join(' and ')} · the hero leads with ${lead}, if the prompt has it`);
console.log(job ? `job: ${jobName} · the action: ${action}\nbuild these, in the order the shape suits (the first right after the hero): ${native.join('; ')} · close on: ${close} (anatomy.md § ${jobName})` : 'no --job given: name the page\'s job (subscribe, book, visit, attend, buy, try, sign up, hire, join, listen) and draw again with --job');
const jobs = 'subscribe, book, visit, attend, buy, try, sign up, hire, join, listen';
console.log(job ? `job: ${jobName} · the action: ${action}\nbuild these, in the order the shape suits (the first right after the hero): ${native.join('; ')} · close on: ${close} (anatomy.md § ${jobName})` : rawJob ? `unknown --job "${rawJob}": name the page's job (${jobs}) and draw again with --job` : `no --job given: name the page's job (${jobs}) and draw again with --job`);
console.log(`photos: pass --seed ${seed} to every theme.mjs photos call, so this build's picks are its own, and take its first fitting pick for the hero rather than hunting for the library's single best frame`);
console.log('take the draw unless the prompt\'s material refuses a pick; name any swap in the Picks block, and stamp draw: ' + seed);
}
Expand Down Expand Up @@ -581,7 +585,9 @@ function validate(files) {
let bad = 0;
for (const f of files) {
try {
const src = readFileSync(f, 'utf8');
// Frontmatter accepts CRLF, so the CSS Build hint matchers must see the same
// normalised text; a raw CRLF file silently skipped every hint check.
const src = readFileSync(f, 'utf8').replace(/\r\n?/g, '\n');
const e = parseHeader(src, f);
const problems = [];
if (!PAPER_BANDS.has(e.paper.band)) problems.push(`paper band ${e.paper.band}`);
Expand Down
19 changes: 19 additions & 0 deletions skills/hallmark/scripts/theme.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ test('validate accepts a theme with either LF or CRLF line endings', () => {
rmSync(dir, { recursive: true, force: true });
}
});

test('validate rejects an invalid Build hint in a CRLF file, like it does in LF', () => {
const source = readFileSync(new URL('../references/themes/hum.md', import.meta.url), 'utf8').replace(/\r\n/g, '\n');
const at = source.indexOf('```css', source.indexOf('## Build hint')) + '```css\n'.length;
const bad = `${source.slice(0, at)} color: black;\n${source.slice(at)}`;
const cli = fileURLToPath(new URL('./theme.mjs', import.meta.url));
const dir = mkdtempSync(join(tmpdir(), 'hallmark-theme-crlf-'));
try {
for (const [name, text] of [['lf', bad], ['crlf', bad.replace(/\n/g, '\r\n')]]) {
const file = join(dir, `${name}.md`);
writeFileSync(file, text);
const result = spawnSync(process.execPath, [cli, 'validate', file], { encoding: 'utf8' });
assert.equal(result.status, 1, `${name}: ${result.stdout}${result.stderr}`);
assert.match(result.stdout, /named colour black in the build hint/, `${name}: ${result.stdout}`);
}
} finally {
rmSync(dir, { recursive: true, force: true });
}
});