usepilot 0.6.0 → 0.7.1
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 +15 -11
- package/cli/index.js +646 -169
- package/dist/{mount-mxONUQQO.js → mount-VNZwYYdw.js} +2684 -2094
- 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,9 +36692,12 @@ 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);
|
|
36699
36702
|
if (changeSet.request?.kind === "break-and-fix") return formatBreakFix(changeSet, changeSet.request);
|
|
36700
36703
|
if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request);
|
|
@@ -36704,13 +36707,8 @@ function formatPrompt(changeSet) {
|
|
|
36704
36707
|
"",
|
|
36705
36708
|
"A designer adjusted the UI below in the browser with Pilot. Apply these changes to the source code.",
|
|
36706
36709
|
"",
|
|
36707
|
-
|
|
36708
|
-
|
|
36709
|
-
"- 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.",
|
|
36710
|
-
"- Change only the listed elements. If an element is a shared component, ask before changing every instance.",
|
|
36711
|
-
`- 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.`,
|
|
36712
|
-
"- 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.",
|
|
36713
|
-
"- 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],
|
|
36714
36712
|
"",
|
|
36715
36713
|
`Page: ${page.url} (${page.title || "untitled"}) at ${page.viewport.width}x${page.viewport.height}`
|
|
36716
36714
|
];
|
|
@@ -36723,19 +36721,56 @@ function formatPrompt(changeSet) {
|
|
|
36723
36721
|
return `${lines.join("\n")}
|
|
36724
36722
|
`;
|
|
36725
36723
|
}
|
|
36726
|
-
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, the component's name in **bold**, 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}`;
|
|
36727
36761
|
var ACTION_ASKED = {
|
|
36728
36762
|
responsive: "asked you to make it responsive",
|
|
36729
36763
|
"break-and-fix": "asked you to break and fix it"
|
|
36730
36764
|
};
|
|
36731
36765
|
function formatBreakFix(changeSet, request) {
|
|
36732
36766
|
const { page, note } = changeSet;
|
|
36733
|
-
const {
|
|
36767
|
+
const { breakpoints } = request;
|
|
36768
|
+
const several = requestTargets(request).length;
|
|
36734
36769
|
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
36735
36770
|
const lines = [
|
|
36736
36771
|
"# Pilot: break and fix",
|
|
36737
36772
|
"",
|
|
36738
|
-
"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.",
|
|
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.",
|
|
36739
36774
|
"",
|
|
36740
36775
|
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36741
36776
|
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
@@ -36743,12 +36778,11 @@ function formatBreakFix(changeSet, request) {
|
|
|
36743
36778
|
ADVANCED_TASK
|
|
36744
36779
|
];
|
|
36745
36780
|
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
36746
|
-
if (request.attachments?.length)
|
|
36781
|
+
if (request.attachments?.length)
|
|
36782
|
+
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
36747
36783
|
lines.push(
|
|
36748
36784
|
"",
|
|
36749
|
-
|
|
36750
|
-
"",
|
|
36751
|
-
...targetLines(target),
|
|
36785
|
+
...elementsSection(request),
|
|
36752
36786
|
"",
|
|
36753
36787
|
"## How to do it",
|
|
36754
36788
|
"",
|
|
@@ -36765,19 +36799,22 @@ function formatBreakFix(changeSet, request) {
|
|
|
36765
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).",
|
|
36766
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.",
|
|
36767
36801
|
"",
|
|
36768
|
-
"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.
|
|
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
|
|
36769
36805
|
);
|
|
36770
36806
|
return `${lines.join("\n")}
|
|
36771
36807
|
`;
|
|
36772
36808
|
}
|
|
36773
36809
|
function formatResponsive(changeSet, request) {
|
|
36774
36810
|
const { page, note } = changeSet;
|
|
36775
|
-
const {
|
|
36811
|
+
const { breakpoints } = request;
|
|
36812
|
+
const several = requestTargets(request).length;
|
|
36776
36813
|
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
36777
36814
|
const lines = [
|
|
36778
36815
|
"# Pilot: make responsive",
|
|
36779
36816
|
"",
|
|
36780
|
-
"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.",
|
|
36781
36818
|
"",
|
|
36782
36819
|
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36783
36820
|
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
@@ -36785,12 +36822,11 @@ function formatResponsive(changeSet, request) {
|
|
|
36785
36822
|
ADVANCED_TASK
|
|
36786
36823
|
];
|
|
36787
36824
|
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
36788
|
-
if (request.attachments?.length)
|
|
36825
|
+
if (request.attachments?.length)
|
|
36826
|
+
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
36789
36827
|
lines.push(
|
|
36790
36828
|
"",
|
|
36791
|
-
|
|
36792
|
-
"",
|
|
36793
|
-
...targetLines(target),
|
|
36829
|
+
...elementsSection(request),
|
|
36794
36830
|
"",
|
|
36795
36831
|
"## How to do it",
|
|
36796
36832
|
"",
|
|
@@ -36801,28 +36837,31 @@ function formatResponsive(changeSet, request) {
|
|
|
36801
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.",
|
|
36802
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.",
|
|
36803
36839
|
"",
|
|
36804
|
-
|
|
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
|
|
36805
36845
|
);
|
|
36806
36846
|
return `${lines.join("\n")}
|
|
36807
36847
|
`;
|
|
36808
36848
|
}
|
|
36809
36849
|
function formatComment(changeSet, request) {
|
|
36810
36850
|
const { page } = changeSet;
|
|
36811
|
-
const {
|
|
36851
|
+
const { thread, breakpoints } = request;
|
|
36852
|
+
const several = requestTargets(request).length;
|
|
36812
36853
|
const latest = thread.at(-1);
|
|
36813
36854
|
const earlier = thread.slice(0, -1);
|
|
36814
36855
|
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
36815
36856
|
const lines = [
|
|
36816
36857
|
"# Pilot: comment",
|
|
36817
36858
|
"",
|
|
36818
|
-
"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).",
|
|
36819
36860
|
"",
|
|
36820
36861
|
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36821
36862
|
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
36822
36863
|
"",
|
|
36823
|
-
|
|
36824
|
-
"",
|
|
36825
|
-
...targetLines(target),
|
|
36864
|
+
...elementsSection(request),
|
|
36826
36865
|
"",
|
|
36827
36866
|
"## The comment",
|
|
36828
36867
|
"",
|
|
@@ -36841,9 +36880,11 @@ function formatComment(changeSet, request) {
|
|
|
36841
36880
|
"## How to do it",
|
|
36842
36881
|
"",
|
|
36843
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.",
|
|
36844
|
-
"- **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.",
|
|
36845
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.`,
|
|
36846
|
-
|
|
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}`,
|
|
36847
36888
|
"- **A question, not a change:** answer it, and change nothing.",
|
|
36848
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."
|
|
36849
36890
|
);
|
|
@@ -36878,12 +36919,25 @@ function countFiles(n) {
|
|
|
36878
36919
|
function quote(text) {
|
|
36879
36920
|
return text.trim().split("\n").map((l) => `> ${l}`).join("\n");
|
|
36880
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
|
+
}
|
|
36881
36930
|
function targetLines(target) {
|
|
36882
36931
|
const out = [`- Selector: \`${target.selector}\``];
|
|
36883
36932
|
if (target.text) out.push(`- Text: "${target.text}"`);
|
|
36884
36933
|
if (target.source?.component || target.source?.file) {
|
|
36885
|
-
const
|
|
36886
|
-
|
|
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`);
|
|
36887
36941
|
}
|
|
36888
36942
|
return out;
|
|
36889
36943
|
}
|
|
@@ -36962,8 +37016,15 @@ function formatWidthCheck(check2) {
|
|
|
36962
37016
|
}
|
|
36963
37017
|
|
|
36964
37018
|
// ../protocol/src/bridge.ts
|
|
36965
|
-
var
|
|
36966
|
-
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
|
+
}
|
|
36967
37028
|
function originOf(url2) {
|
|
36968
37029
|
try {
|
|
36969
37030
|
const u = new URL(url2.includes("://") ? url2 : `http://${url2}`);
|
|
@@ -37166,12 +37227,30 @@ var Hub = class {
|
|
|
37166
37227
|
this.notifyAgents(key);
|
|
37167
37228
|
});
|
|
37168
37229
|
}
|
|
37169
|
-
/**
|
|
37170
|
-
|
|
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) {
|
|
37171
37237
|
const job = this.jobs.get(jobId);
|
|
37172
37238
|
if (!job || job.status === "cancelled") return null;
|
|
37173
37239
|
const agent = this.agents.get(agentId)?.info ?? job.agent;
|
|
37174
|
-
|
|
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);
|
|
37175
37254
|
return job;
|
|
37176
37255
|
}
|
|
37177
37256
|
/**
|
|
@@ -37234,11 +37313,13 @@ var Hub = class {
|
|
|
37234
37313
|
origin: key,
|
|
37235
37314
|
changeSet: post.changeSet,
|
|
37236
37315
|
status: stillWorking ? "working" : "queued",
|
|
37237
|
-
// A follow-up keeps its agent as the one to prefer (see dispatch).
|
|
37238
|
-
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,
|
|
37239
37318
|
attempt: post.attempt ?? 1,
|
|
37240
37319
|
differences: post.differences,
|
|
37241
37320
|
issues: post.issues,
|
|
37321
|
+
question: post.question,
|
|
37322
|
+
answer: post.answer,
|
|
37242
37323
|
createdAt: at,
|
|
37243
37324
|
updatedAt: at
|
|
37244
37325
|
};
|
|
@@ -37276,7 +37357,7 @@ var Hub = class {
|
|
|
37276
37357
|
return [...this.jobs.values()].filter((j) => j.origin === origin && j.status === "queued").sort((a, b) => a.createdAt.localeCompare(b.createdAt))[0];
|
|
37277
37358
|
}
|
|
37278
37359
|
take(job, agent) {
|
|
37279
|
-
this.update(job, { status: "working", agent });
|
|
37360
|
+
this.update(job, { status: "working", agent, takenAt: new Date(this.now()).toISOString() });
|
|
37280
37361
|
return job;
|
|
37281
37362
|
}
|
|
37282
37363
|
/**
|
|
@@ -37390,10 +37471,12 @@ async function handle(hub, req, res, attachments) {
|
|
|
37390
37471
|
if (typeof post?.id !== "string" || !post.changeSet) return json2(res, 400, { error: "job needs id and changeSet" });
|
|
37391
37472
|
return json2(res, 202, { job: hub.postJob(origin, withAttachmentPaths(post, attachments)) });
|
|
37392
37473
|
}
|
|
37393
|
-
const jobRoute = path.match(/^\/jobs\/([^/]+)\/(cancel|retry)$/);
|
|
37474
|
+
const jobRoute = path.match(/^\/jobs\/([^/]+)\/(cancel|retry|answer)$/);
|
|
37394
37475
|
if (jobRoute) {
|
|
37395
37476
|
const [, id, action] = jobRoute;
|
|
37396
|
-
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(
|
|
37397
37480
|
origin,
|
|
37398
37481
|
decodeURIComponent(id),
|
|
37399
37482
|
(data.differences ?? []).slice(0, 200),
|
|
@@ -37447,7 +37530,7 @@ async function handleAgent(hub, action, data, req, res) {
|
|
|
37447
37530
|
}
|
|
37448
37531
|
case "done":
|
|
37449
37532
|
if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
|
|
37450
|
-
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)) });
|
|
37451
37534
|
case "check": {
|
|
37452
37535
|
if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
|
|
37453
37536
|
const check2 = await hub.check(d.jobId, Math.min(d.timeoutMs ?? CHECK_TIMEOUT, 2 * 6e4));
|
|
@@ -37528,8 +37611,8 @@ var LocalApi = class {
|
|
|
37528
37611
|
localAgents.add(agent.id);
|
|
37529
37612
|
return this.hub.wait(agent, origin, timeoutMs, signal);
|
|
37530
37613
|
}
|
|
37531
|
-
async done(agent, jobId, notes) {
|
|
37532
|
-
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);
|
|
37533
37616
|
}
|
|
37534
37617
|
check(_agent, jobId, timeoutMs) {
|
|
37535
37618
|
return this.hub.check(jobId, timeoutMs);
|
|
@@ -37563,8 +37646,8 @@ var RemoteApi = class {
|
|
|
37563
37646
|
wait(agent, origin, timeoutMs, signal) {
|
|
37564
37647
|
return this.post("wait", { agent, origin, timeoutMs }, signal);
|
|
37565
37648
|
}
|
|
37566
|
-
async done(agent, jobId, notes) {
|
|
37567
|
-
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;
|
|
37568
37651
|
}
|
|
37569
37652
|
async check(agent, jobId, timeoutMs) {
|
|
37570
37653
|
return (await this.post("check", { agent, jobId, timeoutMs })).check;
|
|
@@ -37612,8 +37695,8 @@ var Bridge = class {
|
|
|
37612
37695
|
}
|
|
37613
37696
|
}
|
|
37614
37697
|
}
|
|
37615
|
-
done(jobId, notes) {
|
|
37616
|
-
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));
|
|
37617
37700
|
}
|
|
37618
37701
|
/** Pilot's width check of a task's element, measured by the page (null: no page answered). */
|
|
37619
37702
|
check(jobId, timeoutMs = CHECK_TIMEOUT) {
|
|
@@ -37662,7 +37745,7 @@ var Bridge = class {
|
|
|
37662
37745
|
if (!health.pilot) throw new Error(`Port ${this.port} is used by another program. Set PILOT_PORT to use another port.`);
|
|
37663
37746
|
if (health.version !== BRIDGE_VERSION) {
|
|
37664
37747
|
throw new Error(
|
|
37665
|
-
`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.`
|
|
37666
37749
|
);
|
|
37667
37750
|
}
|
|
37668
37751
|
this.api = new RemoteApi(this.port);
|
|
@@ -37704,6 +37787,156 @@ function isConnectionError(error62) {
|
|
|
37704
37787
|
return code === "ECONNREFUSED" || code === "ECONNRESET" || code === "UND_ERR_SOCKET" || /fetch failed|socket hang up|other side closed/i.test(e?.message ?? "");
|
|
37705
37788
|
}
|
|
37706
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
|
+
|
|
37707
37940
|
// src/mcp.ts
|
|
37708
37941
|
function waitMsFor(clientName) {
|
|
37709
37942
|
const configured = Number(process.env.PILOT_WAIT_MS);
|
|
@@ -37716,10 +37949,10 @@ var INSTRUCTIONS = `Pilot lets the designer edit the running app in the browser
|
|
|
37716
37949
|
The loop, when the user asks to launch or start Pilot, runs /pilot, or asks to hand the design over:
|
|
37717
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.
|
|
37718
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.)
|
|
37719
|
-
3. Apply the job's edits to the source,
|
|
37720
|
-
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.
|
|
37721
37954
|
|
|
37722
|
-
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.`;
|
|
37723
37956
|
function agentLabel(clientName, cwd) {
|
|
37724
37957
|
const names = {
|
|
37725
37958
|
"claude-code": "Claude Code",
|
|
@@ -37733,13 +37966,34 @@ function agentLabel(clientName, cwd) {
|
|
|
37733
37966
|
const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
|
|
37734
37967
|
return `${app} \xB7 ${basename2(cwd)}`;
|
|
37735
37968
|
}
|
|
37736
|
-
function jobPrompt(job) {
|
|
37737
|
-
const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : formatPrompt(job.changeSet);
|
|
37738
|
-
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
|
+
` : ""}
|
|
37739
37974
|
---
|
|
37740
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.
|
|
37741
37976
|
`;
|
|
37742
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
|
+
}
|
|
37743
37997
|
function followUp(job) {
|
|
37744
37998
|
const lines = [
|
|
37745
37999
|
"# Pilot design edits: follow-up",
|
|
@@ -37758,6 +38012,24 @@ function followUp(job) {
|
|
|
37758
38012
|
);
|
|
37759
38013
|
return lines.join("\n");
|
|
37760
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
|
+
}
|
|
37761
38033
|
function notesFor(job) {
|
|
37762
38034
|
switch (job.changeSet.request?.kind) {
|
|
37763
38035
|
case "comment":
|
|
@@ -37793,7 +38065,7 @@ function createPilotServer(options = {}) {
|
|
|
37793
38065
|
const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
|
|
37794
38066
|
const cwd = options.cwd ?? process.cwd();
|
|
37795
38067
|
let waitMs = options.waitMs ?? waitMsFor(void 0);
|
|
37796
|
-
const server = new McpServer({ name: "pilot", version: "0.
|
|
38068
|
+
const server = new McpServer({ name: "pilot", version: "0.7.1" }, { instructions: INSTRUCTIONS });
|
|
37797
38069
|
const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
|
|
37798
38070
|
const bridge = new Bridge(agent, port);
|
|
37799
38071
|
let origin = null;
|
|
@@ -37829,7 +38101,11 @@ function createPilotServer(options = {}) {
|
|
|
37829
38101
|
"pilot_wait_for_edits",
|
|
37830
38102
|
{
|
|
37831
38103
|
title: "Wait for design edits",
|
|
37832
|
-
|
|
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")}`,
|
|
37833
38109
|
inputSchema: {}
|
|
37834
38110
|
},
|
|
37835
38111
|
async (_args, extra) => {
|
|
@@ -37846,7 +38122,25 @@ function createPilotServer(options = {}) {
|
|
|
37846
38122
|
try {
|
|
37847
38123
|
const { job } = await bridge.wait(origin, waitMs, extra.signal);
|
|
37848
38124
|
if (!job) return text("No edits yet. Call pilot_wait_for_edits again to keep waiting (the designer can keep editing meanwhile).");
|
|
37849
|
-
|
|
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
|
+
};
|
|
37850
38144
|
} catch (error62) {
|
|
37851
38145
|
return text(`Pilot's bridge failed while waiting: ${error62.message}. Call pilot_wait_for_edits again.`, true);
|
|
37852
38146
|
} finally {
|
|
@@ -37858,16 +38152,26 @@ function createPilotServer(options = {}) {
|
|
|
37858
38152
|
"pilot_done",
|
|
37859
38153
|
{
|
|
37860
38154
|
title: "Report a job done",
|
|
37861
|
-
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.",
|
|
37862
38156
|
inputSchema: {
|
|
37863
38157
|
jobId: external_exports.string().describe("The job's id, from pilot_wait_for_edits."),
|
|
37864
|
-
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, the component's name in **bold** (it's shown as markdown), 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.")
|
|
37865
38165
|
}
|
|
37866
38166
|
},
|
|
37867
|
-
async ({ jobId, notes }) => {
|
|
38167
|
+
async ({ jobId, notes, question }) => {
|
|
37868
38168
|
try {
|
|
37869
|
-
const
|
|
38169
|
+
const asked = questionOf(question);
|
|
38170
|
+
const job = await bridge.done(jobId, notes, asked);
|
|
37870
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.");
|
|
37871
38175
|
return text("Done. Pilot is checking the changes in the page. Call pilot_wait_for_edits for the next job.");
|
|
37872
38176
|
} catch (error62) {
|
|
37873
38177
|
return text(`Pilot couldn't report the job done: ${error62.message}`, true);
|
|
@@ -37903,18 +38207,19 @@ function createPilotServer(options = {}) {
|
|
|
37903
38207
|
|
|
37904
38208
|
// src/init.ts
|
|
37905
38209
|
import { spawnSync } from "child_process";
|
|
37906
|
-
import { existsSync as
|
|
38210
|
+
import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
|
|
37907
38211
|
import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
37908
|
-
import {
|
|
38212
|
+
import { homedir as homedir2 } from "os";
|
|
38213
|
+
import { dirname as dirname2, join as join4, relative as relative3 } from "path";
|
|
37909
38214
|
|
|
37910
38215
|
// src/setup.ts
|
|
37911
|
-
import { existsSync as
|
|
38216
|
+
import { existsSync as existsSync3 } from "fs";
|
|
37912
38217
|
import { lstat, mkdir as mkdir2, readFile as readFile2, unlink, writeFile as writeFile2 } from "fs/promises";
|
|
37913
38218
|
import { homedir } from "os";
|
|
37914
|
-
import { join as
|
|
38219
|
+
import { join as join3, relative as relative2 } from "path";
|
|
37915
38220
|
|
|
37916
38221
|
// ../../skills/pilot/SKILL.md
|
|
37917
|
-
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\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** 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).
|
|
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` (one short sentence, the component's name in **bold**) and `choices` \"All of them\", \"Only this\", \"New variant\" (your suggestion first). Go on with other jobs; the answer comes back as that job. **All of them**: change the component itself. **Only this**: change it where it's used, with what the component accepts (classes through its `className`, merged the project's way; a prop), else the smallest pass-through, not a variant. **New variant**: add a named option the way the component defines variants (`cva`, a `variant` prop), use it here, and name it in your notes. Don't ask when the designer already said, when every copy is in the job, or when nothing else uses that code.\n- **Widths:** a change for some viewport widths goes in a media query; use the project's breakpoints when one matches (or is within a few pixels). \"Every width\" means no media query should override it.\n- **Removed:** the element shouldn't declare the property at all (not `0` or `none`).\n- **Text:** the designer rewrote the element's copy. Change it where it comes from (the markup, a prop, a translation file), for this element only; Pilot checks that the page shows the new text.\n- If you approximated a value to fit a token or scale, say which and by how much in `pilot_done`'s notes (`22px \u2192 pt-6, 24px`). Pilot checks the page after each job: a change that doesn't give the designer's value comes back to you once as a follow-up. Fix it, or keep a deliberate choice and say why; after that, Pilot takes what the code gives.\n- Don't run builds or tests for a job unless it's needed: hot reload shows the result, and the designer is waiting to see it.\n";
|
|
37918
38223
|
|
|
37919
38224
|
// src/setup.ts
|
|
37920
38225
|
var MCP_SERVER = { command: "npx", args: ["-y", "usepilot", "mcp"] };
|
|
@@ -37922,7 +38227,7 @@ async function setup(options = {}) {
|
|
|
37922
38227
|
return options.project ? setupProject(options.cwd ?? process.cwd()) : setupMachine(options.home ?? homedir());
|
|
37923
38228
|
}
|
|
37924
38229
|
async function setupMachine(home) {
|
|
37925
|
-
const file2 = await writeSkill(
|
|
38230
|
+
const file2 = await writeSkill(join3(home, ".claude", "skills", "pilot"));
|
|
37926
38231
|
return `Installed the /pilot skill: ${file2}
|
|
37927
38232
|
|
|
37928
38233
|
Now register Pilot's MCP server with Claude Code, once, for every project:
|
|
@@ -37934,11 +38239,11 @@ Then, in any Claude Code chat: /pilot
|
|
|
37934
38239
|
`;
|
|
37935
38240
|
}
|
|
37936
38241
|
async function setupProject(cwd) {
|
|
37937
|
-
const skillFile = await writeSkill(
|
|
37938
|
-
const mcpFile =
|
|
38242
|
+
const skillFile = await writeSkill(join3(cwd, ".claude", "skills", "pilot"));
|
|
38243
|
+
const mcpFile = join3(cwd, ".mcp.json");
|
|
37939
38244
|
const { added } = await addMcpServer(mcpFile);
|
|
37940
|
-
const rel = (f) =>
|
|
37941
|
-
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";
|
|
37942
38247
|
const width = rel(skillFile).length + 2;
|
|
37943
38248
|
return `Set up /pilot for this repo:
|
|
37944
38249
|
${rel(skillFile).padEnd(width)}the /pilot skill
|
|
@@ -37957,7 +38262,7 @@ Then, in a Claude Code chat in this folder: /pilot
|
|
|
37957
38262
|
async function writeSkill(dir) {
|
|
37958
38263
|
if (await isLink(dir)) await unlink(dir);
|
|
37959
38264
|
await mkdir2(dir, { recursive: true });
|
|
37960
|
-
const file2 =
|
|
38265
|
+
const file2 = join3(dir, "SKILL.md");
|
|
37961
38266
|
await writeFile2(file2, SKILL_default);
|
|
37962
38267
|
return file2;
|
|
37963
38268
|
}
|
|
@@ -37970,7 +38275,7 @@ async function isLink(path) {
|
|
|
37970
38275
|
}
|
|
37971
38276
|
async function addMcpServer(file2) {
|
|
37972
38277
|
let config2 = {};
|
|
37973
|
-
if (
|
|
38278
|
+
if (existsSync3(file2)) {
|
|
37974
38279
|
const text = await readFile2(file2, "utf8");
|
|
37975
38280
|
try {
|
|
37976
38281
|
config2 = text.trim() ? JSON.parse(text) : {};
|
|
@@ -37987,18 +38292,104 @@ async function addMcpServer(file2) {
|
|
|
37987
38292
|
}
|
|
37988
38293
|
|
|
37989
38294
|
// src/init.ts
|
|
37990
|
-
var
|
|
37991
|
-
{ name: "Claude Code", file: ".mcp.json", key: "mcpServers", entry: MCP_SERVER },
|
|
37992
|
-
{ name: "Cursor", file: join3(".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
|
|
37993
|
-
{ name: "VS Code", file: join3(".vscode", "mcp.json"), key: "servers", entry: { type: "stdio", ...MCP_SERVER } }
|
|
37994
|
-
];
|
|
38295
|
+
var AGENT_IDS = ["claude-code", "cursor", "codex", "vscode", "other"];
|
|
37995
38296
|
var COMMAND = `${MCP_SERVER.command} ${MCP_SERVER.args.join(" ")}`;
|
|
37996
|
-
var
|
|
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
|
+
}
|
|
37997
38388
|
async function init(options = {}) {
|
|
37998
38389
|
const cwd = options.cwd ?? process.cwd();
|
|
37999
38390
|
const run = options.run ?? runCommand;
|
|
38000
|
-
const pkgFile =
|
|
38001
|
-
if (!
|
|
38391
|
+
const pkgFile = join4(cwd, "package.json");
|
|
38392
|
+
if (!existsSync4(pkgFile)) {
|
|
38002
38393
|
return `# Pilot: not set up
|
|
38003
38394
|
|
|
38004
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.
|
|
@@ -38026,27 +38417,66 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
|
38026
38417
|
else if (options.install !== false && run(pm, installArgs, cwd))
|
|
38027
38418
|
done.push(`Installed \`usepilot\` as a dev dependency (\`${install}\`).`);
|
|
38028
38419
|
else todo.push(`Install Pilot as a dev dependency: run \`${install}\` in ${cwd}.`);
|
|
38029
|
-
const
|
|
38030
|
-
|
|
38031
|
-
|
|
38032
|
-
|
|
38033
|
-
|
|
38034
|
-
|
|
38035
|
-
|
|
38036
|
-
|
|
38037
|
-
|
|
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
|
+
);
|
|
38038
38473
|
}
|
|
38039
|
-
if (
|
|
38040
|
-
for (const folder of SKILL_FOLDERS) await writeSkill(join3(root, folder, "pilot"));
|
|
38041
|
-
done.push(`Added the \`pilot\` skill (\`/pilot\`; \`$pilot\` in Codex) where agents read skills: ${list(SKILL_FOLDERS.map((f) => `\`${f}/pilot/\``))}.`);
|
|
38042
|
-
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)}\`).`);
|
|
38043
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}. ` : "";
|
|
38044
38478
|
todo.push(
|
|
38045
|
-
`**
|
|
38046
|
-
`**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, or run \`/pilot\` (\`$pilot\` in Codex). The new files (${list([
|
|
38047
|
-
...CLIENTS.map((c) => `\`${c.file}\``),
|
|
38048
|
-
...SKILL_FOLDERS.map((f) => `\`${f}/pilot/\``)
|
|
38049
|
-
])}) 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.`
|
|
38050
38480
|
);
|
|
38051
38481
|
return `# Pilot: set up
|
|
38052
38482
|
|
|
@@ -38059,22 +38489,22 @@ ${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
|
|
|
38059
38489
|
}
|
|
38060
38490
|
function projectRoot(cwd) {
|
|
38061
38491
|
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
38062
|
-
if (
|
|
38492
|
+
if (existsSync4(join4(dir, ".git"))) return dir;
|
|
38063
38493
|
if (dirname2(dir) === dir) return cwd;
|
|
38064
38494
|
}
|
|
38065
38495
|
}
|
|
38066
38496
|
function packageManager(cwd, root) {
|
|
38067
38497
|
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
38068
|
-
if (
|
|
38069
|
-
if (
|
|
38070
|
-
if (
|
|
38071
|
-
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";
|
|
38072
38502
|
if (dir === root || dirname2(dir) === dir) return "npm";
|
|
38073
38503
|
}
|
|
38074
38504
|
}
|
|
38075
38505
|
function detectFramework(cwd, deps) {
|
|
38076
38506
|
const has = (name) => name in deps;
|
|
38077
|
-
const first = (...files) => files.map((f) =>
|
|
38507
|
+
const first = (...files) => files.map((f) => join4(cwd, f)).find((f) => existsSync4(f));
|
|
38078
38508
|
const loads = findLoader(cwd);
|
|
38079
38509
|
const result = (kind, file2) => ({ kind, file: file2, loads });
|
|
38080
38510
|
if (has("next")) {
|
|
@@ -38093,7 +38523,15 @@ function detectFramework(cwd, deps) {
|
|
|
38093
38523
|
if (has("@sveltejs/kit")) return result("sveltekit", first("src/hooks.client.ts", "src/hooks.client.js"));
|
|
38094
38524
|
if (has("astro")) return result("astro");
|
|
38095
38525
|
if (has("@react-router/dev") || has("@remix-run/react")) return result("react-router", first("app/root.tsx", "app/root.jsx"));
|
|
38096
|
-
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
|
+
}
|
|
38097
38535
|
if (has("react-scripts") || has("webpack")) {
|
|
38098
38536
|
return result(
|
|
38099
38537
|
"webpack",
|
|
@@ -38103,12 +38541,16 @@ function detectFramework(cwd, deps) {
|
|
|
38103
38541
|
return { kind: "unknown", loads };
|
|
38104
38542
|
}
|
|
38105
38543
|
function viteEntry(cwd) {
|
|
38106
|
-
const html =
|
|
38107
|
-
if (
|
|
38108
|
-
const
|
|
38109
|
-
|
|
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;
|
|
38110
38552
|
}
|
|
38111
|
-
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));
|
|
38112
38554
|
}
|
|
38113
38555
|
var SOURCE_DIRS = ["src", "app", "pages", "plugins", "components", "lib"];
|
|
38114
38556
|
var SOURCE_FILE = /\.(m?[jt]sx?|vue|svelte|astro|html)$/;
|
|
@@ -38117,13 +38559,13 @@ function findLoader(cwd) {
|
|
|
38117
38559
|
const walk = (dir, depth) => {
|
|
38118
38560
|
let names;
|
|
38119
38561
|
try {
|
|
38120
|
-
names =
|
|
38562
|
+
names = readdirSync2(dir);
|
|
38121
38563
|
} catch {
|
|
38122
38564
|
return void 0;
|
|
38123
38565
|
}
|
|
38124
38566
|
for (const name of names) {
|
|
38125
38567
|
if (budget-- <= 0 || name === "node_modules" || name.startsWith(".")) continue;
|
|
38126
|
-
const path =
|
|
38568
|
+
const path = join4(dir, name);
|
|
38127
38569
|
if (SOURCE_FILE.test(name)) {
|
|
38128
38570
|
if (/["']usepilot(\/auto)?["']/.test(readText(path))) return path;
|
|
38129
38571
|
} else if (depth > 0 && !name.includes(".")) {
|
|
@@ -38133,39 +38575,41 @@ function findLoader(cwd) {
|
|
|
38133
38575
|
}
|
|
38134
38576
|
return void 0;
|
|
38135
38577
|
};
|
|
38136
|
-
const html
|
|
38137
|
-
|
|
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
|
+
}
|
|
38138
38582
|
for (const dir of SOURCE_DIRS) {
|
|
38139
|
-
const found = walk(
|
|
38583
|
+
const found = walk(join4(cwd, dir), 6);
|
|
38140
38584
|
if (found) return found;
|
|
38141
38585
|
}
|
|
38142
38586
|
return void 0;
|
|
38143
38587
|
}
|
|
38144
38588
|
function readText(file2) {
|
|
38145
38589
|
try {
|
|
38146
|
-
return
|
|
38590
|
+
return readFileSync2(file2, "utf8");
|
|
38147
38591
|
} catch {
|
|
38148
38592
|
return "";
|
|
38149
38593
|
}
|
|
38150
38594
|
}
|
|
38151
38595
|
function isWorkspaceRoot(cwd, pkg) {
|
|
38152
|
-
return !!pkg.workspaces ||
|
|
38596
|
+
return !!pkg.workspaces || existsSync4(join4(cwd, "pnpm-workspace.yaml"));
|
|
38153
38597
|
}
|
|
38154
38598
|
function workspaceApps(cwd) {
|
|
38155
38599
|
const found = [];
|
|
38156
38600
|
for (const group of ["apps", "packages", "examples", "sites"]) {
|
|
38157
|
-
const dir =
|
|
38158
|
-
if (!
|
|
38159
|
-
for (const name of
|
|
38160
|
-
const pkg = readJson(
|
|
38161
|
-
if (pkg && detectFramework(
|
|
38162
|
-
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));
|
|
38163
38607
|
}
|
|
38164
38608
|
}
|
|
38165
38609
|
return found;
|
|
38166
38610
|
}
|
|
38167
38611
|
function loadStep(framework, cwd) {
|
|
38168
|
-
const at = (file2,
|
|
38612
|
+
const at = (file2, otherwise) => file2 ? `\`${relative3(cwd, file2)}\`` : otherwise;
|
|
38169
38613
|
const code = (lang, text) => `
|
|
38170
38614
|
|
|
38171
38615
|
\`\`\`${lang}
|
|
@@ -38174,9 +38618,23 @@ ${text.replace(/^(?=.)/gm, " ")}
|
|
|
38174
38618
|
const intro = "**Load Pilot in the app, in development only** (it must never reach production), the way this project writes code.";
|
|
38175
38619
|
switch (framework.kind) {
|
|
38176
38620
|
case "vite":
|
|
38177
|
-
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.`;
|
|
38178
38636
|
case "next-app":
|
|
38179
|
-
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(
|
|
38180
38638
|
"tsx",
|
|
38181
38639
|
`"use client";
|
|
38182
38640
|
import { useEffect } from "react";
|
|
@@ -38189,7 +38647,7 @@ export function Pilot() {
|
|
|
38189
38647
|
}`
|
|
38190
38648
|
)}`;
|
|
38191
38649
|
case "next-pages":
|
|
38192
|
-
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(
|
|
38193
38651
|
"tsx",
|
|
38194
38652
|
`useEffect(() => {
|
|
38195
38653
|
if (process.env.NODE_ENV === "development") import("usepilot/auto");
|
|
@@ -38203,25 +38661,25 @@ export function Pilot() {
|
|
|
38203
38661
|
});`
|
|
38204
38662
|
)}`;
|
|
38205
38663
|
case "sveltekit":
|
|
38206
|
-
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");')}`;
|
|
38207
38665
|
case "astro":
|
|
38208
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>')}`;
|
|
38209
38667
|
case "react-router":
|
|
38210
|
-
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(
|
|
38211
38669
|
"tsx",
|
|
38212
38670
|
`useEffect(() => {
|
|
38213
38671
|
if (import.meta.env.DEV) import("usepilot/auto");
|
|
38214
38672
|
}, []);`
|
|
38215
38673
|
)}`;
|
|
38216
38674
|
case "webpack":
|
|
38217
|
-
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");')}`;
|
|
38218
38676
|
default:
|
|
38219
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.`;
|
|
38220
38678
|
}
|
|
38221
38679
|
}
|
|
38222
38680
|
async function addServer(file2, key, entry) {
|
|
38223
38681
|
let config2 = {};
|
|
38224
|
-
if (
|
|
38682
|
+
if (existsSync4(file2)) {
|
|
38225
38683
|
const text = await readFile3(file2, "utf8");
|
|
38226
38684
|
try {
|
|
38227
38685
|
config2 = text.trim() ? JSON.parse(text) : {};
|
|
@@ -38240,7 +38698,7 @@ async function addServer(file2, key, entry) {
|
|
|
38240
38698
|
}
|
|
38241
38699
|
function readJson(file2) {
|
|
38242
38700
|
try {
|
|
38243
|
-
return JSON.parse(
|
|
38701
|
+
return JSON.parse(readFileSync2(file2, "utf8"));
|
|
38244
38702
|
} catch {
|
|
38245
38703
|
return null;
|
|
38246
38704
|
}
|
|
@@ -38258,9 +38716,14 @@ var HELP = `usepilot: take the controls from your coding agent
|
|
|
38258
38716
|
|
|
38259
38717
|
Usage: npx usepilot <command>
|
|
38260
38718
|
|
|
38261
|
-
init Set Pilot up in this project
|
|
38262
|
-
its MCP server
|
|
38263
|
-
|
|
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
|
|
38264
38727
|
setup Set up /pilot in Claude Code, for every project on this machine
|
|
38265
38728
|
(--project: for this repo, to commit, so everyone gets it)
|
|
38266
38729
|
mcp Run the MCP server (stdio) agents connect to, and the bridge the
|
|
@@ -38279,6 +38742,14 @@ async function runMcp() {
|
|
|
38279
38742
|
await server.connect(new StdioServerTransport());
|
|
38280
38743
|
}
|
|
38281
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
|
+
}
|
|
38282
38753
|
switch (command) {
|
|
38283
38754
|
case "help":
|
|
38284
38755
|
case "--help":
|
|
@@ -38299,7 +38770,13 @@ switch (command) {
|
|
|
38299
38770
|
break;
|
|
38300
38771
|
case "init":
|
|
38301
38772
|
try {
|
|
38302
|
-
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
|
+
);
|
|
38303
38780
|
} catch (error62) {
|
|
38304
38781
|
process.stderr.write(`usepilot init: ${error62.message}
|
|
38305
38782
|
`);
|