usepilot 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/index.js CHANGED
@@ -3912,50 +3912,50 @@ var require_fast_uri = __commonJS({
3912
3912
  schemelessOptions.skipEscape = true;
3913
3913
  return serialize(resolved, schemelessOptions);
3914
3914
  }
3915
- function resolveComponent(base, relative2, options, skipNormalization) {
3915
+ function resolveComponent(base, relative3, options, skipNormalization) {
3916
3916
  const target = {};
3917
3917
  if (!skipNormalization) {
3918
3918
  base = parse3(serialize(base, options), options);
3919
- relative2 = parse3(serialize(relative2, options), options);
3919
+ relative3 = parse3(serialize(relative3, options), options);
3920
3920
  }
3921
3921
  options = options || {};
3922
- if (!options.tolerant && relative2.scheme) {
3923
- target.scheme = relative2.scheme;
3924
- target.userinfo = relative2.userinfo;
3925
- target.host = relative2.host;
3926
- target.port = relative2.port;
3927
- target.path = removeDotSegments(relative2.path || "");
3928
- target.query = relative2.query;
3922
+ if (!options.tolerant && relative3.scheme) {
3923
+ target.scheme = relative3.scheme;
3924
+ target.userinfo = relative3.userinfo;
3925
+ target.host = relative3.host;
3926
+ target.port = relative3.port;
3927
+ target.path = removeDotSegments(relative3.path || "");
3928
+ target.query = relative3.query;
3929
3929
  } else {
3930
- if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
3931
- target.userinfo = relative2.userinfo;
3932
- target.host = relative2.host;
3933
- target.port = relative2.port;
3934
- target.path = removeDotSegments(relative2.path || "");
3935
- target.query = relative2.query;
3930
+ if (relative3.userinfo !== void 0 || relative3.host !== void 0 || relative3.port !== void 0) {
3931
+ target.userinfo = relative3.userinfo;
3932
+ target.host = relative3.host;
3933
+ target.port = relative3.port;
3934
+ target.path = removeDotSegments(relative3.path || "");
3935
+ target.query = relative3.query;
3936
3936
  } else {
3937
- if (!relative2.path) {
3937
+ if (!relative3.path) {
3938
3938
  target.path = base.path;
3939
- if (relative2.query !== void 0) {
3940
- target.query = relative2.query;
3939
+ if (relative3.query !== void 0) {
3940
+ target.query = relative3.query;
3941
3941
  } else {
3942
3942
  target.query = base.query;
3943
3943
  }
3944
3944
  } else {
3945
- if (relative2.path[0] === "/") {
3946
- target.path = removeDotSegments(relative2.path);
3945
+ if (relative3.path[0] === "/") {
3946
+ target.path = removeDotSegments(relative3.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 = "/" + relative2.path;
3950
+ target.path = "/" + relative3.path;
3951
3951
  } else if (!base.path) {
3952
- target.path = relative2.path;
3952
+ target.path = relative3.path;
3953
3953
  } else {
3954
- target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
3954
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative3.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 = relative2.query;
3958
+ target.query = relative3.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 = relative2.fragment;
3966
+ target.fragment = relative3.fragment;
3967
3967
  return target;
3968
3968
  }
3969
3969
  function equal(uriA, uriB, options) {
@@ -7230,8 +7230,8 @@ var require_dist = __commonJS({
7230
7230
  return ajv;
7231
7231
  }
7232
7232
  const [formats, exportName] = opts.mode === "fast" ? [formats_1.fastFormats, fastName] : [formats_1.fullFormats, fullName];
7233
- const list = opts.formats || formats_1.formatNames;
7234
- addFormats(ajv, list, formats, exportName);
7233
+ const list2 = opts.formats || formats_1.formatNames;
7234
+ addFormats(ajv, list2, formats, exportName);
7235
7235
  if (opts.keywords)
7236
7236
  (0, limit_1.default)(ajv);
7237
7237
  return ajv;
@@ -7243,11 +7243,11 @@ var require_dist = __commonJS({
7243
7243
  throw new Error(`Unknown format "${name}"`);
7244
7244
  return f;
7245
7245
  };
7246
- function addFormats(ajv, list, fs, exportName) {
7246
+ function addFormats(ajv, list2, fs, exportName) {
7247
7247
  var _a3;
7248
7248
  var _b;
7249
7249
  (_a3 = (_b = ajv.opts.code).formats) !== null && _a3 !== void 0 ? _a3 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
7250
- for (const f of list)
7250
+ for (const f of list2)
7251
7251
  ajv.addFormat(f, fs[f]);
7252
7252
  }
7253
7253
  module.exports = exports = formatsPlugin;
@@ -8733,7 +8733,7 @@ function $constructor(name, initializer3, proto, params) {
8733
8733
  Internals.prototype = zodProto;
8734
8734
  const protoMembers = proto;
8735
8735
  const initialized = protoMembers && /* @__PURE__ */ new WeakSet();
8736
- function init(inst, def) {
8736
+ function init2(inst, def) {
8737
8737
  if (!inst._zod) {
8738
8738
  _zodDesc.value = new Internals(def);
8739
8739
  try {
@@ -8773,7 +8773,7 @@ function $constructor(name, initializer3, proto, params) {
8773
8773
  Object.defineProperty(Definition, "name", { value: name });
8774
8774
  function _(def) {
8775
8775
  const inst = params?.Parent ? newError(Definition) : this;
8776
- init(inst, def);
8776
+ init2(inst, def);
8777
8777
  const deferred = inst._zod.deferred;
8778
8778
  if (deferred) {
8779
8779
  for (const fn of deferred) {
@@ -8786,7 +8786,7 @@ function $constructor(name, initializer3, proto, params) {
8786
8786
  pp(inst);
8787
8787
  return inst;
8788
8788
  }
8789
- Object.defineProperty(_, "init", { value: init });
8789
+ Object.defineProperty(_, "init", { value: init2 });
8790
8790
  Object.defineProperty(_, Symbol.hasInstance, {
8791
8791
  value: (inst) => {
8792
8792
  if (params?.Parent && inst instanceof params.Parent)
@@ -23464,8 +23464,8 @@ var contributors = {
23464
23464
  function aggregateChecks(schema) {
23465
23465
  const agg = {};
23466
23466
  const def = schema._zod.def;
23467
- const list = schema._zod.traits.has("$ZodCheck") ? [schema, ...def.checks ?? []] : def.checks ?? [];
23468
- for (const ch of list)
23467
+ const list2 = schema._zod.traits.has("$ZodCheck") ? [schema, ...def.checks ?? []] : def.checks ?? [];
23468
+ for (const ch of list2)
23469
23469
  contributors[ch._zod.def.check]?.(agg, ch._zod.def);
23470
23470
  const bag = schema._zod.bag;
23471
23471
  if (bag.minimum !== void 0)
@@ -28613,7 +28613,7 @@ var StdioServerTransport = class {
28613
28613
 
28614
28614
  // src/mcp.ts
28615
28615
  import { randomUUID as randomUUID2 } from "crypto";
28616
- import { basename } from "path";
28616
+ import { basename as basename2 } from "path";
28617
28617
 
28618
28618
  // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v3/helpers/util.js
28619
28619
  var util;
@@ -36659,9 +36659,45 @@ var EMPTY_COMPLETION_RESULT = {
36659
36659
  }
36660
36660
  };
36661
36661
 
36662
+ // ../protocol/src/types.ts
36663
+ var ATTACHMENT_TYPES = {
36664
+ png: "image/png",
36665
+ jpg: "image/jpeg",
36666
+ gif: "image/gif",
36667
+ webp: "image/webp",
36668
+ pdf: "application/pdf",
36669
+ txt: "text/plain",
36670
+ md: "text/markdown",
36671
+ csv: "text/csv",
36672
+ json: "application/json"
36673
+ };
36674
+ var ATTACHMENT_ID = /^[a-f0-9]{64}\.(png|jpg|gif|webp|pdf|txt|md|csv|json)$/;
36675
+ function attachmentKind(name) {
36676
+ const ext = name.split(".").pop()?.toLowerCase();
36677
+ return ext === "pdf" ? "pdf" : ext === "png" || ext === "jpg" || ext === "jpeg" || ext === "gif" || ext === "webp" ? "image" : "text";
36678
+ }
36679
+ var BY_EXTENSION = {
36680
+ png: "image/png",
36681
+ jpg: "image/jpeg",
36682
+ jpeg: "image/jpeg",
36683
+ gif: "image/gif",
36684
+ webp: "image/webp",
36685
+ pdf: "application/pdf",
36686
+ txt: "text/plain",
36687
+ log: "text/plain",
36688
+ text: "text/plain",
36689
+ md: "text/markdown",
36690
+ markdown: "text/markdown",
36691
+ csv: "text/csv",
36692
+ json: "application/json"
36693
+ };
36694
+ var ATTACHMENT_ACCEPT = [...new Set(Object.values(ATTACHMENT_TYPES))].join(",") + "," + Object.keys(BY_EXTENSION).map((e) => `.${e}`).join(",");
36695
+
36662
36696
  // ../protocol/src/format.ts
36663
36697
  function formatPrompt(changeSet) {
36664
36698
  if (changeSet.request?.kind === "responsive") return formatResponsive(changeSet, changeSet.request);
36699
+ if (changeSet.request?.kind === "break-and-fix") return formatBreakFix(changeSet, changeSet.request);
36700
+ if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request);
36665
36701
  const { page, edits, note } = changeSet;
36666
36702
  const lines = [
36667
36703
  "# Pilot design edits",
@@ -36673,6 +36709,7 @@ function formatPrompt(changeSet) {
36673
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.",
36674
36710
  "- Change only the listed elements. If an element is a shared component, ask before changing every instance.",
36675
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.",
36676
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).",
36677
36714
  "",
36678
36715
  `Page: ${page.url} (${page.title || "untitled"}) at ${page.viewport.width}x${page.viewport.height}`
@@ -36687,6 +36724,52 @@ function formatPrompt(changeSet) {
36687
36724
  `;
36688
36725
  }
36689
36726
  var ADVANCED_TASK = '**An advanced task: it needs judgment more than speed.** If you can hand work to a more capable model and aren\'t running on one, do: in Claude Code, unless you already run on Opus, give this whole prompt (with the job id) to a subagent with `model: "opus"` (the Agent tool), have it make the changes and run the width check, and report back; then call `pilot_done` with its notes.';
36727
+ var ACTION_ASKED = {
36728
+ responsive: "asked you to make it responsive",
36729
+ "break-and-fix": "asked you to break and fix it"
36730
+ };
36731
+ function formatBreakFix(changeSet, request) {
36732
+ const { page, note } = changeSet;
36733
+ const { target, breakpoints } = request;
36734
+ const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
36735
+ const lines = [
36736
+ "# Pilot: break and fix",
36737
+ "",
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.",
36739
+ "",
36740
+ `Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
36741
+ `The page's breakpoints (the widths its media queries test): ${widths}`,
36742
+ "",
36743
+ ADVANCED_TASK
36744
+ ];
36745
+ if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
36746
+ if (request.attachments?.length) lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
36747
+ lines.push(
36748
+ "",
36749
+ `## \`${target.path}\``,
36750
+ "",
36751
+ ...targetLines(target),
36752
+ "",
36753
+ "## How to do it",
36754
+ "",
36755
+ "1. **Find the element's component and where its content comes from**: props, data, a CMS or an API, translations. List what can vary: each text, how many repeated items there are, optional parts (an image, a subtitle, a badge), numbers, names, URLs.",
36756
+ "2. **Think of the odd but realistic content each can get**: text far longer than the placeholder (a 120-character title, a long person or product name) and much shorter or empty; long words with no spaces (URLs, emails, IDs, compound words); optional parts missing (no image, no subtitle, an empty list) and many repeated items instead of a few; big numbers and prices; the longer strings of other languages; images (and background images) in odd shapes, very wide, very tall, tiny or low-resolution, and images that fail to load.",
36757
+ "3. **Break it on purpose, temporarily**: put that content in the page (the props, the fixture or data it renders, or the markup), let hot reload show it, and run `pilot_check_widths` with this job's id. It measures the element at every width in the designer's page and reports, as numbers, content sticking out of the viewport, spilling out of its parent, clipped, or overlapping. Read the code too, for what the check can't see: items that shrink when they shouldn't (an icon or avatar squeezed by flex), buttons that stretch, rows that misalign, text wrapping under an icon, images stretched or squashed (a distorted image keeps its box, so the check doesn't report it).",
36758
+ "4. **Fix what breaks, without changing how it looks with its usual content**, the way this project does it (its utilities, its components):",
36759
+ " - **Long text:** truncate it with an ellipsis (`truncate`, `text-overflow: ellipsis`) where one line matters, or clamp it to a few lines (`line-clamp-*`) where it can wrap; when the full text is lost, show it on hover (`title`, or the project's tooltip).",
36760
+ " - **Flex and grid:** `min-width: 0` (`min-w-0`) on items holding text so they can shrink; `flex-shrink: 0` (`shrink-0`) on icons, avatars and buttons that mustn't; `minmax(0, 1fr)` columns; wrapping rows (`flex-wrap`) instead of overflowing ones.",
36761
+ " - **Long words:** `overflow-wrap: anywhere` (`break-words`) where text must wrap.",
36762
+ " - **Images:** `object-fit: cover` for photos that should fill their frame, `contain` where cropping would lose something (logos, product shots); for background images, `background-size: cover` (or `contain`) with a sensible `background-position`. A fixed `aspect-ratio` (or size) on the frame, so the layout doesn't jump while an image loads or when its shape is odd, and a fallback when it fails or is missing (a plain background, initials, an icon), never a broken-image box.",
36763
+ " - **Missing parts:** no gap or empty box left behind; a simple empty state only where one is clearly needed.",
36764
+ " In the check, an ellipsis on your deliberately long text is the fix working, not a problem.",
36765
+ "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
+ "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
+ "",
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. Never leave inline styles."
36769
+ );
36770
+ return `${lines.join("\n")}
36771
+ `;
36772
+ }
36690
36773
  function formatResponsive(changeSet, request) {
36691
36774
  const { page, note } = changeSet;
36692
36775
  const { target, breakpoints } = request;
@@ -36702,6 +36785,7 @@ function formatResponsive(changeSet, request) {
36702
36785
  ADVANCED_TASK
36703
36786
  ];
36704
36787
  if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
36788
+ if (request.attachments?.length) lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
36705
36789
  lines.push(
36706
36790
  "",
36707
36791
  `## \`${target.path}\``,
@@ -36722,6 +36806,78 @@ function formatResponsive(changeSet, request) {
36722
36806
  return `${lines.join("\n")}
36723
36807
  `;
36724
36808
  }
36809
+ function formatComment(changeSet, request) {
36810
+ const { page } = changeSet;
36811
+ const { target, thread, breakpoints } = request;
36812
+ const latest = thread.at(-1);
36813
+ const earlier = thread.slice(0, -1);
36814
+ const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
36815
+ const lines = [
36816
+ "# Pilot: comment",
36817
+ "",
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).",
36819
+ "",
36820
+ `Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
36821
+ `The page's breakpoints (the widths its media queries test): ${widths}`,
36822
+ "",
36823
+ `## \`${target.path}\``,
36824
+ "",
36825
+ ...targetLines(target),
36826
+ "",
36827
+ "## The comment",
36828
+ "",
36829
+ ...commentLines(latest)
36830
+ ];
36831
+ if (earlier.length) {
36832
+ lines.push("", "## The thread so far (you already did what it asked)", "");
36833
+ for (const m of earlier) {
36834
+ const files = m.attachments?.length ? ` (${countFiles(m.attachments.length)})` : "";
36835
+ const action = m.action ? ` (${ACTION_ASKED[m.action]})` : "";
36836
+ lines.push(`- **${m.from === "designer" ? "Designer" : "You"}:**${action}${files} ${m.text.replace(/\s*\n\s*/g, " ")}`.trimEnd());
36837
+ }
36838
+ }
36839
+ lines.push(
36840
+ "",
36841
+ "## How to do it",
36842
+ "",
36843
+ "- **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 and aren't running on one, do: in Claude Code, unless you already run on Opus, give this prompt (with the job id) to a subagent with `model: \"opus\"` (the Agent tool), and report back with its notes.",
36845
+ `- 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
+ "- Change only what the comment is about. Never leave inline styles. If the element comes from a shared component, ask before changing every instance.",
36847
+ "- **A question, not a change:** answer it, and change nothing.",
36848
+ "- **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
+ );
36850
+ return `${lines.join("\n")}
36851
+ `;
36852
+ }
36853
+ function commentLines(message) {
36854
+ const text = message?.text.trim() ?? "";
36855
+ const files = message?.attachments ?? [];
36856
+ const out = text ? [quote(text)] : [];
36857
+ if (!files.length) return out.length ? out : ["> (empty)"];
36858
+ const one = files.length === 1;
36859
+ if (out.length) out.push("");
36860
+ out.push(
36861
+ text ? `The designer attached ${countFiles(files.length)} to it:` : `The comment is ${countFiles(files.length)}, with no words. ${one ? "It" : "They"} may hold the instructions: a screenshot, a sketch, notes, a spec. If it's unclear what to do, ask in your reply instead of guessing.`,
36862
+ "",
36863
+ ...attachmentLines(files)
36864
+ );
36865
+ return out;
36866
+ }
36867
+ function attachmentLines(files, intro) {
36868
+ const lines = files.map((file2) => {
36869
+ const kind = attachmentKind(file2.id);
36870
+ const how = kind === "pdf" ? "a PDF: open it at this path" : kind === "image" ? "an image, shown with this job" : "a text file, its contents shown with this job";
36871
+ return `- ${file2.name ? `${file2.name} ` : ""}(${how}): \`${file2.path ?? file2.id}\``;
36872
+ });
36873
+ return intro ? [intro, "", ...lines] : lines;
36874
+ }
36875
+ function countFiles(n) {
36876
+ return n === 1 ? "a file" : `${n} files`;
36877
+ }
36878
+ function quote(text) {
36879
+ return text.trim().split("\n").map((l) => `> ${l}`).join("\n");
36880
+ }
36725
36881
  function targetLines(target) {
36726
36882
  const out = [`- Selector: \`${target.selector}\``];
36727
36883
  if (target.text) out.push(`- Text: "${target.text}"`);
@@ -36732,8 +36888,10 @@ function targetLines(target) {
36732
36888
  return out;
36733
36889
  }
36734
36890
  function formatEdit(edit, n) {
36735
- const { target, changes } = edit;
36891
+ const { target, changes, texts } = edit;
36736
36892
  const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
36893
+ if (texts?.length) out.push("", "Text (from \u2192 to):", "", ...texts.map((t) => `- ${JSON.stringify(t.from)} \u2192 ${JSON.stringify(t.to)}`));
36894
+ if (!changes.length) return out;
36737
36895
  const withStates = changes.some((c) => c.states?.length);
36738
36896
  out.push(
36739
36897
  "",
@@ -36793,13 +36951,19 @@ function formatWidthCheck(check2) {
36793
36951
  lines.push("", `Changed at the designer's width (${check2.designerWidth}px), which should look as it did:`);
36794
36952
  for (const c of check2.changedAtDesignerWidth) lines.push(`- ${c}`);
36795
36953
  }
36954
+ if (check2.source === "copy") {
36955
+ lines.push(
36956
+ "",
36957
+ "Measured on a copy of the page as the designer has it, with scripts off: layout that only changes through JavaScript (a menu a script toggles, components that measure themselves) isn't reflected here."
36958
+ );
36959
+ }
36796
36960
  return `${lines.join("\n")}
36797
36961
  `;
36798
36962
  }
36799
36963
 
36800
36964
  // ../protocol/src/bridge.ts
36801
36965
  var DEFAULT_BRIDGE_PORT = 4747;
36802
- var BRIDGE_VERSION = 2;
36966
+ var BRIDGE_VERSION = 3;
36803
36967
  function originOf(url2) {
36804
36968
  try {
36805
36969
  const u = new URL(url2.includes("://") ? url2 : `http://${url2}`);
@@ -36815,6 +36979,122 @@ function originKey(origin) {
36815
36979
  // src/server.ts
36816
36980
  import { createServer } from "http";
36817
36981
 
36982
+ // src/attachments.ts
36983
+ import { createHash } from "crypto";
36984
+ import { existsSync } from "fs";
36985
+ import { mkdir, readdir, readFile, rm, stat, writeFile } from "fs/promises";
36986
+ import { tmpdir } from "os";
36987
+ import { basename, dirname, join } from "path";
36988
+ var FOLDER = "pilot-attachments";
36989
+ var MAX_ATTACHMENT_BYTES = 1e7;
36990
+ var MAX_INLINE_IMAGE = 35e5;
36991
+ var MAX_INLINE_TEXT = 1e5;
36992
+ var KEEP_MS = 7 * 24 * 60 * 60 * 1e3;
36993
+ function attachmentsDir(base = tmpdir()) {
36994
+ return join(base, FOLDER);
36995
+ }
36996
+ function extensionOf(type) {
36997
+ const given = type.split(";")[0]?.trim().toLowerCase();
36998
+ const found = Object.entries(ATTACHMENT_TYPES).find(([, t]) => t === given);
36999
+ return found ? found[0] : null;
37000
+ }
37001
+ function looksLike(bytes, ext) {
37002
+ const starts = (...sig) => sig.every((b, i) => bytes[i] === b);
37003
+ switch (ext) {
37004
+ case "png":
37005
+ return starts(137, 80, 78, 71);
37006
+ case "jpg":
37007
+ return starts(255, 216, 255);
37008
+ case "gif":
37009
+ return starts(71, 73, 70, 56);
37010
+ case "webp":
37011
+ return starts(82, 73, 70, 70) && bytes.subarray(8, 12).toString("latin1") === "WEBP";
37012
+ case "pdf":
37013
+ return bytes.subarray(0, 5).toString("latin1") === "%PDF-";
37014
+ default:
37015
+ if (bytes.includes(0)) return false;
37016
+ try {
37017
+ new TextDecoder("utf-8", { fatal: true }).decode(bytes);
37018
+ return true;
37019
+ } catch {
37020
+ return false;
37021
+ }
37022
+ }
37023
+ }
37024
+ async function saveAttachment(bytes, type, dir = attachmentsDir()) {
37025
+ const ext = extensionOf(type);
37026
+ if (!ext || bytes.length === 0 || bytes.length > MAX_ATTACHMENT_BYTES || !looksLike(bytes, ext)) return null;
37027
+ const id = `${createHash("sha256").update(bytes).digest("hex")}.${ext}`;
37028
+ await mkdir(dir, { recursive: true });
37029
+ const path = join(dir, id);
37030
+ if (!existsSync(path)) await writeFile(path, bytes);
37031
+ return id;
37032
+ }
37033
+ function withAttachmentPaths(job, dir = attachmentsDir()) {
37034
+ const request = job.changeSet.request;
37035
+ const kept = (files) => {
37036
+ if (!Array.isArray(files)) return void 0;
37037
+ const valid = files.filter((file2) => typeof file2?.id === "string" && ATTACHMENT_ID.test(file2.id) && existsSync(join(dir, file2.id))).slice(0, 20).map((file2) => ({
37038
+ id: file2.id,
37039
+ name: typeof file2.name === "string" ? file2.name.slice(0, 200) : void 0,
37040
+ path: join(dir, file2.id)
37041
+ }));
37042
+ return valid.length ? valid : void 0;
37043
+ };
37044
+ if (request && request.kind !== "comment")
37045
+ return { ...job, changeSet: { ...job.changeSet, request: { ...request, attachments: kept(request.attachments) } } };
37046
+ if (request?.kind !== "comment") return job;
37047
+ const thread = request.thread.map((message) => message.attachments ? { ...message, attachments: kept(message.attachments) } : message);
37048
+ return { ...job, changeSet: { ...job.changeSet, request: { ...request, thread } } };
37049
+ }
37050
+ async function attachmentBlocks(job) {
37051
+ const request = job.changeSet.request;
37052
+ let files;
37053
+ if (request && request.kind !== "comment") files = request.attachments ?? [];
37054
+ else if (request?.kind === "comment") {
37055
+ const lastReply = request.thread.map((m) => m.from).lastIndexOf("agent");
37056
+ files = request.thread.slice(lastReply + 1).flatMap((m) => m.attachments ?? []);
37057
+ } else return [];
37058
+ const blocks = [];
37059
+ for (const file2 of files) {
37060
+ const path = file2.path;
37061
+ if (!path || basename(dirname(path)) !== FOLDER || !ATTACHMENT_ID.test(basename(path))) continue;
37062
+ const kind = attachmentKind(path);
37063
+ if (kind === "pdf") continue;
37064
+ try {
37065
+ const size = (await stat(path)).size;
37066
+ if (kind === "image") {
37067
+ if (size > MAX_INLINE_IMAGE) continue;
37068
+ const ext = basename(path).split(".").pop();
37069
+ blocks.push({ type: "image", data: (await readFile(path)).toString("base64"), mimeType: ATTACHMENT_TYPES[ext] });
37070
+ } else {
37071
+ if (size > MAX_INLINE_TEXT) continue;
37072
+ const name = file2.name ?? basename(path);
37073
+ blocks.push({
37074
+ type: "text",
37075
+ text: `Attached file ${name}, as the designer sent it:
37076
+
37077
+ ${await readFile(path, "utf8")}
37078
+
37079
+ (end of ${name})`
37080
+ });
37081
+ }
37082
+ } catch {
37083
+ }
37084
+ }
37085
+ return blocks;
37086
+ }
37087
+ async function sweepAttachments(dir = attachmentsDir(), now = Date.now()) {
37088
+ try {
37089
+ for (const name of await readdir(dir)) {
37090
+ if (!ATTACHMENT_ID.test(name)) continue;
37091
+ const path = join(dir, name);
37092
+ if (now - (await stat(path)).mtimeMs > KEEP_MS) await rm(path, { force: true });
37093
+ }
37094
+ } catch {
37095
+ }
37096
+ }
37097
+
36818
37098
  // src/hub.ts
36819
37099
  import { randomUUID } from "crypto";
36820
37100
  var AGENT_TTL = 3e4;
@@ -37042,9 +37322,11 @@ var Hub = class {
37042
37322
  };
37043
37323
 
37044
37324
  // src/server.ts
37045
- function startHub(port, hub = new Hub()) {
37325
+ function startHub(port, hub = new Hub(), options = {}) {
37326
+ const attachments = options.attachments ?? attachmentsDir();
37327
+ void sweepAttachments(attachments);
37046
37328
  const server = createServer((req, res) => {
37047
- handle(hub, req, res).catch((error62) => {
37329
+ handle(hub, req, res, attachments).catch((error62) => {
37048
37330
  if (!res.headersSent) json2(res, 500, { error: String(error62) });
37049
37331
  });
37050
37332
  });
@@ -37071,7 +37353,7 @@ function startHub(port, hub = new Hub()) {
37071
37353
  });
37072
37354
  }
37073
37355
  var localAgents = /* @__PURE__ */ new Set();
37074
- async function handle(hub, req, res) {
37356
+ async function handle(hub, req, res, attachments) {
37075
37357
  const url2 = new URL(req.url ?? "/", "http://127.0.0.1");
37076
37358
  const origin = req.headers.origin;
37077
37359
  const path = url2.pathname;
@@ -37094,11 +37376,19 @@ async function handle(hub, req, res) {
37094
37376
  if (path === "/events" && req.method === "GET") return events(hub, origin, req, res);
37095
37377
  if (req.method !== "POST") return json2(res, 405, { error: "POST only" });
37096
37378
  if (!hub.hasAgents(origin)) return json2(res, 403, { error: "no agent works on this page: run /pilot in your agent" });
37379
+ if (path === "/attachments") {
37380
+ const type = req.headers["content-type"] ?? "";
37381
+ if (!extensionOf(type)) return json2(res, 415, { error: "images (png, jpeg, gif, webp), text files (txt, md, csv, json) and PDFs only" });
37382
+ const bytes = await rawBody(req, MAX_ATTACHMENT_BYTES);
37383
+ if (!bytes) return json2(res, 413, { error: `files up to ${MAX_ATTACHMENT_BYTES / 1e6} MB` });
37384
+ const id = await saveAttachment(bytes, type, attachments);
37385
+ return id ? json2(res, 201, { id }) : json2(res, 400, { error: "not a file of that type" });
37386
+ }
37097
37387
  const data = await body(req);
37098
37388
  if (path === "/jobs") {
37099
37389
  const post = data;
37100
37390
  if (typeof post?.id !== "string" || !post.changeSet) return json2(res, 400, { error: "job needs id and changeSet" });
37101
- return json2(res, 202, { job: hub.postJob(origin, post) });
37391
+ return json2(res, 202, { job: hub.postJob(origin, withAttachmentPaths(post, attachments)) });
37102
37392
  }
37103
37393
  const jobRoute = path.match(/^\/jobs\/([^/]+)\/(cancel|retry)$/);
37104
37394
  if (jobRoute) {
@@ -37179,6 +37469,28 @@ function json2(res, status, data) {
37179
37469
  res.writeHead(status, { "Content-Type": "application/json" });
37180
37470
  res.end(JSON.stringify(data));
37181
37471
  }
37472
+ function rawBody(req, max) {
37473
+ return new Promise((resolve, reject) => {
37474
+ const chunks = [];
37475
+ let size = 0;
37476
+ let over = false;
37477
+ req.on("data", (chunk) => {
37478
+ if (over) return;
37479
+ size += chunk.length;
37480
+ if (size > max) {
37481
+ over = true;
37482
+ resolve(null);
37483
+ req.resume();
37484
+ return;
37485
+ }
37486
+ chunks.push(chunk);
37487
+ });
37488
+ req.on("end", () => {
37489
+ if (!over) resolve(Buffer.concat(chunks));
37490
+ });
37491
+ req.on("error", reject);
37492
+ });
37493
+ }
37182
37494
  function body(req) {
37183
37495
  return new Promise((resolve, reject) => {
37184
37496
  let text = "";
@@ -37401,10 +37713,10 @@ function waitMsFor(clientName) {
37401
37713
  var PROGRESS_MS = 2e4;
37402
37714
  var INSTRUCTIONS = `Pilot lets the designer edit the running app in the browser and send the edits back to you as jobs.
37403
37715
 
37404
- The loop, when the user runs /pilot or asks to hand the design over:
37405
- 1. Call pilot_launch with the URL of the page the designer works on (the app's dev server, e.g. http://localhost:5173). Pilot opens in that page.
37716
+ The loop, when the user asks to launch or start Pilot, runs /pilot, or asks to hand the design over:
37717
+ 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.
37406
37718
  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.)
37407
- 3. Apply the job's edits to the source, in the project's conventions (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. Its prompt lists the steps; check the result with pilot_check_widths (numbers for every width, instead of screenshots). In Claude Code, hand advanced tasks to an Opus subagent unless you run on Opus.
37719
+ 3. Apply the job's edits to the source, in the project's conventions (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). In Claude Code, hand advanced tasks to an Opus subagent unless you run on Opus. 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.
37408
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.
37409
37721
 
37410
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.`;
@@ -37419,13 +37731,13 @@ function agentLabel(clientName, cwd) {
37419
37731
  codex: "Codex"
37420
37732
  };
37421
37733
  const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
37422
- return `${app} \xB7 ${basename(cwd)}`;
37734
+ return `${app} \xB7 ${basename2(cwd)}`;
37423
37735
  }
37424
37736
  function jobPrompt(job) {
37425
37737
  const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : formatPrompt(job.changeSet);
37426
37738
  return `${body2}
37427
37739
  ---
37428
- Pilot job \`${job.id}\`. When you've applied it, call \`pilot_done\` with \`jobId: "${job.id}"\` and short notes (${job.changeSet.request ? "what changed at which widths, which widths you checked in a browser, anything left for the designer" : "values you approximated, anything you did differently"}). Then call \`pilot_wait_for_edits\` again for the next job.
37740
+ 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.
37429
37741
  `;
37430
37742
  }
37431
37743
  function followUp(job) {
@@ -37446,12 +37758,26 @@ function followUp(job) {
37446
37758
  );
37447
37759
  return lines.join("\n");
37448
37760
  }
37761
+ function notesFor(job) {
37762
+ switch (job.changeSet.request?.kind) {
37763
+ case "comment":
37764
+ return "your reply in the designer's comment thread, a small chat box: one short sentence, about 120 characters at most, with what you changed or your answer; no lists or code blocks";
37765
+ case "responsive":
37766
+ return "what changed at which widths, anything left for the designer";
37767
+ case "break-and-fix":
37768
+ return "what broke and how you fixed it, anything for the designer to decide";
37769
+ default:
37770
+ return "values you approximated, anything you did differently";
37771
+ }
37772
+ }
37449
37773
  function taskFollowUp(job) {
37450
- const target = job.changeSet.request?.target;
37774
+ const request = job.changeSet.request;
37775
+ const target = `\`${request?.target.path ?? "the element"}\``;
37776
+ const breakFix = request?.kind === "break-and-fix";
37451
37777
  const lines = [
37452
- "# Pilot: make responsive, follow-up",
37778
+ breakFix ? "# Pilot: break and fix, follow-up" : "# Pilot: make responsive, follow-up",
37453
37779
  "",
37454
- `You made \`${target?.path ?? "the element"}\` responsive, but Pilot's width check (the page measured at each width) still finds these problems:`,
37780
+ breakFix ? `You stress-tested ${target} and reported it done, but Pilot's width check (the page with its usual content, measured at each width) finds these problems. If one comes from test content still in the code, remove it:` : `You made ${target} responsive, but Pilot's width check (the page measured at each width) still finds these problems:`,
37455
37781
  "",
37456
37782
  ...(job.issues ?? []).map((i) => `- ${i}`),
37457
37783
  "",
@@ -37467,7 +37793,7 @@ function createPilotServer(options = {}) {
37467
37793
  const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
37468
37794
  const cwd = options.cwd ?? process.cwd();
37469
37795
  let waitMs = options.waitMs ?? waitMsFor(void 0);
37470
- const server = new McpServer({ name: "pilot", version: "0.4.0" }, { instructions: INSTRUCTIONS });
37796
+ const server = new McpServer({ name: "pilot", version: "0.6.0" }, { instructions: INSTRUCTIONS });
37471
37797
  const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
37472
37798
  const bridge = new Bridge(agent, port);
37473
37799
  let origin = null;
@@ -37481,7 +37807,7 @@ function createPilotServer(options = {}) {
37481
37807
  "pilot_launch",
37482
37808
  {
37483
37809
  title: "Launch Pilot",
37484
- description: "Opens Pilot in the page the designer works on, and routes that page's edits to you. Call it first when the user runs /pilot. Then call pilot_wait_for_edits.",
37810
+ description: "Opens Pilot in the page the designer works on, and routes that page's edits to you. Call it first when the user asks to launch or start Pilot (or runs /pilot). Then call pilot_wait_for_edits.",
37485
37811
  inputSchema: {
37486
37812
  url: external_exports.string().describe("The page's URL on the app's dev server, e.g. http://localhost:5173 (find it in the dev server's config or output).")
37487
37813
  }
@@ -37520,7 +37846,7 @@ function createPilotServer(options = {}) {
37520
37846
  try {
37521
37847
  const { job } = await bridge.wait(origin, waitMs, extra.signal);
37522
37848
  if (!job) return text("No edits yet. Call pilot_wait_for_edits again to keep waiting (the designer can keep editing meanwhile).");
37523
- return text(jobPrompt(job));
37849
+ return { content: [{ type: "text", text: jobPrompt(job) }, ...await attachmentBlocks(job)], isError: false };
37524
37850
  } catch (error62) {
37525
37851
  return text(`Pilot's bridge failed while waiting: ${error62.message}. Call pilot_wait_for_edits again.`, true);
37526
37852
  } finally {
@@ -37552,9 +37878,9 @@ function createPilotServer(options = {}) {
37552
37878
  "pilot_check_widths",
37553
37879
  {
37554
37880
  title: "Check an element at every width",
37555
- description: "For a Make responsive job: Pilot loads the page in hidden frames at a phone width, each breakpoint and just below it, a wide desktop and the designer's width, and measures the job's element in each. Returns each width's size and layout, and problems (sticking out of the viewport, spilling out of its parent, clipped content, overlaps), plus what changed at the designer's width. Use it instead of screenshots; fix the problems and run it again until it finds none.",
37881
+ description: "For a Make responsive or Break and fix job: Pilot loads the page in hidden frames at a phone width, each breakpoint and just below it, a wide desktop and the designer's width, and measures the job's element in each. Returns each width's size and layout, and problems (sticking out of the viewport, spilling out of its parent, clipped content, overlaps), plus what changed at the designer's width. Use it instead of screenshots; fix the problems and run it again until it finds none.",
37556
37882
  inputSchema: {
37557
- jobId: external_exports.string().describe("The Make responsive job's id, from pilot_wait_for_edits.")
37883
+ jobId: external_exports.string().describe("The Make responsive or Break and fix job's id, from pilot_wait_for_edits.")
37558
37884
  }
37559
37885
  },
37560
37886
  async ({ jobId }) => {
@@ -37562,7 +37888,7 @@ function createPilotServer(options = {}) {
37562
37888
  const check2 = await bridge.check(jobId);
37563
37889
  if (!check2) {
37564
37890
  return text(
37565
- `Pilot couldn't check job ${jobId}: no page answered. The page with Pilot must be open (the designer's tab), and the job must be a Make responsive one. If you can, check the widths in a browser instead.`,
37891
+ `Pilot couldn't check job ${jobId}: no page answered. The page with Pilot must be open (the designer's tab), and the job must be a Make responsive or Break and fix one. If you can, check the widths in a browser instead.`,
37566
37892
  true
37567
37893
  );
37568
37894
  }
@@ -37575,14 +37901,20 @@ function createPilotServer(options = {}) {
37575
37901
  return { server, bridge, agent };
37576
37902
  }
37577
37903
 
37904
+ // src/init.ts
37905
+ import { spawnSync } from "child_process";
37906
+ import { existsSync as existsSync3, readdirSync, readFileSync } from "fs";
37907
+ import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
37908
+ import { dirname as dirname2, join as join3, relative as relative2 } from "path";
37909
+
37578
37910
  // src/setup.ts
37579
- import { existsSync } from "fs";
37580
- import { lstat, mkdir, readFile, unlink, writeFile } from "fs/promises";
37911
+ import { existsSync as existsSync2 } from "fs";
37912
+ import { lstat, mkdir as mkdir2, readFile as readFile2, unlink, writeFile as writeFile2 } from "fs/promises";
37581
37913
  import { homedir } from "os";
37582
- import { join, relative } from "path";
37914
+ import { join as join2, relative } from "path";
37583
37915
 
37584
37916
  // ../../skills/pilot/SKILL.md
37585
- 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` on identifiable elements, for you to write into the source in this project's conventions. The designer keeps designing while you work; Pilot previews each job's changes until you report it done, then checks them against the page's real CSS.\n\n## When the user runs /pilot\n\n1. **Find the page.** Work out the URL of the app's dev server: the dev script and its config (`vite.config.*` \u2192 `server.port`, Next.js \u2192 3000, a `--port` flag\u2026), or a server already running in a terminal. If the dev server isn't running, start it in the background. If you can't tell the URL, ask.\n2. **Launch:** call `pilot_launch` with that URL. Pilot opens in the page (if the page isn't open yet, tell the designer to open it).\n3. **Tell the designer** in one line that Pilot is ready: select an element, edit, press Send.\n4. **Wait:** call `pilot_wait_for_edits`. It returns a job when the designer presses Send, or \"no edits yet\" after a while: call it again, without saying anything to the user. In Claude Code, a wait longer than two minutes moves to the background: end your turn with a short \"Waiting for your edits\", and the job arrives as the task's result.\n5. **Apply the job** (below), then call `pilot_done` with the job id and short notes, and go back to step 4.\n\nKeep looping until the user asks you to stop. Keep your messages between jobs short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, and keep (or start again) a wait in the background so their next Send reaches you (queued jobs are kept).\n\n## Applying a job\n\nJobs come in two 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- **Tasks** (advanced), like **Make responsive**: the designer selected an element and asked for an outcome (work at every viewport width). They need judgment more than speed. The prompt has the steps. Check the result with `pilot_check_widths` (numbers for every width, no screenshots needed). In Claude Code, unless you already run on Opus, hand the task to a subagent with `model: \"opus\"`, 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 **intent, not code**. Translate them into this project's conventions:\n\n- **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:** edit the styled definition or `sx` / `style` object where the component is styled.\n\nRules:\n\n- Never leave inline styles 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- If an element comes from a shared component, ask before changing every instance. Otherwise scope the change (a variant, a prop, a class on that use).\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- 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";
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). In Claude Code, unless you already run on Opus, hand the task to a subagent with `model: \"opus\"`, 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 **intent, not code**. Translate them into this project's conventions:\n\n- **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:** edit the styled definition or `sx` / `style` object where the component is styled.\n\nRules:\n\n- Never leave inline styles 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- If an element comes from a shared component, ask before changing every instance. Otherwise scope the change (a variant, a prop, a class on that use).\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";
37586
37918
 
37587
37919
  // src/setup.ts
37588
37920
  var MCP_SERVER = { command: "npx", args: ["-y", "usepilot", "mcp"] };
@@ -37590,7 +37922,7 @@ async function setup(options = {}) {
37590
37922
  return options.project ? setupProject(options.cwd ?? process.cwd()) : setupMachine(options.home ?? homedir());
37591
37923
  }
37592
37924
  async function setupMachine(home) {
37593
- const file2 = await writeSkill(join(home, ".claude", "skills", "pilot"));
37925
+ const file2 = await writeSkill(join2(home, ".claude", "skills", "pilot"));
37594
37926
  return `Installed the /pilot skill: ${file2}
37595
37927
 
37596
37928
  Now register Pilot's MCP server with Claude Code, once, for every project:
@@ -37602,11 +37934,11 @@ Then, in any Claude Code chat: /pilot
37602
37934
  `;
37603
37935
  }
37604
37936
  async function setupProject(cwd) {
37605
- const skillFile = await writeSkill(join(cwd, ".claude", "skills", "pilot"));
37606
- const mcpFile = join(cwd, ".mcp.json");
37937
+ const skillFile = await writeSkill(join2(cwd, ".claude", "skills", "pilot"));
37938
+ const mcpFile = join2(cwd, ".mcp.json");
37607
37939
  const { added } = await addMcpServer(mcpFile);
37608
37940
  const rel = (f) => relative(cwd, f);
37609
- const app = existsSync(join(cwd, "package.json")) ? "" : "\nNo package.json here: run this in the project's root folder, where the app is.\n";
37941
+ const app = existsSync2(join2(cwd, "package.json")) ? "" : "\nNo package.json here: run this in the project's root folder, where the app is.\n";
37610
37942
  const width = rel(skillFile).length + 2;
37611
37943
  return `Set up /pilot for this repo:
37612
37944
  ${rel(skillFile).padEnd(width)}the /pilot skill
@@ -37624,9 +37956,9 @@ Then, in a Claude Code chat in this folder: /pilot
37624
37956
  }
37625
37957
  async function writeSkill(dir) {
37626
37958
  if (await isLink(dir)) await unlink(dir);
37627
- await mkdir(dir, { recursive: true });
37628
- const file2 = join(dir, "SKILL.md");
37629
- await writeFile(file2, SKILL_default);
37959
+ await mkdir2(dir, { recursive: true });
37960
+ const file2 = join2(dir, "SKILL.md");
37961
+ await writeFile2(file2, SKILL_default);
37630
37962
  return file2;
37631
37963
  }
37632
37964
  async function isLink(path) {
@@ -37638,8 +37970,8 @@ async function isLink(path) {
37638
37970
  }
37639
37971
  async function addMcpServer(file2) {
37640
37972
  let config2 = {};
37641
- if (existsSync(file2)) {
37642
- const text = await readFile(file2, "utf8");
37973
+ if (existsSync2(file2)) {
37974
+ const text = await readFile2(file2, "utf8");
37643
37975
  try {
37644
37976
  config2 = text.trim() ? JSON.parse(text) : {};
37645
37977
  } catch {
@@ -37649,16 +37981,286 @@ async function addMcpServer(file2) {
37649
37981
  const servers = config2.mcpServers ?? {};
37650
37982
  const added = !("pilot" in servers);
37651
37983
  config2.mcpServers = { ...servers, pilot: MCP_SERVER };
37652
- await writeFile(file2, `${JSON.stringify(config2, null, 2)}
37984
+ await writeFile2(file2, `${JSON.stringify(config2, null, 2)}
37653
37985
  `);
37654
37986
  return { added };
37655
37987
  }
37656
37988
 
37989
+ // src/init.ts
37990
+ var CLIENTS = [
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
+ ];
37995
+ var COMMAND = `${MCP_SERVER.command} ${MCP_SERVER.args.join(" ")}`;
37996
+ var SKILL_FOLDERS = [join3(".agents", "skills"), join3(".claude", "skills"), join3(".github", "skills")];
37997
+ async function init(options = {}) {
37998
+ const cwd = options.cwd ?? process.cwd();
37999
+ const run = options.run ?? runCommand;
38000
+ const pkgFile = join3(cwd, "package.json");
38001
+ if (!existsSync3(pkgFile)) {
38002
+ return `# Pilot: not set up
38003
+
38004
+ 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.
38005
+ `;
38006
+ }
38007
+ const pkg = readJson(pkgFile) ?? {};
38008
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
38009
+ const root = projectRoot(cwd);
38010
+ const framework = detectFramework(cwd, deps);
38011
+ if (framework.kind === "unknown" && isWorkspaceRoot(cwd, pkg)) {
38012
+ const apps = workspaceApps(cwd);
38013
+ return `# Pilot: not set up yet
38014
+
38015
+ ${cwd} is a monorepo's root, not an app. Run \`npx usepilot@latest init\` again in the folder of the web app the user works on${apps.length ? `, one of:
38016
+
38017
+ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
38018
+ `;
38019
+ }
38020
+ const done = [];
38021
+ const todo = [];
38022
+ const pm = packageManager(cwd, root);
38023
+ const installArgs = pm === "npm" ? ["install", "-D", "usepilot"] : pm === "bun" ? ["add", "-d", "usepilot"] : ["add", "-D", "usepilot"];
38024
+ const install = `${pm} ${installArgs.join(" ")}`;
38025
+ if (deps.usepilot) done.push("`usepilot` was already a dependency.");
38026
+ else if (options.install !== false && run(pm, installArgs, cwd))
38027
+ done.push(`Installed \`usepilot\` as a dev dependency (\`${install}\`).`);
38028
+ else todo.push(`Install Pilot as a dev dependency: run \`${install}\` in ${cwd}.`);
38029
+ const registered = [];
38030
+ for (const client of CLIENTS) {
38031
+ const file2 = join3(root, client.file);
38032
+ const result = await addServer(file2, client.key, client.entry);
38033
+ if (result === "invalid")
38034
+ todo.push(
38035
+ `\`${relative2(root, file2)}\` isn't valid JSON, so Pilot wasn't added to it: fix it, and add the \`pilot\` server (\`${COMMAND}\`).`
38036
+ );
38037
+ else registered.push(`${client.name} (\`${relative2(root, file2)}\`)`);
38038
+ }
38039
+ if (registered.length) done.push(`Registered Pilot's MCP server for ${list(registered)}.`);
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)}\`).`);
38043
+ else todo.push(loadStep(framework, cwd));
38044
+ todo.push(
38045
+ `**If you aren't Claude Code, Cursor or VS Code**, register Pilot's MCP server with yourself too, named \`pilot\`, running \`${COMMAND}\`. Codex: \`codex mcp add pilot -- ${COMMAND}\`. Others: their MCP settings.`,
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.`
38050
+ );
38051
+ return `# Pilot: set up
38052
+
38053
+ Done:
38054
+ ${done.map((d) => `- ${d}`).join("\n")}
38055
+
38056
+ Left for you (the agent), in order:
38057
+ ${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
38058
+ `;
38059
+ }
38060
+ function projectRoot(cwd) {
38061
+ for (let dir = cwd; ; dir = dirname2(dir)) {
38062
+ if (existsSync3(join3(dir, ".git"))) return dir;
38063
+ if (dirname2(dir) === dir) return cwd;
38064
+ }
38065
+ }
38066
+ function packageManager(cwd, root) {
38067
+ for (let dir = cwd; ; dir = dirname2(dir)) {
38068
+ if (existsSync3(join3(dir, "pnpm-lock.yaml"))) return "pnpm";
38069
+ if (existsSync3(join3(dir, "yarn.lock"))) return "yarn";
38070
+ if (existsSync3(join3(dir, "bun.lock")) || existsSync3(join3(dir, "bun.lockb"))) return "bun";
38071
+ if (existsSync3(join3(dir, "package-lock.json"))) return "npm";
38072
+ if (dir === root || dirname2(dir) === dir) return "npm";
38073
+ }
38074
+ }
38075
+ function detectFramework(cwd, deps) {
38076
+ const has = (name) => name in deps;
38077
+ const first = (...files) => files.map((f) => join3(cwd, f)).find((f) => existsSync3(f));
38078
+ const loads = findLoader(cwd);
38079
+ const result = (kind, file2) => ({ kind, file: file2, loads });
38080
+ if (has("next")) {
38081
+ const app = first("src/app", "app");
38082
+ if (app)
38083
+ return result(
38084
+ "next-app",
38085
+ first("src/app/layout.tsx", "src/app/layout.jsx", "src/app/layout.js", "app/layout.tsx", "app/layout.jsx", "app/layout.js")
38086
+ );
38087
+ return result(
38088
+ "next-pages",
38089
+ first("src/pages/_app.tsx", "src/pages/_app.jsx", "src/pages/_app.js", "pages/_app.tsx", "pages/_app.jsx", "pages/_app.js")
38090
+ );
38091
+ }
38092
+ if (has("nuxt")) return result("nuxt", first("plugins/pilot.client.ts", "app/plugins/pilot.client.ts"));
38093
+ if (has("@sveltejs/kit")) return result("sveltekit", first("src/hooks.client.ts", "src/hooks.client.js"));
38094
+ if (has("astro")) return result("astro");
38095
+ 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/"))) return result("vite", viteEntry(cwd));
38097
+ if (has("react-scripts") || has("webpack")) {
38098
+ return result(
38099
+ "webpack",
38100
+ first("src/index.tsx", "src/index.ts", "src/index.jsx", "src/index.js", "src/main.tsx", "src/main.ts", "src/main.js")
38101
+ );
38102
+ }
38103
+ return { kind: "unknown", loads };
38104
+ }
38105
+ function viteEntry(cwd) {
38106
+ const html = join3(cwd, "index.html");
38107
+ if (existsSync3(html)) {
38108
+ const src = /<script[^>]*type=["']module["'][^>]*src=["']\/?([^"']+)["']/i.exec(readFileSync(html, "utf8"))?.[1];
38109
+ if (src && existsSync3(join3(cwd, src))) return join3(cwd, src);
38110
+ }
38111
+ return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) => join3(cwd, f)).find((f) => existsSync3(f));
38112
+ }
38113
+ var SOURCE_DIRS = ["src", "app", "pages", "plugins", "components", "lib"];
38114
+ var SOURCE_FILE = /\.(m?[jt]sx?|vue|svelte|astro|html)$/;
38115
+ function findLoader(cwd) {
38116
+ let budget = 3e3;
38117
+ const walk = (dir, depth) => {
38118
+ let names;
38119
+ try {
38120
+ names = readdirSync(dir);
38121
+ } catch {
38122
+ return void 0;
38123
+ }
38124
+ for (const name of names) {
38125
+ if (budget-- <= 0 || name === "node_modules" || name.startsWith(".")) continue;
38126
+ const path = join3(dir, name);
38127
+ if (SOURCE_FILE.test(name)) {
38128
+ if (/["']usepilot(\/auto)?["']/.test(readText(path))) return path;
38129
+ } else if (depth > 0 && !name.includes(".")) {
38130
+ const found = walk(path, depth - 1);
38131
+ if (found) return found;
38132
+ }
38133
+ }
38134
+ return void 0;
38135
+ };
38136
+ const html = join3(cwd, "index.html");
38137
+ if (existsSync3(html) && /usepilot/.test(readText(html))) return html;
38138
+ for (const dir of SOURCE_DIRS) {
38139
+ const found = walk(join3(cwd, dir), 6);
38140
+ if (found) return found;
38141
+ }
38142
+ return void 0;
38143
+ }
38144
+ function readText(file2) {
38145
+ try {
38146
+ return readFileSync(file2, "utf8");
38147
+ } catch {
38148
+ return "";
38149
+ }
38150
+ }
38151
+ function isWorkspaceRoot(cwd, pkg) {
38152
+ return !!pkg.workspaces || existsSync3(join3(cwd, "pnpm-workspace.yaml"));
38153
+ }
38154
+ function workspaceApps(cwd) {
38155
+ const found = [];
38156
+ for (const group of ["apps", "packages", "examples", "sites"]) {
38157
+ const dir = join3(cwd, group);
38158
+ if (!existsSync3(dir)) continue;
38159
+ for (const name of readdirSync(dir)) {
38160
+ const pkg = readJson(join3(dir, name, "package.json"));
38161
+ if (pkg && detectFramework(join3(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
38162
+ found.push(join3(group, name));
38163
+ }
38164
+ }
38165
+ return found;
38166
+ }
38167
+ function loadStep(framework, cwd) {
38168
+ const at = (file2, fallback) => `\`${file2 ? relative2(cwd, file2) : fallback}\``;
38169
+ const code = (lang, text) => `
38170
+
38171
+ \`\`\`${lang}
38172
+ ${text.replace(/^(?=.)/gm, " ")}
38173
+ \`\`\``;
38174
+ const intro = "**Load Pilot in the app, in development only** (it must never reach production), the way this project writes code.";
38175
+ switch (framework.kind) {
38176
+ case "vite":
38177
+ return `${intro} It's a Vite app: in its entry, ${at(framework.file, "src/main.ts")}, add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
38178
+ case "next-app":
38179
+ return `${intro} It's Next.js (App Router): add a client component, and render it in the root layout (${at(framework.file, "app/layout.tsx")}), inside \`<body>\`:${code(
38180
+ "tsx",
38181
+ `"use client";
38182
+ import { useEffect } from "react";
38183
+
38184
+ export function Pilot() {
38185
+ useEffect(() => {
38186
+ if (process.env.NODE_ENV === "development") import("usepilot/auto");
38187
+ }, []);
38188
+ return null;
38189
+ }`
38190
+ )}`;
38191
+ case "next-pages":
38192
+ return `${intro} It's Next.js (Pages Router): in ${at(framework.file, "pages/_app.tsx")}, in the App component:${code(
38193
+ "tsx",
38194
+ `useEffect(() => {
38195
+ if (process.env.NODE_ENV === "development") import("usepilot/auto");
38196
+ }, []);`
38197
+ )}`;
38198
+ case "nuxt":
38199
+ return `${intro} It's Nuxt: add a client plugin, \`plugins/pilot.client.ts\` (\`app/plugins/\` in Nuxt 4's layout):${code(
38200
+ "ts",
38201
+ `export default defineNuxtPlugin(() => {
38202
+ if (import.meta.dev) import("usepilot/auto");
38203
+ });`
38204
+ )}`;
38205
+ 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");')}`;
38207
+ case "astro":
38208
+ 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
+ case "react-router":
38210
+ return `${intro} It's React Router (or Remix): in ${at(framework.file, "app/root.tsx")}, in the root component:${code(
38211
+ "tsx",
38212
+ `useEffect(() => {
38213
+ if (import.meta.env.DEV) import("usepilot/auto");
38214
+ }, []);`
38215
+ )}`;
38216
+ case "webpack":
38217
+ return `${intro} In the app's entry, ${at(framework.file, "src/index.js")}, add:${code("js", 'if (process.env.NODE_ENV === "development") import("usepilot/auto");')}`;
38218
+ default:
38219
+ 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
+ }
38221
+ }
38222
+ async function addServer(file2, key, entry) {
38223
+ let config2 = {};
38224
+ if (existsSync3(file2)) {
38225
+ const text = await readFile3(file2, "utf8");
38226
+ try {
38227
+ config2 = text.trim() ? JSON.parse(text) : {};
38228
+ } catch {
38229
+ return "invalid";
38230
+ }
38231
+ if (typeof config2 !== "object" || config2 === null || Array.isArray(config2)) return "invalid";
38232
+ }
38233
+ const servers = config2[key] ?? {};
38234
+ const result = "pilot" in servers ? "updated" : "added";
38235
+ config2[key] = { ...servers, pilot: entry };
38236
+ await mkdir3(dirname2(file2), { recursive: true });
38237
+ await writeFile3(file2, `${JSON.stringify(config2, null, 2)}
38238
+ `);
38239
+ return result;
38240
+ }
38241
+ function readJson(file2) {
38242
+ try {
38243
+ return JSON.parse(readFileSync(file2, "utf8"));
38244
+ } catch {
38245
+ return null;
38246
+ }
38247
+ }
38248
+ function list(items) {
38249
+ return items.length < 2 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
38250
+ }
38251
+ function runCommand(command2, args, cwd) {
38252
+ const result = spawnSync(command2, args, { cwd, stdio: ["ignore", "inherit", "inherit"], shell: process.platform === "win32" });
38253
+ return result.status === 0;
38254
+ }
38255
+
37657
38256
  // src/index.ts
37658
38257
  var HELP = `usepilot: take the controls from your coding agent
37659
38258
 
37660
38259
  Usage: npx usepilot <command>
37661
38260
 
38261
+ init Set Pilot up in this project, for any agent: installs it, registers
38262
+ its MCP server, and prints what's left for the agent (loading it in
38263
+ the app). Ask your agent to run it. --no-install: print the command.
37662
38264
  setup Set up /pilot in Claude Code, for every project on this machine
37663
38265
  (--project: for this repo, to commit, so everyone gets it)
37664
38266
  mcp Run the MCP server (stdio) agents connect to, and the bridge the
@@ -37696,9 +38298,13 @@ switch (command) {
37696
38298
  }
37697
38299
  break;
37698
38300
  case "init":
37699
- process.stderr.write(`pilot ${command}: not implemented yet.
38301
+ try {
38302
+ process.stdout.write(await init({ install: !process.argv.includes("--no-install") }));
38303
+ } catch (error62) {
38304
+ process.stderr.write(`usepilot init: ${error62.message}
37700
38305
  `);
37701
- process.exitCode = 1;
38306
+ process.exitCode = 1;
38307
+ }
37702
38308
  break;
37703
38309
  default:
37704
38310
  process.stderr.write(`Unknown command: ${command}