usepilot 0.8.0 → 0.9.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/cli/index.js CHANGED
@@ -3912,50 +3912,50 @@ var require_fast_uri = __commonJS({
3912
3912
  schemelessOptions.skipEscape = true;
3913
3913
  return serialize(resolved, schemelessOptions);
3914
3914
  }
3915
- function resolveComponent(base, relative4, options, skipNormalization) {
3915
+ function resolveComponent(base, relative5, options, skipNormalization) {
3916
3916
  const target = {};
3917
3917
  if (!skipNormalization) {
3918
3918
  base = parse3(serialize(base, options), options);
3919
- relative4 = parse3(serialize(relative4, options), options);
3919
+ relative5 = parse3(serialize(relative5, options), options);
3920
3920
  }
3921
3921
  options = options || {};
3922
- if (!options.tolerant && relative4.scheme) {
3923
- target.scheme = relative4.scheme;
3924
- target.userinfo = relative4.userinfo;
3925
- target.host = relative4.host;
3926
- target.port = relative4.port;
3927
- target.path = removeDotSegments(relative4.path || "");
3928
- target.query = relative4.query;
3922
+ if (!options.tolerant && relative5.scheme) {
3923
+ target.scheme = relative5.scheme;
3924
+ target.userinfo = relative5.userinfo;
3925
+ target.host = relative5.host;
3926
+ target.port = relative5.port;
3927
+ target.path = removeDotSegments(relative5.path || "");
3928
+ target.query = relative5.query;
3929
3929
  } else {
3930
- if (relative4.userinfo !== void 0 || relative4.host !== void 0 || relative4.port !== void 0) {
3931
- target.userinfo = relative4.userinfo;
3932
- target.host = relative4.host;
3933
- target.port = relative4.port;
3934
- target.path = removeDotSegments(relative4.path || "");
3935
- target.query = relative4.query;
3930
+ if (relative5.userinfo !== void 0 || relative5.host !== void 0 || relative5.port !== void 0) {
3931
+ target.userinfo = relative5.userinfo;
3932
+ target.host = relative5.host;
3933
+ target.port = relative5.port;
3934
+ target.path = removeDotSegments(relative5.path || "");
3935
+ target.query = relative5.query;
3936
3936
  } else {
3937
- if (!relative4.path) {
3937
+ if (!relative5.path) {
3938
3938
  target.path = base.path;
3939
- if (relative4.query !== void 0) {
3940
- target.query = relative4.query;
3939
+ if (relative5.query !== void 0) {
3940
+ target.query = relative5.query;
3941
3941
  } else {
3942
3942
  target.query = base.query;
3943
3943
  }
3944
3944
  } else {
3945
- if (relative4.path[0] === "/") {
3946
- target.path = removeDotSegments(relative4.path);
3945
+ if (relative5.path[0] === "/") {
3946
+ target.path = removeDotSegments(relative5.path);
3947
3947
  } else {
3948
3948
  const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
3949
3949
  if (baseHasAuthority && !base.path) {
3950
- target.path = "/" + relative4.path;
3950
+ target.path = "/" + relative5.path;
3951
3951
  } else if (!base.path) {
3952
- target.path = relative4.path;
3952
+ target.path = relative5.path;
3953
3953
  } else {
3954
- target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative4.path;
3954
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative5.path;
3955
3955
  }
3956
3956
  target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
3957
3957
  }
3958
- target.query = relative4.query;
3958
+ target.query = relative5.query;
3959
3959
  }
3960
3960
  target.userinfo = base.userinfo;
3961
3961
  target.host = base.host;
@@ -3963,7 +3963,7 @@ var require_fast_uri = __commonJS({
3963
3963
  }
3964
3964
  target.scheme = base.scheme;
3965
3965
  }
3966
- target.fragment = relative4.fragment;
3966
+ target.fragment = relative5.fragment;
3967
3967
  return target;
3968
3968
  }
3969
3969
  function equal(uriA, uriB, options) {
@@ -26761,21 +26761,21 @@ function visit(schema, fnOrHandlers) {
26761
26761
  const h = fnOrHandlers[node2._zod.def.type];
26762
26762
  return h ? h(node2, rewritten) : node2;
26763
26763
  };
26764
- const cache2 = /* @__PURE__ */ new Map();
26764
+ const cache3 = /* @__PURE__ */ new Map();
26765
26765
  function run(s) {
26766
- const cached2 = cache2.get(s);
26766
+ const cached2 = cache3.get(s);
26767
26767
  if (cached2 === RESOLVING) {
26768
26768
  return new $ZodLazy({
26769
26769
  type: "lazy",
26770
- getter: () => cache2.get(s)
26770
+ getter: () => cache3.get(s)
26771
26771
  });
26772
26772
  }
26773
26773
  if (cached2 !== void 0)
26774
26774
  return cached2;
26775
- cache2.set(s, RESOLVING);
26775
+ cache3.set(s, RESOLVING);
26776
26776
  const inner = mapInner(s);
26777
26777
  const mapped = fn(inner, inner !== s);
26778
- cache2.set(s, mapped);
26778
+ cache3.set(s, mapped);
26779
26779
  return mapped;
26780
26780
  }
26781
26781
  function mapInner(s) {
@@ -28613,8 +28613,8 @@ var StdioServerTransport = class {
28613
28613
 
28614
28614
  // src/mcp.ts
28615
28615
  import { randomUUID as randomUUID2 } from "crypto";
28616
- import { existsSync as existsSync5 } from "fs";
28617
- import { basename as basename3, isAbsolute as isAbsolute2, resolve } from "path";
28616
+ import { existsSync as existsSync6 } from "fs";
28617
+ import { basename as basename4, isAbsolute as isAbsolute2, resolve } from "path";
28618
28618
  import { fileURLToPath } from "url";
28619
28619
 
28620
28620
  // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v3/helpers/util.js
@@ -36662,8 +36662,9 @@ var EMPTY_COMPLETION_RESULT = {
36662
36662
  };
36663
36663
 
36664
36664
  // ../protocol/src/types.ts
36665
- var DOM_REMOVE = "dom:remove";
36666
- var DOM_INSERT = "dom:insert:";
36665
+ function mentionText(reference) {
36666
+ return reference.kind === "token" ? reference.name : `@${reference.name}`;
36667
+ }
36667
36668
  var ATTACHMENT_TYPES = {
36668
36669
  png: "image/png",
36669
36670
  jpg: "image/jpeg",
@@ -36704,7 +36705,8 @@ function requestTargets(request) {
36704
36705
  function formatPrompt(changeSet, options = {}) {
36705
36706
  if (changeSet.request?.kind === "responsive") return formatResponsive(changeSet, changeSet.request);
36706
36707
  if (changeSet.request?.kind === "break-and-fix") return formatBreakFix(changeSet, changeSet.request);
36707
- if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request);
36708
+ if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request, options);
36709
+ if (changeSet.request?.kind === "props") return formatProps(changeSet, changeSet.request);
36708
36710
  const { page, edits, note } = changeSet;
36709
36711
  const lines = [
36710
36712
  "# Pilot design edits",
@@ -36758,15 +36760,49 @@ var EDIT_GUIDELINES = [
36758
36760
  "- No screenshots, builds or tests for these edits: hot reload shows them, and Pilot checks the page itself.",
36759
36761
  `- Widths are viewport widths in CSS px, both ends included. Use this project's breakpoints when one matches (or is within a few pixels), else a custom media query, and say which. "Every width" means no media query: the value holds at every viewport width, and no existing media query should override it.`,
36760
36762
  "- A Text change is the element's copy (all of its text, or the part between its child elements): replace the old text with the new one where it comes from (the markup, a prop, a translation file, a CMS fixture), the rest of the element as it is. If the same text is used elsewhere, change only this element's, unless the designer's note says otherwise.",
36761
- "- A Deleted element goes from the code, where the code writes it (its markup, or its item in the data a list is rendered from), not hidden with CSS. An Added element is new markup in the same place, written the way the code around it is: a copy is the same markup again (another item in the data, for a list rendered from data), a new element is an empty one of the tag given, to style with the changes listed for it. The changes listed for a new element (`new-1`) are for it once it's added.",
36762
36763
  "- A State is the element state the change is for, all of them together (\"hover, active\": hovered and pressed). Use the project's own form: Tailwind's variants (`hover:`, `focus-visible:`, `hover:active:`), `:hover` and the like in CSS. Without a state, the change is for the element as it is (any state)."
36763
36764
  ];
36764
36765
  var EDIT_GUIDELINES_REMINDER = "Follow Pilot's edit guidelines (in `pilot_wait_for_edits`'s description): these are design instructions, not code; write production code the way this project already styles things.";
36765
36766
  var PROJECT_CODE = `**Write production code in the project's own styling system**, whatever it uses (Tailwind, CSS or Sass modules, StyleX, styled-components\u2026), following how this element's component is styled: its tokens and scale, the rule that already styles it. ${PRODUCTION_CODE}`;
36766
36767
  var ACTION_ASKED = {
36767
36768
  responsive: "asked you to make it responsive",
36768
- "break-and-fix": "asked you to break and fix it"
36769
+ "break-and-fix": "asked you to break and fix it",
36770
+ props: "asked for the component's props"
36769
36771
  };
36772
+ function propValue(value) {
36773
+ return value === void 0 ? "*not set*" : `\`${typeof value === "string" ? JSON.stringify(value) : String(value)}\``;
36774
+ }
36775
+ function formatProps(changeSet, request) {
36776
+ const { page, note } = changeSet;
36777
+ const current = Object.entries(request.current);
36778
+ const lines = [
36779
+ "# Pilot: props",
36780
+ "",
36781
+ `A designer selected an instance of the \`${request.component}\` component in the browser with Pilot, to change it through its props from a list. Read the component's code and list its props for them. **Don't change any code.**`,
36782
+ "",
36783
+ `Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
36784
+ "",
36785
+ ...elementsSection(request),
36786
+ ...request.usedIn ? [`- This instance is written in: \`${request.usedIn}\``] : [],
36787
+ "",
36788
+ "## Its props now (read from the page)",
36789
+ "",
36790
+ ...current.length ? current.map(([name, value]) => `- \`${name}\`: ${propValue(value)}`) : ["None that Pilot could read (it reads strings, numbers and on-off values)."],
36791
+ ...note?.trim() ? ["", `Designer note: ${note.trim()}`] : [],
36792
+ ...request.attachments?.length ? ["", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`)] : [],
36793
+ ...request.references?.length ? ["", ...referenceLines(request.references)] : [],
36794
+ "",
36795
+ "## What to list",
36796
+ "",
36797
+ "- **The props that change how it looks or what it shows:** variants, sizes, tones, on-off flags (`disabled`, `loading`), short texts (a label, a title), numbers (a count). Not event handlers, refs, children, class names or styles.",
36798
+ '- **For each:** `name`; `type`: `options` (one of a set of values), `boolean`, `text` or `number`; for `options`, every value it accepts, from its types (a union like `"primary" | "ghost"`), its variants config (cva, tailwind-variants, a variants object), its prop validation (a Vue `validator`, `PropTypes.oneOf`), or how the component uses it; `default` when it has one; `description` in a few words when the name doesn\'t say.',
36799
+ "- The most useful first (the main variant, then the size, then the rest); 12 at most.",
36800
+ "",
36801
+ "Call `pilot_done` with this job's id, the list in `props`, and notes: one short sentence for the designer, like a chat message (\"Button has 3 props you can change\"). Pilot shows the props in the designer's thread, each with its value on this instance; what they pick comes back to you as a comment, a `name: value` line per prop (`tone: dark`), to set where this instance is written. If none is worth listing, say so in the notes and leave `props` out."
36802
+ ];
36803
+ return `${lines.join("\n")}
36804
+ `;
36805
+ }
36770
36806
  function formatBreakFix(changeSet, request) {
36771
36807
  const { page, note } = changeSet;
36772
36808
  const { breakpoints } = request;
@@ -36785,6 +36821,7 @@ function formatBreakFix(changeSet, request) {
36785
36821
  if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
36786
36822
  if (request.attachments?.length)
36787
36823
  lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
36824
+ if (request.references?.length) lines.push("", ...referenceLines(request.references));
36788
36825
  lines.push(
36789
36826
  "",
36790
36827
  ...elementsSection(request),
@@ -36829,6 +36866,7 @@ function formatResponsive(changeSet, request) {
36829
36866
  if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
36830
36867
  if (request.attachments?.length)
36831
36868
  lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
36869
+ if (request.references?.length) lines.push("", ...referenceLines(request.references));
36832
36870
  lines.push(
36833
36871
  "",
36834
36872
  ...elementsSection(request),
@@ -36851,8 +36889,8 @@ function formatResponsive(changeSet, request) {
36851
36889
  return `${lines.join("\n")}
36852
36890
  `;
36853
36891
  }
36854
- function formatComment(changeSet, request) {
36855
- const { page } = changeSet;
36892
+ function formatComment(changeSet, request, options = {}) {
36893
+ const { page, edits } = changeSet;
36856
36894
  const { thread, breakpoints } = request;
36857
36895
  const several = requestTargets(request).length;
36858
36896
  const latest = thread.at(-1);
@@ -36870,8 +36908,33 @@ function formatComment(changeSet, request) {
36870
36908
  "",
36871
36909
  "## The comment",
36872
36910
  "",
36873
- ...commentLines(latest)
36911
+ // Props set from the thread, with no words: the props are the comment.
36912
+ ...latest?.props && !latest.text.trim() && !latest.attachments?.length ? ["The designer set props on this instance (below), with no words."] : commentLines(latest)
36874
36913
  ];
36914
+ if (latest?.props?.set.length) {
36915
+ const { component, usedIn, set: set2 } = latest.props;
36916
+ lines.push(
36917
+ "",
36918
+ "## Props to set",
36919
+ "",
36920
+ `The designer picked new values for this \`${component}\` instance's props from the list you gave (the \`name: value\` lines in their comment):`,
36921
+ "",
36922
+ ...set2.map((c) => `- \`${c.name}\`: ${propValue(c.from)} \u2192 ${propValue(c.to)}`),
36923
+ "",
36924
+ `Set them where this instance is written${usedIn ? ` (\`${usedIn}\`, its \`<${component} \u2026>\`)` : ` (its \`<${component} \u2026>\`)`}, not in the component itself: only this instance changes. If that line renders several instances (a loop over data) or the value comes from data or a variable, ask with \`pilot_done\`'s question and choices before changing it for all of them. Pilot reads the instance's props on the page when you're done.`
36925
+ );
36926
+ }
36927
+ if (edits.length) {
36928
+ lines.push(
36929
+ "",
36930
+ "## The designer's edits, sent with the comment",
36931
+ "",
36932
+ `Before writing it, the designer changed these in Pilot's editor: apply them too, exactly, as design edits. The comment may be about them ("like this, on mobile too"). Pilot checks them on the page when you're done.`,
36933
+ "",
36934
+ ...options.guidelines === false ? [EDIT_GUIDELINES_REMINDER] : ["Guidelines:", ...EDIT_GUIDELINES]
36935
+ );
36936
+ edits.forEach((edit, index) => lines.push("", ...formatEdit(edit, index + 1).map((l) => l.startsWith("## ") ? `#${l}` : l)));
36937
+ }
36875
36938
  if (earlier.length) {
36876
36939
  lines.push("", "## The thread so far (you already did what it asked)", "");
36877
36940
  for (const m of earlier) {
@@ -36900,6 +36963,8 @@ function commentLines(message) {
36900
36963
  const text = message?.text.trim() ?? "";
36901
36964
  const files = message?.attachments ?? [];
36902
36965
  const out = text ? [quote(text)] : [];
36966
+ const references = message?.references ?? [];
36967
+ if (references.length) out.push("", ...referenceLines(references));
36903
36968
  if (!files.length) return out.length ? out : ["> (empty)"];
36904
36969
  const one = files.length === 1;
36905
36970
  if (out.length) out.push("");
@@ -36910,6 +36975,30 @@ function commentLines(message) {
36910
36975
  );
36911
36976
  return out;
36912
36977
  }
36978
+ function referenceLines(references) {
36979
+ const picked = references.some((r) => r.kind !== "unlisted");
36980
+ return [
36981
+ picked ? "What it mentions with `@`, each as it reads in the comment (the ones picked from Pilot's list are exact: use them, don't look for others):" : "What it mentions with `@`, as it reads in the comment:",
36982
+ "",
36983
+ ...references.map(referenceLine)
36984
+ ];
36985
+ }
36986
+ function referenceLine(reference) {
36987
+ const as = `- \`${mentionText(reference)}\`:`;
36988
+ if (reference.kind === "token")
36989
+ return `${as} a design token (a CSS variable on the page), now \`${reference.value}\`. Use this token (\`var(${reference.name})\`, or the project's form of it).`;
36990
+ if (reference.kind === "unlisted")
36991
+ return `${as} a name the designer typed that Pilot didn't find on the page or among the project's components: probably a component or a part of the page. Search the project for \`${reference.name}\`, and ask in your reply if it's unclear what it is.`;
36992
+ if (reference.kind === "component") {
36993
+ const t = reference.target;
36994
+ const source = reference.source ?? (t?.source?.file ? { file: t.source.file, line: t.source.line } : void 0);
36995
+ const where = source ? `, declared in \`${source.file}${source.line ? `:${source.line}` : ""}\`` : `; find its declaration (\`function ${reference.name}\`, \`const ${reference.name} =\`, \`class ${reference.name}\`, or a \`${reference.name}.vue\` or \`.svelte\` file)`;
36996
+ return t ? `${as} the \`${reference.name}\` component${where}; one of its instances on the page: \`${t.selector}\`.` : `${as} the \`${reference.name}\` component${where}. It isn't on this page.`;
36997
+ }
36998
+ const el = reference.target;
36999
+ const component = el.source?.component ? `, inside the \`${el.source.component}\` component` : "";
37000
+ return `${as} an element on the page: \`${el.path}\`, selector \`${el.selector}\`${el.text ? `, text "${el.text}"` : ""}${component}.`;
37001
+ }
36913
37002
  function attachmentLines(files, intro) {
36914
37003
  const lines = files.map((file2) => {
36915
37004
  const kind = attachmentKind(file2.id);
@@ -36947,15 +37036,8 @@ function targetLines(target) {
36947
37036
  return out;
36948
37037
  }
36949
37038
  function formatEdit(edit, n) {
36950
- const { target, changes, texts, removed, inserts, newElement } = edit;
36951
- const out = newElement ? [
36952
- `## ${n}. \`${target.path}\` (in new element \`${newElement}\`)`,
36953
- "",
36954
- `- Not in the code yet: new element \`${newElement}\` is added in this job (or was in an earlier one); this is it or one of its children.`,
36955
- ...target.text ? [`- Text: "${target.text}"`] : []
36956
- ] : [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
36957
- if (removed) out.push("", "**Deleted**: remove this element from the code.");
36958
- if (inserts?.length) out.push("", "Added:", "", ...inserts.map(insertLine));
37039
+ const { target, changes, texts } = edit;
37040
+ const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
36959
37041
  if (texts?.length) out.push("", "Text (from \u2192 to):", "", ...texts.map((t) => `- ${JSON.stringify(t.from)} \u2192 ${JSON.stringify(t.to)}`));
36960
37042
  if (!changes.length) return out;
36961
37043
  const withStates = changes.some((c) => c.states?.length);
@@ -36974,11 +37056,6 @@ function formatEdit(edit, n) {
36974
37056
  if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
36975
37057
  return out;
36976
37058
  }
36977
- function insertLine(insert) {
36978
- const where = insert.place === "after" ? "Right after this element" : "Inside this element, as its last child";
36979
- const what = insert.kind === "copy" ? "a copy of this element as the page shows it (its children too)" : `a new empty \`${insert.tag}\``;
36980
- return `- ${where}: ${what}, new element \`${insert.id}\``;
36981
- }
36982
37059
  function describeStates(states) {
36983
37060
  return states?.length ? states.join(", ") : "\u2014";
36984
37061
  }
@@ -37033,7 +37110,7 @@ function formatWidthCheck(check2) {
37033
37110
  }
37034
37111
 
37035
37112
  // ../protocol/src/bridge.ts
37036
- var BRIDGE_VERSION = 4;
37113
+ var BRIDGE_VERSION = 5;
37037
37114
  var DEFAULT_BRIDGE_PORT = 4747 + BRIDGE_VERSION;
37038
37115
  var MAX_CHOICES = 4;
37039
37116
  function questionOf(value) {
@@ -37042,6 +37119,28 @@ function questionOf(value) {
37042
37119
  const choices = (Array.isArray(q.choices) ? q.choices : []).filter((c) => typeof c === "string").map((c) => c.trim().slice(0, 60)).filter(Boolean).slice(0, MAX_CHOICES);
37043
37120
  return { text: q.text.trim().slice(0, 500), ...choices.length ? { choices } : {} };
37044
37121
  }
37122
+ var MAX_PROPS = 20;
37123
+ function propsOf(value) {
37124
+ if (!Array.isArray(value)) return void 0;
37125
+ const scalar = (v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean";
37126
+ const props = value.flatMap((p) => {
37127
+ const name = typeof p?.name === "string" ? p.name.trim().slice(0, 60) : "";
37128
+ const type = ["options", "boolean", "text", "number"].includes(p?.type) ? p.type : null;
37129
+ if (!name || !type) return [];
37130
+ const options = Array.isArray(p.options) ? [...new Set(p.options.filter(scalar).map(String))].slice(0, 30) : [];
37131
+ if (type === "options" && !options.length) return [];
37132
+ return [
37133
+ {
37134
+ name,
37135
+ type,
37136
+ ...type === "options" ? { options } : {},
37137
+ ...scalar(p.default) ? { default: p.default } : {},
37138
+ ...typeof p.description === "string" && p.description.trim() ? { description: p.description.trim().slice(0, 120) } : {}
37139
+ }
37140
+ ];
37141
+ });
37142
+ return props.length ? props.slice(0, MAX_PROPS) : void 0;
37143
+ }
37045
37144
  function originOf(url2) {
37046
37145
  try {
37047
37146
  const u = new URL(url2.includes("://") ? url2 : `http://${url2}`);
@@ -37173,6 +37272,140 @@ async function sweepAttachments(dir = attachmentsDir(), now = Date.now()) {
37173
37272
  }
37174
37273
  }
37175
37274
 
37275
+ // src/components.ts
37276
+ import { existsSync as existsSync2, readdirSync, readFileSync, statSync } from "fs";
37277
+ import { basename as basename2, dirname as dirname2, extname, join as join2, relative } from "path";
37278
+ var SKIP = /* @__PURE__ */ new Set([
37279
+ "node_modules",
37280
+ "dist",
37281
+ "build",
37282
+ "out",
37283
+ "coverage",
37284
+ "vendor",
37285
+ ".git",
37286
+ ".next",
37287
+ ".nuxt",
37288
+ ".svelte-kit",
37289
+ ".output",
37290
+ ".vercel",
37291
+ ".turbo",
37292
+ ".cache",
37293
+ "storybook-static",
37294
+ "__tests__",
37295
+ "__mocks__"
37296
+ ]);
37297
+ var EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx", ".js", ".vue", ".svelte"]);
37298
+ var NOT_COMPONENTS = /\.(test|spec|stories|story|d)\.[jt]sx?$/;
37299
+ var ROUTE_FILES = /^(page|layout|template|loading|error|not-found|default|route|_app|_document)\.[jt]sx?$/;
37300
+ var MAX_FILES = 8e3;
37301
+ var MAX_FILE_BYTES = 512e3;
37302
+ var BUDGET_MS = 1500;
37303
+ var cache = /* @__PURE__ */ new Map();
37304
+ function projectComponents(folders) {
37305
+ const roots = [...new Set(folders.map(workspaceRoot))];
37306
+ const out = [];
37307
+ const seen = /* @__PURE__ */ new Set();
37308
+ const deadline = Date.now() + BUDGET_MS;
37309
+ for (const root of roots) {
37310
+ for (const c of scan(root, deadline)) {
37311
+ const key = `${c.name} ${c.file}`;
37312
+ if (!seen.has(key)) {
37313
+ seen.add(key);
37314
+ out.push(c);
37315
+ }
37316
+ }
37317
+ }
37318
+ return out;
37319
+ }
37320
+ function workspaceRoot(folder) {
37321
+ let dir = folder;
37322
+ for (; ; ) {
37323
+ if (isWorkspace(dir)) return dir;
37324
+ const parent = dirname2(dir);
37325
+ if (existsSync2(join2(dir, ".git")) || parent === dir) return folder;
37326
+ dir = parent;
37327
+ }
37328
+ }
37329
+ function isWorkspace(dir) {
37330
+ if (["pnpm-workspace.yaml", "lerna.json", "nx.json", "turbo.json"].some((f) => existsSync2(join2(dir, f)))) return true;
37331
+ try {
37332
+ return "workspaces" in JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
37333
+ } catch {
37334
+ return false;
37335
+ }
37336
+ }
37337
+ function scan(root, deadline) {
37338
+ const known = cache.get(root) ?? /* @__PURE__ */ new Map();
37339
+ const now = /* @__PURE__ */ new Map();
37340
+ const out = [];
37341
+ const walk = (dir) => {
37342
+ let entries;
37343
+ try {
37344
+ entries = readdirSync(dir, { withFileTypes: true });
37345
+ } catch {
37346
+ return;
37347
+ }
37348
+ for (const entry of entries) {
37349
+ if (now.size >= MAX_FILES || Date.now() > deadline) return;
37350
+ const name = entry.name;
37351
+ if (SKIP.has(name) || name.startsWith(".")) continue;
37352
+ const path = join2(dir, name);
37353
+ if (entry.isDirectory()) {
37354
+ walk(path);
37355
+ continue;
37356
+ }
37357
+ if (!entry.isFile() || !EXTENSIONS.has(extname(name)) || NOT_COMPONENTS.test(name) || ROUTE_FILES.test(name)) continue;
37358
+ let stat2;
37359
+ try {
37360
+ stat2 = statSync(path);
37361
+ } catch {
37362
+ continue;
37363
+ }
37364
+ if (stat2.size > MAX_FILE_BYTES) continue;
37365
+ const before = known.get(path);
37366
+ const cached2 = before && before.mtime === stat2.mtimeMs ? before : { mtime: stat2.mtimeMs, components: read(path) };
37367
+ now.set(path, cached2);
37368
+ const file2 = relative(root, path);
37369
+ for (const c of cached2.components) out.push({ name: c.name, file: file2, line: c.line });
37370
+ }
37371
+ };
37372
+ walk(root);
37373
+ cache.set(root, now);
37374
+ return out;
37375
+ }
37376
+ function fileComponentName(path) {
37377
+ return basename2(path, extname(path)).split(/[-_.\s]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join("");
37378
+ }
37379
+ var NAME = "[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*";
37380
+ var FUNCTION = new RegExp(`^\\s*(export\\s+)?(?:default\\s+)?(?:async\\s+)?function\\s+(${NAME})\\b`);
37381
+ var CONSTANT = new RegExp(`^\\s*(export\\s+)?(?:const|let|var)\\s+(${NAME})\\s*(?::[^=]+)?=\\s*(.*)$`);
37382
+ var COMPONENT_VALUE = /^(?:\(|async\s*\(|function\b|[A-Za-z_$][\w$]*\s*=>|(?:React\.)?(?:forwardRef|memo|lazy)\b|styled[.(]|defineComponent\b|component\$)/;
37383
+ function read(path) {
37384
+ const ext = extname(path);
37385
+ if (ext === ".vue" || ext === ".svelte") return [{ name: fileComponentName(path), line: 1 }];
37386
+ let source;
37387
+ try {
37388
+ source = readFileSync(path, "utf8");
37389
+ } catch {
37390
+ return [];
37391
+ }
37392
+ if (!/<[A-Za-z]|styled[.(]/.test(source)) return [];
37393
+ const found = [];
37394
+ const lines = source.split("\n");
37395
+ for (let i = 0; i < lines.length; i++) {
37396
+ const line = lines[i];
37397
+ const fn = FUNCTION.exec(line);
37398
+ const constant = fn ? null : CONSTANT.exec(line);
37399
+ const m = fn ?? constant;
37400
+ if (!m) continue;
37401
+ const name = m[2];
37402
+ if (constant && !COMPONENT_VALUE.test((constant[3] ?? "").trim())) continue;
37403
+ const exported = !!m[1] || new RegExp(`export\\s+default\\s+${name}\\b|export\\s*\\{[^}]*\\b${name}\\b[^}]*\\}`).test(source);
37404
+ if (exported && !found.some((f) => f.name === name)) found.push({ name, line: i + 1 });
37405
+ }
37406
+ return found;
37407
+ }
37408
+
37176
37409
  // src/hub.ts
37177
37410
  import { randomUUID } from "crypto";
37178
37411
  var AGENT_TTL = 3e4;
@@ -37191,7 +37424,8 @@ var Hub = class {
37191
37424
  register(info, origin) {
37192
37425
  const key = originKey(origin);
37193
37426
  const known = this.agents.get(info.id);
37194
- this.agents.set(info.id, { info, origin: key, seen: this.now() });
37427
+ const { folder, ...shown } = info;
37428
+ this.agents.set(info.id, { info: shown, origin: key, seen: this.now(), folder: folder ?? known?.folder });
37195
37429
  if (!known || known.origin !== key) {
37196
37430
  if (known) this.notifyAgents(known.origin);
37197
37431
  this.notifyAgents(key);
@@ -37213,6 +37447,15 @@ var Hub = class {
37213
37447
  this.notifyAgents(agent.origin);
37214
37448
  this.dispatch(agent.origin);
37215
37449
  }
37450
+ /** An agent's info as pages see it (no folder). */
37451
+ shown(info) {
37452
+ return this.agents.get(info.id)?.info ?? { id: info.id, label: info.label };
37453
+ }
37454
+ /** The project folders of the agents working on pages of `origin`: where its components are read from. */
37455
+ folders(origin) {
37456
+ const key = originKey(origin);
37457
+ return [...new Set([...this.agents.values()].filter((a) => a.origin === key && a.folder).map((a) => a.folder))];
37458
+ }
37216
37459
  /** Drops agents not heard from in AGENT_TTL (`keep`: the ones in this process, always alive). */
37217
37460
  sweep(keep = /* @__PURE__ */ new Set()) {
37218
37461
  const cutoff = this.now() - AGENT_TTL;
@@ -37223,7 +37466,7 @@ var Hub = class {
37223
37466
  /** An agent ran /pilot: registers it and tells the open pages of `origin` to launch Pilot. Returns how many pages got it. */
37224
37467
  launch(info, origin) {
37225
37468
  this.register(info, origin);
37226
- return this.sendTo(originKey(origin), { type: "launch", agent: info });
37469
+ return this.sendTo(originKey(origin), { type: "launch", agent: this.shown(info) });
37227
37470
  }
37228
37471
  /**
37229
37472
  * The agent's next job for its origin: the oldest queued one right away, or
@@ -37234,7 +37477,7 @@ var Hub = class {
37234
37477
  this.register(info, origin);
37235
37478
  const key = originKey(origin);
37236
37479
  const queued = this.oldestQueued(key);
37237
- if (queued) return Promise.resolve({ job: this.take(queued, info) });
37480
+ if (queued) return Promise.resolve({ job: this.take(queued, this.shown(info)) });
37238
37481
  return new Promise((resolve2) => {
37239
37482
  const waiter = {
37240
37483
  agentId: info.id,
@@ -37258,12 +37501,20 @@ var Hub = class {
37258
37501
  * the answer, see answer). A job asks once: a question on an answered job
37259
37502
  * is dropped. Null for a job the hub doesn't know.
37260
37503
  */
37261
- done(agentId, jobId, notes, question) {
37504
+ done(agentId, jobId, notes, question, props) {
37262
37505
  const job = this.jobs.get(jobId);
37263
37506
  if (!job || job.status === "cancelled") return null;
37264
37507
  const agent = this.agents.get(agentId)?.info ?? job.agent;
37265
37508
  const asks = question && !job.answer ? { question } : {};
37266
- this.update(job, { status: "done", agent, notes: notes?.trim() || void 0, doneAt: new Date(this.now()).toISOString(), ...asks });
37509
+ const listed = props?.length && job.changeSet.request?.kind === "props" ? { props } : {};
37510
+ this.update(job, {
37511
+ status: "done",
37512
+ agent,
37513
+ notes: notes?.trim() || void 0,
37514
+ doneAt: new Date(this.now()).toISOString(),
37515
+ ...asks,
37516
+ ...listed
37517
+ });
37267
37518
  return job;
37268
37519
  }
37269
37520
  /**
@@ -37482,6 +37733,7 @@ async function handle(hub, req, res, attachments) {
37482
37733
  if (path === "/events" && req.method === "GET") return events(hub, origin, req, res);
37483
37734
  if (req.method !== "POST") return json2(res, 405, { error: "POST only" });
37484
37735
  if (!hub.hasAgents(origin)) return json2(res, 403, { error: "no agent works on this page: run /pilot in your agent" });
37736
+ if (path === "/components") return json2(res, 200, { components: projectComponents(hub.folders(origin)) });
37485
37737
  if (path === "/attachments") {
37486
37738
  const type = req.headers["content-type"] ?? "";
37487
37739
  if (!extensionOf(type)) return json2(res, 415, { error: "images (png, jpeg, gif, webp), text files (txt, md, csv, json) and PDFs only" });
@@ -37555,7 +37807,7 @@ async function handleAgent(hub, action, data, req, res) {
37555
37807
  }
37556
37808
  case "done":
37557
37809
  if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
37558
- return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes, questionOf(d.question)) });
37810
+ return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes, questionOf(d.question), propsOf(d.props)) });
37559
37811
  case "check": {
37560
37812
  if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
37561
37813
  const check2 = await hub.check(d.jobId, Math.min(d.timeoutMs ?? CHECK_TIMEOUT, 2 * 6e4));
@@ -37636,8 +37888,8 @@ var LocalApi = class {
37636
37888
  localAgents.add(agent.id);
37637
37889
  return this.hub.wait(agent, origin, timeoutMs, signal);
37638
37890
  }
37639
- async done(agent, jobId, notes, question) {
37640
- return this.hub.done(agent.id, jobId, notes, question);
37891
+ async done(agent, jobId, notes, question, props) {
37892
+ return this.hub.done(agent.id, jobId, notes, question, props);
37641
37893
  }
37642
37894
  check(_agent, jobId, timeoutMs) {
37643
37895
  return this.hub.check(jobId, timeoutMs);
@@ -37671,8 +37923,8 @@ var RemoteApi = class {
37671
37923
  wait(agent, origin, timeoutMs, signal) {
37672
37924
  return this.post("wait", { agent, origin, timeoutMs }, signal);
37673
37925
  }
37674
- async done(agent, jobId, notes, question) {
37675
- return (await this.post("done", { agent, jobId, notes, question })).job;
37926
+ async done(agent, jobId, notes, question, props) {
37927
+ return (await this.post("done", { agent, jobId, notes, question, props })).job;
37676
37928
  }
37677
37929
  async check(agent, jobId, timeoutMs) {
37678
37930
  return (await this.post("check", { agent, jobId, timeoutMs })).check;
@@ -37720,8 +37972,8 @@ var Bridge = class {
37720
37972
  }
37721
37973
  }
37722
37974
  }
37723
- done(jobId, notes, question) {
37724
- return this.call((api) => api.done(this.agent, jobId, notes, question));
37975
+ done(jobId, notes, question, props) {
37976
+ return this.call((api) => api.done(this.agent, jobId, notes, question, props));
37725
37977
  }
37726
37978
  /** Pilot's width check of a task's element, measured by the page (null: no page answered). */
37727
37979
  check(jobId, timeoutMs = CHECK_TIMEOUT) {
@@ -37813,9 +38065,9 @@ function isConnectionError(error62) {
37813
38065
  }
37814
38066
 
37815
38067
  // src/locate.ts
37816
- import { existsSync as existsSync2, readdirSync, readFileSync, statSync } from "fs";
37817
- import { basename as basename2, extname, isAbsolute, join as join2, relative } from "path";
37818
- var SKIP = /* @__PURE__ */ new Set([
38068
+ import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
38069
+ import { basename as basename3, extname as extname2, isAbsolute, join as join3, relative as relative2 } from "path";
38070
+ var SKIP2 = /* @__PURE__ */ new Set([
37819
38071
  "node_modules",
37820
38072
  "dist",
37821
38073
  "build",
@@ -37831,7 +38083,7 @@ var SKIP = /* @__PURE__ */ new Set([
37831
38083
  ".turbo",
37832
38084
  ".cache"
37833
38085
  ]);
37834
- var EXTENSIONS = /* @__PURE__ */ new Set([
38086
+ var EXTENSIONS2 = /* @__PURE__ */ new Set([
37835
38087
  ".html",
37836
38088
  ".htm",
37837
38089
  ".jsx",
@@ -37850,40 +38102,40 @@ var EXTENSIONS = /* @__PURE__ */ new Set([
37850
38102
  ".liquid",
37851
38103
  ".twig"
37852
38104
  ]);
37853
- var MAX_FILES = 4e3;
37854
- var MAX_FILE_BYTES = 512e3;
37855
- var BUDGET_MS = 800;
37856
- var cache = null;
38105
+ var MAX_FILES2 = 4e3;
38106
+ var MAX_FILE_BYTES2 = 512e3;
38107
+ var BUDGET_MS2 = 800;
38108
+ var cache2 = null;
37857
38109
  function sourceFiles(root) {
37858
- if (cache && cache.root === root && Date.now() - cache.at < 3e4) return cache.files;
38110
+ if (cache2 && cache2.root === root && Date.now() - cache2.at < 3e4) return cache2.files;
37859
38111
  const files = [];
37860
38112
  const walk = (dir) => {
37861
38113
  let names;
37862
38114
  try {
37863
- names = readdirSync(dir);
38115
+ names = readdirSync2(dir);
37864
38116
  } catch {
37865
38117
  return;
37866
38118
  }
37867
38119
  for (const name of names) {
37868
- if (files.length >= MAX_FILES) return;
37869
- if (SKIP.has(name) || name.startsWith(".") && name !== ".") continue;
37870
- const path = join2(dir, name);
38120
+ if (files.length >= MAX_FILES2) return;
38121
+ if (SKIP2.has(name) || name.startsWith(".") && name !== ".") continue;
38122
+ const path = join3(dir, name);
37871
38123
  let stat2;
37872
38124
  try {
37873
- stat2 = statSync(path);
38125
+ stat2 = statSync2(path);
37874
38126
  } catch {
37875
38127
  continue;
37876
38128
  }
37877
38129
  if (stat2.isDirectory()) walk(path);
37878
- else if (EXTENSIONS.has(extname(name)) && stat2.size <= MAX_FILE_BYTES) files.push(path);
38130
+ else if (EXTENSIONS2.has(extname2(name)) && stat2.size <= MAX_FILE_BYTES2) files.push(path);
37879
38131
  }
37880
38132
  };
37881
38133
  walk(root);
37882
- cache = { root, at: Date.now(), files };
38134
+ cache2 = { root, at: Date.now(), files };
37883
38135
  return files;
37884
38136
  }
37885
38137
  function searchable(cwd) {
37886
- return existsSync2(join2(cwd, "package.json")) || existsSync2(join2(cwd, ".git"));
38138
+ return existsSync3(join3(cwd, "package.json")) || existsSync3(join3(cwd, ".git"));
37887
38139
  }
37888
38140
  var escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
37889
38141
  function needles(target) {
@@ -37898,12 +38150,12 @@ function needles(target) {
37898
38150
  tag: new RegExp(`<${escape2(target.tag)}[\\s>/]`, "i")
37899
38151
  };
37900
38152
  }
37901
- function locate(target, root, deadline = Date.now() + BUDGET_MS) {
38153
+ function locate(target, root, deadline = Date.now() + BUDGET_MS2) {
37902
38154
  const n = needles(target);
37903
38155
  const known = target.source?.file && target.source.line ? sourcePath(target.source.file, root) : null;
37904
38156
  if (known && target.source?.line) {
37905
38157
  try {
37906
- const lines = readFileSync(join2(root, known), "utf8").split("\n");
38158
+ const lines = readFileSync2(join3(root, known), "utf8").split("\n");
37907
38159
  const from = target.source.line - 1;
37908
38160
  const own2 = bestLine(n, lines, from);
37909
38161
  const index = own2 && own2.score >= 2 ? own2.index : from;
@@ -37917,7 +38169,7 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS) {
37917
38169
  if (Date.now() > deadline) break;
37918
38170
  let content;
37919
38171
  try {
37920
- content = readFileSync(file2, "utf8");
38172
+ content = readFileSync2(file2, "utf8");
37921
38173
  } catch {
37922
38174
  continue;
37923
38175
  }
@@ -37930,7 +38182,7 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS) {
37930
38182
  }
37931
38183
  const enough = best && (best.score >= 6 || n.classes.length >= 3 && best.score >= n.classes.length + 2);
37932
38184
  if (!best || !enough) return null;
37933
- return { file: relative(root, best.file), line: best.line + 1, snippet: snippetAt(best.lines, best.line) };
38185
+ return { file: relative2(root, best.file), line: best.line + 1, snippet: snippetAt(best.lines, best.line) };
37934
38186
  }
37935
38187
  function bestLine(n, lines, from = 0) {
37936
38188
  const classesOn = (i) => lines[i] === void 0 ? 0 : n.classes.filter((re) => re.test(lines[i])).length;
@@ -37954,23 +38206,23 @@ function snippetAt(lines, index) {
37954
38206
  return lines.slice(Math.max(0, index - 2), index + 3).map((l) => l.length > 160 ? `${l.slice(0, 159)}\u2026` : l).join("\n");
37955
38207
  }
37956
38208
  function sourcePath(file2, root) {
37957
- const rel = isAbsolute(file2) ? relative(root, file2) : file2.replace(/^\.\//, "");
38209
+ const rel = isAbsolute(file2) ? relative2(root, file2) : file2.replace(/^\.\//, "");
37958
38210
  if (rel.startsWith("..") || isAbsolute(rel)) return null;
37959
- return existsSync2(join2(root, rel)) ? rel : null;
38211
+ return existsSync3(join3(root, rel)) ? rel : null;
37960
38212
  }
37961
- function componentFile(name, root, deadline = Date.now() + BUDGET_MS, within) {
38213
+ function componentFile(name, root, deadline = Date.now() + BUDGET_MS2, within) {
37962
38214
  if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null;
37963
38215
  const declaration = new RegExp(
37964
38216
  `^\\s*(export\\s+(?:default\\s+)?)?(?:(?:async\\s+)?function\\s*\\*?\\s+${name}\\b|class\\s+${name}\\b|(?:const|let|var)\\s+${name}\\s*[:=])`
37965
38217
  );
37966
38218
  let best = null;
37967
- const files = within ? [join2(root, within)] : sourceFiles(root);
38219
+ const files = within ? [join3(root, within)] : sourceFiles(root);
37968
38220
  for (const file2 of files) {
37969
38221
  if (Date.now() > deadline) break;
37970
38222
  if (!/\.[jt]sx?$|\.mjs$/.test(file2)) continue;
37971
38223
  let content;
37972
38224
  try {
37973
- content = readFileSync(file2, "utf8");
38225
+ content = readFileSync2(file2, "utf8");
37974
38226
  } catch {
37975
38227
  continue;
37976
38228
  }
@@ -37979,16 +38231,16 @@ function componentFile(name, root, deadline = Date.now() + BUDGET_MS, within) {
37979
38231
  for (let i = 0; i < lines.length; i++) {
37980
38232
  const m = declaration.exec(lines[i]);
37981
38233
  if (!m) continue;
37982
- const score = (basename2(file2).replace(/\.[^.]+$/, "") === name ? 2 : 0) + (m[1] ? 1 : 0);
38234
+ const score = (basename3(file2).replace(/\.[^.]+$/, "") === name ? 2 : 0) + (m[1] ? 1 : 0);
37983
38235
  if (!best || score > best.score) best = { file: file2, line: i + 1, score };
37984
38236
  break;
37985
38237
  }
37986
38238
  }
37987
- return best ? { file: relative(root, best.file), line: best.line } : null;
38239
+ return best ? { file: relative2(root, best.file), line: best.line } : null;
37988
38240
  }
37989
38241
  function withComponentFiles(job, root) {
37990
38242
  if (!searchable(root)) return job;
37991
- const deadline = Date.now() + BUDGET_MS;
38243
+ const deadline = Date.now() + BUDGET_MS2;
37992
38244
  const fill = (target) => {
37993
38245
  const source = target.source;
37994
38246
  if (!source?.component || source.line) return target;
@@ -37997,6 +38249,27 @@ function withComponentFiles(job, root) {
37997
38249
  const found = componentFile(source.component, root, deadline, known ?? void 0);
37998
38250
  return found ? { ...target, source: { ...source, file: found.file, line: found.line } } : target;
37999
38251
  };
38252
+ const workspace = workspaceRoot(root);
38253
+ const declared = (name) => {
38254
+ const found = componentFile(name, workspace, deadline);
38255
+ return found ? { file: relative2(root, join3(workspace, found.file)), line: found.line } : null;
38256
+ };
38257
+ const mention = (r) => {
38258
+ if (r.kind === "element") return { ...r, target: fill(r.target) };
38259
+ if (r.kind === "unlisted") {
38260
+ const source2 = declared(r.name);
38261
+ return source2 ? { kind: "component", name: r.name, source: source2 } : r;
38262
+ }
38263
+ if (r.kind !== "component") return r;
38264
+ if (r.source) {
38265
+ const path = join3(workspace, r.source.file);
38266
+ return existsSync3(path) ? { ...r, source: { ...r.source, file: relative2(root, path) } } : r;
38267
+ }
38268
+ if (r.target?.source?.file) return { ...r, target: fill(r.target) };
38269
+ const source = declared(r.name);
38270
+ return source ? { ...r, source } : r;
38271
+ };
38272
+ const mentions = (refs) => refs?.length ? { references: refs.map(mention) } : {};
38000
38273
  const { changeSet } = job;
38001
38274
  const request = changeSet.request;
38002
38275
  return {
@@ -38008,7 +38281,8 @@ function withComponentFiles(job, root) {
38008
38281
  request: {
38009
38282
  ...request,
38010
38283
  target: fill(request.target),
38011
- ...request.others ? { others: request.others.map(fill) } : {}
38284
+ ...request.others ? { others: request.others.map(fill) } : {},
38285
+ ...request.kind === "comment" ? { thread: request.thread.map((m) => ({ ...m, ...mentions(m.references) })) } : mentions(request.references)
38012
38286
  }
38013
38287
  } : {}
38014
38288
  }
@@ -38017,12 +38291,12 @@ function withComponentFiles(job, root) {
38017
38291
  function whereSection(job, root) {
38018
38292
  if (!searchable(root)) return "";
38019
38293
  const targets = job.changeSet.request ? requestTargets(job.changeSet.request) : job.changeSet.edits.map((e) => e.target);
38020
- const deadline = Date.now() + BUDGET_MS;
38294
+ const deadline = Date.now() + BUDGET_MS2;
38021
38295
  const found = [];
38022
38296
  for (const target of targets) {
38023
38297
  const at = locate(target, root, deadline);
38024
38298
  if (!at) continue;
38025
- const lang = extname(at.file).slice(1) || "text";
38299
+ const lang = extname2(at.file).slice(1) || "text";
38026
38300
  found.push(
38027
38301
  `- \`${target.path}\` \u2192 \`${at.file}:${at.line}\`:`,
38028
38302
  "",
@@ -38060,16 +38334,16 @@ function clientOf(name) {
38060
38334
 
38061
38335
  // src/init.ts
38062
38336
  import { spawnSync } from "child_process";
38063
- import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
38337
+ import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync3 } from "fs";
38064
38338
  import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
38065
38339
  import { homedir as homedir2 } from "os";
38066
- import { dirname as dirname2, join as join4, relative as relative3 } from "path";
38340
+ import { dirname as dirname3, join as join5, relative as relative4 } from "path";
38067
38341
 
38068
38342
  // src/setup.ts
38069
- import { existsSync as existsSync3 } from "fs";
38343
+ import { existsSync as existsSync4 } from "fs";
38070
38344
  import { lstat, mkdir as mkdir2, readFile as readFile2, unlink, writeFile as writeFile2 } from "fs/promises";
38071
38345
  import { homedir } from "os";
38072
- import { join as join3, relative as relative2 } from "path";
38346
+ import { join as join4, relative as relative3 } from "path";
38073
38347
 
38074
38348
  // ../../skills/pilot/SKILL.md
38075
38349
  var SKILL_default = "---\nname: pilot\ndescription: Hand the UI to the designer with Pilot, then apply the design edits they send, job after job. Use when the user runs /pilot, says they want to take control of the design or edit the UI in the browser, or pastes a \"Pilot design edits\" brief, or asks to update Pilot.\n---\n\n# Pilot\n\nPilot lets the designer edit the running app in the browser. They select elements, change CSS properties with Pilot's editors, and press **Send**. Each Send reaches you as a **job**: plain CSS `property: from \u2192 to` (and new text, when they rewrote one) on identifiable elements, for you to write into the source in this project's conventions. The designer keeps designing while you work; Pilot previews each job's changes until you report it done, then checks them against the page's real CSS.\n\n## When the user asks to update Pilot\n\nRun `npx usepilot@latest update` in the app's folder (the one with `usepilot` in its `package.json`), and tell the user in a few lines what it prints: the new version and the steps left (restart the app's dev server, open a new chat).\n\n## When the user runs /pilot (or asks to launch Pilot)\n\n0. **Check that Pilot's tools are here** (`pilot_launch`, `pilot_wait_for_edits`, `pilot_done`). If they aren't, don't look for them in files, packages or settings: they come from Pilot's MCP server, which an agent loads when a chat starts, so a chat opened before Pilot was set up doesn't have them. Say so in one or two lines and stop: open a new chat (approve Pilot's server if asked, or turn it on in the agent's MCP settings: Cursor keeps a project's new servers off until they're switched on in Cursor Settings, MCP section), then run `/pilot` there. If the project has no Pilot at all (no `usepilot` in its `package.json`), offer to set it up instead: `npx usepilot@latest init --agent <you>`.\n1. **Find the page.** Work out the URL of the app's dev server: the dev script and its config (`vite.config.*` \u2192 `server.port`, Next.js \u2192 3000, a `--port` flag\u2026), or a server already running in a terminal. If the dev server isn't running, start it in the background. If you can't tell the URL, ask.\n2. **Launch:** call `pilot_launch` with that URL and `folder`, the project's folder as an absolute path (your working directory): Pilot searches the code there for each job, and some agents start its server elsewhere. Pilot opens in the page (if the page isn't open yet, tell the designer to open it).\n3. **Tell the designer** in one line that Pilot is ready: select an element, edit, press Send.\n4. **Wait:** call `pilot_wait_for_edits`. It returns a job when the designer presses Send, or \"no edits yet\" after a while: call it again, without saying anything to the user. In Claude Code, a wait longer than two minutes moves to the background: end your turn with a short \"Waiting for your edits\", and the job arrives as the task's result.\n5. **Apply the job** (below), then call `pilot_done` with the job id and short notes, and go back to step 4. When several jobs were queued, one wait returns them all: do them all, then call `pilot_done` once per job, each with its own id and notes.\n\nKeep looping until the user asks you to stop. Keep your messages between jobs short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, and keep (or start again) a wait in the background so their next Send reaches you (queued jobs are kept).\n\n## Applying a job\n\nJobs come in three kinds:\n\n- **Edits** (basic): the designer set every value; you only translate them. **Speed is what matters**: go straight to the code, apply, call `pilot_done`. No screenshots, browser checks, builds or tests: Pilot checks the page itself and sends back what didn't land.\n- **Comments**: the designer's own words about one element (\"make it the brand green\", \"can this be calmer?\"), with the thread so far. Do what the latest one asks: a specific, small ask right away (like an edit), an open-ended one as an advanced task (below). A question gets an answer and no change. Your `pilot_done` notes are your reply in their thread, a small chat box for quick design back-and-forth: one short sentence, like a chat message (about 120 characters), with no lists or code blocks. Not a report: they see the result on the page.\n- **Tasks** (advanced), like **Make responsive** and **Break and fix**: the designer selected an element and asked for an outcome (work at every viewport width; hold up with odd but realistic content, like very long text, with the real content put back after testing). They need judgment more than speed. The prompt has the steps. Check the result with `pilot_check_widths` (numbers for every width, no screenshots needed). If you can hand it to a more capable model than the one you run on (a subagent, or another model your agent offers), do, then call `pilot_done` with its notes. Pilot checks the widths again when you're done; problems come back once as a follow-up.\n\n### Edits\n\nThe values are **design instructions, not code**: the designer's intent. Use your judgment and write production code the way this project already styles things, whatever it uses. First look at how the element's component is styled, and follow that. For example:\n\n- **Utility classes (Tailwind):** the closest utility or theme value (`border-radius: 12px` \u2192 `rounded-xl`, `padding-top: 24px` \u2192 `pt-6`). Arbitrary values only when nothing fits.\n- **CSS / CSS modules / Sass:** edit the rule that styles the element. Don't add a new override.\n- **Design tokens / CSS variables:** prefer an existing token that matches. Don't hard-code its value.\n- **CSS-in-JS and compiled styles (StyleX, vanilla-extract, Panda, styled-components, Emotion):** edit the style definition where the component is styled, with the project's tokens.\n- **A component library's props (MUI, Chakra\u2026):** use its props and theme values before any custom CSS.\n\nRules:\n\n- Never leave inline styles or `!important` behind. Pilot's preview is only a preview.\n- Find each element by its selector, DOM path and text snippet, then the component that renders it.\n- **Shared code, only some copies:** an element's \"Look-alikes\" line counts the elements like it the job leaves out. If they come from the same code (a shared component, a loop over data) and the designer didn't say which they meant, don't guess: do the rest of the job, leave that part, and ask with `pilot_done`'s `question` (one short sentence, the component's name in **bold**) and `choices` \"All of them\", \"Only this\", \"New variant\" (your suggestion first). Go on with other jobs; the answer comes back as that job. **All of them**: change the component itself. **Only this**: change it where it's used, with what the component accepts (classes through its `className`, merged the project's way; a prop), else the smallest pass-through, not a variant. **New variant**: add a named option the way the component defines variants (`cva`, a `variant` prop), use it here, and name it in your notes. Don't ask when the designer already said, when every copy is in the job, or when nothing else uses that code.\n- **Widths:** a change for some viewport widths goes in a media query; use the project's breakpoints when one matches (or is within a few pixels). \"Every width\" means no media query should override it.\n- **Removed:** the element shouldn't declare the property at all (not `0` or `none`).\n- **Text:** the designer rewrote the element's copy. Change it where it comes from (the markup, a prop, a translation file), for this element only; Pilot checks that the page shows the new text.\n- If you approximated a value to fit a token or scale, say which and by how much in `pilot_done`'s notes (`22px \u2192 pt-6, 24px`). Pilot checks the page after each job: a change that doesn't give the designer's value comes back to you once as a follow-up. Fix it, or keep a deliberate choice and say why; after that, Pilot takes what the code gives.\n- Don't run builds or tests for a job unless it's needed: hot reload shows the result, and the designer is waiting to see it.\n";
@@ -38080,7 +38354,7 @@ async function setup(options = {}) {
38080
38354
  return options.project ? setupProject(options.cwd ?? process.cwd()) : setupMachine(options.home ?? homedir());
38081
38355
  }
38082
38356
  async function setupMachine(home) {
38083
- const file2 = await writeSkill(join3(home, ".claude", "skills", "pilot"));
38357
+ const file2 = await writeSkill(join4(home, ".claude", "skills", "pilot"));
38084
38358
  return `Installed the /pilot skill: ${file2}
38085
38359
 
38086
38360
  Now register Pilot's MCP server with Claude Code, once, for every project:
@@ -38092,11 +38366,11 @@ Then, in any Claude Code chat: /pilot
38092
38366
  `;
38093
38367
  }
38094
38368
  async function setupProject(cwd) {
38095
- const skillFile = await writeSkill(join3(cwd, ".claude", "skills", "pilot"));
38096
- const mcpFile = join3(cwd, ".mcp.json");
38369
+ const skillFile = await writeSkill(join4(cwd, ".claude", "skills", "pilot"));
38370
+ const mcpFile = join4(cwd, ".mcp.json");
38097
38371
  const { added } = await addMcpServer(mcpFile);
38098
- const rel = (f) => relative2(cwd, f);
38099
- const app = existsSync3(join3(cwd, "package.json")) ? "" : "\nNo package.json here: run this in the project's root folder, where the app is.\n";
38372
+ const rel = (f) => relative3(cwd, f);
38373
+ const app = existsSync4(join4(cwd, "package.json")) ? "" : "\nNo package.json here: run this in the project's root folder, where the app is.\n";
38100
38374
  const width = rel(skillFile).length + 2;
38101
38375
  return `Set up /pilot for this repo:
38102
38376
  ${rel(skillFile).padEnd(width)}the /pilot skill
@@ -38115,7 +38389,7 @@ Then, in a Claude Code chat in this folder: /pilot
38115
38389
  async function writeSkill(dir) {
38116
38390
  if (await isLink(dir)) await unlink(dir);
38117
38391
  await mkdir2(dir, { recursive: true });
38118
- const file2 = join3(dir, "SKILL.md");
38392
+ const file2 = join4(dir, "SKILL.md");
38119
38393
  await writeFile2(file2, SKILL_default);
38120
38394
  return file2;
38121
38395
  }
@@ -38128,7 +38402,7 @@ async function isLink(path) {
38128
38402
  }
38129
38403
  async function addMcpServer(file2) {
38130
38404
  let config2 = {};
38131
- if (existsSync3(file2)) {
38405
+ if (existsSync4(file2)) {
38132
38406
  const text = await readFile2(file2, "utf8");
38133
38407
  try {
38134
38408
  config2 = text.trim() ? JSON.parse(text) : {};
@@ -38145,7 +38419,7 @@ async function addMcpServer(file2) {
38145
38419
  }
38146
38420
 
38147
38421
  // src/version.ts
38148
- var VERSION = "0.8.0";
38422
+ var VERSION = "0.9.0";
38149
38423
  function olderThan(a, b) {
38150
38424
  const parts = (v) => v.replace(/^[^\d]*/, "").split(/[.-]/).slice(0, 3).map((n) => Number.parseInt(n, 10) || 0);
38151
38425
  const [x, y] = [parts(a), parts(b)];
@@ -38161,15 +38435,15 @@ var AGENTS = [
38161
38435
  id: "claude-code",
38162
38436
  name: "Claude Code",
38163
38437
  mcp: { file: ".mcp.json", key: "mcpServers", entry: MCP_SERVER },
38164
- skills: join4(".claude", "skills"),
38438
+ skills: join5(".claude", "skills"),
38165
38439
  invoke: "`/pilot`",
38166
38440
  signals: [".mcp.json", ".claude"]
38167
38441
  },
38168
38442
  {
38169
38443
  id: "cursor",
38170
38444
  name: "Cursor",
38171
- mcp: { file: join4(".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
38172
- skills: join4(".cursor", "skills"),
38445
+ mcp: { file: join5(".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
38446
+ skills: join5(".cursor", "skills"),
38173
38447
  invoke: "`/pilot`",
38174
38448
  signals: [".cursor"],
38175
38449
  // Cursor sees a project's new MCP server but leaves it off: it never starts until the user turns it on.
@@ -38178,16 +38452,16 @@ var AGENTS = [
38178
38452
  {
38179
38453
  id: "vscode",
38180
38454
  name: "VS Code",
38181
- mcp: { file: join4(".vscode", "mcp.json"), key: "servers", entry: { type: "stdio", ...MCP_SERVER } },
38182
- skills: join4(".github", "skills"),
38455
+ mcp: { file: join5(".vscode", "mcp.json"), key: "servers", entry: { type: "stdio", ...MCP_SERVER } },
38456
+ skills: join5(".github", "skills"),
38183
38457
  invoke: "`/pilot`",
38184
- signals: [join4(".vscode", "mcp.json"), join4(".github", "skills"), join4(".github", "copilot-instructions.md")]
38458
+ signals: [join5(".vscode", "mcp.json"), join5(".github", "skills"), join5(".github", "copilot-instructions.md")]
38185
38459
  },
38186
38460
  {
38187
38461
  id: "codex",
38188
38462
  name: "Codex",
38189
38463
  register: `\`codex mcp add pilot -- ${COMMAND}\``,
38190
- skills: join4(".agents", "skills"),
38464
+ skills: join5(".agents", "skills"),
38191
38465
  invoke: "`$pilot`",
38192
38466
  signals: [".codex"]
38193
38467
  },
@@ -38196,7 +38470,7 @@ var AGENTS = [
38196
38470
  name: "your agent",
38197
38471
  register: `in your MCP settings: a server named \`pilot\`, running \`${COMMAND}\``,
38198
38472
  // The open skills folder, read by many agents.
38199
- skills: join4(".agents", "skills"),
38473
+ skills: join5(".agents", "skills"),
38200
38474
  invoke: "the `pilot` skill",
38201
38475
  signals: []
38202
38476
  }
@@ -38207,35 +38481,35 @@ var MACHINE = {
38207
38481
  command: {
38208
38482
  cmd: "claude",
38209
38483
  args: ["mcp", "add", "--scope", "user", "pilot", "--", ...MCP_SERVER_ARGV],
38210
- has: (home) => !!readJson(join4(home, ".claude.json"))?.mcpServers?.pilot
38484
+ has: (home) => !!readJson(join5(home, ".claude.json"))?.mcpServers?.pilot
38211
38485
  },
38212
- skills: (home) => join4(home, ".claude", "skills")
38486
+ skills: (home) => join5(home, ".claude", "skills")
38213
38487
  },
38214
38488
  cursor: {
38215
- mcp: { file: (home) => join4(home, ".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
38216
- skills: (home) => join4(home, ".cursor", "skills")
38489
+ mcp: { file: (home) => join5(home, ".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
38490
+ skills: (home) => join5(home, ".cursor", "skills")
38217
38491
  },
38218
38492
  vscode: {
38219
38493
  mcp: {
38220
- file: (home, platform) => join4(vscodeUserDir(home, platform), "mcp.json"),
38494
+ file: (home, platform) => join5(vscodeUserDir(home, platform), "mcp.json"),
38221
38495
  key: "servers",
38222
38496
  entry: { type: "stdio", ...MCP_SERVER }
38223
38497
  },
38224
- skills: (home) => join4(home, ".copilot", "skills")
38498
+ skills: (home) => join5(home, ".copilot", "skills")
38225
38499
  },
38226
38500
  codex: {
38227
38501
  command: {
38228
38502
  cmd: "codex",
38229
38503
  args: ["mcp", "add", "pilot", "--", ...MCP_SERVER_ARGV],
38230
- has: (home) => /\[mcp_servers\.pilot\]/.test(readText(join4(home, ".codex", "config.toml")))
38504
+ has: (home) => /\[mcp_servers\.pilot\]/.test(readText(join5(home, ".codex", "config.toml")))
38231
38505
  },
38232
- skills: (home) => join4(home, ".agents", "skills")
38506
+ skills: (home) => join5(home, ".agents", "skills")
38233
38507
  },
38234
- other: { skills: (home) => join4(home, ".agents", "skills") }
38508
+ other: { skills: (home) => join5(home, ".agents", "skills") }
38235
38509
  };
38236
38510
  function skillFolders(root, home) {
38237
- const machine = AGENT_IDS.map((id) => join4(MACHINE[id].skills(home), "pilot"));
38238
- const project = AGENTS.map((a) => join4(root, a.skills, "pilot"));
38511
+ const machine = AGENT_IDS.map((id) => join5(MACHINE[id].skills(home), "pilot"));
38512
+ const project = AGENTS.map((a) => join5(root, a.skills, "pilot"));
38239
38513
  return [.../* @__PURE__ */ new Set([...machine, ...project])];
38240
38514
  }
38241
38515
  function agentsWithPilot(root, home, platform = process.platform) {
@@ -38245,24 +38519,24 @@ function agentsWithPilot(root, home, platform = process.platform) {
38245
38519
  const machine = MACHINE[a.id];
38246
38520
  if (machine.mcp && hasServer(machine.mcp.file(home, platform), machine.mcp.key)) return true;
38247
38521
  if (machine.command?.has(home)) return true;
38248
- if (a.mcp && hasServer(join4(root, a.mcp.file), a.mcp.key)) return true;
38249
- return a.id !== "codex" && existsSync4(join4(machine.skills(home), "pilot"));
38522
+ if (a.mcp && hasServer(join5(root, a.mcp.file), a.mcp.key)) return true;
38523
+ return a.id !== "codex" && existsSync5(join5(machine.skills(home), "pilot"));
38250
38524
  }).map((a) => a.id);
38251
38525
  }
38252
38526
  function installArgs(pm, spec = "usepilot") {
38253
38527
  return pm === "npm" ? ["install", "-D", spec] : pm === "bun" ? ["add", "-d", spec] : ["add", "-D", spec];
38254
38528
  }
38255
38529
  function installedVersion(cwd, root) {
38256
- for (let dir = cwd; ; dir = dirname2(dir)) {
38257
- const version2 = readJson(join4(dir, "node_modules", "usepilot", "package.json"))?.version;
38530
+ for (let dir = cwd; ; dir = dirname3(dir)) {
38531
+ const version2 = readJson(join5(dir, "node_modules", "usepilot", "package.json"))?.version;
38258
38532
  if (version2) return version2;
38259
- if (dir === root || dirname2(dir) === dir) return null;
38533
+ if (dir === root || dirname3(dir) === dir) return null;
38260
38534
  }
38261
38535
  }
38262
38536
  function vscodeUserDir(home, platform) {
38263
- if (platform === "darwin") return join4(home, "Library", "Application Support", "Code", "User");
38264
- if (platform === "win32") return join4(process.env.APPDATA ?? join4(home, "AppData", "Roaming"), "Code", "User");
38265
- return join4(home, ".config", "Code", "User");
38537
+ if (platform === "darwin") return join5(home, "Library", "Application Support", "Code", "User");
38538
+ if (platform === "win32") return join5(process.env.APPDATA ?? join5(home, "AppData", "Roaming"), "Code", "User");
38539
+ return join5(home, ".config", "Code", "User");
38266
38540
  }
38267
38541
  function tilde(path, home) {
38268
38542
  return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
@@ -38276,8 +38550,8 @@ function detectAgent(env) {
38276
38550
  async function init(options = {}) {
38277
38551
  const cwd = options.cwd ?? process.cwd();
38278
38552
  const run = options.run ?? runCommand;
38279
- const pkgFile = join4(cwd, "package.json");
38280
- if (!existsSync4(pkgFile)) {
38553
+ const pkgFile = join5(cwd, "package.json");
38554
+ if (!existsSync5(pkgFile)) {
38281
38555
  return `# Pilot: not set up
38282
38556
 
38283
38557
  There's no package.json in ${cwd}. Run \`npx usepilot@latest init\` again in the app's folder: the one with the package.json of the web app the user works on.
@@ -38333,16 +38607,16 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
38333
38607
  } else if (agent.register) {
38334
38608
  todo.push(`**Register Pilot's MCP server with yourself**, for every project: ${agent.register}.`);
38335
38609
  }
38336
- const skill = join4(machine.skills(home), "pilot");
38610
+ const skill = join5(machine.skills(home), "pilot");
38337
38611
  await writeSkill(skill);
38338
38612
  parts.push(`the \`pilot\` skill (\`${tilde(skill, home)}/\`)`);
38339
38613
  done.push(`Connected ${agent.name} to Pilot, once for every project on this machine: ${list(parts)}. Nothing was added to the repo.`);
38340
38614
  } else if (named) {
38341
- const present = AGENTS.filter((a) => a.id !== named && a.signals.some((p) => existsSync4(join4(root, p))));
38615
+ const present = AGENTS.filter((a) => a.id !== named && a.signals.some((p) => existsSync5(join5(root, p))));
38342
38616
  for (const agent of [...AGENTS.filter((a) => a.id === named), ...present]) {
38343
38617
  const parts = [];
38344
38618
  if (agent.mcp) {
38345
- const file2 = join4(root, agent.mcp.file);
38619
+ const file2 = join5(root, agent.mcp.file);
38346
38620
  if (await addServer(file2, agent.mcp.key, agent.mcp.entry) === "invalid") {
38347
38621
  todo.push(
38348
38622
  `\`${agent.mcp.file}\` isn't valid JSON, so Pilot wasn't added to it: fix it, and add the \`pilot\` server (\`${COMMAND}\`).`
@@ -38352,8 +38626,8 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
38352
38626
  written.push(`\`${agent.mcp.file}\``);
38353
38627
  }
38354
38628
  }
38355
- const skill = join4(agent.skills, "pilot");
38356
- await writeSkill(join4(root, skill));
38629
+ const skill = join5(agent.skills, "pilot");
38630
+ await writeSkill(join5(root, skill));
38357
38631
  parts.push(`the \`pilot\` skill (\`${skill}/\`)`);
38358
38632
  if (!written.includes(`\`${skill}/\``)) written.push(`\`${skill}/\``);
38359
38633
  done.push(`Set Pilot up for ${agent.name} in this project: ${list(parts)}.`);
@@ -38364,7 +38638,7 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
38364
38638
  `**Connect yourself:** run \`npx usepilot@latest init --agent <you>\` in ${cwd}, with \`<you>\` the agent you are: ${AGENT_IDS.map((a) => `\`${a}\``).join(", ")}.`
38365
38639
  );
38366
38640
  }
38367
- if (framework.loads) done.push(`The app already loads Pilot (\`${relative3(cwd, framework.loads)}\`).`);
38641
+ if (framework.loads) done.push(`The app already loads Pilot (\`${relative4(cwd, framework.loads)}\`).`);
38368
38642
  else todo.push(loadStep(framework, cwd));
38369
38643
  const me = AGENTS.find((a) => a.id === named);
38370
38644
  const enable = project && me?.enable ? `Before that, ${me.enable}. ` : "";
@@ -38381,23 +38655,23 @@ ${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
38381
38655
  `;
38382
38656
  }
38383
38657
  function projectRoot(cwd) {
38384
- for (let dir = cwd; ; dir = dirname2(dir)) {
38385
- if (existsSync4(join4(dir, ".git"))) return dir;
38386
- if (dirname2(dir) === dir) return cwd;
38658
+ for (let dir = cwd; ; dir = dirname3(dir)) {
38659
+ if (existsSync5(join5(dir, ".git"))) return dir;
38660
+ if (dirname3(dir) === dir) return cwd;
38387
38661
  }
38388
38662
  }
38389
38663
  function packageManager(cwd, root) {
38390
- for (let dir = cwd; ; dir = dirname2(dir)) {
38391
- if (existsSync4(join4(dir, "pnpm-lock.yaml"))) return "pnpm";
38392
- if (existsSync4(join4(dir, "yarn.lock"))) return "yarn";
38393
- if (existsSync4(join4(dir, "bun.lock")) || existsSync4(join4(dir, "bun.lockb"))) return "bun";
38394
- if (existsSync4(join4(dir, "package-lock.json"))) return "npm";
38395
- if (dir === root || dirname2(dir) === dir) return "npm";
38664
+ for (let dir = cwd; ; dir = dirname3(dir)) {
38665
+ if (existsSync5(join5(dir, "pnpm-lock.yaml"))) return "pnpm";
38666
+ if (existsSync5(join5(dir, "yarn.lock"))) return "yarn";
38667
+ if (existsSync5(join5(dir, "bun.lock")) || existsSync5(join5(dir, "bun.lockb"))) return "bun";
38668
+ if (existsSync5(join5(dir, "package-lock.json"))) return "npm";
38669
+ if (dir === root || dirname3(dir) === dir) return "npm";
38396
38670
  }
38397
38671
  }
38398
38672
  function detectFramework(cwd, deps) {
38399
38673
  const has = (name) => name in deps;
38400
- const first = (...files) => files.map((f) => join4(cwd, f)).find((f) => existsSync4(f));
38674
+ const first = (...files) => files.map((f) => join5(cwd, f)).find((f) => existsSync5(f));
38401
38675
  const loads = findLoader(cwd);
38402
38676
  const result = (kind, file2) => ({ kind, file: file2, loads });
38403
38677
  if (has("next")) {
@@ -38419,8 +38693,8 @@ function detectFramework(cwd, deps) {
38419
38693
  if (has("vite") || Object.keys(deps).some((d) => d.startsWith("@vitejs/"))) {
38420
38694
  const entry = viteEntry(cwd);
38421
38695
  if (entry) return result("vite", entry);
38422
- if (existsSync4(join4(cwd, "index.html"))) {
38423
- const config2 = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) => join4(cwd, f)).find((f) => existsSync4(f));
38696
+ if (existsSync5(join5(cwd, "index.html"))) {
38697
+ const config2 = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) => join5(cwd, f)).find((f) => existsSync5(f));
38424
38698
  return result("vite-html", config2);
38425
38699
  }
38426
38700
  return result("vite");
@@ -38434,16 +38708,16 @@ function detectFramework(cwd, deps) {
38434
38708
  return { kind: "unknown", loads };
38435
38709
  }
38436
38710
  function viteEntry(cwd) {
38437
- const html = join4(cwd, "index.html");
38438
- if (existsSync4(html)) {
38439
- for (const tag of readFileSync2(html, "utf8").match(/<script\b[^>]*>/gi) ?? []) {
38711
+ const html = join5(cwd, "index.html");
38712
+ if (existsSync5(html)) {
38713
+ for (const tag of readFileSync3(html, "utf8").match(/<script\b[^>]*>/gi) ?? []) {
38440
38714
  if (!/type=["']module["']/i.test(tag)) continue;
38441
38715
  const src = /src=["']\/?([^"'?#]+)/i.exec(tag)?.[1];
38442
- if (src && existsSync4(join4(cwd, src))) return join4(cwd, src);
38716
+ if (src && existsSync5(join5(cwd, src))) return join5(cwd, src);
38443
38717
  }
38444
38718
  return void 0;
38445
38719
  }
38446
- return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) => join4(cwd, f)).find((f) => existsSync4(f));
38720
+ return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) => join5(cwd, f)).find((f) => existsSync5(f));
38447
38721
  }
38448
38722
  var SOURCE_DIRS = ["src", "app", "pages", "plugins", "components", "lib"];
38449
38723
  var SOURCE_FILE = /\.(m?[jt]sx?|vue|svelte|astro|html)$/;
@@ -38452,13 +38726,13 @@ function findLoader(cwd) {
38452
38726
  const walk = (dir, depth) => {
38453
38727
  let names;
38454
38728
  try {
38455
- names = readdirSync2(dir);
38729
+ names = readdirSync3(dir);
38456
38730
  } catch {
38457
38731
  return void 0;
38458
38732
  }
38459
38733
  for (const name of names) {
38460
38734
  if (budget-- <= 0 || name === "node_modules" || name.startsWith(".")) continue;
38461
- const path = join4(dir, name);
38735
+ const path = join5(dir, name);
38462
38736
  if (SOURCE_FILE.test(name)) {
38463
38737
  if (/["']usepilot(\/auto)?["']/.test(readText(path))) return path;
38464
38738
  } else if (depth > 0 && !name.includes(".")) {
@@ -38469,40 +38743,40 @@ function findLoader(cwd) {
38469
38743
  return void 0;
38470
38744
  };
38471
38745
  for (const name of ["index.html", "vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"]) {
38472
- const file2 = join4(cwd, name);
38473
- if (existsSync4(file2) && /usepilot/.test(readText(file2))) return file2;
38746
+ const file2 = join5(cwd, name);
38747
+ if (existsSync5(file2) && /usepilot/.test(readText(file2))) return file2;
38474
38748
  }
38475
38749
  for (const dir of SOURCE_DIRS) {
38476
- const found = walk(join4(cwd, dir), 6);
38750
+ const found = walk(join5(cwd, dir), 6);
38477
38751
  if (found) return found;
38478
38752
  }
38479
38753
  return void 0;
38480
38754
  }
38481
38755
  function readText(file2) {
38482
38756
  try {
38483
- return readFileSync2(file2, "utf8");
38757
+ return readFileSync3(file2, "utf8");
38484
38758
  } catch {
38485
38759
  return "";
38486
38760
  }
38487
38761
  }
38488
38762
  function isWorkspaceRoot(cwd, pkg) {
38489
- return !!pkg.workspaces || existsSync4(join4(cwd, "pnpm-workspace.yaml"));
38763
+ return !!pkg.workspaces || existsSync5(join5(cwd, "pnpm-workspace.yaml"));
38490
38764
  }
38491
38765
  function workspaceApps(cwd) {
38492
38766
  const found = [];
38493
38767
  for (const group of ["apps", "packages", "examples", "sites"]) {
38494
- const dir = join4(cwd, group);
38495
- if (!existsSync4(dir)) continue;
38496
- for (const name of readdirSync2(dir)) {
38497
- const pkg = readJson(join4(dir, name, "package.json"));
38498
- if (pkg && detectFramework(join4(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
38499
- found.push(join4(group, name));
38768
+ const dir = join5(cwd, group);
38769
+ if (!existsSync5(dir)) continue;
38770
+ for (const name of readdirSync3(dir)) {
38771
+ const pkg = readJson(join5(dir, name, "package.json"));
38772
+ if (pkg && detectFramework(join5(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
38773
+ found.push(join5(group, name));
38500
38774
  }
38501
38775
  }
38502
38776
  return found;
38503
38777
  }
38504
38778
  function loadStep(framework, cwd) {
38505
- const at = (file2, otherwise) => file2 ? `\`${relative3(cwd, file2)}\`` : otherwise;
38779
+ const at = (file2, otherwise) => file2 ? `\`${relative4(cwd, file2)}\`` : otherwise;
38506
38780
  const code = (lang, text) => `
38507
38781
 
38508
38782
  \`\`\`${lang}
@@ -38572,7 +38846,7 @@ export function Pilot() {
38572
38846
  }
38573
38847
  async function addServer(file2, key, entry) {
38574
38848
  let config2 = {};
38575
- if (existsSync4(file2)) {
38849
+ if (existsSync5(file2)) {
38576
38850
  const text = await readFile3(file2, "utf8");
38577
38851
  try {
38578
38852
  config2 = text.trim() ? JSON.parse(text) : {};
@@ -38584,14 +38858,14 @@ async function addServer(file2, key, entry) {
38584
38858
  const servers = config2[key] ?? {};
38585
38859
  const result = "pilot" in servers ? "updated" : "added";
38586
38860
  config2[key] = { ...servers, pilot: entry };
38587
- await mkdir3(dirname2(file2), { recursive: true });
38861
+ await mkdir3(dirname3(file2), { recursive: true });
38588
38862
  await writeFile3(file2, `${JSON.stringify(config2, null, 2)}
38589
38863
  `);
38590
38864
  return result;
38591
38865
  }
38592
38866
  function readJson(file2) {
38593
38867
  try {
38594
- return JSON.parse(readFileSync2(file2, "utf8"));
38868
+ return JSON.parse(readFileSync3(file2, "utf8"));
38595
38869
  } catch {
38596
38870
  return null;
38597
38871
  }
@@ -38633,7 +38907,7 @@ function agentLabel(clientName, cwd) {
38633
38907
  codex: "Codex"
38634
38908
  };
38635
38909
  const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
38636
- return `${app} \xB7 ${basename3(cwd)}`;
38910
+ return `${app} \xB7 ${basename4(cwd)}`;
38637
38911
  }
38638
38912
  function jobPrompt(job, where = "") {
38639
38913
  const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : job.answer && job.question ? answered(job) : formatPrompt(job.changeSet, { guidelines: false });
@@ -38673,9 +38947,7 @@ function followUp(job) {
38673
38947
  for (const d of job.differences ?? []) {
38674
38948
  const edit = job.changeSet.edits.find((e) => e.target.selector === d.selector);
38675
38949
  const where = edit ? `\`${edit.target.path}\` (selector \`${d.selector}\`${edit.target.text ? `, text "${edit.target.text}"` : ""})` : `\`${d.selector}\``;
38676
- if (d.property === DOM_REMOVE) lines.push(`- ${where}: deleted by the designer, but it's still on the page.`);
38677
- else if (d.property.startsWith(DOM_INSERT)) lines.push(`- ${where}: ${d.expected} was added by the designer, but it's not on the page.`);
38678
- else lines.push(`- ${where}: \`${d.property}\` should be \`${d.expected}\`, the page gives \`${d.actual ?? "?"}\`.`);
38950
+ lines.push(`- ${where}: \`${d.property}\` should be \`${d.expected}\`, the page gives \`${d.actual ?? "?"}\`.`);
38679
38951
  }
38680
38952
  lines.push(
38681
38953
  "",
@@ -38685,7 +38957,7 @@ function followUp(job) {
38685
38957
  }
38686
38958
  var MAX_BATCH = 6;
38687
38959
  async function takeQueued(first, take) {
38688
- const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment";
38960
+ const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment" && j.changeSet.request.kind !== "props";
38689
38961
  if (advanced(first)) return [];
38690
38962
  const more = [];
38691
38963
  while (more.length < MAX_BATCH - 1) {
@@ -38709,6 +38981,8 @@ function notesFor(job) {
38709
38981
  return "what changed at which widths, anything left for the designer";
38710
38982
  case "break-and-fix":
38711
38983
  return "what broke and how you fixed it, anything for the designer to decide";
38984
+ case "props":
38985
+ return "one short sentence for the designer, like a chat message; the props go in `props`";
38712
38986
  default:
38713
38987
  return "values you approximated, anything you did differently";
38714
38988
  }
@@ -38716,6 +38990,20 @@ function notesFor(job) {
38716
38990
  function taskFollowUp(job) {
38717
38991
  const request = job.changeSet.request;
38718
38992
  const target = `\`${request?.target.path ?? "the element"}\``;
38993
+ if (request?.kind === "comment")
38994
+ return [
38995
+ "# Pilot: props, follow-up",
38996
+ "",
38997
+ `You set the props the designer picked on ${target}, but Pilot read the instance on the page after hot reload, and these aren't what they picked yet:`,
38998
+ "",
38999
+ ...(job.issues ?? []).map((i) => `- ${i}`),
39000
+ "",
39001
+ "Fix them where this instance is written: the usual causes are another instance's line, a value the parent passes from a variable or data, or a default the prop falls back to. If one can't be set there, say why in your notes. Pilot takes what the code gives after this.",
39002
+ "",
39003
+ "The comment, for reference:",
39004
+ "",
39005
+ formatPrompt(job.changeSet, { guidelines: false })
39006
+ ].join("\n");
38719
39007
  const breakFix = request?.kind === "break-and-fix";
38720
39008
  const lines = [
38721
39009
  breakFix ? "# Pilot: break and fix, follow-up" : "# Pilot: make responsive, follow-up",
@@ -38744,7 +39032,7 @@ function projectFolder(candidate) {
38744
39032
  }
38745
39033
  if (!isAbsolute2(path)) return null;
38746
39034
  path = resolve(path);
38747
- return existsSync5(path) && searchable(path) ? path : null;
39035
+ return existsSync6(path) && searchable(path) ? path : null;
38748
39036
  }
38749
39037
  function createPilotServer(options = {}) {
38750
39038
  const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
@@ -38753,12 +39041,13 @@ function createPilotServer(options = {}) {
38753
39041
  let client;
38754
39042
  let waitMs = options.waitMs ?? waitMsFor(void 0);
38755
39043
  const server = new McpServer({ name: "pilot", version: VERSION }, { instructions: INSTRUCTIONS });
38756
- const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
39044
+ const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd), ...searchable(cwd) ? { folder: cwd } : {} };
38757
39045
  const bridge = new Bridge(agent, port);
38758
39046
  let origin = null;
38759
39047
  const useProject = (folder) => {
38760
39048
  project = folder;
38761
39049
  agent.label = agentLabel(client, folder);
39050
+ agent.folder = folder;
38762
39051
  };
38763
39052
  server.server.oninitialized = () => {
38764
39053
  client = server.server.getClientVersion()?.name;
@@ -38860,7 +39149,7 @@ ${p.text}` }, ...p.blocks])
38860
39149
  "pilot_done",
38861
39150
  {
38862
39151
  title: "Report a job done",
38863
- description: "Tells Pilot you applied a job. Pilot then checks each change against the page's real CSS; a change that didn't land comes back to you once as a follow-up. Then call pilot_wait_for_edits again. When part of the job needs the designer's decision (they changed only some copies of shared code), apply the rest, leave that part, and ask with `question`: Pilot shows it in a comment on the element, with one-click `choices`, holds the job until they answer, and their answer comes back to you as this job again. You go on with other jobs meanwhile. A job asks once.",
39152
+ description: "Tells Pilot you applied a job. Pilot then checks each change against the page's real CSS; a change that didn't land comes back to you once as a follow-up. Then call pilot_wait_for_edits again. When part of the job needs the designer's decision (they changed only some copies of shared code), apply the rest, leave that part, and ask with `question`: Pilot shows it in a comment on the element, with one-click `choices`, holds the job until they answer, and their answer comes back to you as this job again. You go on with other jobs meanwhile. A job asks once. For a props job (`/props`), pass the component's props in `props`: Pilot shows them to the designer to pick values from.",
38864
39153
  inputSchema: {
38865
39154
  jobId: external_exports.string().describe("The job's id, from pilot_wait_for_edits."),
38866
39155
  notes: external_exports.string().optional().describe("Short notes for the designer: values you approximated (e.g. 22px \u2192 pt-6, 24px), anything done differently."),
@@ -38869,13 +39158,22 @@ ${p.text}` }, ...p.blocks])
38869
39158
  choices: external_exports.array(external_exports.string()).max(MAX_CHOICES).optional().describe(
38870
39159
  `One-click answers, a few words each (they sit on one line), your suggestion first (it's the main button). For shared code: "${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}". The designer can also write their own.`
38871
39160
  )
38872
- }).optional().describe("Only when part of the job needs the designer's decision: see the description.")
39161
+ }).optional().describe("Only when part of the job needs the designer's decision: see the description."),
39162
+ props: external_exports.array(
39163
+ external_exports.object({
39164
+ name: external_exports.string().describe("The prop's name, as the code has it (`variant`)."),
39165
+ type: external_exports.enum(["options", "boolean", "text", "number"]).describe("`options`: one of a set of values; `boolean`: on or off; `text` or `number`: typed."),
39166
+ options: external_exports.array(external_exports.string()).optional().describe("For `options`: every value it accepts, in the code's order."),
39167
+ default: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()]).optional().describe("Its default value, when it has one."),
39168
+ description: external_exports.string().optional().describe("What it does, in a few words, when the name doesn't say.")
39169
+ })
39170
+ ).max(MAX_PROPS).optional().describe("Only for a props job (`/props`): the component's props the designer can set, the most useful first.")
38873
39171
  }
38874
39172
  },
38875
- async ({ jobId, notes, question }) => {
39173
+ async ({ jobId, notes, question, props }) => {
38876
39174
  try {
38877
39175
  const asked = questionOf(question);
38878
- const job = await bridge.done(jobId, notes, asked);
39176
+ const job = await bridge.done(jobId, notes, asked, propsOf(props));
38879
39177
  if (!job) return text(`Pilot doesn't know job ${jobId} (or the designer cancelled it). Call pilot_wait_for_edits for the next one.`);
38880
39178
  if (asked && job.question)
38881
39179
  return text("Done. Pilot shows your question to the designer; their answer comes back as this job. Call pilot_wait_for_edits for the next job meanwhile.");
@@ -38915,14 +39213,14 @@ ${p.text}` }, ...p.blocks])
38915
39213
 
38916
39214
  // src/update.ts
38917
39215
  import { spawnSync as spawnSync2 } from "child_process";
38918
- import { existsSync as existsSync6, lstatSync, readFileSync as readFileSync3 } from "fs";
39216
+ import { existsSync as existsSync7, lstatSync, readFileSync as readFileSync4 } from "fs";
38919
39217
  import { homedir as homedir3 } from "os";
38920
- import { dirname as dirname3, join as join5 } from "path";
39218
+ import { dirname as dirname4, join as join6 } from "path";
38921
39219
  async function update(options = {}) {
38922
39220
  const cwd = options.cwd ?? process.cwd();
38923
39221
  const run = options.run ?? runCommand2;
38924
39222
  const home = options.home ?? homedir3();
38925
- const pkg = readJson2(join5(cwd, "package.json"));
39223
+ const pkg = readJson2(join6(cwd, "package.json"));
38926
39224
  const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
38927
39225
  if (!pkg || !deps.usepilot) {
38928
39226
  return `# Pilot isn't installed here
@@ -38939,7 +39237,7 @@ Run this in your app's folder, the one where Pilot was set up. To set Pilot up i
38939
39237
  const after = installed ? installedVersion(cwd, root) ?? VERSION : before;
38940
39238
  const skills = [];
38941
39239
  for (const folder of skillFolders(root, home)) {
38942
- if (!existsSync6(folder) || isLink2(folder)) continue;
39240
+ if (!existsSync7(folder) || isLink2(folder)) continue;
38943
39241
  await writeSkill(folder);
38944
39242
  skills.push(folder.startsWith(home) ? `~${folder.slice(home.length)}` : folder);
38945
39243
  }
@@ -38976,13 +39274,13 @@ ${steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}
38976
39274
  ` : "Nothing else to do.\n"}`;
38977
39275
  }
38978
39276
  function bridgeOf(cwd, root) {
38979
- for (let dir = cwd; ; dir = dirname3(dir)) {
38980
- const file2 = join5(dir, "node_modules", "usepilot", "cli", "index.js");
38981
- if (existsSync6(file2)) {
38982
- const match = /BRIDGE_VERSION = (\d+)/.exec(readFileSync3(file2, "utf8"));
39277
+ for (let dir = cwd; ; dir = dirname4(dir)) {
39278
+ const file2 = join6(dir, "node_modules", "usepilot", "cli", "index.js");
39279
+ if (existsSync7(file2)) {
39280
+ const match = /BRIDGE_VERSION = (\d+)/.exec(readFileSync4(file2, "utf8"));
38983
39281
  return match ? Number(match[1]) : null;
38984
39282
  }
38985
- if (dir === root || dirname3(dir) === dir) return null;
39283
+ if (dir === root || dirname4(dir) === dir) return null;
38986
39284
  }
38987
39285
  }
38988
39286
  function isLink2(path) {
@@ -38994,7 +39292,7 @@ function isLink2(path) {
38994
39292
  }
38995
39293
  function readJson2(file2) {
38996
39294
  try {
38997
- return JSON.parse(readFileSync3(file2, "utf8"));
39295
+ return JSON.parse(readFileSync4(file2, "utf8"));
38998
39296
  } catch {
38999
39297
  return null;
39000
39298
  }