usepilot 0.21.0 → 0.23.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.
@@ -320,7 +320,7 @@ function lastLines(text) {
320
320
 
321
321
  // src/run.ts
322
322
  import { randomUUID as randomUUID2 } from "crypto";
323
- import { existsSync as existsSync7 } from "fs";
323
+ import { existsSync as existsSync8 } from "fs";
324
324
  import { basename as basename7 } from "path";
325
325
 
326
326
  // ../protocol/src/types.ts
@@ -571,7 +571,7 @@ function formatAccessible(changeSet, request) {
571
571
  if (request.references?.length) lines.push("", ...referenceLines(request.references));
572
572
  lines.push("", ...elementsSection(request), "", "## What Pilot's audit found", "");
573
573
  if (!request.found)
574
- lines.push("Pilot couldn't audit a copy of the page this time. Check contrast, names, focus, tap targets and motion from the code, then review it (step 2).");
574
+ lines.push("Pilot couldn't audit a copy of the page this time. Check contrast, names, images without `alt`, focus, tap targets and motion from the code, then review it (step 2).");
575
575
  else if (!request.found.length)
576
576
  lines.push(`Pilot audited a copy of the page${tested}: nothing it measures needs fixing. Review the code (step 2) and fix only what it finds.`);
577
577
  else lines.push(`Pilot audited a copy of the page${tested}. Fix each of these:`, "", ...request.found.map((f) => `- ${f}`));
@@ -581,13 +581,14 @@ function formatAccessible(changeSet, request) {
581
581
  "",
582
582
  "1. **Fix what Pilot found**, the way this project does it (its utilities, its components, its tokens):",
583
583
  " - **Contrast:** change the text color (or, when the text color is the brand's, the background) to the nearest shade that passes, in the project's palette or tokens, keeping the hue. Check it in both color schemes when the project has a dark mode. Say each color you changed, old \u2192 new, in your reply: the designer decides brand colors.",
584
- ' - **Names:** an `aria-label` for controls with only an icon (and `aria-hidden="true"` on the icon); `alt` text for meaningful images, saying what they show or do, and `alt=""` for decorative ones; a `<label>` for each field (visually hidden with the project\'s `sr-only` utility when there\'s no visible one; a placeholder isn\'t a label). Never add visible text without asking.',
584
+ " - **Names:** an `aria-label` for controls with only an icon (and `aria-hidden=\"true\"` on the icon); a `<label>` for each field (visually hidden with the project's `sr-only` utility when there's no visible one; a placeholder isn't a label). Never add visible text without asking.",
585
+ " - **Images without `alt`:** give every one an `alt`. A meaningful image gets a short phrase saying what it shows, from the image itself (open its file to look at it if you can), its file name and what's around it (a caption, a heading, the product or person it's for); an image in a link or a button says where it goes or what it does instead. A decorative one (an ornament, or one that repeats the text beside it) gets `alt=\"\"`. Where the images come from data (a list, a CMS, props), write the `alt` from the same data (the product's name), not one fixed text for all. List each `alt` you wrote in your reply, so the designer can check the wording.",
585
586
  " - **Focus:** a visible `:focus-visible` style (`focus-visible:` in Tailwind) for everything that can be tabbed to, in the project's style (its ring or outline utilities); don't remove the browser's outline without a replacement.",
586
587
  " - **Tap targets:** make the hit area at least 24\xD724px on phones **without changing how it looks or moving anything**: a transparent pseudo-element over it (`after:absolute after:-inset-2`, with `relative` on the control), never a bigger visible control or new spacing.",
587
588
  " - **Motion:** keep animations for people who haven't asked for reduced motion (`motion-safe:`, or a `prefers-reduced-motion` media query) and stop or shorten them for those who have.",
588
589
  '2. **Review the code for what Pilot can\'t measure**, in these elements only: clickable `div`s or `span`s that should be a `button` or a link (with the keyboard working); ARIA that\'s wrong or redundant (a `role` without its required states, `aria-hidden` on something focusable, ARIA where a native element would do); headings out of order; link text that says nothing out of context ("click here", "read more" without a visible or hidden label); state shown by color alone; form errors not tied to their field. Fix what\'s clearly wrong; ask about anything that would change how it looks.',
589
590
  "3. **Don't change the layout.** Every element must keep its size and position at every width: no new padding, margins, borders, font sizes or line heights, no wrapping or reordering, nothing added that takes space. Colors, focus styles, and attributes are fine. When you report it done, Pilot audits it again and compares every element's box at a phone width, each breakpoint and a wide desktop with before: anything moved or resized comes back to you, with what's left of the audit, once.",
590
- "4. **Your reply is the designer's comment**: tell them what you changed, a short line per fix, grouped (contrast, names, focus, tap targets, motion, code), with each color change old \u2192 new; then anything they should decide or check. No preamble.",
591
+ "4. **Your reply is the designer's comment**: tell them what you changed, a short line per fix, grouped (contrast, names, alt text, focus, tap targets, motion, code), with each color change old \u2192 new; then anything they should decide or check. No preamble.",
591
592
  "",
592
593
  several > 1 ? `Change only these elements and what they need. If they come from a shared component, fix it there, so every instance gets the fix, as long as its look doesn't change; ask before anything that would. ${firstChecked()}` : "Change only this element and what it needs. If it's a shared component, fix it there, so every instance gets the fix, as long as its look doesn't change; ask before anything that would.",
593
594
  "",
@@ -715,6 +716,7 @@ function formatComment(changeSet, request) {
715
716
  several > 1 ? "- Change only what the comment is about, on each of these elements." : "- Change only what the comment is about.",
716
717
  `- ${sharedCode()}`,
717
718
  "- **A question, not a change:** answer it, and change nothing.",
719
+ "- **Elements you add that won't show on the page as it is now** (empty, or shown only in a state: a closed menu's items, a tooltip on hover, a closed dialog): say in your reply what makes them show. Pilot offers the designer a button that selects what you added.",
718
720
  latest?.skill ? "- **Your notes are your reply in the designer's thread:** reply as the skill says (findings, a report, options to pick from), as long as it needs to be. Markdown shows (lists, bold, inline `code`, code blocks); headings show as bold lines." : "- **Your notes are your reply in the designer's thread, a small chat box for quick design back-and-forth:** keep it concise, like a chat message: what you changed, or your answer, or what you need from them, in a few short sentences at most. No headings, and not a report: the designer sees the result on the page."
719
721
  );
720
722
  return `${lines.join("\n")}
@@ -826,9 +828,10 @@ function styleLine(st) {
826
828
  return `${value}, from \`${source.selector}\`${source.media ? ` in \`@media ${source.media}\`` : ""}${shared}`;
827
829
  }
828
830
  function formatEdit(edit, n) {
829
- const { target, changes, texts } = edit;
831
+ const { target, changes, texts, attributes } = edit;
830
832
  const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
831
833
  if (texts?.length) out.push("", "Text (from \u2192 to):", "", ...texts.map((t) => `- ${JSON.stringify(t.from)} \u2192 ${JSON.stringify(t.to)}`));
834
+ if (attributes?.length) out.push("", ...attributeLines(attributes));
832
835
  if (!changes.length) return out;
833
836
  const withStates = changes.some((c) => c.states?.length);
834
837
  const withWhen = changes.some((c) => c.condition);
@@ -847,6 +850,24 @@ function formatEdit(edit, n) {
847
850
  if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
848
851
  return out;
849
852
  }
853
+ function attributeLines(attributes) {
854
+ const out = [
855
+ "Image (from \u2192 to), for every width and state:",
856
+ "",
857
+ ...attributes.map((a) => `- \`${a.name}\`: ${a.from === void 0 ? "*not set*" : JSON.stringify(a.from)} \u2192 ${JSON.stringify(a.to)}`),
858
+ ""
859
+ ];
860
+ if (attributes.some((a) => a.name === "src"))
861
+ out.push(
862
+ "- `src` is the image the designer picked, by its address on the site as the page loads it: a file in the folder the dev server serves at the root (`/images/hero.jpg` is `public/images/hero.jpg`, or `static/` in SvelteKit), or a built asset (`/assets/hero-a1b2c3.jpg`) whose name gives its source file away, imported the project's way. Change it where the image's address comes from (the markup, a prop, data, a CMS fixture), through the project's image component if it uses one (Next.js's `<Image>`), and keep `srcset`, `sizes`, `width` and `height` in line with the new image."
863
+ );
864
+ if (attributes.some((a) => a.name === "alt"))
865
+ out.push("- `alt` is what a screen reader says for the image: set it as written, where the image's markup or props come from.");
866
+ if (attributes.some((a) => a.name === "alt" && a.to === ""))
867
+ out.push('- `alt` \u2192 `""` marks the image decorative, so screen readers skip it: write `alt=""`, the attribute kept and empty, never left out.');
868
+ out.push("- If the same image element is rendered elsewhere, change only this one's, unless the designer's note says otherwise.");
869
+ return out;
870
+ }
850
871
  function describeStates(states) {
851
872
  return states?.length ? states.join(", ") : "\u2014";
852
873
  }
@@ -1215,13 +1236,13 @@ function scan(root, deadline) {
1215
1236
  const now = /* @__PURE__ */ new Map();
1216
1237
  const out = [];
1217
1238
  const walk = (dir) => {
1218
- let entries;
1239
+ let entries2;
1219
1240
  try {
1220
- entries = readdirSync(dir, { withFileTypes: true });
1241
+ entries2 = readdirSync(dir, { withFileTypes: true });
1221
1242
  } catch {
1222
1243
  return;
1223
1244
  }
1224
- for (const entry of entries) {
1245
+ for (const entry of entries2) {
1225
1246
  if (now.size >= MAX_FILES || Date.now() > deadline) return;
1226
1247
  const name = entry.name;
1227
1248
  if (SKIP.has(name) || name.startsWith(".")) continue;
@@ -1282,18 +1303,95 @@ function read(path) {
1282
1303
  return found;
1283
1304
  }
1284
1305
 
1306
+ // src/images.ts
1307
+ import { existsSync as existsSync3, readdirSync as readdirSync2, statSync as statSync3 } from "fs";
1308
+ import { extname as extname2, join as join4 } from "path";
1309
+ var SERVED = ["public", "static"];
1310
+ var EXTENSIONS2 = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif", ".svg", ".bmp", ".ico"]);
1311
+ var MAX_IMAGES = 500;
1312
+ var MAX_FILES2 = 8e3;
1313
+ var APP_DEPTH = 2;
1314
+ function projectImages(folders) {
1315
+ const out = [];
1316
+ const seen = /* @__PURE__ */ new Set();
1317
+ const budget = { files: 0 };
1318
+ for (const folder of folders) {
1319
+ const root = workspaceRoot(folder);
1320
+ for (const served of servedFolders(folder, root)) {
1321
+ for (const image of imagesIn(served, root, budget)) {
1322
+ if (out.length >= MAX_IMAGES) return out;
1323
+ if (seen.has(image.url)) continue;
1324
+ seen.add(image.url);
1325
+ out.push(image);
1326
+ }
1327
+ }
1328
+ }
1329
+ return out;
1330
+ }
1331
+ function servedFolders(folder, root = folder) {
1332
+ const own = SERVED.map((name) => join4(folder, name)).filter(isDir);
1333
+ if (own.length) return own;
1334
+ if (folder === root) {
1335
+ const apps = appsServed(folder, APP_DEPTH);
1336
+ if (apps.length) return apps;
1337
+ }
1338
+ return existsSync3(join4(folder, "index.html")) ? [folder] : [];
1339
+ }
1340
+ function appsServed(dir, depth) {
1341
+ if (depth === 0) return [];
1342
+ return entries(dir).filter((e) => e.isDirectory() && !SKIP.has(e.name) && !e.name.startsWith(".")).flatMap((e) => {
1343
+ const sub = join4(dir, e.name);
1344
+ const own = SERVED.map((name) => join4(sub, name)).filter(isDir);
1345
+ return own.length ? own : appsServed(sub, depth - 1);
1346
+ });
1347
+ }
1348
+ function imagesIn(served, root, budget) {
1349
+ const out = [];
1350
+ const walk = (dir) => {
1351
+ for (const entry of entries(dir)) {
1352
+ if (budget.files >= MAX_FILES2 || out.length >= MAX_IMAGES) return;
1353
+ const name = entry.name;
1354
+ if (name.startsWith(".") || SKIP.has(name)) continue;
1355
+ const path = join4(dir, name);
1356
+ if (entry.isDirectory()) {
1357
+ walk(path);
1358
+ continue;
1359
+ }
1360
+ budget.files++;
1361
+ if (!entry.isFile() || !EXTENSIONS2.has(extname2(name).toLowerCase())) continue;
1362
+ out.push({ url: `/${relPath(served, path)}`, file: relPath(root, path) });
1363
+ }
1364
+ };
1365
+ walk(served);
1366
+ return out.sort((a, b) => a.url.localeCompare(b.url));
1367
+ }
1368
+ function entries(dir) {
1369
+ try {
1370
+ return readdirSync2(dir, { withFileTypes: true });
1371
+ } catch {
1372
+ return [];
1373
+ }
1374
+ }
1375
+ function isDir(path) {
1376
+ try {
1377
+ return statSync3(path).isDirectory();
1378
+ } catch {
1379
+ return false;
1380
+ }
1381
+ }
1382
+
1285
1383
  // src/skills.ts
1286
- import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync3 } from "fs";
1384
+ import { existsSync as existsSync4, readdirSync as readdirSync3, readFileSync as readFileSync2, statSync as statSync4 } from "fs";
1287
1385
  import { homedir as homedir2 } from "os";
1288
- import { dirname as dirname3, join as join4 } from "path";
1386
+ import { dirname as dirname3, join as join5 } from "path";
1289
1387
  function skillFolders(cli, project, home = homedir2()) {
1290
- const folders = [...projectRoots(project).flatMap((dir) => cli.skills.project.map((rel) => join4(dir, rel))), ...cli.skills.home.map((rel) => join4(home, rel))];
1388
+ const folders = [...projectRoots(project).flatMap((dir) => cli.skills.project.map((rel) => join5(dir, rel))), ...cli.skills.home.map((rel) => join5(home, rel))];
1291
1389
  return [...new Set(folders)];
1292
1390
  }
1293
1391
  function projectRoots(project) {
1294
1392
  const roots = [project];
1295
1393
  let dir = project;
1296
- while (!existsSync3(join4(dir, ".git"))) {
1394
+ while (!existsSync4(join5(dir, ".git"))) {
1297
1395
  const up = dirname3(dir);
1298
1396
  if (up === dir) return [project];
1299
1397
  dir = up;
@@ -1304,15 +1402,15 @@ function projectRoots(project) {
1304
1402
  function findSkills(folders) {
1305
1403
  const found = /* @__PURE__ */ new Map();
1306
1404
  for (const folder of folders) {
1307
- let entries;
1405
+ let entries2;
1308
1406
  try {
1309
- entries = readdirSync2(folder);
1407
+ entries2 = readdirSync3(folder);
1310
1408
  } catch {
1311
1409
  continue;
1312
1410
  }
1313
- for (const entry of entries.sort()) {
1411
+ for (const entry of entries2.sort()) {
1314
1412
  if (entry.startsWith(".")) continue;
1315
- const meta = readSkill(join4(folder, entry, "SKILL.md"));
1413
+ const meta = readSkill(join5(folder, entry, "SKILL.md"));
1316
1414
  if (!meta) continue;
1317
1415
  const name = meta.name || entry;
1318
1416
  if (!SKILL_NAME.test(name) || found.has(name)) continue;
@@ -1326,7 +1424,7 @@ var MAX_DESCRIPTION = 300;
1326
1424
  var MAX_AUTHOR = 60;
1327
1425
  function readSkill(file) {
1328
1426
  try {
1329
- if (statSync3(file).size > MAX_SKILL_BYTES) return null;
1427
+ if (statSync4(file).size > MAX_SKILL_BYTES) return null;
1330
1428
  const text = readFileSync2(file, "utf8");
1331
1429
  const meta = frontmatter(text);
1332
1430
  const description = meta.description?.replace(/\s+/g, " ").trim();
@@ -1378,9 +1476,9 @@ function unquote(value) {
1378
1476
  }
1379
1477
 
1380
1478
  // src/tokenFiles.ts
1381
- import { readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync4 } from "fs";
1382
- import { basename as basename3, dirname as dirname4, join as join5 } from "path";
1383
- var MAX_FILES2 = 8e3;
1479
+ import { readdirSync as readdirSync4, readFileSync as readFileSync3, statSync as statSync5 } from "fs";
1480
+ import { basename as basename3, dirname as dirname4, join as join6 } from "path";
1481
+ var MAX_FILES3 = 8e3;
1384
1482
  var MAX_FILE_BYTES2 = 512e3;
1385
1483
  var MAX_TOKENS = 1e3;
1386
1484
  var BUDGET_MS2 = 1500;
@@ -1415,17 +1513,17 @@ function scan2(root, deadline) {
1415
1513
  const out = [];
1416
1514
  let files = 0;
1417
1515
  const walk = (dir) => {
1418
- let entries;
1516
+ let entries2;
1419
1517
  try {
1420
- entries = readdirSync3(dir, { withFileTypes: true });
1518
+ entries2 = readdirSync4(dir, { withFileTypes: true });
1421
1519
  } catch {
1422
1520
  return;
1423
1521
  }
1424
- for (const entry of entries) {
1425
- if (files >= MAX_FILES2 || Date.now() > deadline) return;
1522
+ for (const entry of entries2) {
1523
+ if (files >= MAX_FILES3 || Date.now() > deadline) return;
1426
1524
  const name = entry.name;
1427
1525
  if (SKIP.has(name) || name.startsWith(".")) continue;
1428
- const path = join5(dir, name);
1526
+ const path = join6(dir, name);
1429
1527
  if (entry.isDirectory()) {
1430
1528
  walk(path);
1431
1529
  continue;
@@ -1435,7 +1533,7 @@ function scan2(root, deadline) {
1435
1533
  if (!entry.isFile() || !(json2 || isTokenSass(path))) continue;
1436
1534
  let stat2;
1437
1535
  try {
1438
- stat2 = statSync4(path);
1536
+ stat2 = statSync5(path);
1439
1537
  } catch {
1440
1538
  continue;
1441
1539
  }
@@ -1928,6 +2026,7 @@ async function handle(hub, req, res, attachments) {
1928
2026
  if (!hub.hasAgents(origin)) return json(res, 403, { error: "Pilot isn't running for this site: run npx usepilot in your project" });
1929
2027
  if (path === "/components") return json(res, 200, { components: projectComponents(hub.folders(origin)) });
1930
2028
  if (path === "/tokens") return json(res, 200, { tokens: fileTokens(hub.folders(origin)) });
2029
+ if (path === "/images") return json(res, 200, { images: projectImages(hub.folders(origin)) });
1931
2030
  if (path === "/skills") return json(res, 200, { skills: findSkills(hub.skillFolders(origin)) });
1932
2031
  if (path === "/attachments") {
1933
2032
  const type = req.headers["content-type"] ?? "";
@@ -2345,10 +2444,10 @@ function isConnectionError(error) {
2345
2444
  // src/config.ts
2346
2445
  import { mkdirSync, readFileSync as readFileSync4, realpathSync, writeFileSync } from "fs";
2347
2446
  import { homedir as homedir3 } from "os";
2348
- import { basename as basename4, dirname as dirname5, join as join6, resolve as resolve2 } from "path";
2447
+ import { basename as basename4, dirname as dirname5, join as join7, resolve as resolve2 } from "path";
2349
2448
  function configFile(env = process.env, platform = process.platform, home = homedir3()) {
2350
- const base = platform === "win32" ? env.APPDATA || join6(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME || join6(home, ".config");
2351
- return join6(base, "usepilot", "projects.json");
2449
+ const base = platform === "win32" ? env.APPDATA || join7(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME || join7(home, ".config");
2450
+ return join7(base, "usepilot", "projects.json");
2352
2451
  }
2353
2452
  function read3(file) {
2354
2453
  try {
@@ -2404,7 +2503,7 @@ function saveSessions(folder, sessions, file = configFile()) {
2404
2503
  }
2405
2504
  function projectName(folder) {
2406
2505
  try {
2407
- const name = projectNameOf(JSON.parse(readFileSync4(join6(folder, "package.json"), "utf8")).name);
2506
+ const name = projectNameOf(JSON.parse(readFileSync4(join7(folder, "package.json"), "utf8")).name);
2408
2507
  if (name) return name;
2409
2508
  } catch {
2410
2509
  }
@@ -2412,12 +2511,12 @@ function projectName(folder) {
2412
2511
  }
2413
2512
 
2414
2513
  // src/facts.ts
2415
- import { existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
2416
- import { dirname as dirname6, join as join9, relative as relative2, resolve as resolve4, sep as sep2 } from "path";
2514
+ import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
2515
+ import { dirname as dirname6, join as join10, relative as relative2, resolve as resolve4, sep as sep2 } from "path";
2417
2516
 
2418
2517
  // src/sources.ts
2419
- import { readdirSync as readdirSync4, readFileSync as readFileSync5, statSync as statSync5 } from "fs";
2420
- import { extname as extname3, join as join7 } from "path";
2518
+ import { readdirSync as readdirSync5, readFileSync as readFileSync5, statSync as statSync6 } from "fs";
2519
+ import { extname as extname4, join as join8 } from "path";
2421
2520
  var SKIP2 = /* @__PURE__ */ new Set([
2422
2521
  "node_modules",
2423
2522
  "dist",
@@ -2435,7 +2534,7 @@ var SKIP2 = /* @__PURE__ */ new Set([
2435
2534
  ".turbo",
2436
2535
  ".cache"
2437
2536
  ]);
2438
- var EXTENSIONS2 = /* @__PURE__ */ new Set([
2537
+ var EXTENSIONS3 = /* @__PURE__ */ new Set([
2439
2538
  ".html",
2440
2539
  ".htm",
2441
2540
  ".jsx",
@@ -2455,7 +2554,7 @@ var EXTENSIONS2 = /* @__PURE__ */ new Set([
2455
2554
  ".twig"
2456
2555
  ]);
2457
2556
  var STYLESHEETS = /* @__PURE__ */ new Set([".css", ".scss", ".sass", ".less", ".styl"]);
2458
- var MAX_FILES3 = 5e4;
2557
+ var MAX_FILES4 = 5e4;
2459
2558
  var MAX_FILE_BYTES3 = 512e3;
2460
2559
  var FRESH_MS = 2e3;
2461
2560
  var Index = class {
@@ -2485,17 +2584,17 @@ var Index = class {
2485
2584
  const walk = (dir) => {
2486
2585
  let names;
2487
2586
  try {
2488
- names = readdirSync4(dir);
2587
+ names = readdirSync5(dir);
2489
2588
  } catch {
2490
2589
  return;
2491
2590
  }
2492
2591
  for (const name of names) {
2493
- if (paths.length >= MAX_FILES3) return;
2592
+ if (paths.length >= MAX_FILES4) return;
2494
2593
  if (SKIP2.has(name) || name.startsWith(".")) continue;
2495
- const path = join7(dir, name);
2594
+ const path = join8(dir, name);
2496
2595
  let stat2;
2497
2596
  try {
2498
- stat2 = statSync5(path);
2597
+ stat2 = statSync6(path);
2499
2598
  } catch {
2500
2599
  continue;
2501
2600
  }
@@ -2503,8 +2602,8 @@ var Index = class {
2503
2602
  walk(path);
2504
2603
  continue;
2505
2604
  }
2506
- if (STYLESHEETS.has(extname3(name)) && stat2.size <= MAX_FILE_BYTES3) styles.push(path);
2507
- if (!EXTENSIONS2.has(extname3(name)) || stat2.size > MAX_FILE_BYTES3) continue;
2605
+ if (STYLESHEETS.has(extname4(name)) && stat2.size <= MAX_FILE_BYTES3) styles.push(path);
2606
+ if (!EXTENSIONS3.has(extname4(name)) || stat2.size > MAX_FILE_BYTES3) continue;
2508
2607
  paths.push(path);
2509
2608
  seen.add(path);
2510
2609
  const known = this.entries.get(path);
@@ -2579,8 +2678,8 @@ function warmSources(root) {
2579
2678
  }
2580
2679
 
2581
2680
  // src/styles.ts
2582
- import { existsSync as existsSync4, readFileSync as readFileSync6, statSync as statSync6 } from "fs";
2583
- import { basename as basename5, extname as extname4, join as join8 } from "path";
2681
+ import { existsSync as existsSync5, readFileSync as readFileSync6, statSync as statSync7 } from "fs";
2682
+ import { basename as basename5, extname as extname5, join as join9 } from "path";
2584
2683
  var STYLE_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".scss", ".sass", ".less", ".styl"]);
2585
2684
  var PREPROCESSED = /* @__PURE__ */ new Set([".scss", ".sass", ".less", ".styl"]);
2586
2685
  var TEMPLATES = /^@(mixin|function|each|for|while|if|else|keyframes|-webkit-keyframes|font-face|property|page|counter-style|theme|utility|variant|custom-variant)\b/;
@@ -2588,7 +2687,7 @@ var parsed = /* @__PURE__ */ new Map();
2588
2687
  function rulesOf(path, root) {
2589
2688
  let stat2;
2590
2689
  try {
2591
- stat2 = statSync6(path);
2690
+ stat2 = statSync7(path);
2592
2691
  } catch {
2593
2692
  return [];
2594
2693
  }
@@ -2663,7 +2762,7 @@ function resolve3(parents, own) {
2663
2762
  return out;
2664
2763
  }
2665
2764
  function parseStylesheet(text, file) {
2666
- const ext = extname4(file);
2765
+ const ext = extname5(file);
2667
2766
  const css = withoutComments(text, ext !== ".css");
2668
2767
  const rules = [];
2669
2768
  const stack = [];
@@ -2757,7 +2856,7 @@ function asWritten(selector) {
2757
2856
  return { selector: normalSelector(out), ...module ? { module } : {}, hashed };
2758
2857
  }
2759
2858
  function warmStyles(root) {
2760
- for (const path of styleFiles(root)) if (STYLE_EXTENSIONS.has(extname4(path))) rulesOf(path, root);
2859
+ for (const path of styleFiles(root)) if (STYLE_EXTENSIONS.has(extname5(path))) rulesOf(path, root);
2761
2860
  }
2762
2861
  function ruleSource(selector, property, root, near = [], media) {
2763
2862
  const wanted = asWritten(selector);
@@ -2770,9 +2869,9 @@ function ruleSource(selector, property, root, near = [], media) {
2770
2869
  found.push({ rule, ...declaration ? { declaration } : {} });
2771
2870
  }
2772
2871
  };
2773
- const sources = new Set(files.filter((f) => PREPROCESSED.has(extname4(f))).map((f) => basename5(f).replace(/^_/, "").replace(/\.\w+$/, "")));
2872
+ const sources = new Set(files.filter((f) => PREPROCESSED.has(extname5(f))).map((f) => basename5(f).replace(/^_/, "").replace(/\.\w+$/, "")));
2774
2873
  for (const path of files) {
2775
- const ext = extname4(path);
2874
+ const ext = extname5(path);
2776
2875
  if (!STYLE_EXTENSIONS.has(ext)) continue;
2777
2876
  if (ext === ".css" && compiled(path, sources)) continue;
2778
2877
  if (wanted.hashed && !/\.module\.\w+$/.test(path)) continue;
@@ -2787,7 +2886,7 @@ function ruleSource(selector, property, root, near = [], media) {
2787
2886
  if (!kept.length) return null;
2788
2887
  if (!sites.size && new Set(kept.map((s) => siteOf(s.rule.file, root))).size > 1) return null;
2789
2888
  const score = (s) => {
2790
- const ext = extname4(s.rule.file);
2889
+ const ext = extname5(s.rule.file);
2791
2890
  const dir = s.rule.file.split(/[\\/]/).slice(0, -1);
2792
2891
  const shared = Math.max(
2793
2892
  0,
@@ -2811,7 +2910,7 @@ function siteOf(file, root) {
2811
2910
  const key = `${root}\0${dir}`;
2812
2911
  let site = siteCache.get(key);
2813
2912
  if (site === void 0) {
2814
- site = SITE_FILES.some((f) => existsSync4(join8(root, dir, f))) ? dir : "";
2913
+ site = SITE_FILES.some((f) => existsSync5(join9(root, dir, f))) ? dir : "";
2815
2914
  siteCache.set(key, site);
2816
2915
  }
2817
2916
  if (site) return site;
@@ -2819,7 +2918,7 @@ function siteOf(file, root) {
2819
2918
  return "";
2820
2919
  }
2821
2920
  function compiled(path, sources) {
2822
- if (existsSync4(`${path}.map`)) return true;
2921
+ if (existsSync5(`${path}.map`)) return true;
2823
2922
  if (sources.has(basename5(path, ".css"))) return true;
2824
2923
  try {
2825
2924
  const text = readFileSync6(path, "utf8");
@@ -2894,8 +2993,8 @@ function prefixed(namespace, values) {
2894
2993
  return Object.fromEntries(Object.entries(values).map(([k, v]) => [`${namespace}-${k}`, v]));
2895
2994
  }
2896
2995
  function tailwindOf(root, near = [], url) {
2897
- const entries = styleFiles(root).filter((f) => importsTailwind(f));
2898
- if (!entries.length) return null;
2996
+ const entries2 = styleFiles(root).filter((f) => importsTailwind(f));
2997
+ if (!entries2.length) return null;
2899
2998
  const route = routeParts(url);
2900
2999
  const closeness = (entry2) => {
2901
3000
  const dir = relative2(root, dirname6(entry2)).split(sep2).filter(Boolean);
@@ -2907,12 +3006,12 @@ function tailwindOf(root, near = [], url) {
2907
3006
  };
2908
3007
  return Math.max(0, ...near.map(shared)) * 10 + (route.includes(dir[0] ?? "") ? 1 : 0);
2909
3008
  };
2910
- const entry = [...entries].sort((a, b) => closeness(b) - closeness(a))[0];
3009
+ const entry = [...entries2].sort((a, b) => closeness(b) - closeness(a))[0];
2911
3010
  const pkg = nearestPackage(dirname6(entry), root);
2912
3011
  const version = installedVersion(dirname6(entry), root) ?? declaredVersion(pkg);
2913
3012
  if (version && !version.replace(/^[^\d]*/, "").startsWith("4")) return null;
2914
3013
  const theme = /* @__PURE__ */ new Map();
2915
- const defaults = findUp(dirname6(entry), root, join9("node_modules", "tailwindcss", "theme.css"));
3014
+ const defaults = findUp(dirname6(entry), root, join10("node_modules", "tailwindcss", "theme.css"));
2916
3015
  if (defaults) readTheme(defaults, theme, 0);
2917
3016
  else for (const [k, v] of DEFAULTS) theme.set(k, v);
2918
3017
  const own = /* @__PURE__ */ new Set();
@@ -2935,8 +3034,8 @@ function routeParts(url) {
2935
3034
  }
2936
3035
  function findUp(dir, root, name) {
2937
3036
  for (let d = resolve4(dir); ; d = dirname6(d)) {
2938
- const path = join9(d, name);
2939
- if (existsSync5(path)) return path;
3037
+ const path = join10(d, name);
3038
+ if (existsSync6(path)) return path;
2940
3039
  if (d === resolve4(root) || d === dirname6(d)) return null;
2941
3040
  }
2942
3041
  }
@@ -2944,7 +3043,7 @@ function nearestPackage(dir, root) {
2944
3043
  return findUp(dir, root, "package.json");
2945
3044
  }
2946
3045
  function installedVersion(dir, root) {
2947
- const pkg = findUp(dir, root, join9("node_modules", "tailwindcss", "package.json"));
3046
+ const pkg = findUp(dir, root, join10("node_modules", "tailwindcss", "package.json"));
2948
3047
  try {
2949
3048
  return pkg ? JSON.parse(readFileSync7(pkg, "utf8")).version : void 0;
2950
3049
  } catch {
@@ -3006,10 +3105,10 @@ function rebuildOf(pkg, root) {
3006
3105
  }
3007
3106
  };
3008
3107
  const escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3009
- for (const file of [.../* @__PURE__ */ new Set([pkg, join9(root, "package.json")])]) {
3108
+ for (const file of [.../* @__PURE__ */ new Set([pkg, join10(root, "package.json")])]) {
3010
3109
  const p = read4(file);
3011
3110
  const scripts = p.scripts ?? {};
3012
- const where = file && file !== join9(root, "package.json") ? ` in \`${relPath(root, dirname6(file))}\`` : "";
3111
+ const where = file && file !== join10(root, "package.json") ? ` in \`${relPath(root, dirname6(file))}\`` : "";
3013
3112
  const runner = (name) => Object.entries(scripts).find(([other, cmd]) => other !== name && new RegExp(`(npm run|pnpm( run)?|yarn|bun run|npm:)\\s*${escape2(name)}\\b`).test(cmd))?.[0];
3014
3113
  const said = (name) => {
3015
3114
  const by = runner(name);
@@ -3017,7 +3116,7 @@ function rebuildOf(pkg, root) {
3017
3116
  };
3018
3117
  const gulpWatches = (() => {
3019
3118
  try {
3020
- return /\bwatch\s*\(/.test(readFileSync7(join9(file ? dirname6(file) : root, "gulpfile.js"), "utf8"));
3119
+ return /\bwatch\s*\(/.test(readFileSync7(join10(file ? dirname6(file) : root, "gulpfile.js"), "utf8"));
3021
3120
  } catch {
3022
3121
  return false;
3023
3122
  }
@@ -3315,8 +3414,8 @@ function factsSection(job, root, near = []) {
3315
3414
  if (tw) lines.push(...tailwindScales(tw));
3316
3415
  else lines.push(...tokenScales(job.changeSet.tokens ?? []));
3317
3416
  }
3318
- const pkg = near.length ? nearestPackage(dirname6(join9(root, near[0])), root) : null;
3319
- const rebuild = rebuildOf(pkg ?? (tw ? nearestPackage(dirname6(join9(root, tw.entry)), root) : null), root);
3417
+ const pkg = near.length ? nearestPackage(dirname6(join10(root, near[0])), root) : null;
3418
+ const rebuild = rebuildOf(pkg ?? (tw ? nearestPackage(dirname6(join10(root, tw.entry)), root) : null), root);
3320
3419
  if (rebuild)
3321
3420
  add(
3322
3421
  rebuild.css ? `- Its CSS is rebuilt on save by ${rebuild.by}, so a change works at once: don't build it or check the compiled CSS.` : `- ${rebuild.by[0]?.toUpperCase()}${rebuild.by.slice(1)} updates the page on save: don't build it or check the compiled output.`
@@ -3363,8 +3462,8 @@ function tokenScales(tokens) {
3363
3462
  }
3364
3463
 
3365
3464
  // src/locate.ts
3366
- import { existsSync as existsSync6, readdirSync as readdirSync5, readFileSync as readFileSync8, statSync as statSync7 } from "fs";
3367
- import { basename as basename6, extname as extname5, isAbsolute, join as join10 } from "path";
3465
+ import { existsSync as existsSync7, readdirSync as readdirSync6, readFileSync as readFileSync8, statSync as statSync8 } from "fs";
3466
+ import { basename as basename6, extname as extname6, isAbsolute, join as join11 } from "path";
3368
3467
  var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3369
3468
  var BUDGET_MS3 = 800;
3370
3469
  var CANDIDATE_FILES = 60;
@@ -3372,7 +3471,7 @@ var PARENT_LINES = 400;
3372
3471
  var BODY_LINES = 80;
3373
3472
  var NEAR_LINES = 30;
3374
3473
  function searchable(cwd) {
3375
- return existsSync6(join10(cwd, "package.json")) || existsSync6(join10(cwd, ".git"));
3474
+ return existsSync7(join11(cwd, "package.json")) || existsSync7(join11(cwd, ".git"));
3376
3475
  }
3377
3476
  var ENTITIES = {
3378
3477
  amp: "&",
@@ -3428,11 +3527,11 @@ function needlesOf(target, url, root, rarity) {
3428
3527
  route = new URL(url).pathname.split("/").map((p) => decodeURIComponent(p).replace(/\.[a-z]+$/i, "")).filter((p) => p && p !== "index");
3429
3528
  } catch {
3430
3529
  }
3431
- const served = route.find((p) => !/[\\/]|^\.+$/.test(p) && isFolder(join10(root, p)));
3530
+ const served = route.find((p) => !/[\\/]|^\.+$/.test(p) && isFolder(join11(root, p)));
3432
3531
  const otherSites = /* @__PURE__ */ new Set();
3433
3532
  if (served) {
3434
3533
  for (const name of safeList(root))
3435
- if (name !== served && INDEX_FILES.some((f) => existsSync6(join10(root, name, f)))) otherSites.add(name);
3534
+ if (name !== served && INDEX_FILES.some((f) => existsSync7(join11(root, name, f)))) otherSites.add(name);
3436
3535
  }
3437
3536
  const before = usable(target.context?.before);
3438
3537
  const after = usable(target.context?.after);
@@ -3716,14 +3815,14 @@ function routeOf(n, rel) {
3716
3815
  var INDEX_FILES = ["index.php", "index.html", "index.htm"];
3717
3816
  var safeList = (dir) => {
3718
3817
  try {
3719
- return readdirSync5(dir).filter((name) => !name.startsWith(".") && isFolder(join10(dir, name)));
3818
+ return readdirSync6(dir).filter((name) => !name.startsWith(".") && isFolder(join11(dir, name)));
3720
3819
  } catch {
3721
3820
  return [];
3722
3821
  }
3723
3822
  };
3724
3823
  var isFolder = (path) => {
3725
3824
  try {
3726
- return statSync7(path).isDirectory();
3825
+ return statSync8(path).isDirectory();
3727
3826
  } catch {
3728
3827
  return false;
3729
3828
  }
@@ -3841,7 +3940,7 @@ function snippetAt(lines, index) {
3841
3940
  function sourcePath(file, root) {
3842
3941
  const rel = isAbsolute(file) ? relPath(root, file) : file.replace(/^\.\//, "");
3843
3942
  if (rel.startsWith("..") || isAbsolute(rel)) return null;
3844
- return existsSync6(join10(root, rel)) ? rel : null;
3943
+ return existsSync7(join11(root, rel)) ? rel : null;
3845
3944
  }
3846
3945
  function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
3847
3946
  if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null;
@@ -3849,7 +3948,7 @@ function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
3849
3948
  `^\\s*(export\\s+(?:default\\s+)?)?(?:(?:async\\s+)?function\\s*\\*?\\s+${name}\\b|class\\s+${name}\\b|(?:const|let|var)\\s+${name}\\s*[:=])`
3850
3949
  );
3851
3950
  let best = null;
3852
- const files = within ? [join10(root, within)] : sourceFiles(root);
3951
+ const files = within ? [join11(root, within)] : sourceFiles(root);
3853
3952
  for (const file of files) {
3854
3953
  if (Date.now() > deadline) break;
3855
3954
  if (!/\.[jt]sx?$|\.mjs$/.test(file)) continue;
@@ -3885,11 +3984,11 @@ function withComponentFiles(job, root) {
3885
3984
  const workspace = workspaceRoot(root);
3886
3985
  const declared = (name) => {
3887
3986
  const found = componentFile(name, workspace, deadline);
3888
- return found ? { file: relPath(root, join10(workspace, found.file)), line: found.line } : null;
3987
+ return found ? { file: relPath(root, join11(workspace, found.file)), line: found.line } : null;
3889
3988
  };
3890
3989
  const local = (file) => {
3891
- const path = join10(workspace, file);
3892
- return existsSync6(path) ? relPath(root, path) : file;
3990
+ const path = join11(workspace, file);
3991
+ return existsSync7(path) ? relPath(root, path) : file;
3893
3992
  };
3894
3993
  const mention = (r) => {
3895
3994
  if (r.kind === "token") return r.source ? { ...r, source: { ...r.source, file: local(r.source.file) } } : r;
@@ -3900,8 +3999,8 @@ function withComponentFiles(job, root) {
3900
3999
  }
3901
4000
  if (r.kind !== "component") return r;
3902
4001
  if (r.source) {
3903
- const path = join10(workspace, r.source.file);
3904
- return existsSync6(path) ? { ...r, source: { ...r.source, file: relPath(root, path) } } : r;
4002
+ const path = join11(workspace, r.source.file);
4003
+ return existsSync7(path) ? { ...r, source: { ...r.source, file: relPath(root, path) } } : r;
3905
4004
  }
3906
4005
  if (r.target?.source?.file) return { ...r, target: fill(r.target) };
3907
4006
  const source = declared(r.name);
@@ -3951,7 +4050,7 @@ function whereSection(job, root, located = jobLocations(job, root)) {
3951
4050
  for (const { target, at } of located) {
3952
4051
  const snippet = (place) => [
3953
4052
  "",
3954
- ` \`\`\`${extname5(place.file).slice(1) || "text"}`,
4053
+ ` \`\`\`${extname6(place.file).slice(1) || "text"}`,
3955
4054
  ...place.snippet.split("\n").map((l) => ` ${l}`),
3956
4055
  " ```"
3957
4056
  ];
@@ -4562,7 +4661,7 @@ function activityOf(bridge, jobId, every = ACTIVITY_EVERY_MS, now = Date.now) {
4562
4661
  }
4563
4662
  async function runAgent(ctx, prompt, options) {
4564
4663
  const { cli } = ctx;
4565
- if (!existsSync7(ctx.bin)) return { error: `${cli.label}'s command-line tool isn't installed any more.` };
4664
+ if (!existsSync8(ctx.bin)) return { error: `${cli.label}'s command-line tool isn't installed any more.` };
4566
4665
  options.onOutput?.();
4567
4666
  const run = await exec(ctx.bin, cli.args({ resume: options.resume, readDirs: [attachmentsDir()], images: options.images }), {
4568
4667
  cwd: ctx.project,
@@ -4644,7 +4743,7 @@ function describeJob(job) {
4644
4743
  return `${follow}comment on ${nameOf(request.target)}: "${latest.length > 60 ? `${latest.slice(0, 60)}\u2026` : latest}"`;
4645
4744
  }
4646
4745
  if (request) return `${follow}${request.kind} on ${requestTargets(request).map(nameOf).join(", ")}`;
4647
- const changes = job.changeSet.edits.reduce((n, e) => n + e.changes.length + (e.texts?.length ?? 0), 0);
4746
+ const changes = job.changeSet.edits.reduce((n, e) => n + e.changes.length + (e.texts?.length ?? 0) + (e.attributes?.length ?? 0), 0);
4648
4747
  return `${follow}${changes} change${changes === 1 ? "" : "s"} on ${job.changeSet.edits.map((e) => nameOf(e.target)).join(", ")}`;
4649
4748
  }
4650
4749
  function firstLine(text) {
@@ -4669,8 +4768,8 @@ function sleep(ms, signal) {
4669
4768
  }
4670
4769
 
4671
4770
  // src/dev.ts
4672
- import { existsSync as existsSync8 } from "fs";
4673
- import { dirname as dirname7, join as join11 } from "path";
4771
+ import { existsSync as existsSync9 } from "fs";
4772
+ import { dirname as dirname7, join as join12 } from "path";
4674
4773
  var RUNNER_ENV = "USEPILOT_RUNNER";
4675
4774
  var STARTED = /* @__PURE__ */ Symbol.for("usepilot.devRunner");
4676
4775
  var OFF_SAID_ENV = "USEPILOT_OFF_SAID";
@@ -4737,7 +4836,7 @@ function startWithDevServer(options = {}) {
4737
4836
  }
4738
4837
  function projectFolder(dir) {
4739
4838
  for (let d = dir; ; d = dirname7(d)) {
4740
- if (existsSync8(join11(d, "package.json"))) return d;
4839
+ if (existsSync9(join12(d, "package.json"))) return d;
4741
4840
  if (dirname7(d) === d) return dir;
4742
4841
  }
4743
4842
  }