usepilot 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,7 +56,17 @@ browser, in development.
56
56
  Pilot works with your coding agent: type `/pilot` in a chat, and Pilot opens
57
57
  in your app. Design, press **Send**, and the agent applies your edits while
58
58
  you keep going. Pilot shows each change until it's really in your code, and
59
- sends back to the agent what didn't land. Once per machine:
59
+ sends back to the agent what didn't land.
60
+
61
+ **For a repo you share**: from its root folder, then commit the two files it
62
+ writes (`.claude/skills/pilot/SKILL.md` and `.mcp.json`), so everyone working
63
+ in the repo gets `/pilot`:
64
+
65
+ ```bash
66
+ npx usepilot setup --project
67
+ ```
68
+
69
+ **Just for you, in every project** (nothing goes in the repo):
60
70
 
61
71
  ```bash
62
72
  npx usepilot setup
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, relative, options, skipNormalization) {
3915
+ function resolveComponent(base, relative2, options, skipNormalization) {
3916
3916
  const target = {};
3917
3917
  if (!skipNormalization) {
3918
3918
  base = parse3(serialize(base, options), options);
3919
- relative = parse3(serialize(relative, options), options);
3919
+ relative2 = parse3(serialize(relative2, options), options);
3920
3920
  }
3921
3921
  options = options || {};
3922
- if (!options.tolerant && relative.scheme) {
3923
- target.scheme = relative.scheme;
3924
- target.userinfo = relative.userinfo;
3925
- target.host = relative.host;
3926
- target.port = relative.port;
3927
- target.path = removeDotSegments(relative.path || "");
3928
- target.query = relative.query;
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;
3929
3929
  } else {
3930
- if (relative.userinfo !== void 0 || relative.host !== void 0 || relative.port !== void 0) {
3931
- target.userinfo = relative.userinfo;
3932
- target.host = relative.host;
3933
- target.port = relative.port;
3934
- target.path = removeDotSegments(relative.path || "");
3935
- target.query = relative.query;
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;
3936
3936
  } else {
3937
- if (!relative.path) {
3937
+ if (!relative2.path) {
3938
3938
  target.path = base.path;
3939
- if (relative.query !== void 0) {
3940
- target.query = relative.query;
3939
+ if (relative2.query !== void 0) {
3940
+ target.query = relative2.query;
3941
3941
  } else {
3942
3942
  target.query = base.query;
3943
3943
  }
3944
3944
  } else {
3945
- if (relative.path[0] === "/") {
3946
- target.path = removeDotSegments(relative.path);
3945
+ if (relative2.path[0] === "/") {
3946
+ target.path = removeDotSegments(relative2.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 = "/" + relative.path;
3950
+ target.path = "/" + relative2.path;
3951
3951
  } else if (!base.path) {
3952
- target.path = relative.path;
3952
+ target.path = relative2.path;
3953
3953
  } else {
3954
- target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative.path;
3954
+ target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.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 = relative.query;
3958
+ target.query = relative2.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 = relative.fragment;
3966
+ target.fragment = relative2.fragment;
3967
3967
  return target;
3968
3968
  }
3969
3969
  function equal(uriA, uriB, options) {
@@ -28612,7 +28612,7 @@ var StdioServerTransport = class {
28612
28612
  };
28613
28613
 
28614
28614
  // src/mcp.ts
28615
- import { randomUUID } from "crypto";
28615
+ import { randomUUID as randomUUID2 } from "crypto";
28616
28616
  import { basename } from "path";
28617
28617
 
28618
28618
  // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v3/helpers/util.js
@@ -36661,6 +36661,7 @@ var EMPTY_COMPLETION_RESULT = {
36661
36661
 
36662
36662
  // ../protocol/src/format.ts
36663
36663
  function formatPrompt(changeSet) {
36664
+ if (changeSet.request?.kind === "responsive") return formatResponsive(changeSet, changeSet.request);
36664
36665
  const { page, edits, note } = changeSet;
36665
36666
  const lines = [
36666
36667
  "# Pilot design edits",
@@ -36672,6 +36673,7 @@ function formatPrompt(changeSet) {
36672
36673
  "- 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.",
36673
36674
  "- Change only the listed elements. If an element is a shared component, ask before changing every instance.",
36674
36675
  `- 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.`,
36676
+ "- 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).",
36675
36677
  "",
36676
36678
  `Page: ${page.url} (${page.title || "untitled"}) at ${page.viewport.width}x${page.viewport.height}`
36677
36679
  ];
@@ -36684,24 +36686,73 @@ function formatPrompt(changeSet) {
36684
36686
  return `${lines.join("\n")}
36685
36687
  `;
36686
36688
  }
36687
- function formatEdit(edit, n) {
36688
- const { target, changes } = edit;
36689
- const out = [`## ${n}. \`${target.path}\``, "", `- Selector: \`${target.selector}\``];
36689
+ 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.';
36690
+ function formatResponsive(changeSet, request) {
36691
+ const { page, note } = changeSet;
36692
+ const { target, breakpoints } = request;
36693
+ const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
36694
+ const lines = [
36695
+ "# Pilot: make responsive",
36696
+ "",
36697
+ "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.",
36698
+ "",
36699
+ `Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
36700
+ `The page's breakpoints (the widths its media queries test): ${widths}`,
36701
+ "",
36702
+ ADVANCED_TASK
36703
+ ];
36704
+ if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
36705
+ lines.push(
36706
+ "",
36707
+ `## \`${target.path}\``,
36708
+ "",
36709
+ ...targetLines(target),
36710
+ "",
36711
+ "## How to do it",
36712
+ "",
36713
+ "1. **Find the element's component** and the layout around it (its parent and siblings): a fix often belongs to the container, not the element.",
36714
+ "2. **Learn how this project does responsive**: its breakpoints and their names (Tailwind config or theme, CSS variables, existing media queries), whether components respond to their container instead (container queries, `@container`), and whether it writes mobile-first (min-width) or desktop-first (max-width). Use its breakpoints; don't invent new ones.",
36715
+ "3. **Find similar components** that already have responsive rules (other cards, lists, headers, forms in this project) and follow the same patterns, so this one behaves like its siblings.",
36716
+ "4. **Make the smallest changes that work**, in the project's conventions (Tailwind variants like `md:`, the media queries it already uses, its tokens): layout first (stacking, wrapping, columns, flex direction), then spacing and type size. Hide content only as a last resort, and say so. Don't change how it looks at the width the designer is working at unless that width has a problem too. Never leave inline styles.",
36717
+ "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.",
36718
+ "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.",
36719
+ "",
36720
+ "Change only this element and what its layout needs (its container, its children). If it's a shared component, ask before changing every instance."
36721
+ );
36722
+ return `${lines.join("\n")}
36723
+ `;
36724
+ }
36725
+ function targetLines(target) {
36726
+ const out = [`- Selector: \`${target.selector}\``];
36690
36727
  if (target.text) out.push(`- Text: "${target.text}"`);
36691
36728
  if (target.source?.component || target.source?.file) {
36692
36729
  const where = [target.source.component, target.source.file && `${target.source.file}${target.source.line ? `:${target.source.line}` : ""}`].filter(Boolean).join(" in ");
36693
36730
  out.push(`- Source hint: ${where}`);
36694
36731
  }
36695
- out.push("", "| Property | From | To | Widths |", "| --- | --- | --- | --- |");
36732
+ return out;
36733
+ }
36734
+ function formatEdit(edit, n) {
36735
+ const { target, changes } = edit;
36736
+ const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
36737
+ const withStates = changes.some((c) => c.states?.length);
36738
+ out.push(
36739
+ "",
36740
+ withStates ? "| Property | From | To | Widths | State |" : "| Property | From | To | Widths |",
36741
+ withStates ? "| --- | --- | --- | --- | --- |" : "| --- | --- | --- | --- |"
36742
+ );
36696
36743
  for (const c of changes) {
36697
36744
  const to = c.removed ? "*removed*" : `\`${c.to}\``;
36698
36745
  const from = c.from ? `\`${c.from}\`` : "*not set*";
36699
- out.push(`| \`${c.property}\` | ${from} | ${to} | ${c.widths ? describeWidths(c.widths) : "every width"} |`);
36746
+ const widths = c.widths ? describeWidths(c.widths) : "every width";
36747
+ out.push(`| \`${c.property}\` | ${from} | ${to} | ${widths} |${withStates ? ` ${describeStates(c.states)} |` : ""}`);
36700
36748
  }
36701
36749
  const notes = changes.flatMap((c) => [c.removed && removalNote(c), mediaNote(c)].filter((n2) => !!n2));
36702
36750
  if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
36703
36751
  return out;
36704
36752
  }
36753
+ function describeStates(states) {
36754
+ return states?.length ? states.join(", ") : "\u2014";
36755
+ }
36705
36756
  function describeWidths({ min, max }) {
36706
36757
  if (min !== void 0 && min === max) return `${min}px only`;
36707
36758
  if (min !== void 0 && max !== void 0) return `${min}\u2013${max}px`;
@@ -36723,10 +36774,32 @@ function removalNote(c) {
36723
36774
  const shared = source.elements && source.elements > 1 ? `, which matches ${source.elements} elements on the page: remove it for this element only, unless the designer's note says otherwise` : "";
36724
36775
  return `${note} It comes from \`${source.selector}\`${shared}.`;
36725
36776
  }
36777
+ function formatWidthCheck(check2) {
36778
+ const lines = [
36779
+ check2.problems ? `Pilot's width check of \`${check2.selector}\`: ${check2.problems} ${check2.problems === 1 ? "problem" : "problems"} to fix.` : `Pilot's width check of \`${check2.selector}\`: no problems found.`,
36780
+ ""
36781
+ ];
36782
+ for (const r of check2.widths) {
36783
+ const mine = r.width === check2.designerWidth ? " (the designer's width)" : "";
36784
+ if (!r.found) {
36785
+ lines.push(`- ${r.width}px${mine}: the element isn't on the page at this width (or its selector no longer matches it).`);
36786
+ continue;
36787
+ }
36788
+ lines.push(`- ${r.width}px${mine}: ${[r.size, r.layout].filter(Boolean).join(", ")}${r.issues.length ? "" : ". OK"}`);
36789
+ for (const issue2 of r.issues) lines.push(` - Problem: ${issue2}`);
36790
+ for (const note of r.notes) lines.push(` - Note: ${note}`);
36791
+ }
36792
+ if (check2.changedAtDesignerWidth?.length) {
36793
+ lines.push("", `Changed at the designer's width (${check2.designerWidth}px), which should look as it did:`);
36794
+ for (const c of check2.changedAtDesignerWidth) lines.push(`- ${c}`);
36795
+ }
36796
+ return `${lines.join("\n")}
36797
+ `;
36798
+ }
36726
36799
 
36727
36800
  // ../protocol/src/bridge.ts
36728
36801
  var DEFAULT_BRIDGE_PORT = 4747;
36729
- var BRIDGE_VERSION = 1;
36802
+ var BRIDGE_VERSION = 2;
36730
36803
  function originOf(url2) {
36731
36804
  try {
36732
36805
  const u = new URL(url2.includes("://") ? url2 : `http://${url2}`);
@@ -36743,6 +36816,7 @@ function originKey(origin) {
36743
36816
  import { createServer } from "http";
36744
36817
 
36745
36818
  // src/hub.ts
36819
+ import { randomUUID } from "crypto";
36746
36820
  var AGENT_TTL = 3e4;
36747
36821
  var Hub = class {
36748
36822
  constructor(now = Date.now) {
@@ -36753,6 +36827,7 @@ var Hub = class {
36753
36827
  pages = /* @__PURE__ */ new Set();
36754
36828
  jobs = /* @__PURE__ */ new Map();
36755
36829
  waiters = [];
36830
+ checks = /* @__PURE__ */ new Map();
36756
36831
  // Agents
36757
36832
  /** An agent works on pages of `origin` (again: also how a remote one says it's alive). */
36758
36833
  register(info, origin) {
@@ -36819,6 +36894,34 @@ var Hub = class {
36819
36894
  this.update(job, { status: "done", agent, notes: notes?.trim() || void 0 });
36820
36895
  return job;
36821
36896
  }
36897
+ /**
36898
+ * An agent asks for Pilot's width check of a task's element: the open
36899
+ * pages of the job's origin get a `check` event, and the one that has the
36900
+ * job measures it and posts the answer (checkResult). Null when no page
36901
+ * is open, the hub doesn't know the job, or no answer comes in `timeoutMs`.
36902
+ */
36903
+ check(jobId, timeoutMs) {
36904
+ const job = this.jobs.get(jobId);
36905
+ if (!job) return Promise.resolve(null);
36906
+ const requestId = randomUUID();
36907
+ return new Promise((resolve) => {
36908
+ const timer = setTimeout(() => finish(null), timeoutMs);
36909
+ const finish = (check2) => {
36910
+ clearTimeout(timer);
36911
+ this.checks.delete(requestId);
36912
+ resolve(check2);
36913
+ };
36914
+ this.checks.set(requestId, { origin: job.origin, resolve: finish });
36915
+ if (!this.sendTo(job.origin, { type: "check", requestId, jobId })) finish(null);
36916
+ });
36917
+ }
36918
+ /** A page's answer to a width check: false when nothing waits for it from that origin. */
36919
+ checkResult(origin, requestId, check2) {
36920
+ const pending = this.checks.get(requestId);
36921
+ if (!pending || pending.origin !== originKey(origin)) return false;
36922
+ pending.resolve(check2);
36923
+ return true;
36924
+ }
36822
36925
  // Pages
36823
36926
  addPage(page) {
36824
36927
  const conn = { ...page, origin: originKey(page.origin) };
@@ -36855,6 +36958,7 @@ var Hub = class {
36855
36958
  agent: stillWorking || post.attempt === 2 ? post.agent : void 0,
36856
36959
  attempt: post.attempt ?? 1,
36857
36960
  differences: post.differences,
36961
+ issues: post.issues,
36858
36962
  createdAt: at,
36859
36963
  updatedAt: at
36860
36964
  };
@@ -36871,15 +36975,16 @@ var Hub = class {
36871
36975
  return job;
36872
36976
  }
36873
36977
  /**
36874
- * Some changes of a done job didn't come out as the designer set them: the
36875
- * job goes back to the queue once, as a follow-up with the `differences`,
36978
+ * Some changes of a done job didn't come out as the designer set them (or
36979
+ * a task's width check found problems, `issues`): the job goes back to
36980
+ * the queue once, as a follow-up with the `differences`,
36876
36981
  * preferably to the agent that did it. Null when it can't (not done, or
36877
36982
  * already a follow-up: then the page takes what the code gives).
36878
36983
  */
36879
- retry(origin, jobId, differences) {
36984
+ retry(origin, jobId, differences, issues) {
36880
36985
  const job = this.jobs.get(jobId);
36881
36986
  if (!job || job.origin !== originKey(origin) || job.status !== "done" || (job.attempt ?? 1) >= 2) return null;
36882
- this.update(job, { status: "queued", attempt: 2, differences, notes: void 0 });
36987
+ this.update(job, { status: "queued", attempt: 2, differences, issues, notes: void 0 });
36883
36988
  this.dispatch(job.origin);
36884
36989
  return job;
36885
36990
  }
@@ -36998,9 +37103,20 @@ async function handle(hub, req, res) {
36998
37103
  const jobRoute = path.match(/^\/jobs\/([^/]+)\/(cancel|retry)$/);
36999
37104
  if (jobRoute) {
37000
37105
  const [, id, action] = jobRoute;
37001
- const job = action === "cancel" ? hub.cancel(origin, decodeURIComponent(id)) : hub.retry(origin, decodeURIComponent(id), (data.differences ?? []).slice(0, 200));
37106
+ const job = action === "cancel" ? hub.cancel(origin, decodeURIComponent(id)) : hub.retry(
37107
+ origin,
37108
+ decodeURIComponent(id),
37109
+ (data.differences ?? []).slice(0, 200),
37110
+ stringsOf(data.issues)
37111
+ );
37002
37112
  return job ? json2(res, 200, { job }) : json2(res, 409, { error: `can't ${action} this job` });
37003
37113
  }
37114
+ const checkRoute = path.match(/^\/checks\/([^/]+)$/);
37115
+ if (checkRoute) {
37116
+ const check2 = data.check;
37117
+ if (!check2 || !Array.isArray(check2.widths)) return json2(res, 400, { error: "check needed" });
37118
+ return hub.checkResult(origin, decodeURIComponent(checkRoute[1]), check2) ? json2(res, 200, { ok: true }) : json2(res, 409, { error: "no check waits for this" });
37119
+ }
37004
37120
  return json2(res, 404, { error: "not found" });
37005
37121
  }
37006
37122
  function events(hub, origin, req, res) {
@@ -37042,6 +37158,11 @@ async function handleAgent(hub, action, data, req, res) {
37042
37158
  case "done":
37043
37159
  if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
37044
37160
  return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes) });
37161
+ case "check": {
37162
+ if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
37163
+ const check2 = await hub.check(d.jobId, Math.min(d.timeoutMs ?? CHECK_TIMEOUT, 2 * 6e4));
37164
+ return json2(res, 200, { check: check2 });
37165
+ }
37045
37166
  case "leave":
37046
37167
  hub.unregister(d.agent.id);
37047
37168
  return json2(res, 200, { ok: true });
@@ -37049,6 +37170,11 @@ async function handleAgent(hub, action, data, req, res) {
37049
37170
  return json2(res, 404, { error: "not found" });
37050
37171
  }
37051
37172
  }
37173
+ var CHECK_TIMEOUT = 6e4;
37174
+ function stringsOf(value) {
37175
+ if (!Array.isArray(value)) return void 0;
37176
+ return value.filter((v) => typeof v === "string").slice(0, 100).map((v) => v.slice(0, 2e3));
37177
+ }
37052
37178
  function json2(res, status, data) {
37053
37179
  res.writeHead(status, { "Content-Type": "application/json" });
37054
37180
  res.end(JSON.stringify(data));
@@ -37093,6 +37219,9 @@ var LocalApi = class {
37093
37219
  async done(agent, jobId, notes) {
37094
37220
  return this.hub.done(agent.id, jobId, notes);
37095
37221
  }
37222
+ check(_agent, jobId, timeoutMs) {
37223
+ return this.hub.check(jobId, timeoutMs);
37224
+ }
37096
37225
  async leave(agent) {
37097
37226
  localAgents.delete(agent.id);
37098
37227
  this.hub.unregister(agent.id);
@@ -37125,6 +37254,9 @@ var RemoteApi = class {
37125
37254
  async done(agent, jobId, notes) {
37126
37255
  return (await this.post("done", { agent, jobId, notes })).job;
37127
37256
  }
37257
+ async check(agent, jobId, timeoutMs) {
37258
+ return (await this.post("check", { agent, jobId, timeoutMs })).check;
37259
+ }
37128
37260
  async leave(agent) {
37129
37261
  await this.post("leave", { agent });
37130
37262
  }
@@ -37171,6 +37303,10 @@ var Bridge = class {
37171
37303
  done(jobId, notes) {
37172
37304
  return this.call((api) => api.done(this.agent, jobId, notes));
37173
37305
  }
37306
+ /** Pilot's width check of a task's element, measured by the page (null: no page answered). */
37307
+ check(jobId, timeoutMs = CHECK_TIMEOUT) {
37308
+ return this.call((api) => api.check(this.agent, jobId, timeoutMs));
37309
+ }
37174
37310
  async close() {
37175
37311
  if (this.heartbeat) clearInterval(this.heartbeat);
37176
37312
  try {
@@ -37268,7 +37404,7 @@ var INSTRUCTIONS = `Pilot lets the designer edit the running app in the browser
37268
37404
  The loop, when the user runs /pilot or asks to hand the design over:
37269
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.
37270
37406
  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.)
37271
- 3. Apply the job's edits to the source, in the project's conventions (see the job's guidelines).
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.
37272
37408
  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.
37273
37409
 
37274
37410
  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.`;
@@ -37286,10 +37422,10 @@ function agentLabel(clientName, cwd) {
37286
37422
  return `${app} \xB7 ${basename(cwd)}`;
37287
37423
  }
37288
37424
  function jobPrompt(job) {
37289
- const body2 = job.attempt === 2 && job.differences?.length ? followUp(job) : formatPrompt(job.changeSet);
37425
+ const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : formatPrompt(job.changeSet);
37290
37426
  return `${body2}
37291
37427
  ---
37292
- Pilot job \`${job.id}\`. When you've applied it, call \`pilot_done\` with \`jobId: "${job.id}"\` and short notes (values you approximated, anything you did differently). Then call \`pilot_wait_for_edits\` again for the next job.
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.
37293
37429
  `;
37294
37430
  }
37295
37431
  function followUp(job) {
@@ -37310,12 +37446,29 @@ function followUp(job) {
37310
37446
  );
37311
37447
  return lines.join("\n");
37312
37448
  }
37449
+ function taskFollowUp(job) {
37450
+ const target = job.changeSet.request?.target;
37451
+ const lines = [
37452
+ "# Pilot: make responsive, follow-up",
37453
+ "",
37454
+ `You made \`${target?.path ?? "the element"}\` responsive, but Pilot's width check (the page measured at each width) still finds these problems:`,
37455
+ "",
37456
+ ...(job.issues ?? []).map((i) => `- ${i}`),
37457
+ "",
37458
+ "Fix them, then run `pilot_check_widths` to confirm before `pilot_done`. If one is deliberate, keep it and say why in your notes. Pilot takes what the code gives after this.",
37459
+ "",
37460
+ "The task, for reference:",
37461
+ "",
37462
+ formatPrompt(job.changeSet)
37463
+ ];
37464
+ return lines.join("\n");
37465
+ }
37313
37466
  function createPilotServer(options = {}) {
37314
37467
  const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
37315
37468
  const cwd = options.cwd ?? process.cwd();
37316
37469
  let waitMs = options.waitMs ?? waitMsFor(void 0);
37317
- const server = new McpServer({ name: "pilot", version: "0.3.0" }, { instructions: INSTRUCTIONS });
37318
- const agent = { id: randomUUID(), label: agentLabel(void 0, cwd) };
37470
+ const server = new McpServer({ name: "pilot", version: "0.4.0" }, { instructions: INSTRUCTIONS });
37471
+ const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
37319
37472
  const bridge = new Bridge(agent, port);
37320
37473
  let origin = null;
37321
37474
  server.server.oninitialized = () => {
@@ -37395,23 +37548,49 @@ function createPilotServer(options = {}) {
37395
37548
  }
37396
37549
  }
37397
37550
  );
37551
+ server.registerTool(
37552
+ "pilot_check_widths",
37553
+ {
37554
+ 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.",
37556
+ inputSchema: {
37557
+ jobId: external_exports.string().describe("The Make responsive job's id, from pilot_wait_for_edits.")
37558
+ }
37559
+ },
37560
+ async ({ jobId }) => {
37561
+ try {
37562
+ const check2 = await bridge.check(jobId);
37563
+ if (!check2) {
37564
+ 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.`,
37566
+ true
37567
+ );
37568
+ }
37569
+ return text(formatWidthCheck(check2));
37570
+ } catch (error62) {
37571
+ return text(`Pilot couldn't run the width check: ${error62.message}`, true);
37572
+ }
37573
+ }
37574
+ );
37398
37575
  return { server, bridge, agent };
37399
37576
  }
37400
37577
 
37401
37578
  // src/setup.ts
37402
- import { mkdir, writeFile } from "fs/promises";
37579
+ import { existsSync } from "fs";
37580
+ import { lstat, mkdir, readFile, unlink, writeFile } from "fs/promises";
37403
37581
  import { homedir } from "os";
37404
- import { join } from "path";
37582
+ import { join, relative } from "path";
37405
37583
 
37406
37584
  // ../../skills/pilot/SKILL.md
37407
- 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\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";
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";
37408
37586
 
37409
37587
  // src/setup.ts
37410
- async function setup() {
37411
- const dir = join(homedir(), ".claude", "skills", "pilot");
37412
- await mkdir(dir, { recursive: true });
37413
- const file2 = join(dir, "SKILL.md");
37414
- await writeFile(file2, SKILL_default);
37588
+ var MCP_SERVER = { command: "npx", args: ["-y", "usepilot", "mcp"] };
37589
+ async function setup(options = {}) {
37590
+ return options.project ? setupProject(options.cwd ?? process.cwd()) : setupMachine(options.home ?? homedir());
37591
+ }
37592
+ async function setupMachine(home) {
37593
+ const file2 = await writeSkill(join(home, ".claude", "skills", "pilot"));
37415
37594
  return `Installed the /pilot skill: ${file2}
37416
37595
 
37417
37596
  Now register Pilot's MCP server with Claude Code, once, for every project:
@@ -37419,15 +37598,69 @@ Now register Pilot's MCP server with Claude Code, once, for every project:
37419
37598
  claude mcp add --scope user pilot -- npx -y usepilot mcp
37420
37599
 
37421
37600
  Then, in any Claude Code chat: /pilot
37601
+ (For a repo you share, run \`npx usepilot setup --project\` in it instead.)
37422
37602
  `;
37423
37603
  }
37604
+ async function setupProject(cwd) {
37605
+ const skillFile = await writeSkill(join(cwd, ".claude", "skills", "pilot"));
37606
+ const mcpFile = join(cwd, ".mcp.json");
37607
+ const { added } = await addMcpServer(mcpFile);
37608
+ 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";
37610
+ const width = rel(skillFile).length + 2;
37611
+ return `Set up /pilot for this repo:
37612
+ ${rel(skillFile).padEnd(width)}the /pilot skill
37613
+ ${rel(mcpFile).padEnd(width)}Pilot's MCP server${added ? "" : " (it was there: updated)"}
37614
+ ${app}
37615
+ Commit both: everyone working in the repo gets /pilot in Claude Code (it asks
37616
+ each of them once to approve the project's MCP server).
37617
+
37618
+ The app needs Pilot too, in development, if it doesn't have it yet:
37619
+ npm install -D usepilot
37620
+ if (import.meta.env.DEV) import("usepilot/auto"); (in the app's entry file)
37621
+
37622
+ Then, in a Claude Code chat in this folder: /pilot
37623
+ `;
37624
+ }
37625
+ async function writeSkill(dir) {
37626
+ 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);
37630
+ return file2;
37631
+ }
37632
+ async function isLink(path) {
37633
+ try {
37634
+ return (await lstat(path)).isSymbolicLink();
37635
+ } catch {
37636
+ return false;
37637
+ }
37638
+ }
37639
+ async function addMcpServer(file2) {
37640
+ let config2 = {};
37641
+ if (existsSync(file2)) {
37642
+ const text = await readFile(file2, "utf8");
37643
+ try {
37644
+ config2 = text.trim() ? JSON.parse(text) : {};
37645
+ } catch {
37646
+ throw new Error(`${file2} isn't valid JSON: fix it, then run setup again.`);
37647
+ }
37648
+ }
37649
+ const servers = config2.mcpServers ?? {};
37650
+ const added = !("pilot" in servers);
37651
+ config2.mcpServers = { ...servers, pilot: MCP_SERVER };
37652
+ await writeFile(file2, `${JSON.stringify(config2, null, 2)}
37653
+ `);
37654
+ return { added };
37655
+ }
37424
37656
 
37425
37657
  // src/index.ts
37426
37658
  var HELP = `usepilot: take the controls from your coding agent
37427
37659
 
37428
37660
  Usage: npx usepilot <command>
37429
37661
 
37430
- setup Install the /pilot skill for Claude Code (every project)
37662
+ setup Set up /pilot in Claude Code, for every project on this machine
37663
+ (--project: for this repo, to commit, so everyone gets it)
37431
37664
  mcp Run the MCP server (stdio) agents connect to, and the bridge the
37432
37665
  page talks to. Agents start it: register it with your agent.
37433
37666
  help Show this message
@@ -37454,7 +37687,13 @@ switch (command) {
37454
37687
  await runMcp();
37455
37688
  break;
37456
37689
  case "setup":
37457
- process.stdout.write(await setup());
37690
+ try {
37691
+ process.stdout.write(await setup({ project: process.argv.includes("--project") }));
37692
+ } catch (error62) {
37693
+ process.stderr.write(`usepilot setup: ${error62.message}
37694
+ `);
37695
+ process.exitCode = 1;
37696
+ }
37458
37697
  break;
37459
37698
  case "init":
37460
37699
  process.stderr.write(`pilot ${command}: not implemented yet.