usepilot 0.22.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.
- package/GUIDE.md +11 -6
- package/README.md +1 -1
- package/cli/{chunk-HVM5DNLS.js → chunk-MKYAH7CZ.js} +182 -84
- package/cli/index.js +3 -3
- package/cli/next.js +1 -1
- package/cli/vite.js +1 -1
- package/dist/{mount-CcEEbgxv.js → mount-BGG4C6zS.js} +6289 -5837
- package/dist/pilot-auto.js +1 -1
- package/dist/pilot.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +1 -1
|
@@ -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
|
|
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
|
-
|
|
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
|
"",
|
|
@@ -827,9 +828,10 @@ function styleLine(st) {
|
|
|
827
828
|
return `${value}, from \`${source.selector}\`${source.media ? ` in \`@media ${source.media}\`` : ""}${shared}`;
|
|
828
829
|
}
|
|
829
830
|
function formatEdit(edit, n) {
|
|
830
|
-
const { target, changes, texts } = edit;
|
|
831
|
+
const { target, changes, texts, attributes } = edit;
|
|
831
832
|
const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
|
|
832
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));
|
|
833
835
|
if (!changes.length) return out;
|
|
834
836
|
const withStates = changes.some((c) => c.states?.length);
|
|
835
837
|
const withWhen = changes.some((c) => c.condition);
|
|
@@ -848,6 +850,24 @@ function formatEdit(edit, n) {
|
|
|
848
850
|
if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
|
|
849
851
|
return out;
|
|
850
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
|
+
}
|
|
851
871
|
function describeStates(states) {
|
|
852
872
|
return states?.length ? states.join(", ") : "\u2014";
|
|
853
873
|
}
|
|
@@ -1216,13 +1236,13 @@ function scan(root, deadline) {
|
|
|
1216
1236
|
const now = /* @__PURE__ */ new Map();
|
|
1217
1237
|
const out = [];
|
|
1218
1238
|
const walk = (dir) => {
|
|
1219
|
-
let
|
|
1239
|
+
let entries2;
|
|
1220
1240
|
try {
|
|
1221
|
-
|
|
1241
|
+
entries2 = readdirSync(dir, { withFileTypes: true });
|
|
1222
1242
|
} catch {
|
|
1223
1243
|
return;
|
|
1224
1244
|
}
|
|
1225
|
-
for (const entry of
|
|
1245
|
+
for (const entry of entries2) {
|
|
1226
1246
|
if (now.size >= MAX_FILES || Date.now() > deadline) return;
|
|
1227
1247
|
const name = entry.name;
|
|
1228
1248
|
if (SKIP.has(name) || name.startsWith(".")) continue;
|
|
@@ -1283,18 +1303,95 @@ function read(path) {
|
|
|
1283
1303
|
return found;
|
|
1284
1304
|
}
|
|
1285
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
|
+
|
|
1286
1383
|
// src/skills.ts
|
|
1287
|
-
import { existsSync as
|
|
1384
|
+
import { existsSync as existsSync4, readdirSync as readdirSync3, readFileSync as readFileSync2, statSync as statSync4 } from "fs";
|
|
1288
1385
|
import { homedir as homedir2 } from "os";
|
|
1289
|
-
import { dirname as dirname3, join as
|
|
1386
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1290
1387
|
function skillFolders(cli, project, home = homedir2()) {
|
|
1291
|
-
const folders = [...projectRoots(project).flatMap((dir) => cli.skills.project.map((rel) =>
|
|
1388
|
+
const folders = [...projectRoots(project).flatMap((dir) => cli.skills.project.map((rel) => join5(dir, rel))), ...cli.skills.home.map((rel) => join5(home, rel))];
|
|
1292
1389
|
return [...new Set(folders)];
|
|
1293
1390
|
}
|
|
1294
1391
|
function projectRoots(project) {
|
|
1295
1392
|
const roots = [project];
|
|
1296
1393
|
let dir = project;
|
|
1297
|
-
while (!
|
|
1394
|
+
while (!existsSync4(join5(dir, ".git"))) {
|
|
1298
1395
|
const up = dirname3(dir);
|
|
1299
1396
|
if (up === dir) return [project];
|
|
1300
1397
|
dir = up;
|
|
@@ -1305,15 +1402,15 @@ function projectRoots(project) {
|
|
|
1305
1402
|
function findSkills(folders) {
|
|
1306
1403
|
const found = /* @__PURE__ */ new Map();
|
|
1307
1404
|
for (const folder of folders) {
|
|
1308
|
-
let
|
|
1405
|
+
let entries2;
|
|
1309
1406
|
try {
|
|
1310
|
-
|
|
1407
|
+
entries2 = readdirSync3(folder);
|
|
1311
1408
|
} catch {
|
|
1312
1409
|
continue;
|
|
1313
1410
|
}
|
|
1314
|
-
for (const entry of
|
|
1411
|
+
for (const entry of entries2.sort()) {
|
|
1315
1412
|
if (entry.startsWith(".")) continue;
|
|
1316
|
-
const meta = readSkill(
|
|
1413
|
+
const meta = readSkill(join5(folder, entry, "SKILL.md"));
|
|
1317
1414
|
if (!meta) continue;
|
|
1318
1415
|
const name = meta.name || entry;
|
|
1319
1416
|
if (!SKILL_NAME.test(name) || found.has(name)) continue;
|
|
@@ -1327,7 +1424,7 @@ var MAX_DESCRIPTION = 300;
|
|
|
1327
1424
|
var MAX_AUTHOR = 60;
|
|
1328
1425
|
function readSkill(file) {
|
|
1329
1426
|
try {
|
|
1330
|
-
if (
|
|
1427
|
+
if (statSync4(file).size > MAX_SKILL_BYTES) return null;
|
|
1331
1428
|
const text = readFileSync2(file, "utf8");
|
|
1332
1429
|
const meta = frontmatter(text);
|
|
1333
1430
|
const description = meta.description?.replace(/\s+/g, " ").trim();
|
|
@@ -1379,9 +1476,9 @@ function unquote(value) {
|
|
|
1379
1476
|
}
|
|
1380
1477
|
|
|
1381
1478
|
// src/tokenFiles.ts
|
|
1382
|
-
import { readdirSync as
|
|
1383
|
-
import { basename as basename3, dirname as dirname4, join as
|
|
1384
|
-
var
|
|
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;
|
|
1385
1482
|
var MAX_FILE_BYTES2 = 512e3;
|
|
1386
1483
|
var MAX_TOKENS = 1e3;
|
|
1387
1484
|
var BUDGET_MS2 = 1500;
|
|
@@ -1416,17 +1513,17 @@ function scan2(root, deadline) {
|
|
|
1416
1513
|
const out = [];
|
|
1417
1514
|
let files = 0;
|
|
1418
1515
|
const walk = (dir) => {
|
|
1419
|
-
let
|
|
1516
|
+
let entries2;
|
|
1420
1517
|
try {
|
|
1421
|
-
|
|
1518
|
+
entries2 = readdirSync4(dir, { withFileTypes: true });
|
|
1422
1519
|
} catch {
|
|
1423
1520
|
return;
|
|
1424
1521
|
}
|
|
1425
|
-
for (const entry of
|
|
1426
|
-
if (files >=
|
|
1522
|
+
for (const entry of entries2) {
|
|
1523
|
+
if (files >= MAX_FILES3 || Date.now() > deadline) return;
|
|
1427
1524
|
const name = entry.name;
|
|
1428
1525
|
if (SKIP.has(name) || name.startsWith(".")) continue;
|
|
1429
|
-
const path =
|
|
1526
|
+
const path = join6(dir, name);
|
|
1430
1527
|
if (entry.isDirectory()) {
|
|
1431
1528
|
walk(path);
|
|
1432
1529
|
continue;
|
|
@@ -1436,7 +1533,7 @@ function scan2(root, deadline) {
|
|
|
1436
1533
|
if (!entry.isFile() || !(json2 || isTokenSass(path))) continue;
|
|
1437
1534
|
let stat2;
|
|
1438
1535
|
try {
|
|
1439
|
-
stat2 =
|
|
1536
|
+
stat2 = statSync5(path);
|
|
1440
1537
|
} catch {
|
|
1441
1538
|
continue;
|
|
1442
1539
|
}
|
|
@@ -1929,6 +2026,7 @@ async function handle(hub, req, res, attachments) {
|
|
|
1929
2026
|
if (!hub.hasAgents(origin)) return json(res, 403, { error: "Pilot isn't running for this site: run npx usepilot in your project" });
|
|
1930
2027
|
if (path === "/components") return json(res, 200, { components: projectComponents(hub.folders(origin)) });
|
|
1931
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)) });
|
|
1932
2030
|
if (path === "/skills") return json(res, 200, { skills: findSkills(hub.skillFolders(origin)) });
|
|
1933
2031
|
if (path === "/attachments") {
|
|
1934
2032
|
const type = req.headers["content-type"] ?? "";
|
|
@@ -2346,10 +2444,10 @@ function isConnectionError(error) {
|
|
|
2346
2444
|
// src/config.ts
|
|
2347
2445
|
import { mkdirSync, readFileSync as readFileSync4, realpathSync, writeFileSync } from "fs";
|
|
2348
2446
|
import { homedir as homedir3 } from "os";
|
|
2349
|
-
import { basename as basename4, dirname as dirname5, join as
|
|
2447
|
+
import { basename as basename4, dirname as dirname5, join as join7, resolve as resolve2 } from "path";
|
|
2350
2448
|
function configFile(env = process.env, platform = process.platform, home = homedir3()) {
|
|
2351
|
-
const base = platform === "win32" ? env.APPDATA ||
|
|
2352
|
-
return
|
|
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");
|
|
2353
2451
|
}
|
|
2354
2452
|
function read3(file) {
|
|
2355
2453
|
try {
|
|
@@ -2405,7 +2503,7 @@ function saveSessions(folder, sessions, file = configFile()) {
|
|
|
2405
2503
|
}
|
|
2406
2504
|
function projectName(folder) {
|
|
2407
2505
|
try {
|
|
2408
|
-
const name = projectNameOf(JSON.parse(readFileSync4(
|
|
2506
|
+
const name = projectNameOf(JSON.parse(readFileSync4(join7(folder, "package.json"), "utf8")).name);
|
|
2409
2507
|
if (name) return name;
|
|
2410
2508
|
} catch {
|
|
2411
2509
|
}
|
|
@@ -2413,12 +2511,12 @@ function projectName(folder) {
|
|
|
2413
2511
|
}
|
|
2414
2512
|
|
|
2415
2513
|
// src/facts.ts
|
|
2416
|
-
import { existsSync as
|
|
2417
|
-
import { dirname as dirname6, join as
|
|
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";
|
|
2418
2516
|
|
|
2419
2517
|
// src/sources.ts
|
|
2420
|
-
import { readdirSync as
|
|
2421
|
-
import { extname as
|
|
2518
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync5, statSync as statSync6 } from "fs";
|
|
2519
|
+
import { extname as extname4, join as join8 } from "path";
|
|
2422
2520
|
var SKIP2 = /* @__PURE__ */ new Set([
|
|
2423
2521
|
"node_modules",
|
|
2424
2522
|
"dist",
|
|
@@ -2436,7 +2534,7 @@ var SKIP2 = /* @__PURE__ */ new Set([
|
|
|
2436
2534
|
".turbo",
|
|
2437
2535
|
".cache"
|
|
2438
2536
|
]);
|
|
2439
|
-
var
|
|
2537
|
+
var EXTENSIONS3 = /* @__PURE__ */ new Set([
|
|
2440
2538
|
".html",
|
|
2441
2539
|
".htm",
|
|
2442
2540
|
".jsx",
|
|
@@ -2456,7 +2554,7 @@ var EXTENSIONS2 = /* @__PURE__ */ new Set([
|
|
|
2456
2554
|
".twig"
|
|
2457
2555
|
]);
|
|
2458
2556
|
var STYLESHEETS = /* @__PURE__ */ new Set([".css", ".scss", ".sass", ".less", ".styl"]);
|
|
2459
|
-
var
|
|
2557
|
+
var MAX_FILES4 = 5e4;
|
|
2460
2558
|
var MAX_FILE_BYTES3 = 512e3;
|
|
2461
2559
|
var FRESH_MS = 2e3;
|
|
2462
2560
|
var Index = class {
|
|
@@ -2486,17 +2584,17 @@ var Index = class {
|
|
|
2486
2584
|
const walk = (dir) => {
|
|
2487
2585
|
let names;
|
|
2488
2586
|
try {
|
|
2489
|
-
names =
|
|
2587
|
+
names = readdirSync5(dir);
|
|
2490
2588
|
} catch {
|
|
2491
2589
|
return;
|
|
2492
2590
|
}
|
|
2493
2591
|
for (const name of names) {
|
|
2494
|
-
if (paths.length >=
|
|
2592
|
+
if (paths.length >= MAX_FILES4) return;
|
|
2495
2593
|
if (SKIP2.has(name) || name.startsWith(".")) continue;
|
|
2496
|
-
const path =
|
|
2594
|
+
const path = join8(dir, name);
|
|
2497
2595
|
let stat2;
|
|
2498
2596
|
try {
|
|
2499
|
-
stat2 =
|
|
2597
|
+
stat2 = statSync6(path);
|
|
2500
2598
|
} catch {
|
|
2501
2599
|
continue;
|
|
2502
2600
|
}
|
|
@@ -2504,8 +2602,8 @@ var Index = class {
|
|
|
2504
2602
|
walk(path);
|
|
2505
2603
|
continue;
|
|
2506
2604
|
}
|
|
2507
|
-
if (STYLESHEETS.has(
|
|
2508
|
-
if (!
|
|
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;
|
|
2509
2607
|
paths.push(path);
|
|
2510
2608
|
seen.add(path);
|
|
2511
2609
|
const known = this.entries.get(path);
|
|
@@ -2580,8 +2678,8 @@ function warmSources(root) {
|
|
|
2580
2678
|
}
|
|
2581
2679
|
|
|
2582
2680
|
// src/styles.ts
|
|
2583
|
-
import { existsSync as
|
|
2584
|
-
import { basename as basename5, extname as
|
|
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";
|
|
2585
2683
|
var STYLE_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".scss", ".sass", ".less", ".styl"]);
|
|
2586
2684
|
var PREPROCESSED = /* @__PURE__ */ new Set([".scss", ".sass", ".less", ".styl"]);
|
|
2587
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/;
|
|
@@ -2589,7 +2687,7 @@ var parsed = /* @__PURE__ */ new Map();
|
|
|
2589
2687
|
function rulesOf(path, root) {
|
|
2590
2688
|
let stat2;
|
|
2591
2689
|
try {
|
|
2592
|
-
stat2 =
|
|
2690
|
+
stat2 = statSync7(path);
|
|
2593
2691
|
} catch {
|
|
2594
2692
|
return [];
|
|
2595
2693
|
}
|
|
@@ -2664,7 +2762,7 @@ function resolve3(parents, own) {
|
|
|
2664
2762
|
return out;
|
|
2665
2763
|
}
|
|
2666
2764
|
function parseStylesheet(text, file) {
|
|
2667
|
-
const ext =
|
|
2765
|
+
const ext = extname5(file);
|
|
2668
2766
|
const css = withoutComments(text, ext !== ".css");
|
|
2669
2767
|
const rules = [];
|
|
2670
2768
|
const stack = [];
|
|
@@ -2758,7 +2856,7 @@ function asWritten(selector) {
|
|
|
2758
2856
|
return { selector: normalSelector(out), ...module ? { module } : {}, hashed };
|
|
2759
2857
|
}
|
|
2760
2858
|
function warmStyles(root) {
|
|
2761
|
-
for (const path of styleFiles(root)) if (STYLE_EXTENSIONS.has(
|
|
2859
|
+
for (const path of styleFiles(root)) if (STYLE_EXTENSIONS.has(extname5(path))) rulesOf(path, root);
|
|
2762
2860
|
}
|
|
2763
2861
|
function ruleSource(selector, property, root, near = [], media) {
|
|
2764
2862
|
const wanted = asWritten(selector);
|
|
@@ -2771,9 +2869,9 @@ function ruleSource(selector, property, root, near = [], media) {
|
|
|
2771
2869
|
found.push({ rule, ...declaration ? { declaration } : {} });
|
|
2772
2870
|
}
|
|
2773
2871
|
};
|
|
2774
|
-
const sources = new Set(files.filter((f) => PREPROCESSED.has(
|
|
2872
|
+
const sources = new Set(files.filter((f) => PREPROCESSED.has(extname5(f))).map((f) => basename5(f).replace(/^_/, "").replace(/\.\w+$/, "")));
|
|
2775
2873
|
for (const path of files) {
|
|
2776
|
-
const ext =
|
|
2874
|
+
const ext = extname5(path);
|
|
2777
2875
|
if (!STYLE_EXTENSIONS.has(ext)) continue;
|
|
2778
2876
|
if (ext === ".css" && compiled(path, sources)) continue;
|
|
2779
2877
|
if (wanted.hashed && !/\.module\.\w+$/.test(path)) continue;
|
|
@@ -2788,7 +2886,7 @@ function ruleSource(selector, property, root, near = [], media) {
|
|
|
2788
2886
|
if (!kept.length) return null;
|
|
2789
2887
|
if (!sites.size && new Set(kept.map((s) => siteOf(s.rule.file, root))).size > 1) return null;
|
|
2790
2888
|
const score = (s) => {
|
|
2791
|
-
const ext =
|
|
2889
|
+
const ext = extname5(s.rule.file);
|
|
2792
2890
|
const dir = s.rule.file.split(/[\\/]/).slice(0, -1);
|
|
2793
2891
|
const shared = Math.max(
|
|
2794
2892
|
0,
|
|
@@ -2812,7 +2910,7 @@ function siteOf(file, root) {
|
|
|
2812
2910
|
const key = `${root}\0${dir}`;
|
|
2813
2911
|
let site = siteCache.get(key);
|
|
2814
2912
|
if (site === void 0) {
|
|
2815
|
-
site = SITE_FILES.some((f) =>
|
|
2913
|
+
site = SITE_FILES.some((f) => existsSync5(join9(root, dir, f))) ? dir : "";
|
|
2816
2914
|
siteCache.set(key, site);
|
|
2817
2915
|
}
|
|
2818
2916
|
if (site) return site;
|
|
@@ -2820,7 +2918,7 @@ function siteOf(file, root) {
|
|
|
2820
2918
|
return "";
|
|
2821
2919
|
}
|
|
2822
2920
|
function compiled(path, sources) {
|
|
2823
|
-
if (
|
|
2921
|
+
if (existsSync5(`${path}.map`)) return true;
|
|
2824
2922
|
if (sources.has(basename5(path, ".css"))) return true;
|
|
2825
2923
|
try {
|
|
2826
2924
|
const text = readFileSync6(path, "utf8");
|
|
@@ -2895,8 +2993,8 @@ function prefixed(namespace, values) {
|
|
|
2895
2993
|
return Object.fromEntries(Object.entries(values).map(([k, v]) => [`${namespace}-${k}`, v]));
|
|
2896
2994
|
}
|
|
2897
2995
|
function tailwindOf(root, near = [], url) {
|
|
2898
|
-
const
|
|
2899
|
-
if (!
|
|
2996
|
+
const entries2 = styleFiles(root).filter((f) => importsTailwind(f));
|
|
2997
|
+
if (!entries2.length) return null;
|
|
2900
2998
|
const route = routeParts(url);
|
|
2901
2999
|
const closeness = (entry2) => {
|
|
2902
3000
|
const dir = relative2(root, dirname6(entry2)).split(sep2).filter(Boolean);
|
|
@@ -2908,12 +3006,12 @@ function tailwindOf(root, near = [], url) {
|
|
|
2908
3006
|
};
|
|
2909
3007
|
return Math.max(0, ...near.map(shared)) * 10 + (route.includes(dir[0] ?? "") ? 1 : 0);
|
|
2910
3008
|
};
|
|
2911
|
-
const entry = [...
|
|
3009
|
+
const entry = [...entries2].sort((a, b) => closeness(b) - closeness(a))[0];
|
|
2912
3010
|
const pkg = nearestPackage(dirname6(entry), root);
|
|
2913
3011
|
const version = installedVersion(dirname6(entry), root) ?? declaredVersion(pkg);
|
|
2914
3012
|
if (version && !version.replace(/^[^\d]*/, "").startsWith("4")) return null;
|
|
2915
3013
|
const theme = /* @__PURE__ */ new Map();
|
|
2916
|
-
const defaults = findUp(dirname6(entry), root,
|
|
3014
|
+
const defaults = findUp(dirname6(entry), root, join10("node_modules", "tailwindcss", "theme.css"));
|
|
2917
3015
|
if (defaults) readTheme(defaults, theme, 0);
|
|
2918
3016
|
else for (const [k, v] of DEFAULTS) theme.set(k, v);
|
|
2919
3017
|
const own = /* @__PURE__ */ new Set();
|
|
@@ -2936,8 +3034,8 @@ function routeParts(url) {
|
|
|
2936
3034
|
}
|
|
2937
3035
|
function findUp(dir, root, name) {
|
|
2938
3036
|
for (let d = resolve4(dir); ; d = dirname6(d)) {
|
|
2939
|
-
const path =
|
|
2940
|
-
if (
|
|
3037
|
+
const path = join10(d, name);
|
|
3038
|
+
if (existsSync6(path)) return path;
|
|
2941
3039
|
if (d === resolve4(root) || d === dirname6(d)) return null;
|
|
2942
3040
|
}
|
|
2943
3041
|
}
|
|
@@ -2945,7 +3043,7 @@ function nearestPackage(dir, root) {
|
|
|
2945
3043
|
return findUp(dir, root, "package.json");
|
|
2946
3044
|
}
|
|
2947
3045
|
function installedVersion(dir, root) {
|
|
2948
|
-
const pkg = findUp(dir, root,
|
|
3046
|
+
const pkg = findUp(dir, root, join10("node_modules", "tailwindcss", "package.json"));
|
|
2949
3047
|
try {
|
|
2950
3048
|
return pkg ? JSON.parse(readFileSync7(pkg, "utf8")).version : void 0;
|
|
2951
3049
|
} catch {
|
|
@@ -3007,10 +3105,10 @@ function rebuildOf(pkg, root) {
|
|
|
3007
3105
|
}
|
|
3008
3106
|
};
|
|
3009
3107
|
const escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3010
|
-
for (const file of [.../* @__PURE__ */ new Set([pkg,
|
|
3108
|
+
for (const file of [.../* @__PURE__ */ new Set([pkg, join10(root, "package.json")])]) {
|
|
3011
3109
|
const p = read4(file);
|
|
3012
3110
|
const scripts = p.scripts ?? {};
|
|
3013
|
-
const where = file && file !==
|
|
3111
|
+
const where = file && file !== join10(root, "package.json") ? ` in \`${relPath(root, dirname6(file))}\`` : "";
|
|
3014
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];
|
|
3015
3113
|
const said = (name) => {
|
|
3016
3114
|
const by = runner(name);
|
|
@@ -3018,7 +3116,7 @@ function rebuildOf(pkg, root) {
|
|
|
3018
3116
|
};
|
|
3019
3117
|
const gulpWatches = (() => {
|
|
3020
3118
|
try {
|
|
3021
|
-
return /\bwatch\s*\(/.test(readFileSync7(
|
|
3119
|
+
return /\bwatch\s*\(/.test(readFileSync7(join10(file ? dirname6(file) : root, "gulpfile.js"), "utf8"));
|
|
3022
3120
|
} catch {
|
|
3023
3121
|
return false;
|
|
3024
3122
|
}
|
|
@@ -3316,8 +3414,8 @@ function factsSection(job, root, near = []) {
|
|
|
3316
3414
|
if (tw) lines.push(...tailwindScales(tw));
|
|
3317
3415
|
else lines.push(...tokenScales(job.changeSet.tokens ?? []));
|
|
3318
3416
|
}
|
|
3319
|
-
const pkg = near.length ? nearestPackage(dirname6(
|
|
3320
|
-
const rebuild = rebuildOf(pkg ?? (tw ? nearestPackage(dirname6(
|
|
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);
|
|
3321
3419
|
if (rebuild)
|
|
3322
3420
|
add(
|
|
3323
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.`
|
|
@@ -3364,8 +3462,8 @@ function tokenScales(tokens) {
|
|
|
3364
3462
|
}
|
|
3365
3463
|
|
|
3366
3464
|
// src/locate.ts
|
|
3367
|
-
import { existsSync as
|
|
3368
|
-
import { basename as basename6, extname as
|
|
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";
|
|
3369
3467
|
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3370
3468
|
var BUDGET_MS3 = 800;
|
|
3371
3469
|
var CANDIDATE_FILES = 60;
|
|
@@ -3373,7 +3471,7 @@ var PARENT_LINES = 400;
|
|
|
3373
3471
|
var BODY_LINES = 80;
|
|
3374
3472
|
var NEAR_LINES = 30;
|
|
3375
3473
|
function searchable(cwd) {
|
|
3376
|
-
return
|
|
3474
|
+
return existsSync7(join11(cwd, "package.json")) || existsSync7(join11(cwd, ".git"));
|
|
3377
3475
|
}
|
|
3378
3476
|
var ENTITIES = {
|
|
3379
3477
|
amp: "&",
|
|
@@ -3429,11 +3527,11 @@ function needlesOf(target, url, root, rarity) {
|
|
|
3429
3527
|
route = new URL(url).pathname.split("/").map((p) => decodeURIComponent(p).replace(/\.[a-z]+$/i, "")).filter((p) => p && p !== "index");
|
|
3430
3528
|
} catch {
|
|
3431
3529
|
}
|
|
3432
|
-
const served = route.find((p) => !/[\\/]|^\.+$/.test(p) && isFolder(
|
|
3530
|
+
const served = route.find((p) => !/[\\/]|^\.+$/.test(p) && isFolder(join11(root, p)));
|
|
3433
3531
|
const otherSites = /* @__PURE__ */ new Set();
|
|
3434
3532
|
if (served) {
|
|
3435
3533
|
for (const name of safeList(root))
|
|
3436
|
-
if (name !== served && INDEX_FILES.some((f) =>
|
|
3534
|
+
if (name !== served && INDEX_FILES.some((f) => existsSync7(join11(root, name, f)))) otherSites.add(name);
|
|
3437
3535
|
}
|
|
3438
3536
|
const before = usable(target.context?.before);
|
|
3439
3537
|
const after = usable(target.context?.after);
|
|
@@ -3717,14 +3815,14 @@ function routeOf(n, rel) {
|
|
|
3717
3815
|
var INDEX_FILES = ["index.php", "index.html", "index.htm"];
|
|
3718
3816
|
var safeList = (dir) => {
|
|
3719
3817
|
try {
|
|
3720
|
-
return
|
|
3818
|
+
return readdirSync6(dir).filter((name) => !name.startsWith(".") && isFolder(join11(dir, name)));
|
|
3721
3819
|
} catch {
|
|
3722
3820
|
return [];
|
|
3723
3821
|
}
|
|
3724
3822
|
};
|
|
3725
3823
|
var isFolder = (path) => {
|
|
3726
3824
|
try {
|
|
3727
|
-
return
|
|
3825
|
+
return statSync8(path).isDirectory();
|
|
3728
3826
|
} catch {
|
|
3729
3827
|
return false;
|
|
3730
3828
|
}
|
|
@@ -3842,7 +3940,7 @@ function snippetAt(lines, index) {
|
|
|
3842
3940
|
function sourcePath(file, root) {
|
|
3843
3941
|
const rel = isAbsolute(file) ? relPath(root, file) : file.replace(/^\.\//, "");
|
|
3844
3942
|
if (rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
3845
|
-
return
|
|
3943
|
+
return existsSync7(join11(root, rel)) ? rel : null;
|
|
3846
3944
|
}
|
|
3847
3945
|
function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
|
|
3848
3946
|
if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null;
|
|
@@ -3850,7 +3948,7 @@ function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
|
|
|
3850
3948
|
`^\\s*(export\\s+(?:default\\s+)?)?(?:(?:async\\s+)?function\\s*\\*?\\s+${name}\\b|class\\s+${name}\\b|(?:const|let|var)\\s+${name}\\s*[:=])`
|
|
3851
3949
|
);
|
|
3852
3950
|
let best = null;
|
|
3853
|
-
const files = within ? [
|
|
3951
|
+
const files = within ? [join11(root, within)] : sourceFiles(root);
|
|
3854
3952
|
for (const file of files) {
|
|
3855
3953
|
if (Date.now() > deadline) break;
|
|
3856
3954
|
if (!/\.[jt]sx?$|\.mjs$/.test(file)) continue;
|
|
@@ -3886,11 +3984,11 @@ function withComponentFiles(job, root) {
|
|
|
3886
3984
|
const workspace = workspaceRoot(root);
|
|
3887
3985
|
const declared = (name) => {
|
|
3888
3986
|
const found = componentFile(name, workspace, deadline);
|
|
3889
|
-
return found ? { file: relPath(root,
|
|
3987
|
+
return found ? { file: relPath(root, join11(workspace, found.file)), line: found.line } : null;
|
|
3890
3988
|
};
|
|
3891
3989
|
const local = (file) => {
|
|
3892
|
-
const path =
|
|
3893
|
-
return
|
|
3990
|
+
const path = join11(workspace, file);
|
|
3991
|
+
return existsSync7(path) ? relPath(root, path) : file;
|
|
3894
3992
|
};
|
|
3895
3993
|
const mention = (r) => {
|
|
3896
3994
|
if (r.kind === "token") return r.source ? { ...r, source: { ...r.source, file: local(r.source.file) } } : r;
|
|
@@ -3901,8 +3999,8 @@ function withComponentFiles(job, root) {
|
|
|
3901
3999
|
}
|
|
3902
4000
|
if (r.kind !== "component") return r;
|
|
3903
4001
|
if (r.source) {
|
|
3904
|
-
const path =
|
|
3905
|
-
return
|
|
4002
|
+
const path = join11(workspace, r.source.file);
|
|
4003
|
+
return existsSync7(path) ? { ...r, source: { ...r.source, file: relPath(root, path) } } : r;
|
|
3906
4004
|
}
|
|
3907
4005
|
if (r.target?.source?.file) return { ...r, target: fill(r.target) };
|
|
3908
4006
|
const source = declared(r.name);
|
|
@@ -3952,7 +4050,7 @@ function whereSection(job, root, located = jobLocations(job, root)) {
|
|
|
3952
4050
|
for (const { target, at } of located) {
|
|
3953
4051
|
const snippet = (place) => [
|
|
3954
4052
|
"",
|
|
3955
|
-
` \`\`\`${
|
|
4053
|
+
` \`\`\`${extname6(place.file).slice(1) || "text"}`,
|
|
3956
4054
|
...place.snippet.split("\n").map((l) => ` ${l}`),
|
|
3957
4055
|
" ```"
|
|
3958
4056
|
];
|
|
@@ -4563,7 +4661,7 @@ function activityOf(bridge, jobId, every = ACTIVITY_EVERY_MS, now = Date.now) {
|
|
|
4563
4661
|
}
|
|
4564
4662
|
async function runAgent(ctx, prompt, options) {
|
|
4565
4663
|
const { cli } = ctx;
|
|
4566
|
-
if (!
|
|
4664
|
+
if (!existsSync8(ctx.bin)) return { error: `${cli.label}'s command-line tool isn't installed any more.` };
|
|
4567
4665
|
options.onOutput?.();
|
|
4568
4666
|
const run = await exec(ctx.bin, cli.args({ resume: options.resume, readDirs: [attachmentsDir()], images: options.images }), {
|
|
4569
4667
|
cwd: ctx.project,
|
|
@@ -4645,7 +4743,7 @@ function describeJob(job) {
|
|
|
4645
4743
|
return `${follow}comment on ${nameOf(request.target)}: "${latest.length > 60 ? `${latest.slice(0, 60)}\u2026` : latest}"`;
|
|
4646
4744
|
}
|
|
4647
4745
|
if (request) return `${follow}${request.kind} on ${requestTargets(request).map(nameOf).join(", ")}`;
|
|
4648
|
-
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);
|
|
4649
4747
|
return `${follow}${changes} change${changes === 1 ? "" : "s"} on ${job.changeSet.edits.map((e) => nameOf(e.target)).join(", ")}`;
|
|
4650
4748
|
}
|
|
4651
4749
|
function firstLine(text) {
|
|
@@ -4670,8 +4768,8 @@ function sleep(ms, signal) {
|
|
|
4670
4768
|
}
|
|
4671
4769
|
|
|
4672
4770
|
// src/dev.ts
|
|
4673
|
-
import { existsSync as
|
|
4674
|
-
import { dirname as dirname7, join as
|
|
4771
|
+
import { existsSync as existsSync9 } from "fs";
|
|
4772
|
+
import { dirname as dirname7, join as join12 } from "path";
|
|
4675
4773
|
var RUNNER_ENV = "USEPILOT_RUNNER";
|
|
4676
4774
|
var STARTED = /* @__PURE__ */ Symbol.for("usepilot.devRunner");
|
|
4677
4775
|
var OFF_SAID_ENV = "USEPILOT_OFF_SAID";
|
|
@@ -4738,7 +4836,7 @@ function startWithDevServer(options = {}) {
|
|
|
4738
4836
|
}
|
|
4739
4837
|
function projectFolder(dir) {
|
|
4740
4838
|
for (let d = dir; ; d = dirname7(d)) {
|
|
4741
|
-
if (
|
|
4839
|
+
if (existsSync9(join12(d, "package.json"))) return d;
|
|
4742
4840
|
if (dirname7(d) === d) return dir;
|
|
4743
4841
|
}
|
|
4744
4842
|
}
|