usepilot 0.5.0 → 0.7.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/README.md +18 -14
- package/cli/index.js +722 -180
- package/dist/{mount-C8kQoeYt.js → mount-axJemjam.js} +2742 -2055
- package/dist/pilot-auto.js +1 -1
- package/dist/pilot.js +1 -1
- package/package.json +1 -1
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,
|
|
3915
|
+
function resolveComponent(base, relative4, options, skipNormalization) {
|
|
3916
3916
|
const target = {};
|
|
3917
3917
|
if (!skipNormalization) {
|
|
3918
3918
|
base = parse3(serialize(base, options), options);
|
|
3919
|
-
|
|
3919
|
+
relative4 = parse3(serialize(relative4, options), options);
|
|
3920
3920
|
}
|
|
3921
3921
|
options = options || {};
|
|
3922
|
-
if (!options.tolerant &&
|
|
3923
|
-
target.scheme =
|
|
3924
|
-
target.userinfo =
|
|
3925
|
-
target.host =
|
|
3926
|
-
target.port =
|
|
3927
|
-
target.path = removeDotSegments(
|
|
3928
|
-
target.query =
|
|
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;
|
|
3929
3929
|
} else {
|
|
3930
|
-
if (
|
|
3931
|
-
target.userinfo =
|
|
3932
|
-
target.host =
|
|
3933
|
-
target.port =
|
|
3934
|
-
target.path = removeDotSegments(
|
|
3935
|
-
target.query =
|
|
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;
|
|
3936
3936
|
} else {
|
|
3937
|
-
if (!
|
|
3937
|
+
if (!relative4.path) {
|
|
3938
3938
|
target.path = base.path;
|
|
3939
|
-
if (
|
|
3940
|
-
target.query =
|
|
3939
|
+
if (relative4.query !== void 0) {
|
|
3940
|
+
target.query = relative4.query;
|
|
3941
3941
|
} else {
|
|
3942
3942
|
target.query = base.query;
|
|
3943
3943
|
}
|
|
3944
3944
|
} else {
|
|
3945
|
-
if (
|
|
3946
|
-
target.path = removeDotSegments(
|
|
3945
|
+
if (relative4.path[0] === "/") {
|
|
3946
|
+
target.path = removeDotSegments(relative4.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 = "/" +
|
|
3950
|
+
target.path = "/" + relative4.path;
|
|
3951
3951
|
} else if (!base.path) {
|
|
3952
|
-
target.path =
|
|
3952
|
+
target.path = relative4.path;
|
|
3953
3953
|
} else {
|
|
3954
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
3954
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative4.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 =
|
|
3958
|
+
target.query = relative4.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 =
|
|
3966
|
+
target.fragment = relative4.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
|
|
26764
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
26765
26765
|
function run(s) {
|
|
26766
|
-
const cached2 =
|
|
26766
|
+
const cached2 = cache2.get(s);
|
|
26767
26767
|
if (cached2 === RESOLVING) {
|
|
26768
26768
|
return new $ZodLazy({
|
|
26769
26769
|
type: "lazy",
|
|
26770
|
-
getter: () =>
|
|
26770
|
+
getter: () => cache2.get(s)
|
|
26771
26771
|
});
|
|
26772
26772
|
}
|
|
26773
26773
|
if (cached2 !== void 0)
|
|
26774
26774
|
return cached2;
|
|
26775
|
-
|
|
26775
|
+
cache2.set(s, RESOLVING);
|
|
26776
26776
|
const inner = mapInner(s);
|
|
26777
26777
|
const mapped = fn(inner, inner !== s);
|
|
26778
|
-
|
|
26778
|
+
cache2.set(s, mapped);
|
|
26779
26779
|
return mapped;
|
|
26780
26780
|
}
|
|
26781
26781
|
function mapInner(s) {
|
|
@@ -36692,10 +36692,14 @@ var BY_EXTENSION = {
|
|
|
36692
36692
|
json: "application/json"
|
|
36693
36693
|
};
|
|
36694
36694
|
var ATTACHMENT_ACCEPT = [...new Set(Object.values(ATTACHMENT_TYPES))].join(",") + "," + Object.keys(BY_EXTENSION).map((e) => `.${e}`).join(",");
|
|
36695
|
+
function requestTargets(request) {
|
|
36696
|
+
return [request.target, ...request.others ?? []];
|
|
36697
|
+
}
|
|
36695
36698
|
|
|
36696
36699
|
// ../protocol/src/format.ts
|
|
36697
|
-
function formatPrompt(changeSet) {
|
|
36700
|
+
function formatPrompt(changeSet, options = {}) {
|
|
36698
36701
|
if (changeSet.request?.kind === "responsive") return formatResponsive(changeSet, changeSet.request);
|
|
36702
|
+
if (changeSet.request?.kind === "break-and-fix") return formatBreakFix(changeSet, changeSet.request);
|
|
36699
36703
|
if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request);
|
|
36700
36704
|
const { page, edits, note } = changeSet;
|
|
36701
36705
|
const lines = [
|
|
@@ -36703,13 +36707,8 @@ function formatPrompt(changeSet) {
|
|
|
36703
36707
|
"",
|
|
36704
36708
|
"A designer adjusted the UI below in the browser with Pilot. Apply these changes to the source code.",
|
|
36705
36709
|
"",
|
|
36706
|
-
|
|
36707
|
-
|
|
36708
|
-
"- Prefer an existing token or utility when it matches the value (or is within a pixel or two); mention any value you had to approximate.",
|
|
36709
|
-
"- Change only the listed elements. If an element is a shared component, ask before changing every instance.",
|
|
36710
|
-
`- 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.`,
|
|
36711
|
-
"- 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.",
|
|
36712
|
-
"- 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).",
|
|
36710
|
+
// In full when pasted; an agent connected to Pilot read them once (pilot_wait_for_edits's description).
|
|
36711
|
+
...options.guidelines === false ? [EDIT_GUIDELINES_REMINDER] : ["Guidelines:", ...EDIT_GUIDELINES],
|
|
36713
36712
|
"",
|
|
36714
36713
|
`Page: ${page.url} (${page.title || "untitled"}) at ${page.viewport.width}x${page.viewport.height}`
|
|
36715
36714
|
];
|
|
@@ -36722,15 +36721,100 @@ function formatPrompt(changeSet) {
|
|
|
36722
36721
|
return `${lines.join("\n")}
|
|
36723
36722
|
`;
|
|
36724
36723
|
}
|
|
36725
|
-
var ADVANCED_TASK =
|
|
36724
|
+
var ADVANCED_TASK = "**An advanced task: it needs judgment more than speed.** If you can hand work to a more capable model than the one you run on (a subagent, or another model your agent offers), do: give it this whole prompt (with the job id), have it make the changes and run the width check, and report back; then call `pilot_done` with its notes.";
|
|
36725
|
+
var DESIGN_INTENT = "**These are design instructions, not code**: the designer's intent, shown as plain CSS values. Use your judgment and write production code the way this project already styles things, whatever it uses (Tailwind, CSS or Sass modules, StyleX, vanilla-extract, Panda, styled-components, Emotion, a component library's props\u2026). First look at how each element's component is styled, and follow that: its tokens and scale, its variants and props, and the rule that already styles it rather than a new override.";
|
|
36726
|
+
var PRODUCTION_CODE = "No inline styles, no `!important`, no hard-coded values where a token or utility fits.";
|
|
36727
|
+
var SHARED_CHOICES = {
|
|
36728
|
+
all: { label: "All of them", means: "change the component (or the shared code) itself, so every instance gets it." },
|
|
36729
|
+
one: {
|
|
36730
|
+
label: "Only this",
|
|
36731
|
+
means: "change it where this instance is used, with what the component already accepts: classes passed through its `className` (merged the way the project does, `cn`, `twMerge`), or one of its props. If it accepts neither, add the smallest pass-through (accept a `className`), not a variant. Never inline styles."
|
|
36732
|
+
},
|
|
36733
|
+
variant: {
|
|
36734
|
+
label: "New variant",
|
|
36735
|
+
means: "add a named option to the component, the way it defines its variants (a `cva` variant, a `variant` or `size` prop, a modifier class), named for its purpose, and use it here. Say its name in your notes."
|
|
36736
|
+
}
|
|
36737
|
+
};
|
|
36738
|
+
function sharedChoiceMeaning(answer) {
|
|
36739
|
+
const said = answer.trim().toLowerCase();
|
|
36740
|
+
const choice = Object.values(SHARED_CHOICES).find((c) => c.label.toLowerCase() === said);
|
|
36741
|
+
return choice ? `**${choice.label}**: ${choice.means}` : null;
|
|
36742
|
+
}
|
|
36743
|
+
var SHARED_CODE = [
|
|
36744
|
+
`**Shared code, only some copies:** an element's "Look-alikes" line counts the elements like it that this job leaves out (other instances of its component, or the same part of other copies). 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 in one short sentence with three choices, your suggestion first: "${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}" (Pilot's \`pilot_done\` takes a \`question\`; without Pilot's tools, ask in your reply). Their answer comes back to you as this job.`,
|
|
36745
|
+
...Object.values(SHARED_CHOICES).map((c) => `**${c.label}**: ${c.means}`),
|
|
36746
|
+
`Don't ask when the designer already said (in the comment or note: "only here", "every card", "as a variant"), when every copy is in the job, or when nothing else uses that code: just change it.`
|
|
36747
|
+
].join(" ");
|
|
36748
|
+
var EDIT_GUIDELINES = [
|
|
36749
|
+
`- ${DESIGN_INTENT}`,
|
|
36750
|
+
`- ${PRODUCTION_CODE} Prefer an existing token or utility when it matches the value (or is within a pixel or two): utility classes take the closest one in the project's scale or theme (\`padding-top: 24px\` \u2192 \`pt-6\`), arbitrary values only when nothing fits. Mention any value you had to approximate.`,
|
|
36751
|
+
"- Find each element by its selector, DOM path and text, then the component that renders it. Change only the listed elements.",
|
|
36752
|
+
`- ${SHARED_CODE}`,
|
|
36753
|
+
"- A removed property means the element shouldn't declare it at all: not `0` or `none`, the declaration gone.",
|
|
36754
|
+
"- No screenshots, builds or tests for these edits: hot reload shows them, and Pilot checks the page itself.",
|
|
36755
|
+
`- 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.`,
|
|
36756
|
+
"- 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.",
|
|
36757
|
+
"- 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)."
|
|
36758
|
+
];
|
|
36759
|
+
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.";
|
|
36760
|
+
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}`;
|
|
36761
|
+
var ACTION_ASKED = {
|
|
36762
|
+
responsive: "asked you to make it responsive",
|
|
36763
|
+
"break-and-fix": "asked you to break and fix it"
|
|
36764
|
+
};
|
|
36765
|
+
function formatBreakFix(changeSet, request) {
|
|
36766
|
+
const { page, note } = changeSet;
|
|
36767
|
+
const { breakpoints } = request;
|
|
36768
|
+
const several = requestTargets(request).length;
|
|
36769
|
+
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
36770
|
+
const lines = [
|
|
36771
|
+
"# Pilot: break and fix",
|
|
36772
|
+
"",
|
|
36773
|
+
several > 1 ? `A designer selected the ${several} elements below together in the browser with Pilot and asked you to stress-test each of them: make sure they hold up with real-world content, not only the placeholder values they were built with, and fix what breaks. Content should never break the layout.` : "A designer selected the element below in the browser with Pilot and asked you to stress-test it: make sure it holds up with real-world content, not only the placeholder values it was built with, and fix what breaks. Content should never break the layout.",
|
|
36774
|
+
"",
|
|
36775
|
+
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36776
|
+
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
36777
|
+
"",
|
|
36778
|
+
ADVANCED_TASK
|
|
36779
|
+
];
|
|
36780
|
+
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
36781
|
+
if (request.attachments?.length)
|
|
36782
|
+
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
36783
|
+
lines.push(
|
|
36784
|
+
"",
|
|
36785
|
+
...elementsSection(request),
|
|
36786
|
+
"",
|
|
36787
|
+
"## How to do it",
|
|
36788
|
+
"",
|
|
36789
|
+
"1. **Find the element's component and where its content comes from**: props, data, a CMS or an API, translations. List what can vary: each text, how many repeated items there are, optional parts (an image, a subtitle, a badge), numbers, names, URLs.",
|
|
36790
|
+
"2. **Think of the odd but realistic content each can get**: text far longer than the placeholder (a 120-character title, a long person or product name) and much shorter or empty; long words with no spaces (URLs, emails, IDs, compound words); optional parts missing (no image, no subtitle, an empty list) and many repeated items instead of a few; big numbers and prices; the longer strings of other languages; images (and background images) in odd shapes, very wide, very tall, tiny or low-resolution, and images that fail to load.",
|
|
36791
|
+
"3. **Break it on purpose, temporarily**: put that content in the page (the props, the fixture or data it renders, or the markup), let hot reload show it, and run `pilot_check_widths` with this job's id. It measures the element at every width in the designer's page and reports, as numbers, content sticking out of the viewport, spilling out of its parent, clipped, or overlapping. Read the code too, for what the check can't see: items that shrink when they shouldn't (an icon or avatar squeezed by flex), buttons that stretch, rows that misalign, text wrapping under an icon, images stretched or squashed (a distorted image keeps its box, so the check doesn't report it).",
|
|
36792
|
+
"4. **Fix what breaks, without changing how it looks with its usual content**, the way this project does it (its utilities, its components):",
|
|
36793
|
+
" - **Long text:** truncate it with an ellipsis (`truncate`, `text-overflow: ellipsis`) where one line matters, or clamp it to a few lines (`line-clamp-*`) where it can wrap; when the full text is lost, show it on hover (`title`, or the project's tooltip).",
|
|
36794
|
+
" - **Flex and grid:** `min-width: 0` (`min-w-0`) on items holding text so they can shrink; `flex-shrink: 0` (`shrink-0`) on icons, avatars and buttons that mustn't; `minmax(0, 1fr)` columns; wrapping rows (`flex-wrap`) instead of overflowing ones.",
|
|
36795
|
+
" - **Long words:** `overflow-wrap: anywhere` (`break-words`) where text must wrap.",
|
|
36796
|
+
" - **Images:** `object-fit: cover` for photos that should fill their frame, `contain` where cropping would lose something (logos, product shots); for background images, `background-size: cover` (or `contain`) with a sensible `background-position`. A fixed `aspect-ratio` (or size) on the frame, so the layout doesn't jump while an image loads or when its shape is odd, and a fallback when it fails or is missing (a plain background, initials, an icon), never a broken-image box.",
|
|
36797
|
+
" - **Missing parts:** no gap or empty box left behind; a simple empty state only where one is clearly needed.",
|
|
36798
|
+
" In the check, an ellipsis on your deliberately long text is the fix working, not a problem.",
|
|
36799
|
+
"5. **Put the real content back.** Remove every temporary value you added: nothing of the test may stay in the code. Then run `pilot_check_widths` again: with its usual content, the element must look as it did at the designer's width (the check reports any change there).",
|
|
36800
|
+
"6. **Report** in your notes, in a line or two, what broke and how you fixed it, and anything for the designer to decide (a content limit to agree on, an empty state to design). When you report it done, Pilot runs the width check once more, with the usual content: problems come back to you once, as a follow-up.",
|
|
36801
|
+
"",
|
|
36802
|
+
several > 1 ? `Change only these elements and what they need (their children, their containers). If they come from a shared component, fix it there, so every instance gets sturdier, as long as its usual look doesn't change; ask before anything that would. ${FIRST_CHECKED}` : "Change only this element and what it needs (its children, its container). If it's a shared component, fix it there, so every instance gets sturdier, as long as its usual look doesn't change; ask before anything that would.",
|
|
36803
|
+
"",
|
|
36804
|
+
PROJECT_CODE
|
|
36805
|
+
);
|
|
36806
|
+
return `${lines.join("\n")}
|
|
36807
|
+
`;
|
|
36808
|
+
}
|
|
36726
36809
|
function formatResponsive(changeSet, request) {
|
|
36727
36810
|
const { page, note } = changeSet;
|
|
36728
|
-
const {
|
|
36811
|
+
const { breakpoints } = request;
|
|
36812
|
+
const several = requestTargets(request).length;
|
|
36729
36813
|
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
36730
36814
|
const lines = [
|
|
36731
36815
|
"# Pilot: make responsive",
|
|
36732
36816
|
"",
|
|
36733
|
-
"A designer selected the element below in the browser with Pilot and asked you to make it work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.",
|
|
36817
|
+
several > 1 ? `A designer selected the ${several} elements below together in the browser with Pilot and asked you to make each of them work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.` : "A designer selected the element below in the browser with Pilot and asked you to make it work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.",
|
|
36734
36818
|
"",
|
|
36735
36819
|
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36736
36820
|
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
@@ -36738,11 +36822,11 @@ function formatResponsive(changeSet, request) {
|
|
|
36738
36822
|
ADVANCED_TASK
|
|
36739
36823
|
];
|
|
36740
36824
|
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
36825
|
+
if (request.attachments?.length)
|
|
36826
|
+
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
36741
36827
|
lines.push(
|
|
36742
36828
|
"",
|
|
36743
|
-
|
|
36744
|
-
"",
|
|
36745
|
-
...targetLines(target),
|
|
36829
|
+
...elementsSection(request),
|
|
36746
36830
|
"",
|
|
36747
36831
|
"## How to do it",
|
|
36748
36832
|
"",
|
|
@@ -36753,28 +36837,31 @@ function formatResponsive(changeSet, request) {
|
|
|
36753
36837
|
"5. **Check every width with `pilot_check_widths`** (Pilot's tool, with this job's id). It loads the page at a phone width (375px), each breakpoint and 1px below it, a wide desktop (1440px) and the designer's width, measures the element in each, and reports problems as numbers: sticking out of the viewport, spilling out of its parent, clipped content, overlaps, and anything that changed at the designer's width. No screenshots needed. Fix what it finds and run it again until it finds none. Without that tool (a pasted prompt), check those widths in a browser if you have one, and say which widths you couldn't check.",
|
|
36754
36838
|
"6. **Report** in your notes what changed at which widths, in a line or two, and anything you left for the designer to decide. When you report it done, Pilot runs the width check once more: problems come back to you once, as a follow-up.",
|
|
36755
36839
|
"",
|
|
36756
|
-
|
|
36840
|
+
several > 1 ? `Change only these elements and what their layout needs (their containers, their children). ${FIRST_CHECKED}` : "Change only this element and what its layout needs (its container, its children).",
|
|
36841
|
+
"",
|
|
36842
|
+
SHARED_CODE,
|
|
36843
|
+
"",
|
|
36844
|
+
PROJECT_CODE
|
|
36757
36845
|
);
|
|
36758
36846
|
return `${lines.join("\n")}
|
|
36759
36847
|
`;
|
|
36760
36848
|
}
|
|
36761
36849
|
function formatComment(changeSet, request) {
|
|
36762
36850
|
const { page } = changeSet;
|
|
36763
|
-
const {
|
|
36851
|
+
const { thread, breakpoints } = request;
|
|
36852
|
+
const several = requestTargets(request).length;
|
|
36764
36853
|
const latest = thread.at(-1);
|
|
36765
36854
|
const earlier = thread.slice(0, -1);
|
|
36766
36855
|
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
36767
36856
|
const lines = [
|
|
36768
36857
|
"# Pilot: comment",
|
|
36769
36858
|
"",
|
|
36770
|
-
"A designer left a comment on the element below, in the browser with Pilot. Do what it asks in the source code (or, if it's a question, answer it).",
|
|
36859
|
+
several > 1 ? `A designer left a comment on the ${several} elements below, selected together in the browser with Pilot: it's about each of them. Do what it asks in the source code (or, if it's a question, answer it).` : "A designer left a comment on the element below, in the browser with Pilot. Do what it asks in the source code (or, if it's a question, answer it).",
|
|
36771
36860
|
"",
|
|
36772
36861
|
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36773
36862
|
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
36774
36863
|
"",
|
|
36775
|
-
|
|
36776
|
-
"",
|
|
36777
|
-
...targetLines(target),
|
|
36864
|
+
...elementsSection(request),
|
|
36778
36865
|
"",
|
|
36779
36866
|
"## The comment",
|
|
36780
36867
|
"",
|
|
@@ -36784,7 +36871,8 @@ function formatComment(changeSet, request) {
|
|
|
36784
36871
|
lines.push("", "## The thread so far (you already did what it asked)", "");
|
|
36785
36872
|
for (const m of earlier) {
|
|
36786
36873
|
const files = m.attachments?.length ? ` (${countFiles(m.attachments.length)})` : "";
|
|
36787
|
-
|
|
36874
|
+
const action = m.action ? ` (${ACTION_ASKED[m.action]})` : "";
|
|
36875
|
+
lines.push(`- **${m.from === "designer" ? "Designer" : "You"}:**${action}${files} ${m.text.replace(/\s*\n\s*/g, " ")}`.trimEnd());
|
|
36788
36876
|
}
|
|
36789
36877
|
}
|
|
36790
36878
|
lines.push(
|
|
@@ -36792,9 +36880,11 @@ function formatComment(changeSet, request) {
|
|
|
36792
36880
|
"## How to do it",
|
|
36793
36881
|
"",
|
|
36794
36882
|
"- **A specific, small ask** (a color, a size, a spacing, a text): make it right away, in the project's conventions (its tokens, utilities, components). Speed matters: no screenshots or builds.",
|
|
36795
|
-
"- **An open-ended ask that needs design judgment** (make it calmer, rework this layout): it's an advanced task. If you can hand work to a more capable model
|
|
36883
|
+
"- **An open-ended ask that needs design judgment** (make it calmer, rework this layout): it's an advanced task. If you can hand work to a more capable model than the one you run on (a subagent, or another model your agent offers), do: give it this prompt (with the job id), and report back with its notes.",
|
|
36796
36884
|
`- The designer was looking at the page ${page.viewport.width}px wide. If the comment is about how it looks at that width only, scope the change with the project's breakpoints; otherwise it's for every width.`,
|
|
36797
|
-
|
|
36885
|
+
`- ${PROJECT_CODE}`,
|
|
36886
|
+
several > 1 ? "- Change only what the comment is about, on each of these elements." : "- Change only what the comment is about.",
|
|
36887
|
+
`- ${SHARED_CODE}`,
|
|
36798
36888
|
"- **A question, not a change:** answer it, and change nothing.",
|
|
36799
36889
|
"- **Your notes are your reply in the designer's thread, a small chat box for quick design back-and-forth:** keep it to one short sentence, like a chat message (about 120 characters at most): what you changed, or your answer, or the one thing you need from them. No lists, headings or code blocks; inline `code` for a value or a file name at most. Not a report: the designer sees the result on the page."
|
|
36800
36890
|
);
|
|
@@ -36811,26 +36901,43 @@ function commentLines(message) {
|
|
|
36811
36901
|
out.push(
|
|
36812
36902
|
text ? `The designer attached ${countFiles(files.length)} to it:` : `The comment is ${countFiles(files.length)}, with no words. ${one ? "It" : "They"} may hold the instructions: a screenshot, a sketch, notes, a spec. If it's unclear what to do, ask in your reply instead of guessing.`,
|
|
36813
36903
|
"",
|
|
36814
|
-
...files
|
|
36815
|
-
const kind = attachmentKind(file2.id);
|
|
36816
|
-
const how = kind === "pdf" ? "a PDF: open it at this path" : kind === "image" ? "an image, shown with this job" : "a text file, its contents shown with this job";
|
|
36817
|
-
return `- ${file2.name ? `${file2.name} ` : ""}(${how}): \`${file2.path ?? file2.id}\``;
|
|
36818
|
-
})
|
|
36904
|
+
...attachmentLines(files)
|
|
36819
36905
|
);
|
|
36820
36906
|
return out;
|
|
36821
36907
|
}
|
|
36908
|
+
function attachmentLines(files, intro) {
|
|
36909
|
+
const lines = files.map((file2) => {
|
|
36910
|
+
const kind = attachmentKind(file2.id);
|
|
36911
|
+
const how = kind === "pdf" ? "a PDF: open it at this path" : kind === "image" ? "an image, shown with this job" : "a text file, its contents shown with this job";
|
|
36912
|
+
return `- ${file2.name ? `${file2.name} ` : ""}(${how}): \`${file2.path ?? file2.id}\``;
|
|
36913
|
+
});
|
|
36914
|
+
return intro ? [intro, "", ...lines] : lines;
|
|
36915
|
+
}
|
|
36822
36916
|
function countFiles(n) {
|
|
36823
36917
|
return n === 1 ? "a file" : `${n} files`;
|
|
36824
36918
|
}
|
|
36825
36919
|
function quote(text) {
|
|
36826
36920
|
return text.trim().split("\n").map((l) => `> ${l}`).join("\n");
|
|
36827
36921
|
}
|
|
36922
|
+
var FIRST_CHECKED = "Pilot's width check (`pilot_check_widths`, and the one after you're done) measures the first of them; read the code for the others.";
|
|
36923
|
+
function elementsSection(request) {
|
|
36924
|
+
const targets = requestTargets(request);
|
|
36925
|
+
if (targets.length === 1) return [`## \`${request.target.path}\``, "", ...targetLines(request.target)];
|
|
36926
|
+
const out = [`## The elements (${targets.length})`];
|
|
36927
|
+
targets.forEach((target, i) => out.push("", `### ${i + 1}. \`${target.path}\``, "", ...targetLines(target)));
|
|
36928
|
+
return out;
|
|
36929
|
+
}
|
|
36828
36930
|
function targetLines(target) {
|
|
36829
36931
|
const out = [`- Selector: \`${target.selector}\``];
|
|
36830
36932
|
if (target.text) out.push(`- Text: "${target.text}"`);
|
|
36831
36933
|
if (target.source?.component || target.source?.file) {
|
|
36832
|
-
const
|
|
36833
|
-
|
|
36934
|
+
const { component, file: file2, line } = target.source;
|
|
36935
|
+
const where = [component && `\`${component}\``, file2 && `\`${file2}${line ? `:${line}` : ""}\``].filter(Boolean).join(", in ");
|
|
36936
|
+
out.push(`- Component: ${where} (from the framework's dev info)`);
|
|
36937
|
+
}
|
|
36938
|
+
if (target.lookAlikes) {
|
|
36939
|
+
const of = target.lookAlikesOf ? `other instances of \`${target.lookAlikesOf}\`, the same part of each` : "the same part of other copies";
|
|
36940
|
+
out.push(`- Look-alikes: ${target.lookAlikes} more on the page (${of}), not in this job`);
|
|
36834
36941
|
}
|
|
36835
36942
|
return out;
|
|
36836
36943
|
}
|
|
@@ -36909,8 +37016,15 @@ function formatWidthCheck(check2) {
|
|
|
36909
37016
|
}
|
|
36910
37017
|
|
|
36911
37018
|
// ../protocol/src/bridge.ts
|
|
36912
|
-
var
|
|
36913
|
-
var
|
|
37019
|
+
var BRIDGE_VERSION = 4;
|
|
37020
|
+
var DEFAULT_BRIDGE_PORT = 4747 + BRIDGE_VERSION;
|
|
37021
|
+
var MAX_CHOICES = 4;
|
|
37022
|
+
function questionOf(value) {
|
|
37023
|
+
const q = value;
|
|
37024
|
+
if (typeof q?.text !== "string" || !q.text.trim()) return void 0;
|
|
37025
|
+
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);
|
|
37026
|
+
return { text: q.text.trim().slice(0, 500), ...choices.length ? { choices } : {} };
|
|
37027
|
+
}
|
|
36914
37028
|
function originOf(url2) {
|
|
36915
37029
|
try {
|
|
36916
37030
|
const u = new URL(url2.includes("://") ? url2 : `http://${url2}`);
|
|
@@ -36979,23 +37093,29 @@ async function saveAttachment(bytes, type, dir = attachmentsDir()) {
|
|
|
36979
37093
|
}
|
|
36980
37094
|
function withAttachmentPaths(job, dir = attachmentsDir()) {
|
|
36981
37095
|
const request = job.changeSet.request;
|
|
36982
|
-
|
|
36983
|
-
|
|
36984
|
-
|
|
36985
|
-
const attachments = message.attachments.filter((file2) => typeof file2?.id === "string" && ATTACHMENT_ID.test(file2.id) && existsSync(join(dir, file2.id))).slice(0, 20).map((file2) => ({
|
|
37096
|
+
const kept = (files) => {
|
|
37097
|
+
if (!Array.isArray(files)) return void 0;
|
|
37098
|
+
const valid = files.filter((file2) => typeof file2?.id === "string" && ATTACHMENT_ID.test(file2.id) && existsSync(join(dir, file2.id))).slice(0, 20).map((file2) => ({
|
|
36986
37099
|
id: file2.id,
|
|
36987
37100
|
name: typeof file2.name === "string" ? file2.name.slice(0, 200) : void 0,
|
|
36988
37101
|
path: join(dir, file2.id)
|
|
36989
37102
|
}));
|
|
36990
|
-
return
|
|
36991
|
-
}
|
|
37103
|
+
return valid.length ? valid : void 0;
|
|
37104
|
+
};
|
|
37105
|
+
if (request && request.kind !== "comment")
|
|
37106
|
+
return { ...job, changeSet: { ...job.changeSet, request: { ...request, attachments: kept(request.attachments) } } };
|
|
37107
|
+
if (request?.kind !== "comment") return job;
|
|
37108
|
+
const thread = request.thread.map((message) => message.attachments ? { ...message, attachments: kept(message.attachments) } : message);
|
|
36992
37109
|
return { ...job, changeSet: { ...job.changeSet, request: { ...request, thread } } };
|
|
36993
37110
|
}
|
|
36994
37111
|
async function attachmentBlocks(job) {
|
|
36995
37112
|
const request = job.changeSet.request;
|
|
36996
|
-
|
|
36997
|
-
|
|
36998
|
-
|
|
37113
|
+
let files;
|
|
37114
|
+
if (request && request.kind !== "comment") files = request.attachments ?? [];
|
|
37115
|
+
else if (request?.kind === "comment") {
|
|
37116
|
+
const lastReply = request.thread.map((m) => m.from).lastIndexOf("agent");
|
|
37117
|
+
files = request.thread.slice(lastReply + 1).flatMap((m) => m.attachments ?? []);
|
|
37118
|
+
} else return [];
|
|
36999
37119
|
const blocks = [];
|
|
37000
37120
|
for (const file2 of files) {
|
|
37001
37121
|
const path = file2.path;
|
|
@@ -37107,12 +37227,30 @@ var Hub = class {
|
|
|
37107
37227
|
this.notifyAgents(key);
|
|
37108
37228
|
});
|
|
37109
37229
|
}
|
|
37110
|
-
/**
|
|
37111
|
-
|
|
37230
|
+
/**
|
|
37231
|
+
* The agent applied a job: done, with its notes, and its `question` for
|
|
37232
|
+
* the designer if it asked one (the page shows it and holds the job until
|
|
37233
|
+
* the answer, see answer). A job asks once: a question on an answered job
|
|
37234
|
+
* is dropped. Null for a job the hub doesn't know.
|
|
37235
|
+
*/
|
|
37236
|
+
done(agentId, jobId, notes, question) {
|
|
37112
37237
|
const job = this.jobs.get(jobId);
|
|
37113
37238
|
if (!job || job.status === "cancelled") return null;
|
|
37114
37239
|
const agent = this.agents.get(agentId)?.info ?? job.agent;
|
|
37115
|
-
|
|
37240
|
+
const asks = question && !job.answer ? { question } : {};
|
|
37241
|
+
this.update(job, { status: "done", agent, notes: notes?.trim() || void 0, doneAt: new Date(this.now()).toISOString(), ...asks });
|
|
37242
|
+
return job;
|
|
37243
|
+
}
|
|
37244
|
+
/**
|
|
37245
|
+
* The designer answered a done job's question: the job goes back to the
|
|
37246
|
+
* queue with the answer, preferably to the agent that asked. Null when it
|
|
37247
|
+
* can't (not done, no question, or answered already).
|
|
37248
|
+
*/
|
|
37249
|
+
answer(origin, jobId, answer) {
|
|
37250
|
+
const job = this.jobs.get(jobId);
|
|
37251
|
+
if (!job || job.origin !== originKey(origin) || job.status !== "done" || !job.question || job.answer) return null;
|
|
37252
|
+
this.update(job, { status: "queued", answer, notes: void 0 });
|
|
37253
|
+
this.dispatch(job.origin);
|
|
37116
37254
|
return job;
|
|
37117
37255
|
}
|
|
37118
37256
|
/**
|
|
@@ -37175,11 +37313,13 @@ var Hub = class {
|
|
|
37175
37313
|
origin: key,
|
|
37176
37314
|
changeSet: post.changeSet,
|
|
37177
37315
|
status: stillWorking ? "working" : "queued",
|
|
37178
|
-
// A follow-up keeps its agent as the one to prefer (see dispatch).
|
|
37179
|
-
agent: stillWorking || post.attempt === 2 ? post.agent : void 0,
|
|
37316
|
+
// A follow-up (or an answered question) keeps its agent as the one to prefer (see dispatch).
|
|
37317
|
+
agent: stillWorking || post.attempt === 2 || post.answer ? post.agent : void 0,
|
|
37180
37318
|
attempt: post.attempt ?? 1,
|
|
37181
37319
|
differences: post.differences,
|
|
37182
37320
|
issues: post.issues,
|
|
37321
|
+
question: post.question,
|
|
37322
|
+
answer: post.answer,
|
|
37183
37323
|
createdAt: at,
|
|
37184
37324
|
updatedAt: at
|
|
37185
37325
|
};
|
|
@@ -37217,7 +37357,7 @@ var Hub = class {
|
|
|
37217
37357
|
return [...this.jobs.values()].filter((j) => j.origin === origin && j.status === "queued").sort((a, b) => a.createdAt.localeCompare(b.createdAt))[0];
|
|
37218
37358
|
}
|
|
37219
37359
|
take(job, agent) {
|
|
37220
|
-
this.update(job, { status: "working", agent });
|
|
37360
|
+
this.update(job, { status: "working", agent, takenAt: new Date(this.now()).toISOString() });
|
|
37221
37361
|
return job;
|
|
37222
37362
|
}
|
|
37223
37363
|
/**
|
|
@@ -37331,10 +37471,12 @@ async function handle(hub, req, res, attachments) {
|
|
|
37331
37471
|
if (typeof post?.id !== "string" || !post.changeSet) return json2(res, 400, { error: "job needs id and changeSet" });
|
|
37332
37472
|
return json2(res, 202, { job: hub.postJob(origin, withAttachmentPaths(post, attachments)) });
|
|
37333
37473
|
}
|
|
37334
|
-
const jobRoute = path.match(/^\/jobs\/([^/]+)\/(cancel|retry)$/);
|
|
37474
|
+
const jobRoute = path.match(/^\/jobs\/([^/]+)\/(cancel|retry|answer)$/);
|
|
37335
37475
|
if (jobRoute) {
|
|
37336
37476
|
const [, id, action] = jobRoute;
|
|
37337
|
-
const
|
|
37477
|
+
const answer = data.answer;
|
|
37478
|
+
if (action === "answer" && (typeof answer !== "string" || !answer.trim())) return json2(res, 400, { error: "answer needed" });
|
|
37479
|
+
const job = action === "cancel" ? hub.cancel(origin, decodeURIComponent(id)) : action === "answer" ? hub.answer(origin, decodeURIComponent(id), answer.trim().slice(0, 2e3)) : hub.retry(
|
|
37338
37480
|
origin,
|
|
37339
37481
|
decodeURIComponent(id),
|
|
37340
37482
|
(data.differences ?? []).slice(0, 200),
|
|
@@ -37388,7 +37530,7 @@ async function handleAgent(hub, action, data, req, res) {
|
|
|
37388
37530
|
}
|
|
37389
37531
|
case "done":
|
|
37390
37532
|
if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
|
|
37391
|
-
return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes) });
|
|
37533
|
+
return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes, questionOf(d.question)) });
|
|
37392
37534
|
case "check": {
|
|
37393
37535
|
if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
|
|
37394
37536
|
const check2 = await hub.check(d.jobId, Math.min(d.timeoutMs ?? CHECK_TIMEOUT, 2 * 6e4));
|
|
@@ -37469,8 +37611,8 @@ var LocalApi = class {
|
|
|
37469
37611
|
localAgents.add(agent.id);
|
|
37470
37612
|
return this.hub.wait(agent, origin, timeoutMs, signal);
|
|
37471
37613
|
}
|
|
37472
|
-
async done(agent, jobId, notes) {
|
|
37473
|
-
return this.hub.done(agent.id, jobId, notes);
|
|
37614
|
+
async done(agent, jobId, notes, question) {
|
|
37615
|
+
return this.hub.done(agent.id, jobId, notes, question);
|
|
37474
37616
|
}
|
|
37475
37617
|
check(_agent, jobId, timeoutMs) {
|
|
37476
37618
|
return this.hub.check(jobId, timeoutMs);
|
|
@@ -37504,8 +37646,8 @@ var RemoteApi = class {
|
|
|
37504
37646
|
wait(agent, origin, timeoutMs, signal) {
|
|
37505
37647
|
return this.post("wait", { agent, origin, timeoutMs }, signal);
|
|
37506
37648
|
}
|
|
37507
|
-
async done(agent, jobId, notes) {
|
|
37508
|
-
return (await this.post("done", { agent, jobId, notes })).job;
|
|
37649
|
+
async done(agent, jobId, notes, question) {
|
|
37650
|
+
return (await this.post("done", { agent, jobId, notes, question })).job;
|
|
37509
37651
|
}
|
|
37510
37652
|
async check(agent, jobId, timeoutMs) {
|
|
37511
37653
|
return (await this.post("check", { agent, jobId, timeoutMs })).check;
|
|
@@ -37553,8 +37695,8 @@ var Bridge = class {
|
|
|
37553
37695
|
}
|
|
37554
37696
|
}
|
|
37555
37697
|
}
|
|
37556
|
-
done(jobId, notes) {
|
|
37557
|
-
return this.call((api) => api.done(this.agent, jobId, notes));
|
|
37698
|
+
done(jobId, notes, question) {
|
|
37699
|
+
return this.call((api) => api.done(this.agent, jobId, notes, question));
|
|
37558
37700
|
}
|
|
37559
37701
|
/** Pilot's width check of a task's element, measured by the page (null: no page answered). */
|
|
37560
37702
|
check(jobId, timeoutMs = CHECK_TIMEOUT) {
|
|
@@ -37603,7 +37745,7 @@ var Bridge = class {
|
|
|
37603
37745
|
if (!health.pilot) throw new Error(`Port ${this.port} is used by another program. Set PILOT_PORT to use another port.`);
|
|
37604
37746
|
if (health.version !== BRIDGE_VERSION) {
|
|
37605
37747
|
throw new Error(
|
|
37606
|
-
`Another Pilot version (bridge ${health.version}) runs on port ${this.port}.
|
|
37748
|
+
`Another Pilot version (bridge ${health.version}) runs on port ${this.port}. Each version has its own port, so this one was set by hand (PILOT_PORT): unset it, or use the same Pilot version everywhere.`
|
|
37607
37749
|
);
|
|
37608
37750
|
}
|
|
37609
37751
|
this.api = new RemoteApi(this.port);
|
|
@@ -37645,6 +37787,156 @@ function isConnectionError(error62) {
|
|
|
37645
37787
|
return code === "ECONNREFUSED" || code === "ECONNRESET" || code === "UND_ERR_SOCKET" || /fetch failed|socket hang up|other side closed/i.test(e?.message ?? "");
|
|
37646
37788
|
}
|
|
37647
37789
|
|
|
37790
|
+
// src/locate.ts
|
|
37791
|
+
import { existsSync as existsSync2, readdirSync, readFileSync, statSync } from "fs";
|
|
37792
|
+
import { extname, join as join2, relative } from "path";
|
|
37793
|
+
var SKIP = /* @__PURE__ */ new Set([
|
|
37794
|
+
"node_modules",
|
|
37795
|
+
"dist",
|
|
37796
|
+
"build",
|
|
37797
|
+
"out",
|
|
37798
|
+
"coverage",
|
|
37799
|
+
"vendor",
|
|
37800
|
+
".git",
|
|
37801
|
+
".next",
|
|
37802
|
+
".nuxt",
|
|
37803
|
+
".svelte-kit",
|
|
37804
|
+
".output",
|
|
37805
|
+
".vercel",
|
|
37806
|
+
".turbo",
|
|
37807
|
+
".cache"
|
|
37808
|
+
]);
|
|
37809
|
+
var EXTENSIONS = /* @__PURE__ */ new Set([
|
|
37810
|
+
".html",
|
|
37811
|
+
".htm",
|
|
37812
|
+
".jsx",
|
|
37813
|
+
".tsx",
|
|
37814
|
+
".js",
|
|
37815
|
+
".ts",
|
|
37816
|
+
".mjs",
|
|
37817
|
+
".vue",
|
|
37818
|
+
".svelte",
|
|
37819
|
+
".astro",
|
|
37820
|
+
".mdx",
|
|
37821
|
+
".php",
|
|
37822
|
+
".erb",
|
|
37823
|
+
".hbs",
|
|
37824
|
+
".njk",
|
|
37825
|
+
".liquid",
|
|
37826
|
+
".twig"
|
|
37827
|
+
]);
|
|
37828
|
+
var MAX_FILES = 4e3;
|
|
37829
|
+
var MAX_FILE_BYTES = 512e3;
|
|
37830
|
+
var BUDGET_MS = 800;
|
|
37831
|
+
var cache = null;
|
|
37832
|
+
function sourceFiles(root) {
|
|
37833
|
+
if (cache && cache.root === root && Date.now() - cache.at < 3e4) return cache.files;
|
|
37834
|
+
const files = [];
|
|
37835
|
+
const walk = (dir) => {
|
|
37836
|
+
let names;
|
|
37837
|
+
try {
|
|
37838
|
+
names = readdirSync(dir);
|
|
37839
|
+
} catch {
|
|
37840
|
+
return;
|
|
37841
|
+
}
|
|
37842
|
+
for (const name of names) {
|
|
37843
|
+
if (files.length >= MAX_FILES) return;
|
|
37844
|
+
if (SKIP.has(name) || name.startsWith(".") && name !== ".") continue;
|
|
37845
|
+
const path = join2(dir, name);
|
|
37846
|
+
let stat2;
|
|
37847
|
+
try {
|
|
37848
|
+
stat2 = statSync(path);
|
|
37849
|
+
} catch {
|
|
37850
|
+
continue;
|
|
37851
|
+
}
|
|
37852
|
+
if (stat2.isDirectory()) walk(path);
|
|
37853
|
+
else if (EXTENSIONS.has(extname(name)) && stat2.size <= MAX_FILE_BYTES) files.push(path);
|
|
37854
|
+
}
|
|
37855
|
+
};
|
|
37856
|
+
walk(root);
|
|
37857
|
+
cache = { root, at: Date.now(), files };
|
|
37858
|
+
return files;
|
|
37859
|
+
}
|
|
37860
|
+
function searchable(cwd) {
|
|
37861
|
+
return existsSync2(join2(cwd, "package.json")) || existsSync2(join2(cwd, ".git"));
|
|
37862
|
+
}
|
|
37863
|
+
var escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37864
|
+
function needles(target) {
|
|
37865
|
+
const text = target.text?.replace(/…$/, "").trim();
|
|
37866
|
+
const words = text?.split(/\s+/) ?? [];
|
|
37867
|
+
return {
|
|
37868
|
+
id: target.id ? new RegExp(`\\bid\\s*=\\s*[{"']*${escape2(target.id)}["'}]`) : null,
|
|
37869
|
+
// The whole text when it's short; else its first words (the rest may be split across lines or tags).
|
|
37870
|
+
text: text && text.length >= 3 && text.length <= 60 ? text : null,
|
|
37871
|
+
lead: words.length >= 3 ? words.slice(0, 3).join(" ") : null,
|
|
37872
|
+
classes: target.classes.filter((c) => c.length >= 2).map((c) => new RegExp(`(^|[\\s"'\`{])${escape2(c)}($|[\\s"'\`}])`)),
|
|
37873
|
+
tag: new RegExp(`<${escape2(target.tag)}[\\s>/]`, "i")
|
|
37874
|
+
};
|
|
37875
|
+
}
|
|
37876
|
+
function locate(target, root, deadline = Date.now() + BUDGET_MS) {
|
|
37877
|
+
const n = needles(target);
|
|
37878
|
+
if (!n.id && !n.text && !n.lead && n.classes.length < 3) return null;
|
|
37879
|
+
let best = null;
|
|
37880
|
+
for (const file2 of sourceFiles(root)) {
|
|
37881
|
+
if (Date.now() > deadline) break;
|
|
37882
|
+
let content;
|
|
37883
|
+
try {
|
|
37884
|
+
content = readFileSync(file2, "utf8");
|
|
37885
|
+
} catch {
|
|
37886
|
+
continue;
|
|
37887
|
+
}
|
|
37888
|
+
if (!(n.id && content.includes(target.id)) && !(n.text && content.includes(n.text)) && !(n.lead && content.includes(n.lead))) {
|
|
37889
|
+
if (n.classes.length < 3) continue;
|
|
37890
|
+
}
|
|
37891
|
+
const lines = content.split("\n");
|
|
37892
|
+
const classesOn = (i) => lines[i] === void 0 ? 0 : n.classes.filter((re) => re.test(lines[i])).length;
|
|
37893
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37894
|
+
const line = lines[i];
|
|
37895
|
+
let score = 0;
|
|
37896
|
+
if (n.id?.test(line)) score += 8;
|
|
37897
|
+
if (n.text && line.includes(n.text)) score += 6;
|
|
37898
|
+
else if (n.lead && line.includes(n.lead)) score += 4;
|
|
37899
|
+
let classes = 0;
|
|
37900
|
+
for (let j = Math.max(0, i - 3); j <= i; j++) classes = Math.max(classes, classesOn(j));
|
|
37901
|
+
score += classes;
|
|
37902
|
+
if (n.classes.length && classes === n.classes.length) score += 2;
|
|
37903
|
+
if (n.tag.test(line)) score += 1;
|
|
37904
|
+
if (!best || score > best.score) best = { file: file2, line: i, score, lines };
|
|
37905
|
+
}
|
|
37906
|
+
}
|
|
37907
|
+
const enough = best && (best.score >= 6 || n.classes.length >= 3 && best.score >= n.classes.length + 2);
|
|
37908
|
+
if (!best || !enough) return null;
|
|
37909
|
+
const from = Math.max(0, best.line - 2);
|
|
37910
|
+
const snippet = best.lines.slice(from, best.line + 3).map((l) => l.length > 160 ? `${l.slice(0, 159)}\u2026` : l).join("\n");
|
|
37911
|
+
return { file: relative(root, best.file), line: best.line + 1, snippet };
|
|
37912
|
+
}
|
|
37913
|
+
function whereSection(job, root) {
|
|
37914
|
+
if (!searchable(root)) return "";
|
|
37915
|
+
const targets = job.changeSet.request ? requestTargets(job.changeSet.request) : job.changeSet.edits.map((e) => e.target);
|
|
37916
|
+
const deadline = Date.now() + BUDGET_MS;
|
|
37917
|
+
const found = [];
|
|
37918
|
+
for (const target of targets) {
|
|
37919
|
+
const at = locate(target, root, deadline);
|
|
37920
|
+
if (!at) continue;
|
|
37921
|
+
const lang = extname(at.file).slice(1) || "text";
|
|
37922
|
+
found.push(
|
|
37923
|
+
`- \`${target.path}\` \u2192 \`${at.file}:${at.line}\`:`,
|
|
37924
|
+
"",
|
|
37925
|
+
` \`\`\`${lang}`,
|
|
37926
|
+
...at.snippet.split("\n").map((l) => ` ${l}`),
|
|
37927
|
+
" ```"
|
|
37928
|
+
);
|
|
37929
|
+
}
|
|
37930
|
+
if (!found.length) return "";
|
|
37931
|
+
return [
|
|
37932
|
+
"## Where the code probably is",
|
|
37933
|
+
"",
|
|
37934
|
+
"Pilot searched the project for these elements (by id, text and classes). Start there; if it isn't the right place (the text comes from a prop, a translation, a CMS), search as usual.",
|
|
37935
|
+
"",
|
|
37936
|
+
...found
|
|
37937
|
+
].join("\n");
|
|
37938
|
+
}
|
|
37939
|
+
|
|
37648
37940
|
// src/mcp.ts
|
|
37649
37941
|
function waitMsFor(clientName) {
|
|
37650
37942
|
const configured = Number(process.env.PILOT_WAIT_MS);
|
|
@@ -37657,10 +37949,10 @@ var INSTRUCTIONS = `Pilot lets the designer edit the running app in the browser
|
|
|
37657
37949
|
The loop, when the user asks to launch or start Pilot, runs /pilot, or asks to hand the design over:
|
|
37658
37950
|
1. Find the page: the URL of the app's dev server, from the dev script and its config (vite.config \u2192 server.port, Next.js \u2192 3000, a --port flag\u2026) or a server already running. If it isn't running, start it in the background; if you can't tell the URL, ask. Call pilot_launch with that URL: Pilot opens in that page (if the page isn't open, tell the user to open it), then tell the user in one line that Pilot is ready: select an element, edit, press Send.
|
|
37659
37951
|
2. Call pilot_wait_for_edits. It returns a job when the designer presses Send, or "no edits yet" after a while: then call it again. (In Claude Code a long wait moves to the background: the job arrives as its result.)
|
|
37660
|
-
3. Apply the job's edits to the source,
|
|
37661
|
-
4. Call pilot_done with the job id and short notes (values you approximated, anything you did differently). Then call pilot_wait_for_edits again.
|
|
37952
|
+
3. Apply the job's edits to the source: they're design instructions, not code, so write production code the way the project already styles things, whatever it uses (see the job's guidelines). Edits are basic: every value is given, so be fast (no screenshots or browser checks: Pilot checks the page). A "make responsive" job is an advanced task: make one element work at every viewport width. A "break and fix" job is one too: stress-test one element with odd but realistic content, fix what breaks, and put the real content back. Their prompts list the steps; check the result with pilot_check_widths (numbers for every width, instead of screenshots). If you can hand advanced tasks to a more capable model than the one you run on (a subagent, or another model your agent offers), do. A "comment" job is the designer's own words about one element: do what it asks (simple asks right away, open-ended ones as advanced tasks), and your pilot_done notes are your reply in their thread: one short sentence, like a chat message, not a report.
|
|
37953
|
+
4. Call pilot_done with the job id and short notes (values you approximated, anything you did differently). When part of a job needs the designer's decision (they changed only some copies of shared code: each element's "Look-alikes" line counts the others; the jobs' guidelines say when, and what each answer means), do the rest, leave that part, and ask with pilot_done's question and choices ("${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}", your suggestion first); go on with other jobs, and their answer comes back as that job. Then call pilot_wait_for_edits again. 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.
|
|
37662
37954
|
|
|
37663
|
-
Keep looping until the user interrupts you. Pilot keeps previewing each job's changes until you call pilot_done, then checks them against the page's real CSS: changes that didn't land come back once as a follow-up job with what the page gives instead.`;
|
|
37955
|
+
Keep looping until the user interrupts you. Between jobs keep your messages short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, then wait again: queued jobs are kept. Pilot keeps previewing each job's changes until you call pilot_done, then checks them against the page's real CSS: changes that didn't land come back once as a follow-up job with what the page gives instead.`;
|
|
37664
37956
|
function agentLabel(clientName, cwd) {
|
|
37665
37957
|
const names = {
|
|
37666
37958
|
"claude-code": "Claude Code",
|
|
@@ -37674,13 +37966,34 @@ function agentLabel(clientName, cwd) {
|
|
|
37674
37966
|
const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
|
|
37675
37967
|
return `${app} \xB7 ${basename2(cwd)}`;
|
|
37676
37968
|
}
|
|
37677
|
-
function jobPrompt(job) {
|
|
37678
|
-
const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : formatPrompt(job.changeSet);
|
|
37679
|
-
return `${body2}
|
|
37969
|
+
function jobPrompt(job, where = "") {
|
|
37970
|
+
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 });
|
|
37971
|
+
return `${body2}${where ? `
|
|
37972
|
+
${where}
|
|
37973
|
+
` : ""}
|
|
37680
37974
|
---
|
|
37681
37975
|
Pilot job \`${job.id}\`. When you've applied it, call \`pilot_done\` with \`jobId: "${job.id}"\` and short notes (${notesFor(job)}). Then call \`pilot_wait_for_edits\` again for the next job.
|
|
37682
37976
|
`;
|
|
37683
37977
|
}
|
|
37978
|
+
function answered(job) {
|
|
37979
|
+
const meaning = job.answer ? sharedChoiceMeaning(job.answer) : null;
|
|
37980
|
+
return [
|
|
37981
|
+
"# Pilot: the designer answered your question",
|
|
37982
|
+
"",
|
|
37983
|
+
`You did this job and asked the designer: ${job.question?.text}`,
|
|
37984
|
+
"",
|
|
37985
|
+
"Their answer:",
|
|
37986
|
+
"",
|
|
37987
|
+
job.answer?.trim().split("\n").map((l) => `> ${l}`).join("\n"),
|
|
37988
|
+
"",
|
|
37989
|
+
...meaning ? [`What that means for the code: ${meaning}`, ""] : [],
|
|
37990
|
+
"Do what's left of the job the way they answered, then call `pilot_done` again. Pilot then checks it like any job. (Don't ask again: say anything still open in your notes.)",
|
|
37991
|
+
"",
|
|
37992
|
+
"The job, for reference:",
|
|
37993
|
+
"",
|
|
37994
|
+
formatPrompt(job.changeSet, { guidelines: false })
|
|
37995
|
+
].join("\n");
|
|
37996
|
+
}
|
|
37684
37997
|
function followUp(job) {
|
|
37685
37998
|
const lines = [
|
|
37686
37999
|
"# Pilot design edits: follow-up",
|
|
@@ -37699,22 +38012,44 @@ function followUp(job) {
|
|
|
37699
38012
|
);
|
|
37700
38013
|
return lines.join("\n");
|
|
37701
38014
|
}
|
|
38015
|
+
var MAX_BATCH = 6;
|
|
38016
|
+
async function takeQueued(first, take) {
|
|
38017
|
+
const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment";
|
|
38018
|
+
if (advanced(first)) return [];
|
|
38019
|
+
const more = [];
|
|
38020
|
+
while (more.length < MAX_BATCH - 1) {
|
|
38021
|
+
const { job } = await take();
|
|
38022
|
+
if (!job) break;
|
|
38023
|
+
more.push(job);
|
|
38024
|
+
if (advanced(job)) break;
|
|
38025
|
+
}
|
|
38026
|
+
return more;
|
|
38027
|
+
}
|
|
38028
|
+
function batchIntro(jobs) {
|
|
38029
|
+
return `# Pilot: ${jobs.length} jobs
|
|
38030
|
+
|
|
38031
|
+
The designer sent these while you were busy. Do them all (they're on different elements), then call \`pilot_done\` once per job, each with its own id and notes (you can make the calls together): ${jobs.map((j) => `\`${j.id}\``).join(", ")}. Then call \`pilot_wait_for_edits\` again.`;
|
|
38032
|
+
}
|
|
37702
38033
|
function notesFor(job) {
|
|
37703
38034
|
switch (job.changeSet.request?.kind) {
|
|
37704
38035
|
case "comment":
|
|
37705
38036
|
return "your reply in the designer's comment thread, a small chat box: one short sentence, about 120 characters at most, with what you changed or your answer; no lists or code blocks";
|
|
37706
38037
|
case "responsive":
|
|
37707
38038
|
return "what changed at which widths, anything left for the designer";
|
|
38039
|
+
case "break-and-fix":
|
|
38040
|
+
return "what broke and how you fixed it, anything for the designer to decide";
|
|
37708
38041
|
default:
|
|
37709
38042
|
return "values you approximated, anything you did differently";
|
|
37710
38043
|
}
|
|
37711
38044
|
}
|
|
37712
38045
|
function taskFollowUp(job) {
|
|
37713
|
-
const
|
|
38046
|
+
const request = job.changeSet.request;
|
|
38047
|
+
const target = `\`${request?.target.path ?? "the element"}\``;
|
|
38048
|
+
const breakFix = request?.kind === "break-and-fix";
|
|
37714
38049
|
const lines = [
|
|
37715
|
-
"# Pilot: make responsive, follow-up",
|
|
38050
|
+
breakFix ? "# Pilot: break and fix, follow-up" : "# Pilot: make responsive, follow-up",
|
|
37716
38051
|
"",
|
|
37717
|
-
`You
|
|
38052
|
+
breakFix ? `You stress-tested ${target} and reported it done, but Pilot's width check (the page with its usual content, measured at each width) finds these problems. If one comes from test content still in the code, remove it:` : `You made ${target} responsive, but Pilot's width check (the page measured at each width) still finds these problems:`,
|
|
37718
38053
|
"",
|
|
37719
38054
|
...(job.issues ?? []).map((i) => `- ${i}`),
|
|
37720
38055
|
"",
|
|
@@ -37730,7 +38065,7 @@ function createPilotServer(options = {}) {
|
|
|
37730
38065
|
const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
|
|
37731
38066
|
const cwd = options.cwd ?? process.cwd();
|
|
37732
38067
|
let waitMs = options.waitMs ?? waitMsFor(void 0);
|
|
37733
|
-
const server = new McpServer({ name: "pilot", version: "0.
|
|
38068
|
+
const server = new McpServer({ name: "pilot", version: "0.7.0" }, { instructions: INSTRUCTIONS });
|
|
37734
38069
|
const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
|
|
37735
38070
|
const bridge = new Bridge(agent, port);
|
|
37736
38071
|
let origin = null;
|
|
@@ -37766,7 +38101,11 @@ function createPilotServer(options = {}) {
|
|
|
37766
38101
|
"pilot_wait_for_edits",
|
|
37767
38102
|
{
|
|
37768
38103
|
title: "Wait for design edits",
|
|
37769
|
-
|
|
38104
|
+
// The edit guidelines live here, read once with the tool, not repeated in every job (they're the most frequent).
|
|
38105
|
+
description: `Waits for the designer to press Send in Pilot, and returns the job to apply (or several, when they were queued: do them all, and report each done). Returns "no edits yet" after a few minutes: call it again to keep waiting. Call pilot_launch first.
|
|
38106
|
+
|
|
38107
|
+
Guidelines for every design-edits job (the job doesn't repeat them):
|
|
38108
|
+
${EDIT_GUIDELINES.join("\n")}`,
|
|
37770
38109
|
inputSchema: {}
|
|
37771
38110
|
},
|
|
37772
38111
|
async (_args, extra) => {
|
|
@@ -37783,7 +38122,25 @@ function createPilotServer(options = {}) {
|
|
|
37783
38122
|
try {
|
|
37784
38123
|
const { job } = await bridge.wait(origin, waitMs, extra.signal);
|
|
37785
38124
|
if (!job) return text("No edits yet. Call pilot_wait_for_edits again to keep waiting (the designer can keep editing meanwhile).");
|
|
37786
|
-
|
|
38125
|
+
const jobs = [job, ...await takeQueued(job, () => bridge.wait(origin, 0, extra.signal))];
|
|
38126
|
+
const parts = await Promise.all(
|
|
38127
|
+
jobs.map(async (j) => ({
|
|
38128
|
+
// Where its elements' code probably is: found here, in the project, so the agent can go straight to the edit.
|
|
38129
|
+
text: jobPrompt(j, j.attempt === 2 ? "" : whereSection(j, cwd)),
|
|
38130
|
+
// A comment's images and text files come with it, so the agent sees them without opening files.
|
|
38131
|
+
blocks: await attachmentBlocks(j)
|
|
38132
|
+
}))
|
|
38133
|
+
);
|
|
38134
|
+
if (parts.length === 1) return { content: [{ type: "text", text: parts[0]?.text ?? "" }, ...parts[0]?.blocks ?? []], isError: false };
|
|
38135
|
+
return {
|
|
38136
|
+
content: [
|
|
38137
|
+
{ type: "text", text: batchIntro(jobs) },
|
|
38138
|
+
...parts.flatMap((p, i) => [{ type: "text", text: `## Job ${i + 1} of ${jobs.length}
|
|
38139
|
+
|
|
38140
|
+
${p.text}` }, ...p.blocks])
|
|
38141
|
+
],
|
|
38142
|
+
isError: false
|
|
38143
|
+
};
|
|
37787
38144
|
} catch (error62) {
|
|
37788
38145
|
return text(`Pilot's bridge failed while waiting: ${error62.message}. Call pilot_wait_for_edits again.`, true);
|
|
37789
38146
|
} finally {
|
|
@@ -37795,16 +38152,26 @@ function createPilotServer(options = {}) {
|
|
|
37795
38152
|
"pilot_done",
|
|
37796
38153
|
{
|
|
37797
38154
|
title: "Report a job done",
|
|
37798
|
-
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.",
|
|
38155
|
+
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.",
|
|
37799
38156
|
inputSchema: {
|
|
37800
38157
|
jobId: external_exports.string().describe("The job's id, from pilot_wait_for_edits."),
|
|
37801
|
-
notes: external_exports.string().optional().describe("Short notes for the designer: values you approximated (e.g. 22px \u2192 pt-6, 24px), anything done differently.")
|
|
38158
|
+
notes: external_exports.string().optional().describe("Short notes for the designer: values you approximated (e.g. 22px \u2192 pt-6, 24px), anything done differently."),
|
|
38159
|
+
question: external_exports.object({
|
|
38160
|
+
text: external_exports.string().describe('One short sentence, e.g. "This title comes from the shared Card: change every card, or only this one?"'),
|
|
38161
|
+
choices: external_exports.array(external_exports.string()).max(MAX_CHOICES).optional().describe(
|
|
38162
|
+
`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.`
|
|
38163
|
+
)
|
|
38164
|
+
}).optional().describe("Only when part of the job needs the designer's decision: see the description.")
|
|
37802
38165
|
}
|
|
37803
38166
|
},
|
|
37804
|
-
async ({ jobId, notes }) => {
|
|
38167
|
+
async ({ jobId, notes, question }) => {
|
|
37805
38168
|
try {
|
|
37806
|
-
const
|
|
38169
|
+
const asked = questionOf(question);
|
|
38170
|
+
const job = await bridge.done(jobId, notes, asked);
|
|
37807
38171
|
if (!job) return text(`Pilot doesn't know job ${jobId} (or the designer cancelled it). Call pilot_wait_for_edits for the next one.`);
|
|
38172
|
+
if (asked && job.question)
|
|
38173
|
+
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.");
|
|
38174
|
+
if (asked) return text("Done. This job was answered already, so the question wasn't asked: Pilot is checking the changes. Say it in your notes next time. Call pilot_wait_for_edits for the next job.");
|
|
37808
38175
|
return text("Done. Pilot is checking the changes in the page. Call pilot_wait_for_edits for the next job.");
|
|
37809
38176
|
} catch (error62) {
|
|
37810
38177
|
return text(`Pilot couldn't report the job done: ${error62.message}`, true);
|
|
@@ -37815,9 +38182,9 @@ function createPilotServer(options = {}) {
|
|
|
37815
38182
|
"pilot_check_widths",
|
|
37816
38183
|
{
|
|
37817
38184
|
title: "Check an element at every width",
|
|
37818
|
-
description: "For a Make responsive job: Pilot loads the page in hidden frames at a phone width, each breakpoint and just below it, a wide desktop and the designer's width, and measures the job's element in each. Returns each width's size and layout, and problems (sticking out of the viewport, spilling out of its parent, clipped content, overlaps), plus what changed at the designer's width. Use it instead of screenshots; fix the problems and run it again until it finds none.",
|
|
38185
|
+
description: "For a Make responsive or Break and fix job: Pilot loads the page in hidden frames at a phone width, each breakpoint and just below it, a wide desktop and the designer's width, and measures the job's element in each. Returns each width's size and layout, and problems (sticking out of the viewport, spilling out of its parent, clipped content, overlaps), plus what changed at the designer's width. Use it instead of screenshots; fix the problems and run it again until it finds none.",
|
|
37819
38186
|
inputSchema: {
|
|
37820
|
-
jobId: external_exports.string().describe("The Make responsive job's id, from pilot_wait_for_edits.")
|
|
38187
|
+
jobId: external_exports.string().describe("The Make responsive or Break and fix job's id, from pilot_wait_for_edits.")
|
|
37821
38188
|
}
|
|
37822
38189
|
},
|
|
37823
38190
|
async ({ jobId }) => {
|
|
@@ -37825,7 +38192,7 @@ function createPilotServer(options = {}) {
|
|
|
37825
38192
|
const check2 = await bridge.check(jobId);
|
|
37826
38193
|
if (!check2) {
|
|
37827
38194
|
return text(
|
|
37828
|
-
`Pilot couldn't check job ${jobId}: no page answered. The page with Pilot must be open (the designer's tab), and the job must be a Make responsive one. If you can, check the widths in a browser instead.`,
|
|
38195
|
+
`Pilot couldn't check job ${jobId}: no page answered. The page with Pilot must be open (the designer's tab), and the job must be a Make responsive or Break and fix one. If you can, check the widths in a browser instead.`,
|
|
37829
38196
|
true
|
|
37830
38197
|
);
|
|
37831
38198
|
}
|
|
@@ -37840,18 +38207,19 @@ function createPilotServer(options = {}) {
|
|
|
37840
38207
|
|
|
37841
38208
|
// src/init.ts
|
|
37842
38209
|
import { spawnSync } from "child_process";
|
|
37843
|
-
import { existsSync as
|
|
38210
|
+
import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
|
|
37844
38211
|
import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
37845
|
-
import {
|
|
38212
|
+
import { homedir as homedir2 } from "os";
|
|
38213
|
+
import { dirname as dirname2, join as join4, relative as relative3 } from "path";
|
|
37846
38214
|
|
|
37847
38215
|
// src/setup.ts
|
|
37848
|
-
import { existsSync as
|
|
38216
|
+
import { existsSync as existsSync3 } from "fs";
|
|
37849
38217
|
import { lstat, mkdir as mkdir2, readFile as readFile2, unlink, writeFile as writeFile2 } from "fs/promises";
|
|
37850
38218
|
import { homedir } from "os";
|
|
37851
|
-
import { join as
|
|
38219
|
+
import { join as join3, relative as relative2 } from "path";
|
|
37852
38220
|
|
|
37853
38221
|
// ../../skills/pilot/SKILL.md
|
|
37854
|
-
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.\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 runs /pilot\n\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. 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.\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**: the designer selected an element and asked for an outcome (work at every viewport width). 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).
|
|
38222
|
+
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.\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 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. 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` 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";
|
|
37855
38223
|
|
|
37856
38224
|
// src/setup.ts
|
|
37857
38225
|
var MCP_SERVER = { command: "npx", args: ["-y", "usepilot", "mcp"] };
|
|
@@ -37859,7 +38227,7 @@ async function setup(options = {}) {
|
|
|
37859
38227
|
return options.project ? setupProject(options.cwd ?? process.cwd()) : setupMachine(options.home ?? homedir());
|
|
37860
38228
|
}
|
|
37861
38229
|
async function setupMachine(home) {
|
|
37862
|
-
const file2 = await writeSkill(
|
|
38230
|
+
const file2 = await writeSkill(join3(home, ".claude", "skills", "pilot"));
|
|
37863
38231
|
return `Installed the /pilot skill: ${file2}
|
|
37864
38232
|
|
|
37865
38233
|
Now register Pilot's MCP server with Claude Code, once, for every project:
|
|
@@ -37871,11 +38239,11 @@ Then, in any Claude Code chat: /pilot
|
|
|
37871
38239
|
`;
|
|
37872
38240
|
}
|
|
37873
38241
|
async function setupProject(cwd) {
|
|
37874
|
-
const skillFile = await writeSkill(
|
|
37875
|
-
const mcpFile =
|
|
38242
|
+
const skillFile = await writeSkill(join3(cwd, ".claude", "skills", "pilot"));
|
|
38243
|
+
const mcpFile = join3(cwd, ".mcp.json");
|
|
37876
38244
|
const { added } = await addMcpServer(mcpFile);
|
|
37877
|
-
const rel = (f) =>
|
|
37878
|
-
const app =
|
|
38245
|
+
const rel = (f) => relative2(cwd, f);
|
|
38246
|
+
const app = existsSync3(join3(cwd, "package.json")) ? "" : "\nNo package.json here: run this in the project's root folder, where the app is.\n";
|
|
37879
38247
|
const width = rel(skillFile).length + 2;
|
|
37880
38248
|
return `Set up /pilot for this repo:
|
|
37881
38249
|
${rel(skillFile).padEnd(width)}the /pilot skill
|
|
@@ -37894,7 +38262,7 @@ Then, in a Claude Code chat in this folder: /pilot
|
|
|
37894
38262
|
async function writeSkill(dir) {
|
|
37895
38263
|
if (await isLink(dir)) await unlink(dir);
|
|
37896
38264
|
await mkdir2(dir, { recursive: true });
|
|
37897
|
-
const file2 =
|
|
38265
|
+
const file2 = join3(dir, "SKILL.md");
|
|
37898
38266
|
await writeFile2(file2, SKILL_default);
|
|
37899
38267
|
return file2;
|
|
37900
38268
|
}
|
|
@@ -37907,7 +38275,7 @@ async function isLink(path) {
|
|
|
37907
38275
|
}
|
|
37908
38276
|
async function addMcpServer(file2) {
|
|
37909
38277
|
let config2 = {};
|
|
37910
|
-
if (
|
|
38278
|
+
if (existsSync3(file2)) {
|
|
37911
38279
|
const text = await readFile2(file2, "utf8");
|
|
37912
38280
|
try {
|
|
37913
38281
|
config2 = text.trim() ? JSON.parse(text) : {};
|
|
@@ -37924,17 +38292,104 @@ async function addMcpServer(file2) {
|
|
|
37924
38292
|
}
|
|
37925
38293
|
|
|
37926
38294
|
// src/init.ts
|
|
37927
|
-
var
|
|
37928
|
-
{ name: "Claude Code", file: ".mcp.json", key: "mcpServers", entry: MCP_SERVER },
|
|
37929
|
-
{ name: "Cursor", file: join3(".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
|
|
37930
|
-
{ name: "VS Code", file: join3(".vscode", "mcp.json"), key: "servers", entry: { type: "stdio", ...MCP_SERVER } }
|
|
37931
|
-
];
|
|
38295
|
+
var AGENT_IDS = ["claude-code", "cursor", "codex", "vscode", "other"];
|
|
37932
38296
|
var COMMAND = `${MCP_SERVER.command} ${MCP_SERVER.args.join(" ")}`;
|
|
38297
|
+
var AGENTS = [
|
|
38298
|
+
{
|
|
38299
|
+
id: "claude-code",
|
|
38300
|
+
name: "Claude Code",
|
|
38301
|
+
mcp: { file: ".mcp.json", key: "mcpServers", entry: MCP_SERVER },
|
|
38302
|
+
skills: join4(".claude", "skills"),
|
|
38303
|
+
invoke: "`/pilot`",
|
|
38304
|
+
signals: [".mcp.json", ".claude"]
|
|
38305
|
+
},
|
|
38306
|
+
{
|
|
38307
|
+
id: "cursor",
|
|
38308
|
+
name: "Cursor",
|
|
38309
|
+
mcp: { file: join4(".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
|
|
38310
|
+
skills: join4(".cursor", "skills"),
|
|
38311
|
+
invoke: "`/pilot`",
|
|
38312
|
+
signals: [".cursor"],
|
|
38313
|
+
// Cursor sees a project's new MCP server but leaves it off: it never starts until the user turns it on.
|
|
38314
|
+
enable: "**turn Pilot on first**: Cursor keeps a project's new MCP servers off. In Cursor Settings, in the MCP section, switch on `pilot` (once per project)"
|
|
38315
|
+
},
|
|
38316
|
+
{
|
|
38317
|
+
id: "vscode",
|
|
38318
|
+
name: "VS Code",
|
|
38319
|
+
mcp: { file: join4(".vscode", "mcp.json"), key: "servers", entry: { type: "stdio", ...MCP_SERVER } },
|
|
38320
|
+
skills: join4(".github", "skills"),
|
|
38321
|
+
invoke: "`/pilot`",
|
|
38322
|
+
signals: [join4(".vscode", "mcp.json"), join4(".github", "skills"), join4(".github", "copilot-instructions.md")]
|
|
38323
|
+
},
|
|
38324
|
+
{
|
|
38325
|
+
id: "codex",
|
|
38326
|
+
name: "Codex",
|
|
38327
|
+
register: `\`codex mcp add pilot -- ${COMMAND}\``,
|
|
38328
|
+
skills: join4(".agents", "skills"),
|
|
38329
|
+
invoke: "`$pilot`",
|
|
38330
|
+
signals: [".codex"]
|
|
38331
|
+
},
|
|
38332
|
+
{
|
|
38333
|
+
id: "other",
|
|
38334
|
+
name: "your agent",
|
|
38335
|
+
register: `in your MCP settings: a server named \`pilot\`, running \`${COMMAND}\``,
|
|
38336
|
+
// The open skills folder, read by many agents.
|
|
38337
|
+
skills: join4(".agents", "skills"),
|
|
38338
|
+
invoke: "the `pilot` skill",
|
|
38339
|
+
signals: []
|
|
38340
|
+
}
|
|
38341
|
+
];
|
|
38342
|
+
var MCP_SERVER_ARGV = [MCP_SERVER.command, ...MCP_SERVER.args];
|
|
38343
|
+
var MACHINE = {
|
|
38344
|
+
"claude-code": {
|
|
38345
|
+
command: {
|
|
38346
|
+
cmd: "claude",
|
|
38347
|
+
args: ["mcp", "add", "--scope", "user", "pilot", "--", ...MCP_SERVER_ARGV],
|
|
38348
|
+
has: (home) => !!readJson(join4(home, ".claude.json"))?.mcpServers?.pilot
|
|
38349
|
+
},
|
|
38350
|
+
skills: (home) => join4(home, ".claude", "skills")
|
|
38351
|
+
},
|
|
38352
|
+
cursor: {
|
|
38353
|
+
mcp: { file: (home) => join4(home, ".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
|
|
38354
|
+
skills: (home) => join4(home, ".cursor", "skills")
|
|
38355
|
+
},
|
|
38356
|
+
vscode: {
|
|
38357
|
+
mcp: {
|
|
38358
|
+
file: (home, platform) => join4(vscodeUserDir(home, platform), "mcp.json"),
|
|
38359
|
+
key: "servers",
|
|
38360
|
+
entry: { type: "stdio", ...MCP_SERVER }
|
|
38361
|
+
},
|
|
38362
|
+
skills: (home) => join4(home, ".copilot", "skills")
|
|
38363
|
+
},
|
|
38364
|
+
codex: {
|
|
38365
|
+
command: {
|
|
38366
|
+
cmd: "codex",
|
|
38367
|
+
args: ["mcp", "add", "pilot", "--", ...MCP_SERVER_ARGV],
|
|
38368
|
+
has: (home) => /\[mcp_servers\.pilot\]/.test(readText(join4(home, ".codex", "config.toml")))
|
|
38369
|
+
},
|
|
38370
|
+
skills: (home) => join4(home, ".agents", "skills")
|
|
38371
|
+
},
|
|
38372
|
+
other: { skills: (home) => join4(home, ".agents", "skills") }
|
|
38373
|
+
};
|
|
38374
|
+
function vscodeUserDir(home, platform) {
|
|
38375
|
+
if (platform === "darwin") return join4(home, "Library", "Application Support", "Code", "User");
|
|
38376
|
+
if (platform === "win32") return join4(process.env.APPDATA ?? join4(home, "AppData", "Roaming"), "Code", "User");
|
|
38377
|
+
return join4(home, ".config", "Code", "User");
|
|
38378
|
+
}
|
|
38379
|
+
function tilde(path, home) {
|
|
38380
|
+
return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
38381
|
+
}
|
|
38382
|
+
function detectAgent(env) {
|
|
38383
|
+
if (env.CLAUDECODE) return "claude-code";
|
|
38384
|
+
if (env.CURSOR_AGENT || env.CURSOR_TRACE_ID) return "cursor";
|
|
38385
|
+
if (env.CODEX_SANDBOX || env.CODEX_SANDBOX_NETWORK_DISABLED || env.CODEX_MANAGED_BY_NPM) return "codex";
|
|
38386
|
+
return null;
|
|
38387
|
+
}
|
|
37933
38388
|
async function init(options = {}) {
|
|
37934
38389
|
const cwd = options.cwd ?? process.cwd();
|
|
37935
38390
|
const run = options.run ?? runCommand;
|
|
37936
|
-
const pkgFile =
|
|
37937
|
-
if (!
|
|
38391
|
+
const pkgFile = join4(cwd, "package.json");
|
|
38392
|
+
if (!existsSync4(pkgFile)) {
|
|
37938
38393
|
return `# Pilot: not set up
|
|
37939
38394
|
|
|
37940
38395
|
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.
|
|
@@ -37962,26 +38417,66 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
|
37962
38417
|
else if (options.install !== false && run(pm, installArgs, cwd))
|
|
37963
38418
|
done.push(`Installed \`usepilot\` as a dev dependency (\`${install}\`).`);
|
|
37964
38419
|
else todo.push(`Install Pilot as a dev dependency: run \`${install}\` in ${cwd}.`);
|
|
37965
|
-
const
|
|
37966
|
-
|
|
37967
|
-
|
|
37968
|
-
|
|
37969
|
-
|
|
37970
|
-
|
|
37971
|
-
|
|
37972
|
-
|
|
37973
|
-
|
|
38420
|
+
const named = options.agent ?? detectAgent(options.env ?? process.env);
|
|
38421
|
+
const project = options.scope === "project";
|
|
38422
|
+
const home = options.home ?? homedir2();
|
|
38423
|
+
const written = [];
|
|
38424
|
+
if (named && !project) {
|
|
38425
|
+
const agent = AGENTS.find((a) => a.id === named);
|
|
38426
|
+
const machine = MACHINE[named];
|
|
38427
|
+
const parts = [];
|
|
38428
|
+
if (machine.mcp) {
|
|
38429
|
+
const file2 = machine.mcp.file(home, options.platform ?? process.platform);
|
|
38430
|
+
if (await addServer(file2, machine.mcp.key, machine.mcp.entry) === "invalid") {
|
|
38431
|
+
todo.push(
|
|
38432
|
+
`\`${tilde(file2, home)}\` isn't valid JSON, so Pilot wasn't added to it: fix it, and add the \`pilot\` server (\`${COMMAND}\`).`
|
|
38433
|
+
);
|
|
38434
|
+
} else parts.push(`its MCP server (\`${tilde(file2, home)}\`)`);
|
|
38435
|
+
} else if (machine.command) {
|
|
38436
|
+
const display = `${machine.command.cmd} ${machine.command.args.join(" ")}`;
|
|
38437
|
+
if (machine.command.has(home)) parts.push("its MCP server (registered already)");
|
|
38438
|
+
else if (run(machine.command.cmd, machine.command.args, cwd)) parts.push(`its MCP server (\`${display}\`)`);
|
|
38439
|
+
else todo.push(`**Register Pilot's MCP server with yourself**: run \`${display}\`.`);
|
|
38440
|
+
} else if (agent.register) {
|
|
38441
|
+
todo.push(`**Register Pilot's MCP server with yourself**, for every project: ${agent.register}.`);
|
|
38442
|
+
}
|
|
38443
|
+
const skill = join4(machine.skills(home), "pilot");
|
|
38444
|
+
await writeSkill(skill);
|
|
38445
|
+
parts.push(`the \`pilot\` skill (\`${tilde(skill, home)}/\`)`);
|
|
38446
|
+
done.push(`Connected ${agent.name} to Pilot, once for every project on this machine: ${list(parts)}. Nothing was added to the repo.`);
|
|
38447
|
+
} else if (named) {
|
|
38448
|
+
const present = AGENTS.filter((a) => a.id !== named && a.signals.some((p) => existsSync4(join4(root, p))));
|
|
38449
|
+
for (const agent of [...AGENTS.filter((a) => a.id === named), ...present]) {
|
|
38450
|
+
const parts = [];
|
|
38451
|
+
if (agent.mcp) {
|
|
38452
|
+
const file2 = join4(root, agent.mcp.file);
|
|
38453
|
+
if (await addServer(file2, agent.mcp.key, agent.mcp.entry) === "invalid") {
|
|
38454
|
+
todo.push(
|
|
38455
|
+
`\`${agent.mcp.file}\` isn't valid JSON, so Pilot wasn't added to it: fix it, and add the \`pilot\` server (\`${COMMAND}\`).`
|
|
38456
|
+
);
|
|
38457
|
+
} else {
|
|
38458
|
+
parts.push(`its MCP server (\`${agent.mcp.file}\`)`);
|
|
38459
|
+
written.push(`\`${agent.mcp.file}\``);
|
|
38460
|
+
}
|
|
38461
|
+
}
|
|
38462
|
+
const skill = join4(agent.skills, "pilot");
|
|
38463
|
+
await writeSkill(join4(root, skill));
|
|
38464
|
+
parts.push(`the \`pilot\` skill (\`${skill}/\`)`);
|
|
38465
|
+
if (!written.includes(`\`${skill}/\``)) written.push(`\`${skill}/\``);
|
|
38466
|
+
done.push(`Set Pilot up for ${agent.name} in this project: ${list(parts)}.`);
|
|
38467
|
+
if (agent.register && agent.id === named) todo.push(`**Register Pilot's MCP server with yourself**: ${agent.register}.`);
|
|
38468
|
+
}
|
|
38469
|
+
} else {
|
|
38470
|
+
todo.push(
|
|
38471
|
+
`**Connect yourself:** run \`npx usepilot@latest init --agent <you>\` in ${cwd}, with \`<you>\` the agent you are: ${AGENT_IDS.map((a) => `\`${a}\``).join(", ")}.`
|
|
38472
|
+
);
|
|
37974
38473
|
}
|
|
37975
|
-
if (
|
|
37976
|
-
const skill = await writeSkill(join3(root, ".claude", "skills", "pilot"));
|
|
37977
|
-
done.push(`Added the \`/pilot\` command for Claude Code (\`${relative2(root, skill)}\`).`);
|
|
37978
|
-
if (framework.loads) done.push(`The app already loads Pilot (\`${relative2(cwd, framework.loads)}\`).`);
|
|
38474
|
+
if (framework.loads) done.push(`The app already loads Pilot (\`${relative3(cwd, framework.loads)}\`).`);
|
|
37979
38475
|
else todo.push(loadStep(framework, cwd));
|
|
38476
|
+
const me = AGENTS.find((a) => a.id === named);
|
|
38477
|
+
const enable = project && me?.enable ? `Before that, ${me.enable}. ` : "";
|
|
37980
38478
|
todo.push(
|
|
37981
|
-
`**
|
|
37982
|
-
`**Tell the user**, in a few lines: Pilot is set up. To start, open a new chat (agents load MCP servers when a chat starts; some ask once to approve the project's server), then ask to launch Pilot (in Claude Code: \`/pilot\`). The new files (${list(
|
|
37983
|
-
[...CLIENTS.map((c) => `\`${c.file}\``), "`.claude/skills/pilot/`"]
|
|
37984
|
-
)}) can be committed, so everyone on the project gets it. Without an agent, Option+P (Alt+P) in the app opens Pilot, and Copy prompt hands the changes over.`
|
|
38479
|
+
`**Tell the user**, in a few lines: Pilot is set up, and works from a **new chat**, not this one: agents load MCP servers when a chat starts (some ask once to approve the project's server). ${enable}In the new chat, ask to launch Pilot${me && me.id !== "other" ? `, or run ${me.invoke}` : ""}.${written.length ? ` The files it added (${list(written)}) can be committed, so everyone on the project using the same agent gets it.` : project ? "" : " It's connected for every project on this machine; a teammate pastes the same install prompt in their own agent."} Without an agent, Option+P (Alt+P) in the app opens Pilot, and Copy prompt hands the changes over.`
|
|
37985
38480
|
);
|
|
37986
38481
|
return `# Pilot: set up
|
|
37987
38482
|
|
|
@@ -37994,22 +38489,22 @@ ${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
|
|
|
37994
38489
|
}
|
|
37995
38490
|
function projectRoot(cwd) {
|
|
37996
38491
|
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
37997
|
-
if (
|
|
38492
|
+
if (existsSync4(join4(dir, ".git"))) return dir;
|
|
37998
38493
|
if (dirname2(dir) === dir) return cwd;
|
|
37999
38494
|
}
|
|
38000
38495
|
}
|
|
38001
38496
|
function packageManager(cwd, root) {
|
|
38002
38497
|
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
38003
|
-
if (
|
|
38004
|
-
if (
|
|
38005
|
-
if (
|
|
38006
|
-
if (
|
|
38498
|
+
if (existsSync4(join4(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
38499
|
+
if (existsSync4(join4(dir, "yarn.lock"))) return "yarn";
|
|
38500
|
+
if (existsSync4(join4(dir, "bun.lock")) || existsSync4(join4(dir, "bun.lockb"))) return "bun";
|
|
38501
|
+
if (existsSync4(join4(dir, "package-lock.json"))) return "npm";
|
|
38007
38502
|
if (dir === root || dirname2(dir) === dir) return "npm";
|
|
38008
38503
|
}
|
|
38009
38504
|
}
|
|
38010
38505
|
function detectFramework(cwd, deps) {
|
|
38011
38506
|
const has = (name) => name in deps;
|
|
38012
|
-
const first = (...files) => files.map((f) =>
|
|
38507
|
+
const first = (...files) => files.map((f) => join4(cwd, f)).find((f) => existsSync4(f));
|
|
38013
38508
|
const loads = findLoader(cwd);
|
|
38014
38509
|
const result = (kind, file2) => ({ kind, file: file2, loads });
|
|
38015
38510
|
if (has("next")) {
|
|
@@ -38028,7 +38523,15 @@ function detectFramework(cwd, deps) {
|
|
|
38028
38523
|
if (has("@sveltejs/kit")) return result("sveltekit", first("src/hooks.client.ts", "src/hooks.client.js"));
|
|
38029
38524
|
if (has("astro")) return result("astro");
|
|
38030
38525
|
if (has("@react-router/dev") || has("@remix-run/react")) return result("react-router", first("app/root.tsx", "app/root.jsx"));
|
|
38031
|
-
if (has("vite") || Object.keys(deps).some((d) => d.startsWith("@vitejs/")))
|
|
38526
|
+
if (has("vite") || Object.keys(deps).some((d) => d.startsWith("@vitejs/"))) {
|
|
38527
|
+
const entry = viteEntry(cwd);
|
|
38528
|
+
if (entry) return result("vite", entry);
|
|
38529
|
+
if (existsSync4(join4(cwd, "index.html"))) {
|
|
38530
|
+
const config2 = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) => join4(cwd, f)).find((f) => existsSync4(f));
|
|
38531
|
+
return result("vite-html", config2);
|
|
38532
|
+
}
|
|
38533
|
+
return result("vite");
|
|
38534
|
+
}
|
|
38032
38535
|
if (has("react-scripts") || has("webpack")) {
|
|
38033
38536
|
return result(
|
|
38034
38537
|
"webpack",
|
|
@@ -38038,12 +38541,16 @@ function detectFramework(cwd, deps) {
|
|
|
38038
38541
|
return { kind: "unknown", loads };
|
|
38039
38542
|
}
|
|
38040
38543
|
function viteEntry(cwd) {
|
|
38041
|
-
const html =
|
|
38042
|
-
if (
|
|
38043
|
-
const
|
|
38044
|
-
|
|
38544
|
+
const html = join4(cwd, "index.html");
|
|
38545
|
+
if (existsSync4(html)) {
|
|
38546
|
+
for (const tag of readFileSync2(html, "utf8").match(/<script\b[^>]*>/gi) ?? []) {
|
|
38547
|
+
if (!/type=["']module["']/i.test(tag)) continue;
|
|
38548
|
+
const src = /src=["']\/?([^"'?#]+)/i.exec(tag)?.[1];
|
|
38549
|
+
if (src && existsSync4(join4(cwd, src))) return join4(cwd, src);
|
|
38550
|
+
}
|
|
38551
|
+
return void 0;
|
|
38045
38552
|
}
|
|
38046
|
-
return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) =>
|
|
38553
|
+
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));
|
|
38047
38554
|
}
|
|
38048
38555
|
var SOURCE_DIRS = ["src", "app", "pages", "plugins", "components", "lib"];
|
|
38049
38556
|
var SOURCE_FILE = /\.(m?[jt]sx?|vue|svelte|astro|html)$/;
|
|
@@ -38052,13 +38559,13 @@ function findLoader(cwd) {
|
|
|
38052
38559
|
const walk = (dir, depth) => {
|
|
38053
38560
|
let names;
|
|
38054
38561
|
try {
|
|
38055
|
-
names =
|
|
38562
|
+
names = readdirSync2(dir);
|
|
38056
38563
|
} catch {
|
|
38057
38564
|
return void 0;
|
|
38058
38565
|
}
|
|
38059
38566
|
for (const name of names) {
|
|
38060
38567
|
if (budget-- <= 0 || name === "node_modules" || name.startsWith(".")) continue;
|
|
38061
|
-
const path =
|
|
38568
|
+
const path = join4(dir, name);
|
|
38062
38569
|
if (SOURCE_FILE.test(name)) {
|
|
38063
38570
|
if (/["']usepilot(\/auto)?["']/.test(readText(path))) return path;
|
|
38064
38571
|
} else if (depth > 0 && !name.includes(".")) {
|
|
@@ -38068,39 +38575,41 @@ function findLoader(cwd) {
|
|
|
38068
38575
|
}
|
|
38069
38576
|
return void 0;
|
|
38070
38577
|
};
|
|
38071
|
-
const html
|
|
38072
|
-
|
|
38578
|
+
for (const name of ["index.html", "vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"]) {
|
|
38579
|
+
const file2 = join4(cwd, name);
|
|
38580
|
+
if (existsSync4(file2) && /usepilot/.test(readText(file2))) return file2;
|
|
38581
|
+
}
|
|
38073
38582
|
for (const dir of SOURCE_DIRS) {
|
|
38074
|
-
const found = walk(
|
|
38583
|
+
const found = walk(join4(cwd, dir), 6);
|
|
38075
38584
|
if (found) return found;
|
|
38076
38585
|
}
|
|
38077
38586
|
return void 0;
|
|
38078
38587
|
}
|
|
38079
38588
|
function readText(file2) {
|
|
38080
38589
|
try {
|
|
38081
|
-
return
|
|
38590
|
+
return readFileSync2(file2, "utf8");
|
|
38082
38591
|
} catch {
|
|
38083
38592
|
return "";
|
|
38084
38593
|
}
|
|
38085
38594
|
}
|
|
38086
38595
|
function isWorkspaceRoot(cwd, pkg) {
|
|
38087
|
-
return !!pkg.workspaces ||
|
|
38596
|
+
return !!pkg.workspaces || existsSync4(join4(cwd, "pnpm-workspace.yaml"));
|
|
38088
38597
|
}
|
|
38089
38598
|
function workspaceApps(cwd) {
|
|
38090
38599
|
const found = [];
|
|
38091
38600
|
for (const group of ["apps", "packages", "examples", "sites"]) {
|
|
38092
|
-
const dir =
|
|
38093
|
-
if (!
|
|
38094
|
-
for (const name of
|
|
38095
|
-
const pkg = readJson(
|
|
38096
|
-
if (pkg && detectFramework(
|
|
38097
|
-
found.push(
|
|
38601
|
+
const dir = join4(cwd, group);
|
|
38602
|
+
if (!existsSync4(dir)) continue;
|
|
38603
|
+
for (const name of readdirSync2(dir)) {
|
|
38604
|
+
const pkg = readJson(join4(dir, name, "package.json"));
|
|
38605
|
+
if (pkg && detectFramework(join4(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
|
|
38606
|
+
found.push(join4(group, name));
|
|
38098
38607
|
}
|
|
38099
38608
|
}
|
|
38100
38609
|
return found;
|
|
38101
38610
|
}
|
|
38102
38611
|
function loadStep(framework, cwd) {
|
|
38103
|
-
const at = (file2,
|
|
38612
|
+
const at = (file2, otherwise) => file2 ? `\`${relative3(cwd, file2)}\`` : otherwise;
|
|
38104
38613
|
const code = (lang, text) => `
|
|
38105
38614
|
|
|
38106
38615
|
\`\`\`${lang}
|
|
@@ -38109,9 +38618,23 @@ ${text.replace(/^(?=.)/gm, " ")}
|
|
|
38109
38618
|
const intro = "**Load Pilot in the app, in development only** (it must never reach production), the way this project writes code.";
|
|
38110
38619
|
switch (framework.kind) {
|
|
38111
38620
|
case "vite":
|
|
38112
|
-
return `${intro} It's a Vite app: in its entry, ${at(framework.file, "src
|
|
38621
|
+
return `${intro} It's a Vite app: in its entry module, ${at(framework.file, 'the module its HTML page loads (`<script type="module" src=\u2026>`)')}, add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
38622
|
+
case "vite-html":
|
|
38623
|
+
return `${intro} It's a Vite app whose pages load no module of their own (classic scripts only, which Vite doesn't process), and its HTML may be deployed as it is. So don't edit the HTML: inject Pilot from ${at(framework.file, "its Vite config (create `vite.config.js` if there's none)")}, only while Vite serves. Add this plugin to its \`plugins\` (keep any that are there):${code(
|
|
38624
|
+
"js",
|
|
38625
|
+
`{
|
|
38626
|
+
name: "pilot",
|
|
38627
|
+
apply: "serve", // development only: builds never get it
|
|
38628
|
+
transformIndexHtml: {
|
|
38629
|
+
order: "pre", // before Vite's own processing, so it resolves the package
|
|
38630
|
+
handler: () => [{ tag: "script", attrs: { type: "module" }, children: 'import("usepilot/auto");', injectTo: "body" }],
|
|
38631
|
+
},
|
|
38632
|
+
}`
|
|
38633
|
+
)}
|
|
38634
|
+
|
|
38635
|
+
It's added to every HTML page Vite serves.`;
|
|
38113
38636
|
case "next-app":
|
|
38114
|
-
return `${intro} It's Next.js (App Router): add a client component, and render it in
|
|
38637
|
+
return `${intro} It's Next.js (App Router): add a client component, and render it in ${at(framework.file, "the root layout")}, inside \`<body>\`:${code(
|
|
38115
38638
|
"tsx",
|
|
38116
38639
|
`"use client";
|
|
38117
38640
|
import { useEffect } from "react";
|
|
@@ -38124,7 +38647,7 @@ export function Pilot() {
|
|
|
38124
38647
|
}`
|
|
38125
38648
|
)}`;
|
|
38126
38649
|
case "next-pages":
|
|
38127
|
-
return `${intro} It's Next.js (Pages Router): in ${at(framework.file, "pages/_app
|
|
38650
|
+
return `${intro} It's Next.js (Pages Router): in ${at(framework.file, "the custom App, `pages/_app` (create it if there's none)")}, in the App component:${code(
|
|
38128
38651
|
"tsx",
|
|
38129
38652
|
`useEffect(() => {
|
|
38130
38653
|
if (process.env.NODE_ENV === "development") import("usepilot/auto");
|
|
@@ -38138,25 +38661,25 @@ export function Pilot() {
|
|
|
38138
38661
|
});`
|
|
38139
38662
|
)}`;
|
|
38140
38663
|
case "sveltekit":
|
|
38141
|
-
return `${intro} It's SvelteKit: in ${at(framework.file, "src/hooks.client.ts")} (create it if there's none), add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
38664
|
+
return `${intro} It's SvelteKit: in ${at(framework.file, "`src/hooks.client.ts`")} (create it if there's none), add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
38142
38665
|
case "astro":
|
|
38143
38666
|
return `${intro} It's Astro: in the layout every page uses, add:${code("astro", '<script>\n if (import.meta.env.DEV) import("usepilot/auto");\n</script>')}`;
|
|
38144
38667
|
case "react-router":
|
|
38145
|
-
return `${intro} It's React Router (or Remix): in ${at(framework.file, "
|
|
38668
|
+
return `${intro} It's React Router (or Remix): in ${at(framework.file, "the root route module (`root.tsx` in the app folder)")}, in the root component:${code(
|
|
38146
38669
|
"tsx",
|
|
38147
38670
|
`useEffect(() => {
|
|
38148
38671
|
if (import.meta.env.DEV) import("usepilot/auto");
|
|
38149
38672
|
}, []);`
|
|
38150
38673
|
)}`;
|
|
38151
38674
|
case "webpack":
|
|
38152
|
-
return `${intro} In the app's entry, ${at(framework.file, "
|
|
38675
|
+
return `${intro} In the app's entry file, ${at(framework.file, "the one its bundler config starts from")}, add:${code("js", 'if (process.env.NODE_ENV === "development") import("usepilot/auto");')}`;
|
|
38153
38676
|
default:
|
|
38154
38677
|
return `${intro} Import \`usepilot/auto\` from code that runs in the browser, only in development (\`import.meta.env.DEV\` with Vite, \`process.env.NODE_ENV === "development"\` with webpack). It shows the toolbar when the page loads.`;
|
|
38155
38678
|
}
|
|
38156
38679
|
}
|
|
38157
38680
|
async function addServer(file2, key, entry) {
|
|
38158
38681
|
let config2 = {};
|
|
38159
|
-
if (
|
|
38682
|
+
if (existsSync4(file2)) {
|
|
38160
38683
|
const text = await readFile3(file2, "utf8");
|
|
38161
38684
|
try {
|
|
38162
38685
|
config2 = text.trim() ? JSON.parse(text) : {};
|
|
@@ -38175,7 +38698,7 @@ async function addServer(file2, key, entry) {
|
|
|
38175
38698
|
}
|
|
38176
38699
|
function readJson(file2) {
|
|
38177
38700
|
try {
|
|
38178
|
-
return JSON.parse(
|
|
38701
|
+
return JSON.parse(readFileSync2(file2, "utf8"));
|
|
38179
38702
|
} catch {
|
|
38180
38703
|
return null;
|
|
38181
38704
|
}
|
|
@@ -38193,9 +38716,14 @@ var HELP = `usepilot: take the controls from your coding agent
|
|
|
38193
38716
|
|
|
38194
38717
|
Usage: npx usepilot <command>
|
|
38195
38718
|
|
|
38196
|
-
init Set Pilot up in this project
|
|
38197
|
-
its MCP server
|
|
38198
|
-
|
|
38719
|
+
init Set Pilot up in this project for your agent: installs it, connects
|
|
38720
|
+
the agent (its MCP server and the pilot skill, nothing for other
|
|
38721
|
+
agents), and prints what's left for it (loading Pilot in the app).
|
|
38722
|
+
Ask your agent to run it.
|
|
38723
|
+
--agent <claude-code|cursor|codex|vscode|other>: the agent running it
|
|
38724
|
+
--project: connect the agent in this repo (files to commit, for a
|
|
38725
|
+
team) instead of once for every project on this machine
|
|
38726
|
+
--no-install: print the install command instead of running it
|
|
38199
38727
|
setup Set up /pilot in Claude Code, for every project on this machine
|
|
38200
38728
|
(--project: for this repo, to commit, so everyone gets it)
|
|
38201
38729
|
mcp Run the MCP server (stdio) agents connect to, and the bridge the
|
|
@@ -38214,6 +38742,14 @@ async function runMcp() {
|
|
|
38214
38742
|
await server.connect(new StdioServerTransport());
|
|
38215
38743
|
}
|
|
38216
38744
|
var [command = "help"] = process.argv.slice(2);
|
|
38745
|
+
function agentArg() {
|
|
38746
|
+
const args = process.argv.slice(3);
|
|
38747
|
+
const i = args.findIndex((a) => a === "--agent" || a.startsWith("--agent="));
|
|
38748
|
+
if (i < 0) return void 0;
|
|
38749
|
+
const value = (args[i]?.includes("=") ? args[i].split("=")[1] : args[i + 1])?.toLowerCase();
|
|
38750
|
+
if (value && AGENT_IDS.includes(value)) return value;
|
|
38751
|
+
throw new Error(`--agent takes one of: ${AGENT_IDS.join(", ")}.`);
|
|
38752
|
+
}
|
|
38217
38753
|
switch (command) {
|
|
38218
38754
|
case "help":
|
|
38219
38755
|
case "--help":
|
|
@@ -38234,7 +38770,13 @@ switch (command) {
|
|
|
38234
38770
|
break;
|
|
38235
38771
|
case "init":
|
|
38236
38772
|
try {
|
|
38237
|
-
process.stdout.write(
|
|
38773
|
+
process.stdout.write(
|
|
38774
|
+
await init({
|
|
38775
|
+
install: !process.argv.includes("--no-install"),
|
|
38776
|
+
agent: agentArg(),
|
|
38777
|
+
scope: process.argv.includes("--project") ? "project" : "machine"
|
|
38778
|
+
})
|
|
38779
|
+
);
|
|
38238
38780
|
} catch (error62) {
|
|
38239
38781
|
process.stderr.write(`usepilot init: ${error62.message}
|
|
38240
38782
|
`);
|