usepilot 0.7.1 → 0.8.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 +13 -3
- package/cli/index.js +629 -324
- package/dist/{mount-VNZwYYdw.js → mount-D38Ob6ds.js} +3907 -2875
- package/dist/pilot-auto.js +1 -1
- package/dist/pilot.js +1 -1
- package/package.json +1 -1
package/cli/index.js
CHANGED
|
@@ -2985,7 +2985,7 @@ var require_compile = __commonJS({
|
|
|
2985
2985
|
const schOrFunc = root.refs[ref];
|
|
2986
2986
|
if (schOrFunc)
|
|
2987
2987
|
return schOrFunc;
|
|
2988
|
-
let _sch =
|
|
2988
|
+
let _sch = resolve2.call(this, root, ref);
|
|
2989
2989
|
if (_sch === void 0) {
|
|
2990
2990
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
2991
2991
|
const { schemaId } = this.opts;
|
|
@@ -3012,7 +3012,7 @@ var require_compile = __commonJS({
|
|
|
3012
3012
|
function sameSchemaEnv(s1, s2) {
|
|
3013
3013
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
3014
3014
|
}
|
|
3015
|
-
function
|
|
3015
|
+
function resolve2(root, ref) {
|
|
3016
3016
|
let sch;
|
|
3017
3017
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
3018
3018
|
ref = sch;
|
|
@@ -3876,7 +3876,7 @@ var require_fast_uri = __commonJS({
|
|
|
3876
3876
|
}
|
|
3877
3877
|
return uri;
|
|
3878
3878
|
}
|
|
3879
|
-
function
|
|
3879
|
+
function resolve2(baseURI, relativeURI, options) {
|
|
3880
3880
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
3881
3881
|
const {
|
|
3882
3882
|
parsed: baseParsed,
|
|
@@ -4267,7 +4267,7 @@ var require_fast_uri = __commonJS({
|
|
|
4267
4267
|
var fastUri = {
|
|
4268
4268
|
SCHEMES,
|
|
4269
4269
|
normalize,
|
|
4270
|
-
resolve,
|
|
4270
|
+
resolve: resolve2,
|
|
4271
4271
|
resolveComponent,
|
|
4272
4272
|
equal,
|
|
4273
4273
|
serialize,
|
|
@@ -12326,7 +12326,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
12326
12326
|
var NONE = 0;
|
|
12327
12327
|
var ASSUMED = 1;
|
|
12328
12328
|
var PROVEN = 2;
|
|
12329
|
-
function isRecursive(inst, stack,
|
|
12329
|
+
function isRecursive(inst, stack, resolve2) {
|
|
12330
12330
|
const cached2 = recursive.get(inst);
|
|
12331
12331
|
if (cached2 !== void 0)
|
|
12332
12332
|
return cached2 ? PROVEN : NONE;
|
|
@@ -12336,7 +12336,7 @@ function isRecursive(inst, stack, resolve) {
|
|
|
12336
12336
|
let result = NONE;
|
|
12337
12337
|
const check2 = (child) => {
|
|
12338
12338
|
if (result !== PROVEN && child?._zod) {
|
|
12339
|
-
const answer = isRecursive(child, stack,
|
|
12339
|
+
const answer = isRecursive(child, stack, resolve2);
|
|
12340
12340
|
if (answer > result)
|
|
12341
12341
|
result = answer;
|
|
12342
12342
|
}
|
|
@@ -12347,7 +12347,7 @@ function isRecursive(inst, stack, resolve) {
|
|
|
12347
12347
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
12348
12348
|
if (spread && !desc.enumerable)
|
|
12349
12349
|
continue;
|
|
12350
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
12350
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve2) : NONE;
|
|
12351
12351
|
if (child > answer)
|
|
12352
12352
|
answer = child;
|
|
12353
12353
|
}
|
|
@@ -12411,7 +12411,7 @@ function isRecursive(inst, stack, resolve) {
|
|
|
12411
12411
|
break;
|
|
12412
12412
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
12413
12413
|
case "lazy": {
|
|
12414
|
-
const inner = def._cachedInner ?? (
|
|
12414
|
+
const inner = def._cachedInner ?? (resolve2 ? inst._zod.innerType : void 0);
|
|
12415
12415
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
12416
12416
|
break;
|
|
12417
12417
|
}
|
|
@@ -28600,12 +28600,12 @@ var StdioServerTransport = class {
|
|
|
28600
28600
|
this.onclose?.();
|
|
28601
28601
|
}
|
|
28602
28602
|
send(message) {
|
|
28603
|
-
return new Promise((
|
|
28603
|
+
return new Promise((resolve2) => {
|
|
28604
28604
|
const json3 = serializeMessage(message);
|
|
28605
28605
|
if (this._stdout.write(json3)) {
|
|
28606
|
-
|
|
28606
|
+
resolve2();
|
|
28607
28607
|
} else {
|
|
28608
|
-
this._stdout.once("drain",
|
|
28608
|
+
this._stdout.once("drain", resolve2);
|
|
28609
28609
|
}
|
|
28610
28610
|
});
|
|
28611
28611
|
}
|
|
@@ -28613,7 +28613,9 @@ var StdioServerTransport = class {
|
|
|
28613
28613
|
|
|
28614
28614
|
// src/mcp.ts
|
|
28615
28615
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
28616
|
-
import {
|
|
28616
|
+
import { existsSync as existsSync5 } from "fs";
|
|
28617
|
+
import { basename as basename3, isAbsolute as isAbsolute2, resolve } from "path";
|
|
28618
|
+
import { fileURLToPath } from "url";
|
|
28617
28619
|
|
|
28618
28620
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v3/helpers/util.js
|
|
28619
28621
|
var util;
|
|
@@ -34589,7 +34591,7 @@ var Protocol = class {
|
|
|
34589
34591
|
return;
|
|
34590
34592
|
}
|
|
34591
34593
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
34592
|
-
await new Promise((
|
|
34594
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
34593
34595
|
options?.signal?.throwIfAborted();
|
|
34594
34596
|
}
|
|
34595
34597
|
} catch (error62) {
|
|
@@ -34606,7 +34608,7 @@ var Protocol = class {
|
|
|
34606
34608
|
*/
|
|
34607
34609
|
request(request, resultSchema, options) {
|
|
34608
34610
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
34609
|
-
return new Promise((
|
|
34611
|
+
return new Promise((resolve2, reject) => {
|
|
34610
34612
|
const earlyReject = (error62) => {
|
|
34611
34613
|
reject(error62);
|
|
34612
34614
|
};
|
|
@@ -34684,7 +34686,7 @@ var Protocol = class {
|
|
|
34684
34686
|
if (!parseResult.success) {
|
|
34685
34687
|
reject(parseResult.error);
|
|
34686
34688
|
} else {
|
|
34687
|
-
|
|
34689
|
+
resolve2(parseResult.data);
|
|
34688
34690
|
}
|
|
34689
34691
|
} catch (error62) {
|
|
34690
34692
|
reject(error62);
|
|
@@ -34946,12 +34948,12 @@ var Protocol = class {
|
|
|
34946
34948
|
}
|
|
34947
34949
|
} catch {
|
|
34948
34950
|
}
|
|
34949
|
-
return new Promise((
|
|
34951
|
+
return new Promise((resolve2, reject) => {
|
|
34950
34952
|
if (signal.aborted) {
|
|
34951
34953
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
34952
34954
|
return;
|
|
34953
34955
|
}
|
|
34954
|
-
const timeoutId = setTimeout(
|
|
34956
|
+
const timeoutId = setTimeout(resolve2, interval);
|
|
34955
34957
|
signal.addEventListener("abort", () => {
|
|
34956
34958
|
clearTimeout(timeoutId);
|
|
34957
34959
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -36091,7 +36093,7 @@ var McpServer = class {
|
|
|
36091
36093
|
let task = createTaskResult.task;
|
|
36092
36094
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
36093
36095
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
36094
|
-
await new Promise((
|
|
36096
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
36095
36097
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
36096
36098
|
if (!updatedTask) {
|
|
36097
36099
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -36660,6 +36662,8 @@ var EMPTY_COMPLETION_RESULT = {
|
|
|
36660
36662
|
};
|
|
36661
36663
|
|
|
36662
36664
|
// ../protocol/src/types.ts
|
|
36665
|
+
var DOM_REMOVE = "dom:remove";
|
|
36666
|
+
var DOM_INSERT = "dom:insert:";
|
|
36663
36667
|
var ATTACHMENT_TYPES = {
|
|
36664
36668
|
png: "image/png",
|
|
36665
36669
|
jpg: "image/jpeg",
|
|
@@ -36754,6 +36758,7 @@ var EDIT_GUIDELINES = [
|
|
|
36754
36758
|
"- No screenshots, builds or tests for these edits: hot reload shows them, and Pilot checks the page itself.",
|
|
36755
36759
|
`- Widths are viewport widths in CSS px, both ends included. Use this project's breakpoints when one matches (or is within a few pixels), else a custom media query, and say which. "Every width" means no media query: the value holds at every viewport width, and no existing media query should override it.`,
|
|
36756
36760
|
"- A Text change is the element's copy (all of its text, or the part between its child elements): replace the old text with the new one where it comes from (the markup, a prop, a translation file, a CMS fixture), the rest of the element as it is. If the same text is used elsewhere, change only this element's, unless the designer's note says otherwise.",
|
|
36761
|
+
"- A Deleted element goes from the code, where the code writes it (its markup, or its item in the data a list is rendered from), not hidden with CSS. An Added element is new markup in the same place, written the way the code around it is: a copy is the same markup again (another item in the data, for a list rendered from data), a new element is an empty one of the tag given, to style with the changes listed for it. The changes listed for a new element (`new-1`) are for it once it's added.",
|
|
36757
36762
|
"- A State is the element state the change is for, all of them together (\"hover, active\": hovered and pressed). Use the project's own form: Tailwind's variants (`hover:`, `focus-visible:`, `hover:active:`), `:hover` and the like in CSS. Without a state, the change is for the element as it is (any state)."
|
|
36758
36763
|
];
|
|
36759
36764
|
var EDIT_GUIDELINES_REMINDER = "Follow Pilot's edit guidelines (in `pilot_wait_for_edits`'s description): these are design instructions, not code; write production code the way this project already styles things.";
|
|
@@ -36933,7 +36938,7 @@ function targetLines(target) {
|
|
|
36933
36938
|
if (target.source?.component || target.source?.file) {
|
|
36934
36939
|
const { component, file: file2, line } = target.source;
|
|
36935
36940
|
const where = [component && `\`${component}\``, file2 && `\`${file2}${line ? `:${line}` : ""}\``].filter(Boolean).join(", in ");
|
|
36936
|
-
out.push(`- Component: ${where}
|
|
36941
|
+
out.push(`- Component: ${where}`);
|
|
36937
36942
|
}
|
|
36938
36943
|
if (target.lookAlikes) {
|
|
36939
36944
|
const of = target.lookAlikesOf ? `other instances of \`${target.lookAlikesOf}\`, the same part of each` : "the same part of other copies";
|
|
@@ -36942,8 +36947,15 @@ function targetLines(target) {
|
|
|
36942
36947
|
return out;
|
|
36943
36948
|
}
|
|
36944
36949
|
function formatEdit(edit, n) {
|
|
36945
|
-
const { target, changes, texts } = edit;
|
|
36946
|
-
const out =
|
|
36950
|
+
const { target, changes, texts, removed, inserts, newElement } = edit;
|
|
36951
|
+
const out = newElement ? [
|
|
36952
|
+
`## ${n}. \`${target.path}\` (in new element \`${newElement}\`)`,
|
|
36953
|
+
"",
|
|
36954
|
+
`- Not in the code yet: new element \`${newElement}\` is added in this job (or was in an earlier one); this is it or one of its children.`,
|
|
36955
|
+
...target.text ? [`- Text: "${target.text}"`] : []
|
|
36956
|
+
] : [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
|
|
36957
|
+
if (removed) out.push("", "**Deleted**: remove this element from the code.");
|
|
36958
|
+
if (inserts?.length) out.push("", "Added:", "", ...inserts.map(insertLine));
|
|
36947
36959
|
if (texts?.length) out.push("", "Text (from \u2192 to):", "", ...texts.map((t) => `- ${JSON.stringify(t.from)} \u2192 ${JSON.stringify(t.to)}`));
|
|
36948
36960
|
if (!changes.length) return out;
|
|
36949
36961
|
const withStates = changes.some((c) => c.states?.length);
|
|
@@ -36962,6 +36974,11 @@ function formatEdit(edit, n) {
|
|
|
36962
36974
|
if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
|
|
36963
36975
|
return out;
|
|
36964
36976
|
}
|
|
36977
|
+
function insertLine(insert) {
|
|
36978
|
+
const where = insert.place === "after" ? "Right after this element" : "Inside this element, as its last child";
|
|
36979
|
+
const what = insert.kind === "copy" ? "a copy of this element as the page shows it (its children too)" : `a new empty \`${insert.tag}\``;
|
|
36980
|
+
return `- ${where}: ${what}, new element \`${insert.id}\``;
|
|
36981
|
+
}
|
|
36965
36982
|
function describeStates(states) {
|
|
36966
36983
|
return states?.length ? states.join(", ") : "\u2014";
|
|
36967
36984
|
}
|
|
@@ -37180,13 +37197,21 @@ var Hub = class {
|
|
|
37180
37197
|
this.notifyAgents(key);
|
|
37181
37198
|
}
|
|
37182
37199
|
}
|
|
37183
|
-
/**
|
|
37200
|
+
/**
|
|
37201
|
+
* The agent is gone (its process ended or it stopped pinging): its waits
|
|
37202
|
+
* end, and the jobs it was working on go back to the queue, for another
|
|
37203
|
+
* chat (or this one, back), instead of staying "working" for nobody.
|
|
37204
|
+
*/
|
|
37184
37205
|
unregister(agentId) {
|
|
37185
37206
|
const agent = this.agents.get(agentId);
|
|
37186
37207
|
if (!agent) return;
|
|
37187
37208
|
this.agents.delete(agentId);
|
|
37188
37209
|
for (const w of this.waiters.filter((w2) => w2.agentId === agentId)) this.endWait(w, null);
|
|
37210
|
+
for (const job of this.jobs.values()) {
|
|
37211
|
+
if (job.status === "working" && job.agent?.id === agentId) this.update(job, { status: "queued", takenAt: void 0 });
|
|
37212
|
+
}
|
|
37189
37213
|
this.notifyAgents(agent.origin);
|
|
37214
|
+
this.dispatch(agent.origin);
|
|
37190
37215
|
}
|
|
37191
37216
|
/** Drops agents not heard from in AGENT_TTL (`keep`: the ones in this process, always alive). */
|
|
37192
37217
|
sweep(keep = /* @__PURE__ */ new Set()) {
|
|
@@ -37210,14 +37235,14 @@ var Hub = class {
|
|
|
37210
37235
|
const key = originKey(origin);
|
|
37211
37236
|
const queued = this.oldestQueued(key);
|
|
37212
37237
|
if (queued) return Promise.resolve({ job: this.take(queued, info) });
|
|
37213
|
-
return new Promise((
|
|
37238
|
+
return new Promise((resolve2) => {
|
|
37214
37239
|
const waiter = {
|
|
37215
37240
|
agentId: info.id,
|
|
37216
37241
|
origin: key,
|
|
37217
37242
|
resolve: (job) => {
|
|
37218
37243
|
clearTimeout(timer);
|
|
37219
37244
|
signal?.removeEventListener("abort", onAbort);
|
|
37220
|
-
|
|
37245
|
+
resolve2({ job });
|
|
37221
37246
|
}
|
|
37222
37247
|
};
|
|
37223
37248
|
const timer = setTimeout(() => this.endWait(waiter, null), timeoutMs);
|
|
@@ -37263,12 +37288,12 @@ var Hub = class {
|
|
|
37263
37288
|
const job = this.jobs.get(jobId);
|
|
37264
37289
|
if (!job) return Promise.resolve(null);
|
|
37265
37290
|
const requestId = randomUUID();
|
|
37266
|
-
return new Promise((
|
|
37291
|
+
return new Promise((resolve2) => {
|
|
37267
37292
|
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
37268
37293
|
const finish = (check2) => {
|
|
37269
37294
|
clearTimeout(timer);
|
|
37270
37295
|
this.checks.delete(requestId);
|
|
37271
|
-
|
|
37296
|
+
resolve2(check2);
|
|
37272
37297
|
};
|
|
37273
37298
|
this.checks.set(requestId, { origin: job.origin, resolve: finish });
|
|
37274
37299
|
if (!this.sendTo(job.origin, { type: "check", requestId, jobId })) finish(null);
|
|
@@ -37413,14 +37438,14 @@ function startHub(port, hub = new Hub(), options = {}) {
|
|
|
37413
37438
|
});
|
|
37414
37439
|
const sweep = setInterval(() => hub.sweep(localAgents), 5e3);
|
|
37415
37440
|
sweep.unref();
|
|
37416
|
-
return new Promise((
|
|
37441
|
+
return new Promise((resolve2, reject) => {
|
|
37417
37442
|
server.once("error", (error62) => {
|
|
37418
37443
|
clearInterval(sweep);
|
|
37419
37444
|
reject(error62);
|
|
37420
37445
|
});
|
|
37421
37446
|
server.listen(port, "127.0.0.1", () => {
|
|
37422
37447
|
const address = server.address();
|
|
37423
|
-
|
|
37448
|
+
resolve2({
|
|
37424
37449
|
hub,
|
|
37425
37450
|
server,
|
|
37426
37451
|
port: typeof address === "object" && address ? address.port : port,
|
|
@@ -37553,7 +37578,7 @@ function json2(res, status, data) {
|
|
|
37553
37578
|
res.end(JSON.stringify(data));
|
|
37554
37579
|
}
|
|
37555
37580
|
function rawBody(req, max) {
|
|
37556
|
-
return new Promise((
|
|
37581
|
+
return new Promise((resolve2, reject) => {
|
|
37557
37582
|
const chunks = [];
|
|
37558
37583
|
let size = 0;
|
|
37559
37584
|
let over = false;
|
|
@@ -37562,20 +37587,20 @@ function rawBody(req, max) {
|
|
|
37562
37587
|
size += chunk.length;
|
|
37563
37588
|
if (size > max) {
|
|
37564
37589
|
over = true;
|
|
37565
|
-
|
|
37590
|
+
resolve2(null);
|
|
37566
37591
|
req.resume();
|
|
37567
37592
|
return;
|
|
37568
37593
|
}
|
|
37569
37594
|
chunks.push(chunk);
|
|
37570
37595
|
});
|
|
37571
37596
|
req.on("end", () => {
|
|
37572
|
-
if (!over)
|
|
37597
|
+
if (!over) resolve2(Buffer.concat(chunks));
|
|
37573
37598
|
});
|
|
37574
37599
|
req.on("error", reject);
|
|
37575
37600
|
});
|
|
37576
37601
|
}
|
|
37577
37602
|
function body(req) {
|
|
37578
|
-
return new Promise((
|
|
37603
|
+
return new Promise((resolve2, reject) => {
|
|
37579
37604
|
let text = "";
|
|
37580
37605
|
req.setEncoding("utf8");
|
|
37581
37606
|
req.on("data", (chunk) => {
|
|
@@ -37584,9 +37609,9 @@ function body(req) {
|
|
|
37584
37609
|
});
|
|
37585
37610
|
req.on("end", () => {
|
|
37586
37611
|
try {
|
|
37587
|
-
|
|
37612
|
+
resolve2(text ? JSON.parse(text) : {});
|
|
37588
37613
|
} catch {
|
|
37589
|
-
|
|
37614
|
+
resolve2({});
|
|
37590
37615
|
}
|
|
37591
37616
|
});
|
|
37592
37617
|
req.on("error", reject);
|
|
@@ -37789,7 +37814,7 @@ function isConnectionError(error62) {
|
|
|
37789
37814
|
|
|
37790
37815
|
// src/locate.ts
|
|
37791
37816
|
import { existsSync as existsSync2, readdirSync, readFileSync, statSync } from "fs";
|
|
37792
|
-
import { extname, join as join2, relative } from "path";
|
|
37817
|
+
import { basename as basename2, extname, isAbsolute, join as join2, relative } from "path";
|
|
37793
37818
|
var SKIP = /* @__PURE__ */ new Set([
|
|
37794
37819
|
"node_modules",
|
|
37795
37820
|
"dist",
|
|
@@ -37875,6 +37900,17 @@ function needles(target) {
|
|
|
37875
37900
|
}
|
|
37876
37901
|
function locate(target, root, deadline = Date.now() + BUDGET_MS) {
|
|
37877
37902
|
const n = needles(target);
|
|
37903
|
+
const known = target.source?.file && target.source.line ? sourcePath(target.source.file, root) : null;
|
|
37904
|
+
if (known && target.source?.line) {
|
|
37905
|
+
try {
|
|
37906
|
+
const lines = readFileSync(join2(root, known), "utf8").split("\n");
|
|
37907
|
+
const from = target.source.line - 1;
|
|
37908
|
+
const own2 = bestLine(n, lines, from);
|
|
37909
|
+
const index = own2 && own2.score >= 2 ? own2.index : from;
|
|
37910
|
+
return { file: known, line: index + 1, snippet: snippetAt(lines, index) };
|
|
37911
|
+
} catch {
|
|
37912
|
+
}
|
|
37913
|
+
}
|
|
37878
37914
|
if (!n.id && !n.text && !n.lead && n.classes.length < 3) return null;
|
|
37879
37915
|
let best = null;
|
|
37880
37916
|
for (const file2 of sourceFiles(root)) {
|
|
@@ -37889,26 +37925,94 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS) {
|
|
|
37889
37925
|
if (n.classes.length < 3) continue;
|
|
37890
37926
|
}
|
|
37891
37927
|
const lines = content.split("\n");
|
|
37892
|
-
const
|
|
37893
|
-
|
|
37894
|
-
const line = lines[i];
|
|
37895
|
-
let score = 0;
|
|
37896
|
-
if (n.id?.test(line)) score += 8;
|
|
37897
|
-
if (n.text && line.includes(n.text)) score += 6;
|
|
37898
|
-
else if (n.lead && line.includes(n.lead)) score += 4;
|
|
37899
|
-
let classes = 0;
|
|
37900
|
-
for (let j = Math.max(0, i - 3); j <= i; j++) classes = Math.max(classes, classesOn(j));
|
|
37901
|
-
score += classes;
|
|
37902
|
-
if (n.classes.length && classes === n.classes.length) score += 2;
|
|
37903
|
-
if (n.tag.test(line)) score += 1;
|
|
37904
|
-
if (!best || score > best.score) best = { file: file2, line: i, score, lines };
|
|
37905
|
-
}
|
|
37928
|
+
const found = bestLine(n, lines);
|
|
37929
|
+
if (found && (!best || found.score > best.score)) best = { file: file2, line: found.index, score: found.score, lines };
|
|
37906
37930
|
}
|
|
37907
37931
|
const enough = best && (best.score >= 6 || n.classes.length >= 3 && best.score >= n.classes.length + 2);
|
|
37908
37932
|
if (!best || !enough) return null;
|
|
37909
|
-
|
|
37910
|
-
|
|
37911
|
-
|
|
37933
|
+
return { file: relative(root, best.file), line: best.line + 1, snippet: snippetAt(best.lines, best.line) };
|
|
37934
|
+
}
|
|
37935
|
+
function bestLine(n, lines, from = 0) {
|
|
37936
|
+
const classesOn = (i) => lines[i] === void 0 ? 0 : n.classes.filter((re) => re.test(lines[i])).length;
|
|
37937
|
+
let best = null;
|
|
37938
|
+
for (let i = from; i < lines.length; i++) {
|
|
37939
|
+
const line = lines[i];
|
|
37940
|
+
let score = 0;
|
|
37941
|
+
if (n.id?.test(line)) score += 8;
|
|
37942
|
+
if (n.text && line.includes(n.text)) score += 6;
|
|
37943
|
+
else if (n.lead && line.includes(n.lead)) score += 4;
|
|
37944
|
+
let classes = 0;
|
|
37945
|
+
for (let j = Math.max(from, i - 3); j <= i; j++) classes = Math.max(classes, classesOn(j));
|
|
37946
|
+
score += classes;
|
|
37947
|
+
if (n.classes.length && classes === n.classes.length) score += 2;
|
|
37948
|
+
if (n.tag.test(line)) score += 1;
|
|
37949
|
+
if (!best || score > best.score) best = { index: i, score };
|
|
37950
|
+
}
|
|
37951
|
+
return best;
|
|
37952
|
+
}
|
|
37953
|
+
function snippetAt(lines, index) {
|
|
37954
|
+
return lines.slice(Math.max(0, index - 2), index + 3).map((l) => l.length > 160 ? `${l.slice(0, 159)}\u2026` : l).join("\n");
|
|
37955
|
+
}
|
|
37956
|
+
function sourcePath(file2, root) {
|
|
37957
|
+
const rel = isAbsolute(file2) ? relative(root, file2) : file2.replace(/^\.\//, "");
|
|
37958
|
+
if (rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
37959
|
+
return existsSync2(join2(root, rel)) ? rel : null;
|
|
37960
|
+
}
|
|
37961
|
+
function componentFile(name, root, deadline = Date.now() + BUDGET_MS, within) {
|
|
37962
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null;
|
|
37963
|
+
const declaration = new RegExp(
|
|
37964
|
+
`^\\s*(export\\s+(?:default\\s+)?)?(?:(?:async\\s+)?function\\s*\\*?\\s+${name}\\b|class\\s+${name}\\b|(?:const|let|var)\\s+${name}\\s*[:=])`
|
|
37965
|
+
);
|
|
37966
|
+
let best = null;
|
|
37967
|
+
const files = within ? [join2(root, within)] : sourceFiles(root);
|
|
37968
|
+
for (const file2 of files) {
|
|
37969
|
+
if (Date.now() > deadline) break;
|
|
37970
|
+
if (!/\.[jt]sx?$|\.mjs$/.test(file2)) continue;
|
|
37971
|
+
let content;
|
|
37972
|
+
try {
|
|
37973
|
+
content = readFileSync(file2, "utf8");
|
|
37974
|
+
} catch {
|
|
37975
|
+
continue;
|
|
37976
|
+
}
|
|
37977
|
+
if (!content.includes(name)) continue;
|
|
37978
|
+
const lines = content.split("\n");
|
|
37979
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37980
|
+
const m = declaration.exec(lines[i]);
|
|
37981
|
+
if (!m) continue;
|
|
37982
|
+
const score = (basename2(file2).replace(/\.[^.]+$/, "") === name ? 2 : 0) + (m[1] ? 1 : 0);
|
|
37983
|
+
if (!best || score > best.score) best = { file: file2, line: i + 1, score };
|
|
37984
|
+
break;
|
|
37985
|
+
}
|
|
37986
|
+
}
|
|
37987
|
+
return best ? { file: relative(root, best.file), line: best.line } : null;
|
|
37988
|
+
}
|
|
37989
|
+
function withComponentFiles(job, root) {
|
|
37990
|
+
if (!searchable(root)) return job;
|
|
37991
|
+
const deadline = Date.now() + BUDGET_MS;
|
|
37992
|
+
const fill = (target) => {
|
|
37993
|
+
const source = target.source;
|
|
37994
|
+
if (!source?.component || source.line) return target;
|
|
37995
|
+
const known = source.file ? sourcePath(source.file, root) : null;
|
|
37996
|
+
if (source.file && !known) return target;
|
|
37997
|
+
const found = componentFile(source.component, root, deadline, known ?? void 0);
|
|
37998
|
+
return found ? { ...target, source: { ...source, file: found.file, line: found.line } } : target;
|
|
37999
|
+
};
|
|
38000
|
+
const { changeSet } = job;
|
|
38001
|
+
const request = changeSet.request;
|
|
38002
|
+
return {
|
|
38003
|
+
...job,
|
|
38004
|
+
changeSet: {
|
|
38005
|
+
...changeSet,
|
|
38006
|
+
edits: changeSet.edits.map((e) => ({ ...e, target: fill(e.target) })),
|
|
38007
|
+
...request ? {
|
|
38008
|
+
request: {
|
|
38009
|
+
...request,
|
|
38010
|
+
target: fill(request.target),
|
|
38011
|
+
...request.others ? { others: request.others.map(fill) } : {}
|
|
38012
|
+
}
|
|
38013
|
+
} : {}
|
|
38014
|
+
}
|
|
38015
|
+
};
|
|
37912
38016
|
}
|
|
37913
38017
|
function whereSection(job, root) {
|
|
37914
38018
|
if (!searchable(root)) return "";
|
|
@@ -37931,278 +38035,27 @@ function whereSection(job, root) {
|
|
|
37931
38035
|
return [
|
|
37932
38036
|
"## Where the code probably is",
|
|
37933
38037
|
"",
|
|
37934
|
-
"Pilot searched the project for these elements (by id, text and classes). Start there; if it isn't the right place (the text comes from a prop, a translation, a CMS), search as usual.",
|
|
38038
|
+
"Pilot searched the project for these elements (by component, id, text and classes). Start there; if it isn't the right place (the text comes from a prop, a translation, a CMS), search as usual.",
|
|
37935
38039
|
"",
|
|
37936
38040
|
...found
|
|
37937
38041
|
].join("\n");
|
|
37938
38042
|
}
|
|
37939
38043
|
|
|
37940
|
-
// src/
|
|
37941
|
-
|
|
37942
|
-
|
|
37943
|
-
|
|
37944
|
-
|
|
37945
|
-
|
|
37946
|
-
|
|
37947
|
-
|
|
37948
|
-
|
|
37949
|
-
|
|
37950
|
-
|
|
37951
|
-
|
|
37952
|
-
|
|
37953
|
-
|
|
37954
|
-
|
|
37955
|
-
Keep looping until the user interrupts you. Between jobs keep your messages short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, then wait again: queued jobs are kept. Pilot keeps previewing each job's changes until you call pilot_done, then checks them against the page's real CSS: changes that didn't land come back once as a follow-up job with what the page gives instead.`;
|
|
37956
|
-
function agentLabel(clientName, cwd) {
|
|
37957
|
-
const names = {
|
|
37958
|
-
"claude-code": "Claude Code",
|
|
37959
|
-
"claude-ai": "Claude",
|
|
37960
|
-
cursor: "Cursor",
|
|
37961
|
-
"cursor-vscode": "Cursor",
|
|
37962
|
-
vscode: "VS Code",
|
|
37963
|
-
windsurf: "Windsurf",
|
|
37964
|
-
codex: "Codex"
|
|
37965
|
-
};
|
|
37966
|
-
const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
|
|
37967
|
-
return `${app} \xB7 ${basename2(cwd)}`;
|
|
37968
|
-
}
|
|
37969
|
-
function jobPrompt(job, where = "") {
|
|
37970
|
-
const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : job.answer && job.question ? answered(job) : formatPrompt(job.changeSet, { guidelines: false });
|
|
37971
|
-
return `${body2}${where ? `
|
|
37972
|
-
${where}
|
|
37973
|
-
` : ""}
|
|
37974
|
-
---
|
|
37975
|
-
Pilot job \`${job.id}\`. When you've applied it, call \`pilot_done\` with \`jobId: "${job.id}"\` and short notes (${notesFor(job)}). Then call \`pilot_wait_for_edits\` again for the next job.
|
|
37976
|
-
`;
|
|
37977
|
-
}
|
|
37978
|
-
function answered(job) {
|
|
37979
|
-
const meaning = job.answer ? sharedChoiceMeaning(job.answer) : null;
|
|
37980
|
-
return [
|
|
37981
|
-
"# Pilot: the designer answered your question",
|
|
37982
|
-
"",
|
|
37983
|
-
`You did this job and asked the designer: ${job.question?.text}`,
|
|
37984
|
-
"",
|
|
37985
|
-
"Their answer:",
|
|
37986
|
-
"",
|
|
37987
|
-
job.answer?.trim().split("\n").map((l) => `> ${l}`).join("\n"),
|
|
37988
|
-
"",
|
|
37989
|
-
...meaning ? [`What that means for the code: ${meaning}`, ""] : [],
|
|
37990
|
-
"Do what's left of the job the way they answered, then call `pilot_done` again. Pilot then checks it like any job. (Don't ask again: say anything still open in your notes.)",
|
|
37991
|
-
"",
|
|
37992
|
-
"The job, for reference:",
|
|
37993
|
-
"",
|
|
37994
|
-
formatPrompt(job.changeSet, { guidelines: false })
|
|
37995
|
-
].join("\n");
|
|
37996
|
-
}
|
|
37997
|
-
function followUp(job) {
|
|
37998
|
-
const lines = [
|
|
37999
|
-
"# Pilot design edits: follow-up",
|
|
38000
|
-
"",
|
|
38001
|
-
"You applied this job, but Pilot checked the page and these changes don't give the designer's value yet (the values are what the browser computes for the element):",
|
|
38002
|
-
""
|
|
38003
|
-
];
|
|
38004
|
-
for (const d of job.differences ?? []) {
|
|
38005
|
-
const edit = job.changeSet.edits.find((e) => e.target.selector === d.selector);
|
|
38006
|
-
const where = edit ? `\`${edit.target.path}\` (selector \`${d.selector}\`${edit.target.text ? `, text "${edit.target.text}"` : ""})` : `\`${d.selector}\``;
|
|
38007
|
-
lines.push(`- ${where}: \`${d.property}\` should be \`${d.expected}\`, the page gives \`${d.actual ?? "?"}\`.`);
|
|
38008
|
-
}
|
|
38009
|
-
lines.push(
|
|
38010
|
-
"",
|
|
38011
|
-
"Fix them: the usual causes are a rule that overrides yours (more specific, later, or in a media query), an edit in the wrong file or component, or a missed change. If you chose a different value on purpose (a token or the nearest step in the project's scale), keep it and say so in your notes. Pilot takes what the code gives after this."
|
|
38012
|
-
);
|
|
38013
|
-
return lines.join("\n");
|
|
38014
|
-
}
|
|
38015
|
-
var MAX_BATCH = 6;
|
|
38016
|
-
async function takeQueued(first, take) {
|
|
38017
|
-
const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment";
|
|
38018
|
-
if (advanced(first)) return [];
|
|
38019
|
-
const more = [];
|
|
38020
|
-
while (more.length < MAX_BATCH - 1) {
|
|
38021
|
-
const { job } = await take();
|
|
38022
|
-
if (!job) break;
|
|
38023
|
-
more.push(job);
|
|
38024
|
-
if (advanced(job)) break;
|
|
38025
|
-
}
|
|
38026
|
-
return more;
|
|
38027
|
-
}
|
|
38028
|
-
function batchIntro(jobs) {
|
|
38029
|
-
return `# Pilot: ${jobs.length} jobs
|
|
38030
|
-
|
|
38031
|
-
The designer sent these while you were busy. Do them all (they're on different elements), then call \`pilot_done\` once per job, each with its own id and notes (you can make the calls together): ${jobs.map((j) => `\`${j.id}\``).join(", ")}. Then call \`pilot_wait_for_edits\` again.`;
|
|
38032
|
-
}
|
|
38033
|
-
function notesFor(job) {
|
|
38034
|
-
switch (job.changeSet.request?.kind) {
|
|
38035
|
-
case "comment":
|
|
38036
|
-
return "your reply in the designer's comment thread, a small chat box: one short sentence, about 120 characters at most, with what you changed or your answer; no lists or code blocks";
|
|
38037
|
-
case "responsive":
|
|
38038
|
-
return "what changed at which widths, anything left for the designer";
|
|
38039
|
-
case "break-and-fix":
|
|
38040
|
-
return "what broke and how you fixed it, anything for the designer to decide";
|
|
38041
|
-
default:
|
|
38042
|
-
return "values you approximated, anything you did differently";
|
|
38043
|
-
}
|
|
38044
|
-
}
|
|
38045
|
-
function taskFollowUp(job) {
|
|
38046
|
-
const request = job.changeSet.request;
|
|
38047
|
-
const target = `\`${request?.target.path ?? "the element"}\``;
|
|
38048
|
-
const breakFix = request?.kind === "break-and-fix";
|
|
38049
|
-
const lines = [
|
|
38050
|
-
breakFix ? "# Pilot: break and fix, follow-up" : "# Pilot: make responsive, follow-up",
|
|
38051
|
-
"",
|
|
38052
|
-
breakFix ? `You stress-tested ${target} and reported it done, but Pilot's width check (the page with its usual content, measured at each width) finds these problems. If one comes from test content still in the code, remove it:` : `You made ${target} responsive, but Pilot's width check (the page measured at each width) still finds these problems:`,
|
|
38053
|
-
"",
|
|
38054
|
-
...(job.issues ?? []).map((i) => `- ${i}`),
|
|
38055
|
-
"",
|
|
38056
|
-
"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.",
|
|
38057
|
-
"",
|
|
38058
|
-
"The task, for reference:",
|
|
38059
|
-
"",
|
|
38060
|
-
formatPrompt(job.changeSet)
|
|
38061
|
-
];
|
|
38062
|
-
return lines.join("\n");
|
|
38063
|
-
}
|
|
38064
|
-
function createPilotServer(options = {}) {
|
|
38065
|
-
const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
|
|
38066
|
-
const cwd = options.cwd ?? process.cwd();
|
|
38067
|
-
let waitMs = options.waitMs ?? waitMsFor(void 0);
|
|
38068
|
-
const server = new McpServer({ name: "pilot", version: "0.7.1" }, { instructions: INSTRUCTIONS });
|
|
38069
|
-
const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
|
|
38070
|
-
const bridge = new Bridge(agent, port);
|
|
38071
|
-
let origin = null;
|
|
38072
|
-
server.server.oninitialized = () => {
|
|
38073
|
-
const client = server.server.getClientVersion()?.name;
|
|
38074
|
-
agent.label = agentLabel(client, cwd);
|
|
38075
|
-
waitMs = options.waitMs ?? waitMsFor(client);
|
|
38076
|
-
};
|
|
38077
|
-
const text = (t, isError = false) => ({ content: [{ type: "text", text: t }], isError });
|
|
38078
|
-
server.registerTool(
|
|
38079
|
-
"pilot_launch",
|
|
38080
|
-
{
|
|
38081
|
-
title: "Launch Pilot",
|
|
38082
|
-
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.",
|
|
38083
|
-
inputSchema: {
|
|
38084
|
-
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).")
|
|
38085
|
-
}
|
|
38086
|
-
},
|
|
38087
|
-
async ({ url: url2 }) => {
|
|
38088
|
-
const o = originOf(url2);
|
|
38089
|
-
if (!o) return text(`"${url2}" isn't a page URL. Pass the dev server's URL, e.g. http://localhost:5173.`, true);
|
|
38090
|
-
origin = o;
|
|
38091
|
-
try {
|
|
38092
|
-
const pages = await bridge.launch(o);
|
|
38093
|
-
const where = pages > 0 ? `Pilot is open in ${pages === 1 ? "the page" : `${pages} pages`} at ${o}.` : `No page at ${o} is connected yet. Ask the designer to open ${url2} (with the dev server running): Pilot opens there.`;
|
|
38094
|
-
return text(`${where} Now call pilot_wait_for_edits and wait for the designer to press Send.`);
|
|
38095
|
-
} catch (error62) {
|
|
38096
|
-
return text(`Pilot couldn't start its bridge: ${error62.message}`, true);
|
|
38097
|
-
}
|
|
38098
|
-
}
|
|
38099
|
-
);
|
|
38100
|
-
server.registerTool(
|
|
38101
|
-
"pilot_wait_for_edits",
|
|
38102
|
-
{
|
|
38103
|
-
title: "Wait for design edits",
|
|
38104
|
-
// The edit guidelines live here, read once with the tool, not repeated in every job (they're the most frequent).
|
|
38105
|
-
description: `Waits for the designer to press Send in Pilot, and returns the job to apply (or several, when they were queued: do them all, and report each done). Returns "no edits yet" after a few minutes: call it again to keep waiting. Call pilot_launch first.
|
|
38106
|
-
|
|
38107
|
-
Guidelines for every design-edits job (the job doesn't repeat them):
|
|
38108
|
-
${EDIT_GUIDELINES.join("\n")}`,
|
|
38109
|
-
inputSchema: {}
|
|
38110
|
-
},
|
|
38111
|
-
async (_args, extra) => {
|
|
38112
|
-
if (!origin) return text("Call pilot_launch with the page's URL first.", true);
|
|
38113
|
-
const token = extra._meta?.progressToken;
|
|
38114
|
-
let progress = 0;
|
|
38115
|
-
const ticker = token !== void 0 ? setInterval(() => {
|
|
38116
|
-
extra.sendNotification({
|
|
38117
|
-
method: "notifications/progress",
|
|
38118
|
-
params: { progressToken: token, progress: ++progress, message: "Waiting for the designer to send edits" }
|
|
38119
|
-
}).catch(() => {
|
|
38120
|
-
});
|
|
38121
|
-
}, PROGRESS_MS) : null;
|
|
38122
|
-
try {
|
|
38123
|
-
const { job } = await bridge.wait(origin, waitMs, extra.signal);
|
|
38124
|
-
if (!job) return text("No edits yet. Call pilot_wait_for_edits again to keep waiting (the designer can keep editing meanwhile).");
|
|
38125
|
-
const jobs = [job, ...await takeQueued(job, () => bridge.wait(origin, 0, extra.signal))];
|
|
38126
|
-
const parts = await Promise.all(
|
|
38127
|
-
jobs.map(async (j) => ({
|
|
38128
|
-
// Where its elements' code probably is: found here, in the project, so the agent can go straight to the edit.
|
|
38129
|
-
text: jobPrompt(j, j.attempt === 2 ? "" : whereSection(j, cwd)),
|
|
38130
|
-
// A comment's images and text files come with it, so the agent sees them without opening files.
|
|
38131
|
-
blocks: await attachmentBlocks(j)
|
|
38132
|
-
}))
|
|
38133
|
-
);
|
|
38134
|
-
if (parts.length === 1) return { content: [{ type: "text", text: parts[0]?.text ?? "" }, ...parts[0]?.blocks ?? []], isError: false };
|
|
38135
|
-
return {
|
|
38136
|
-
content: [
|
|
38137
|
-
{ type: "text", text: batchIntro(jobs) },
|
|
38138
|
-
...parts.flatMap((p, i) => [{ type: "text", text: `## Job ${i + 1} of ${jobs.length}
|
|
38139
|
-
|
|
38140
|
-
${p.text}` }, ...p.blocks])
|
|
38141
|
-
],
|
|
38142
|
-
isError: false
|
|
38143
|
-
};
|
|
38144
|
-
} catch (error62) {
|
|
38145
|
-
return text(`Pilot's bridge failed while waiting: ${error62.message}. Call pilot_wait_for_edits again.`, true);
|
|
38146
|
-
} finally {
|
|
38147
|
-
if (ticker) clearInterval(ticker);
|
|
38148
|
-
}
|
|
38149
|
-
}
|
|
38150
|
-
);
|
|
38151
|
-
server.registerTool(
|
|
38152
|
-
"pilot_done",
|
|
38153
|
-
{
|
|
38154
|
-
title: "Report a job done",
|
|
38155
|
-
description: "Tells Pilot you applied a job. Pilot then checks each change against the page's real CSS; a change that didn't land comes back to you once as a follow-up. Then call pilot_wait_for_edits again. When part of the job needs the designer's decision (they changed only some copies of shared code), apply the rest, leave that part, and ask with `question`: Pilot shows it in a comment on the element, with one-click `choices`, holds the job until they answer, and their answer comes back to you as this job again. You go on with other jobs meanwhile. A job asks once.",
|
|
38156
|
-
inputSchema: {
|
|
38157
|
-
jobId: external_exports.string().describe("The job's id, from pilot_wait_for_edits."),
|
|
38158
|
-
notes: external_exports.string().optional().describe("Short notes for the designer: values you approximated (e.g. 22px \u2192 pt-6, 24px), anything done differently."),
|
|
38159
|
-
question: external_exports.object({
|
|
38160
|
-
text: external_exports.string().describe(`One short sentence, the component's name in **bold** (it's shown as markdown), e.g. "This title comes from the shared **Card**: change every card, or only this one?"`),
|
|
38161
|
-
choices: external_exports.array(external_exports.string()).max(MAX_CHOICES).optional().describe(
|
|
38162
|
-
`One-click answers, a few words each (they sit on one line), your suggestion first (it's the main button). For shared code: "${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}". The designer can also write their own.`
|
|
38163
|
-
)
|
|
38164
|
-
}).optional().describe("Only when part of the job needs the designer's decision: see the description.")
|
|
38165
|
-
}
|
|
38166
|
-
},
|
|
38167
|
-
async ({ jobId, notes, question }) => {
|
|
38168
|
-
try {
|
|
38169
|
-
const asked = questionOf(question);
|
|
38170
|
-
const job = await bridge.done(jobId, notes, asked);
|
|
38171
|
-
if (!job) return text(`Pilot doesn't know job ${jobId} (or the designer cancelled it). Call pilot_wait_for_edits for the next one.`);
|
|
38172
|
-
if (asked && job.question)
|
|
38173
|
-
return text("Done. Pilot shows your question to the designer; their answer comes back as this job. Call pilot_wait_for_edits for the next job meanwhile.");
|
|
38174
|
-
if (asked) return text("Done. This job was answered already, so the question wasn't asked: Pilot is checking the changes. Say it in your notes next time. Call pilot_wait_for_edits for the next job.");
|
|
38175
|
-
return text("Done. Pilot is checking the changes in the page. Call pilot_wait_for_edits for the next job.");
|
|
38176
|
-
} catch (error62) {
|
|
38177
|
-
return text(`Pilot couldn't report the job done: ${error62.message}`, true);
|
|
38178
|
-
}
|
|
38179
|
-
}
|
|
38180
|
-
);
|
|
38181
|
-
server.registerTool(
|
|
38182
|
-
"pilot_check_widths",
|
|
38183
|
-
{
|
|
38184
|
-
title: "Check an element at every width",
|
|
38185
|
-
description: "For a Make responsive or Break and fix job: Pilot loads the page in hidden frames at a phone width, each breakpoint and just below it, a wide desktop and the designer's width, and measures the job's element in each. Returns each width's size and layout, and problems (sticking out of the viewport, spilling out of its parent, clipped content, overlaps), plus what changed at the designer's width. Use it instead of screenshots; fix the problems and run it again until it finds none.",
|
|
38186
|
-
inputSchema: {
|
|
38187
|
-
jobId: external_exports.string().describe("The Make responsive or Break and fix job's id, from pilot_wait_for_edits.")
|
|
38188
|
-
}
|
|
38189
|
-
},
|
|
38190
|
-
async ({ jobId }) => {
|
|
38191
|
-
try {
|
|
38192
|
-
const check2 = await bridge.check(jobId);
|
|
38193
|
-
if (!check2) {
|
|
38194
|
-
return text(
|
|
38195
|
-
`Pilot couldn't check job ${jobId}: no page answered. The page with Pilot must be open (the designer's tab), and the job must be a Make responsive or Break and fix one. If you can, check the widths in a browser instead.`,
|
|
38196
|
-
true
|
|
38197
|
-
);
|
|
38198
|
-
}
|
|
38199
|
-
return text(formatWidthCheck(check2));
|
|
38200
|
-
} catch (error62) {
|
|
38201
|
-
return text(`Pilot couldn't run the width check: ${error62.message}`, true);
|
|
38202
|
-
}
|
|
38203
|
-
}
|
|
38204
|
-
);
|
|
38205
|
-
return { server, bridge, agent };
|
|
38044
|
+
// src/clients.ts
|
|
38045
|
+
var RESTART = {
|
|
38046
|
+
"claude-code": "In Claude Code, open a new chat (or run `/mcp` and reconnect `pilot`).",
|
|
38047
|
+
cursor: "In Cursor, restart Pilot's server: Cursor Settings, MCP section, switch `pilot` off and on. A new chat isn't enough: Cursor keeps one server for all its chats.",
|
|
38048
|
+
vscode: "In VS Code, restart Pilot's server: run **MCP: List Servers** from the Command Palette, pick `pilot`, then **Restart Server**.",
|
|
38049
|
+
codex: "In Codex, start a new session.",
|
|
38050
|
+
other: "Restart Pilot's server in your agent (its MCP settings), or restart the agent."
|
|
38051
|
+
};
|
|
38052
|
+
function clientOf(name) {
|
|
38053
|
+
const n = name?.toLowerCase() ?? "";
|
|
38054
|
+
if (n.startsWith("claude-code") || n === "claude-ai") return "claude-code";
|
|
38055
|
+
if (n.startsWith("cursor")) return "cursor";
|
|
38056
|
+
if (n === "vscode" || n.includes("visual studio code")) return "vscode";
|
|
38057
|
+
if (n.startsWith("codex")) return "codex";
|
|
38058
|
+
return null;
|
|
38206
38059
|
}
|
|
38207
38060
|
|
|
38208
38061
|
// src/init.ts
|
|
@@ -38219,7 +38072,7 @@ import { homedir } from "os";
|
|
|
38219
38072
|
import { join as join3, relative as relative2 } from "path";
|
|
38220
38073
|
|
|
38221
38074
|
// ../../skills/pilot/SKILL.md
|
|
38222
|
-
var SKILL_default = "---\nname: pilot\ndescription: Hand the UI to the designer with Pilot, then apply the design edits they send, job after job. Use when the user runs /pilot, says they want to take control of the design or edit the UI in the browser, or pastes a \"Pilot design edits\" brief.\n---\n\n# Pilot\n\nPilot lets the designer edit the running app in the browser. They select elements, change CSS properties with Pilot's editors, and press **Send**. Each Send reaches you as a **job**: plain CSS `property: from \u2192 to` (and new text, when they rewrote one) on identifiable elements, for you to write into the source in this project's conventions. The designer keeps designing while you work; Pilot previews each job's changes until you report it done, then checks them against the page's real CSS.\n\n## When the user runs /pilot (or asks to launch Pilot)\n\n0. **Check that Pilot's tools are here** (`pilot_launch`, `pilot_wait_for_edits`, `pilot_done`). If they aren't, don't look for them in files, packages or settings: they come from Pilot's MCP server, which an agent loads when a chat starts, so a chat opened before Pilot was set up doesn't have them. Say so in one or two lines and stop: open a new chat (approve Pilot's server if asked, or turn it on in the agent's MCP settings: Cursor keeps a project's new servers off until they're switched on in Cursor Settings, MCP section), then run `/pilot` there. If the project has no Pilot at all (no `usepilot` in its `package.json`), offer to set it up instead: `npx usepilot@latest init --agent <you>`.\n1. **Find the page.** Work out the URL of the app's dev server: the dev script and its config (`vite.config.*` \u2192 `server.port`, Next.js \u2192 3000, a `--port` flag\u2026), or a server already running in a terminal. If the dev server isn't running, start it in the background. If you can't tell the URL, ask.\n2. **Launch:** call `pilot_launch` with that URL. Pilot opens in the page (if the page isn't open yet, tell the designer to open it).\n3. **Tell the designer** in one line that Pilot is ready: select an element, edit, press Send.\n4. **Wait:** call `pilot_wait_for_edits`. It returns a job when the designer presses Send, or \"no edits yet\" after a while: call it again, without saying anything to the user. In Claude Code, a wait longer than two minutes moves to the background: end your turn with a short \"Waiting for your edits\", and the job arrives as the task's result.\n5. **Apply the job** (below), then call `pilot_done` with the job id and short notes, and go back to step 4. When several jobs were queued, one wait returns them all: do them all, then call `pilot_done` once per job, each with its own id and notes.\n\nKeep looping until the user asks you to stop. Keep your messages between jobs short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, and keep (or start again) a wait in the background so their next Send reaches you (queued jobs are kept).\n\n## Applying a job\n\nJobs come in three kinds:\n\n- **Edits** (basic): the designer set every value; you only translate them. **Speed is what matters**: go straight to the code, apply, call `pilot_done`. No screenshots, browser checks, builds or tests: Pilot checks the page itself and sends back what didn't land.\n- **Comments**: the designer's own words about one element (\"make it the brand green\", \"can this be calmer?\"), with the thread so far. Do what the latest one asks: a specific, small ask right away (like an edit), an open-ended one as an advanced task (below). A question gets an answer and no change. Your `pilot_done` notes are your reply in their thread, a small chat box for quick design back-and-forth: one short sentence, like a chat message (about 120 characters), with no lists or code blocks. Not a report: they see the result on the page.\n- **Tasks** (advanced), like **Make responsive** and **Break and fix**: the designer selected an element and asked for an outcome (work at every viewport width; hold up with odd but realistic content, like very long text, with the real content put back after testing). They need judgment more than speed. The prompt has the steps. Check the result with `pilot_check_widths` (numbers for every width, no screenshots needed). If you can hand it to a more capable model than the one you run on (a subagent, or another model your agent offers), do, then call `pilot_done` with its notes. Pilot checks the widths again when you're done; problems come back once as a follow-up.\n\n### Edits\n\nThe values are **design instructions, not code**: the designer's intent. Use your judgment and write production code the way this project already styles things, whatever it uses. First look at how the element's component is styled, and follow that. For example:\n\n- **Utility classes (Tailwind):** the closest utility or theme value (`border-radius: 12px` \u2192 `rounded-xl`, `padding-top: 24px` \u2192 `pt-6`). Arbitrary values only when nothing fits.\n- **CSS / CSS modules / Sass:** edit the rule that styles the element. Don't add a new override.\n- **Design tokens / CSS variables:** prefer an existing token that matches. Don't hard-code its value.\n- **CSS-in-JS and compiled styles (StyleX, vanilla-extract, Panda, styled-components, Emotion):** edit the style definition where the component is styled, with the project's tokens.\n- **A component library's props (MUI, Chakra\u2026):** use its props and theme values before any custom CSS.\n\nRules:\n\n- Never leave inline styles or `!important` behind. Pilot's preview is only a preview.\n- Find each element by its selector, DOM path and text snippet, then the component that renders it.\n- **Shared code, only some copies:** an element's \"Look-alikes\" line counts the elements like it the job leaves out. If they come from the same code (a shared component, a loop over data) and the designer didn't say which they meant, don't guess: do the rest of the job, leave that part, and ask with `pilot_done`'s `question` (one short sentence, the component's name in **bold**) and `choices` \"All of them\", \"Only this\", \"New variant\" (your suggestion first). Go on with other jobs; the answer comes back as that job. **All of them**: change the component itself. **Only this**: change it where it's used, with what the component accepts (classes through its `className`, merged the project's way; a prop), else the smallest pass-through, not a variant. **New variant**: add a named option the way the component defines variants (`cva`, a `variant` prop), use it here, and name it in your notes. Don't ask when the designer already said, when every copy is in the job, or when nothing else uses that code.\n- **Widths:** a change for some viewport widths goes in a media query; use the project's breakpoints when one matches (or is within a few pixels). \"Every width\" means no media query should override it.\n- **Removed:** the element shouldn't declare the property at all (not `0` or `none`).\n- **Text:** the designer rewrote the element's copy. Change it where it comes from (the markup, a prop, a translation file), for this element only; Pilot checks that the page shows the new text.\n- If you approximated a value to fit a token or scale, say which and by how much in `pilot_done`'s notes (`22px \u2192 pt-6, 24px`). Pilot checks the page after each job: a change that doesn't give the designer's value comes back to you once as a follow-up. Fix it, or keep a deliberate choice and say why; after that, Pilot takes what the code gives.\n- Don't run builds or tests for a job unless it's needed: hot reload shows the result, and the designer is waiting to see it.\n";
|
|
38075
|
+
var SKILL_default = "---\nname: pilot\ndescription: Hand the UI to the designer with Pilot, then apply the design edits they send, job after job. Use when the user runs /pilot, says they want to take control of the design or edit the UI in the browser, or pastes a \"Pilot design edits\" brief, or asks to update Pilot.\n---\n\n# Pilot\n\nPilot lets the designer edit the running app in the browser. They select elements, change CSS properties with Pilot's editors, and press **Send**. Each Send reaches you as a **job**: plain CSS `property: from \u2192 to` (and new text, when they rewrote one) on identifiable elements, for you to write into the source in this project's conventions. The designer keeps designing while you work; Pilot previews each job's changes until you report it done, then checks them against the page's real CSS.\n\n## When the user asks to update Pilot\n\nRun `npx usepilot@latest update` in the app's folder (the one with `usepilot` in its `package.json`), and tell the user in a few lines what it prints: the new version and the steps left (restart the app's dev server, open a new chat).\n\n## When the user runs /pilot (or asks to launch Pilot)\n\n0. **Check that Pilot's tools are here** (`pilot_launch`, `pilot_wait_for_edits`, `pilot_done`). If they aren't, don't look for them in files, packages or settings: they come from Pilot's MCP server, which an agent loads when a chat starts, so a chat opened before Pilot was set up doesn't have them. Say so in one or two lines and stop: open a new chat (approve Pilot's server if asked, or turn it on in the agent's MCP settings: Cursor keeps a project's new servers off until they're switched on in Cursor Settings, MCP section), then run `/pilot` there. If the project has no Pilot at all (no `usepilot` in its `package.json`), offer to set it up instead: `npx usepilot@latest init --agent <you>`.\n1. **Find the page.** Work out the URL of the app's dev server: the dev script and its config (`vite.config.*` \u2192 `server.port`, Next.js \u2192 3000, a `--port` flag\u2026), or a server already running in a terminal. If the dev server isn't running, start it in the background. If you can't tell the URL, ask.\n2. **Launch:** call `pilot_launch` with that URL and `folder`, the project's folder as an absolute path (your working directory): Pilot searches the code there for each job, and some agents start its server elsewhere. Pilot opens in the page (if the page isn't open yet, tell the designer to open it).\n3. **Tell the designer** in one line that Pilot is ready: select an element, edit, press Send.\n4. **Wait:** call `pilot_wait_for_edits`. It returns a job when the designer presses Send, or \"no edits yet\" after a while: call it again, without saying anything to the user. In Claude Code, a wait longer than two minutes moves to the background: end your turn with a short \"Waiting for your edits\", and the job arrives as the task's result.\n5. **Apply the job** (below), then call `pilot_done` with the job id and short notes, and go back to step 4. When several jobs were queued, one wait returns them all: do them all, then call `pilot_done` once per job, each with its own id and notes.\n\nKeep looping until the user asks you to stop. Keep your messages between jobs short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, and keep (or start again) a wait in the background so their next Send reaches you (queued jobs are kept).\n\n## Applying a job\n\nJobs come in three kinds:\n\n- **Edits** (basic): the designer set every value; you only translate them. **Speed is what matters**: go straight to the code, apply, call `pilot_done`. No screenshots, browser checks, builds or tests: Pilot checks the page itself and sends back what didn't land.\n- **Comments**: the designer's own words about one element (\"make it the brand green\", \"can this be calmer?\"), with the thread so far. Do what the latest one asks: a specific, small ask right away (like an edit), an open-ended one as an advanced task (below). A question gets an answer and no change. Your `pilot_done` notes are your reply in their thread, a small chat box for quick design back-and-forth: one short sentence, like a chat message (about 120 characters), with no lists or code blocks. Not a report: they see the result on the page.\n- **Tasks** (advanced), like **Make responsive** and **Break and fix**: the designer selected an element and asked for an outcome (work at every viewport width; hold up with odd but realistic content, like very long text, with the real content put back after testing). They need judgment more than speed. The prompt has the steps. Check the result with `pilot_check_widths` (numbers for every width, no screenshots needed). If you can hand it to a more capable model than the one you run on (a subagent, or another model your agent offers), do, then call `pilot_done` with its notes. Pilot checks the widths again when you're done; problems come back once as a follow-up.\n\n### Edits\n\nThe values are **design instructions, not code**: the designer's intent. Use your judgment and write production code the way this project already styles things, whatever it uses. First look at how the element's component is styled, and follow that. For example:\n\n- **Utility classes (Tailwind):** the closest utility or theme value (`border-radius: 12px` \u2192 `rounded-xl`, `padding-top: 24px` \u2192 `pt-6`). Arbitrary values only when nothing fits.\n- **CSS / CSS modules / Sass:** edit the rule that styles the element. Don't add a new override.\n- **Design tokens / CSS variables:** prefer an existing token that matches. Don't hard-code its value.\n- **CSS-in-JS and compiled styles (StyleX, vanilla-extract, Panda, styled-components, Emotion):** edit the style definition where the component is styled, with the project's tokens.\n- **A component library's props (MUI, Chakra\u2026):** use its props and theme values before any custom CSS.\n\nRules:\n\n- Never leave inline styles or `!important` behind. Pilot's preview is only a preview.\n- Find each element by its selector, DOM path and text snippet, then the component that renders it.\n- **Shared code, only some copies:** an element's \"Look-alikes\" line counts the elements like it the job leaves out. If they come from the same code (a shared component, a loop over data) and the designer didn't say which they meant, don't guess: do the rest of the job, leave that part, and ask with `pilot_done`'s `question` (one short sentence, the component's name in **bold**) and `choices` \"All of them\", \"Only this\", \"New variant\" (your suggestion first). Go on with other jobs; the answer comes back as that job. **All of them**: change the component itself. **Only this**: change it where it's used, with what the component accepts (classes through its `className`, merged the project's way; a prop), else the smallest pass-through, not a variant. **New variant**: add a named option the way the component defines variants (`cva`, a `variant` prop), use it here, and name it in your notes. Don't ask when the designer already said, when every copy is in the job, or when nothing else uses that code.\n- **Widths:** a change for some viewport widths goes in a media query; use the project's breakpoints when one matches (or is within a few pixels). \"Every width\" means no media query should override it.\n- **Removed:** the element shouldn't declare the property at all (not `0` or `none`).\n- **Text:** the designer rewrote the element's copy. Change it where it comes from (the markup, a prop, a translation file), for this element only; Pilot checks that the page shows the new text.\n- If you approximated a value to fit a token or scale, say which and by how much in `pilot_done`'s notes (`22px \u2192 pt-6, 24px`). Pilot checks the page after each job: a change that doesn't give the designer's value comes back to you once as a follow-up. Fix it, or keep a deliberate choice and say why; after that, Pilot takes what the code gives.\n- Don't run builds or tests for a job unless it's needed: hot reload shows the result, and the designer is waiting to see it.\n";
|
|
38223
38076
|
|
|
38224
38077
|
// src/setup.ts
|
|
38225
38078
|
var MCP_SERVER = { command: "npx", args: ["-y", "usepilot", "mcp"] };
|
|
@@ -38291,6 +38144,15 @@ async function addMcpServer(file2) {
|
|
|
38291
38144
|
return { added };
|
|
38292
38145
|
}
|
|
38293
38146
|
|
|
38147
|
+
// src/version.ts
|
|
38148
|
+
var VERSION = "0.8.0";
|
|
38149
|
+
function olderThan(a, b) {
|
|
38150
|
+
const parts = (v) => v.replace(/^[^\d]*/, "").split(/[.-]/).slice(0, 3).map((n) => Number.parseInt(n, 10) || 0);
|
|
38151
|
+
const [x, y] = [parts(a), parts(b)];
|
|
38152
|
+
for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) < (y[i] ?? 0);
|
|
38153
|
+
return false;
|
|
38154
|
+
}
|
|
38155
|
+
|
|
38294
38156
|
// src/init.ts
|
|
38295
38157
|
var AGENT_IDS = ["claude-code", "cursor", "codex", "vscode", "other"];
|
|
38296
38158
|
var COMMAND = `${MCP_SERVER.command} ${MCP_SERVER.args.join(" ")}`;
|
|
@@ -38371,6 +38233,32 @@ var MACHINE = {
|
|
|
38371
38233
|
},
|
|
38372
38234
|
other: { skills: (home) => join4(home, ".agents", "skills") }
|
|
38373
38235
|
};
|
|
38236
|
+
function skillFolders(root, home) {
|
|
38237
|
+
const machine = AGENT_IDS.map((id) => join4(MACHINE[id].skills(home), "pilot"));
|
|
38238
|
+
const project = AGENTS.map((a) => join4(root, a.skills, "pilot"));
|
|
38239
|
+
return [.../* @__PURE__ */ new Set([...machine, ...project])];
|
|
38240
|
+
}
|
|
38241
|
+
function agentsWithPilot(root, home, platform = process.platform) {
|
|
38242
|
+
const hasServer = (file2, key) => !!(readJson(file2)?.[key] ?? {}).pilot;
|
|
38243
|
+
return AGENTS.filter((a) => {
|
|
38244
|
+
if (a.id === "other") return false;
|
|
38245
|
+
const machine = MACHINE[a.id];
|
|
38246
|
+
if (machine.mcp && hasServer(machine.mcp.file(home, platform), machine.mcp.key)) return true;
|
|
38247
|
+
if (machine.command?.has(home)) return true;
|
|
38248
|
+
if (a.mcp && hasServer(join4(root, a.mcp.file), a.mcp.key)) return true;
|
|
38249
|
+
return a.id !== "codex" && existsSync4(join4(machine.skills(home), "pilot"));
|
|
38250
|
+
}).map((a) => a.id);
|
|
38251
|
+
}
|
|
38252
|
+
function installArgs(pm, spec = "usepilot") {
|
|
38253
|
+
return pm === "npm" ? ["install", "-D", spec] : pm === "bun" ? ["add", "-d", spec] : ["add", "-D", spec];
|
|
38254
|
+
}
|
|
38255
|
+
function installedVersion(cwd, root) {
|
|
38256
|
+
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
38257
|
+
const version2 = readJson(join4(dir, "node_modules", "usepilot", "package.json"))?.version;
|
|
38258
|
+
if (version2) return version2;
|
|
38259
|
+
if (dir === root || dirname2(dir) === dir) return null;
|
|
38260
|
+
}
|
|
38261
|
+
}
|
|
38374
38262
|
function vscodeUserDir(home, platform) {
|
|
38375
38263
|
if (platform === "darwin") return join4(home, "Library", "Application Support", "Code", "User");
|
|
38376
38264
|
if (platform === "win32") return join4(process.env.APPDATA ?? join4(home, "AppData", "Roaming"), "Code", "User");
|
|
@@ -38411,10 +38299,15 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
|
38411
38299
|
const done = [];
|
|
38412
38300
|
const todo = [];
|
|
38413
38301
|
const pm = packageManager(cwd, root);
|
|
38414
|
-
const
|
|
38415
|
-
const install = `${pm} ${
|
|
38302
|
+
const args = installArgs(pm);
|
|
38303
|
+
const install = `${pm} ${args.join(" ")}`;
|
|
38304
|
+
const installed = deps.usepilot ? installedVersion(cwd, root) : null;
|
|
38305
|
+
if (deps.usepilot && installed && olderThan(installed, VERSION))
|
|
38306
|
+
todo.push(
|
|
38307
|
+
`**Tell the user** Pilot ${installed} is installed here, and ${VERSION} is out: \`npx usepilot@latest update\` updates it (run it now if they ask).`
|
|
38308
|
+
);
|
|
38416
38309
|
if (deps.usepilot) done.push("`usepilot` was already a dependency.");
|
|
38417
|
-
else if (options.install !== false && run(pm,
|
|
38310
|
+
else if (options.install !== false && run(pm, args, cwd))
|
|
38418
38311
|
done.push(`Installed \`usepilot\` as a dev dependency (\`${install}\`).`);
|
|
38419
38312
|
else todo.push(`Install Pilot as a dev dependency: run \`${install}\` in ${cwd}.`);
|
|
38420
38313
|
const named = options.agent ?? detectAgent(options.env ?? process.env);
|
|
@@ -38711,8 +38604,408 @@ function runCommand(command2, args, cwd) {
|
|
|
38711
38604
|
return result.status === 0;
|
|
38712
38605
|
}
|
|
38713
38606
|
|
|
38607
|
+
// src/mcp.ts
|
|
38608
|
+
function waitMsFor(clientName) {
|
|
38609
|
+
const configured = Number(process.env.PILOT_WAIT_MS);
|
|
38610
|
+
if (configured > 0) return configured;
|
|
38611
|
+
return clientName === "claude-code" ? 25 * 6e4 : 5e4;
|
|
38612
|
+
}
|
|
38613
|
+
var PROGRESS_MS = 2e4;
|
|
38614
|
+
var INSTRUCTIONS = `Pilot lets the designer edit the running app in the browser and send the edits back to you as jobs.
|
|
38615
|
+
|
|
38616
|
+
The loop, when the user asks to launch or start Pilot, runs /pilot, or asks to hand the design over:
|
|
38617
|
+
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 and \`folder\`, the project's folder as an absolute path (your working directory: Pilot searches the code there for each job, and some clients start its server in another folder): 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.
|
|
38618
|
+
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.)
|
|
38619
|
+
3. Apply the job's edits to the source: they're design instructions, not code, so write production code the way the project already styles things, whatever it uses (see the job's guidelines). Edits are basic: every value is given, so be fast (no screenshots or browser checks: Pilot checks the page). A "make responsive" job is an advanced task: make one element work at every viewport width. A "break and fix" job is one too: stress-test one element with odd but realistic content, fix what breaks, and put the real content back. Their prompts list the steps; check the result with pilot_check_widths (numbers for every width, instead of screenshots). If you can hand advanced tasks to a more capable model than the one you run on (a subagent, or another model your agent offers), do. A "comment" job is the designer's own words about one element: do what it asks (simple asks right away, open-ended ones as advanced tasks), and your pilot_done notes are your reply in their thread: one short sentence, like a chat message, not a report.
|
|
38620
|
+
4. Call pilot_done with the job id and short notes (values you approximated, anything you did differently). When part of a job needs the designer's decision (they changed only some copies of shared code: each element's "Look-alikes" line counts the others; the jobs' guidelines say when, and what each answer means), do the rest, leave that part, and ask with pilot_done's question and choices ("${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}", your suggestion first); go on with other jobs, and their answer comes back as that job. Then call pilot_wait_for_edits again. When several jobs were queued, one wait returns them all: do them all, then call pilot_done once per job, each with its own id and notes.
|
|
38621
|
+
|
|
38622
|
+
When the user asks to update Pilot: run \`npx usepilot@latest update\` in the app's folder and tell them, in a few lines, what it prints (the new version, and the steps left).
|
|
38623
|
+
|
|
38624
|
+
Keep looping until the user interrupts you. Between jobs keep your messages short: a line on what you changed (and anything you approximated) is enough. If the user talks to you meanwhile, help them, then wait again: queued jobs are kept. Pilot keeps previewing each job's changes until you call pilot_done, then checks them against the page's real CSS: changes that didn't land come back once as a follow-up job with what the page gives instead.`;
|
|
38625
|
+
function agentLabel(clientName, cwd) {
|
|
38626
|
+
const names = {
|
|
38627
|
+
"claude-code": "Claude Code",
|
|
38628
|
+
"claude-ai": "Claude",
|
|
38629
|
+
cursor: "Cursor",
|
|
38630
|
+
"cursor-vscode": "Cursor",
|
|
38631
|
+
vscode: "VS Code",
|
|
38632
|
+
windsurf: "Windsurf",
|
|
38633
|
+
codex: "Codex"
|
|
38634
|
+
};
|
|
38635
|
+
const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
|
|
38636
|
+
return `${app} \xB7 ${basename3(cwd)}`;
|
|
38637
|
+
}
|
|
38638
|
+
function jobPrompt(job, where = "") {
|
|
38639
|
+
const body2 = job.attempt === 2 && job.issues?.length ? taskFollowUp(job) : job.attempt === 2 && job.differences?.length ? followUp(job) : job.answer && job.question ? answered(job) : formatPrompt(job.changeSet, { guidelines: false });
|
|
38640
|
+
return `${body2}${where ? `
|
|
38641
|
+
${where}
|
|
38642
|
+
` : ""}
|
|
38643
|
+
---
|
|
38644
|
+
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.
|
|
38645
|
+
`;
|
|
38646
|
+
}
|
|
38647
|
+
function answered(job) {
|
|
38648
|
+
const meaning = job.answer ? sharedChoiceMeaning(job.answer) : null;
|
|
38649
|
+
return [
|
|
38650
|
+
"# Pilot: the designer answered your question",
|
|
38651
|
+
"",
|
|
38652
|
+
`You did this job and asked the designer: ${job.question?.text}`,
|
|
38653
|
+
"",
|
|
38654
|
+
"Their answer:",
|
|
38655
|
+
"",
|
|
38656
|
+
job.answer?.trim().split("\n").map((l) => `> ${l}`).join("\n"),
|
|
38657
|
+
"",
|
|
38658
|
+
...meaning ? [`What that means for the code: ${meaning}`, ""] : [],
|
|
38659
|
+
"Do what's left of the job the way they answered, then call `pilot_done` again. Pilot then checks it like any job. (Don't ask again: say anything still open in your notes.)",
|
|
38660
|
+
"",
|
|
38661
|
+
"The job, for reference:",
|
|
38662
|
+
"",
|
|
38663
|
+
formatPrompt(job.changeSet, { guidelines: false })
|
|
38664
|
+
].join("\n");
|
|
38665
|
+
}
|
|
38666
|
+
function followUp(job) {
|
|
38667
|
+
const lines = [
|
|
38668
|
+
"# Pilot design edits: follow-up",
|
|
38669
|
+
"",
|
|
38670
|
+
"You applied this job, but Pilot checked the page and these changes don't give the designer's value yet (the values are what the browser computes for the element):",
|
|
38671
|
+
""
|
|
38672
|
+
];
|
|
38673
|
+
for (const d of job.differences ?? []) {
|
|
38674
|
+
const edit = job.changeSet.edits.find((e) => e.target.selector === d.selector);
|
|
38675
|
+
const where = edit ? `\`${edit.target.path}\` (selector \`${d.selector}\`${edit.target.text ? `, text "${edit.target.text}"` : ""})` : `\`${d.selector}\``;
|
|
38676
|
+
if (d.property === DOM_REMOVE) lines.push(`- ${where}: deleted by the designer, but it's still on the page.`);
|
|
38677
|
+
else if (d.property.startsWith(DOM_INSERT)) lines.push(`- ${where}: ${d.expected} was added by the designer, but it's not on the page.`);
|
|
38678
|
+
else lines.push(`- ${where}: \`${d.property}\` should be \`${d.expected}\`, the page gives \`${d.actual ?? "?"}\`.`);
|
|
38679
|
+
}
|
|
38680
|
+
lines.push(
|
|
38681
|
+
"",
|
|
38682
|
+
"Fix them: the usual causes are a rule that overrides yours (more specific, later, or in a media query), an edit in the wrong file or component, or a missed change. If you chose a different value on purpose (a token or the nearest step in the project's scale), keep it and say so in your notes. Pilot takes what the code gives after this."
|
|
38683
|
+
);
|
|
38684
|
+
return lines.join("\n");
|
|
38685
|
+
}
|
|
38686
|
+
var MAX_BATCH = 6;
|
|
38687
|
+
async function takeQueued(first, take) {
|
|
38688
|
+
const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment";
|
|
38689
|
+
if (advanced(first)) return [];
|
|
38690
|
+
const more = [];
|
|
38691
|
+
while (more.length < MAX_BATCH - 1) {
|
|
38692
|
+
const { job } = await take();
|
|
38693
|
+
if (!job) break;
|
|
38694
|
+
more.push(job);
|
|
38695
|
+
if (advanced(job)) break;
|
|
38696
|
+
}
|
|
38697
|
+
return more;
|
|
38698
|
+
}
|
|
38699
|
+
function batchIntro(jobs) {
|
|
38700
|
+
return `# Pilot: ${jobs.length} jobs
|
|
38701
|
+
|
|
38702
|
+
The designer sent these while you were busy. Do them all (they're on different elements), then call \`pilot_done\` once per job, each with its own id and notes (you can make the calls together): ${jobs.map((j) => `\`${j.id}\``).join(", ")}. Then call \`pilot_wait_for_edits\` again.`;
|
|
38703
|
+
}
|
|
38704
|
+
function notesFor(job) {
|
|
38705
|
+
switch (job.changeSet.request?.kind) {
|
|
38706
|
+
case "comment":
|
|
38707
|
+
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";
|
|
38708
|
+
case "responsive":
|
|
38709
|
+
return "what changed at which widths, anything left for the designer";
|
|
38710
|
+
case "break-and-fix":
|
|
38711
|
+
return "what broke and how you fixed it, anything for the designer to decide";
|
|
38712
|
+
default:
|
|
38713
|
+
return "values you approximated, anything you did differently";
|
|
38714
|
+
}
|
|
38715
|
+
}
|
|
38716
|
+
function taskFollowUp(job) {
|
|
38717
|
+
const request = job.changeSet.request;
|
|
38718
|
+
const target = `\`${request?.target.path ?? "the element"}\``;
|
|
38719
|
+
const breakFix = request?.kind === "break-and-fix";
|
|
38720
|
+
const lines = [
|
|
38721
|
+
breakFix ? "# Pilot: break and fix, follow-up" : "# Pilot: make responsive, follow-up",
|
|
38722
|
+
"",
|
|
38723
|
+
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:`,
|
|
38724
|
+
"",
|
|
38725
|
+
...(job.issues ?? []).map((i) => `- ${i}`),
|
|
38726
|
+
"",
|
|
38727
|
+
"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.",
|
|
38728
|
+
"",
|
|
38729
|
+
"The task, for reference:",
|
|
38730
|
+
"",
|
|
38731
|
+
formatPrompt(job.changeSet)
|
|
38732
|
+
];
|
|
38733
|
+
return lines.join("\n");
|
|
38734
|
+
}
|
|
38735
|
+
function projectFolder(candidate) {
|
|
38736
|
+
if (!candidate) return null;
|
|
38737
|
+
let path = candidate;
|
|
38738
|
+
if (path.startsWith("file://")) {
|
|
38739
|
+
try {
|
|
38740
|
+
path = fileURLToPath(path);
|
|
38741
|
+
} catch {
|
|
38742
|
+
return null;
|
|
38743
|
+
}
|
|
38744
|
+
}
|
|
38745
|
+
if (!isAbsolute2(path)) return null;
|
|
38746
|
+
path = resolve(path);
|
|
38747
|
+
return existsSync5(path) && searchable(path) ? path : null;
|
|
38748
|
+
}
|
|
38749
|
+
function createPilotServer(options = {}) {
|
|
38750
|
+
const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
|
|
38751
|
+
const cwd = options.cwd ?? process.cwd();
|
|
38752
|
+
let project = cwd;
|
|
38753
|
+
let client;
|
|
38754
|
+
let waitMs = options.waitMs ?? waitMsFor(void 0);
|
|
38755
|
+
const server = new McpServer({ name: "pilot", version: VERSION }, { instructions: INSTRUCTIONS });
|
|
38756
|
+
const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
|
|
38757
|
+
const bridge = new Bridge(agent, port);
|
|
38758
|
+
let origin = null;
|
|
38759
|
+
const useProject = (folder) => {
|
|
38760
|
+
project = folder;
|
|
38761
|
+
agent.label = agentLabel(client, folder);
|
|
38762
|
+
};
|
|
38763
|
+
server.server.oninitialized = () => {
|
|
38764
|
+
client = server.server.getClientVersion()?.name;
|
|
38765
|
+
agent.label = agentLabel(client, project);
|
|
38766
|
+
waitMs = options.waitMs ?? waitMsFor(client);
|
|
38767
|
+
if (searchable(project) || !server.server.getClientCapabilities()?.roots) return;
|
|
38768
|
+
void server.server.listRoots().then(({ roots }) => {
|
|
38769
|
+
const folder = roots.map((r) => projectFolder(r.uri)).find((f) => !!f);
|
|
38770
|
+
if (folder && !searchable(project)) useProject(folder);
|
|
38771
|
+
}).catch(() => {
|
|
38772
|
+
});
|
|
38773
|
+
};
|
|
38774
|
+
const text = (t, isError = false) => ({ content: [{ type: "text", text: t }], isError });
|
|
38775
|
+
server.registerTool(
|
|
38776
|
+
"pilot_launch",
|
|
38777
|
+
{
|
|
38778
|
+
title: "Launch Pilot",
|
|
38779
|
+
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.",
|
|
38780
|
+
inputSchema: {
|
|
38781
|
+
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)."),
|
|
38782
|
+
folder: external_exports.string().optional().describe(
|
|
38783
|
+
"The project's folder, as an absolute path: your working directory (the app's folder, with its package.json). Pilot searches its code there for each job. Always pass it: some clients start Pilot's server in another folder."
|
|
38784
|
+
)
|
|
38785
|
+
}
|
|
38786
|
+
},
|
|
38787
|
+
async ({ url: url2, folder }) => {
|
|
38788
|
+
const o = originOf(url2);
|
|
38789
|
+
if (!o) return text(`"${url2}" isn't a page URL. Pass the dev server's URL, e.g. http://localhost:5173.`, true);
|
|
38790
|
+
origin = o;
|
|
38791
|
+
const given = projectFolder(folder);
|
|
38792
|
+
if (given) useProject(given);
|
|
38793
|
+
const lost = !searchable(project) && !given ? ` Pilot can't search the project's code from ${project}${folder ? ` (nor from ${folder}: it needs a package.json or a .git)` : ""}: call pilot_launch again with \`folder\` set to the project's folder (absolute).` : "";
|
|
38794
|
+
try {
|
|
38795
|
+
const pages = await bridge.launch(o);
|
|
38796
|
+
const where = pages > 0 ? `Pilot is open in ${pages === 1 ? "the page" : `${pages} pages`} at ${o}.` : `No page at ${o} is connected yet. Ask the designer to open ${url2} (with the dev server running): Pilot opens there.`;
|
|
38797
|
+
const installed = searchable(project) ? installedVersion(project, project) : null;
|
|
38798
|
+
const stale = installed && olderThan(VERSION, installed) ? ` This chat's Pilot server is ${VERSION}, older than the project's ${installed}: tell the user to restart it, so it loads ${installed}. ${RESTART[clientOf(client) ?? "other"]}` : "";
|
|
38799
|
+
return text(`${where} Now call pilot_wait_for_edits and wait for the designer to press Send.${lost}${stale}`);
|
|
38800
|
+
} catch (error62) {
|
|
38801
|
+
return text(`Pilot couldn't start its bridge: ${error62.message}`, true);
|
|
38802
|
+
}
|
|
38803
|
+
}
|
|
38804
|
+
);
|
|
38805
|
+
server.registerTool(
|
|
38806
|
+
"pilot_wait_for_edits",
|
|
38807
|
+
{
|
|
38808
|
+
title: "Wait for design edits",
|
|
38809
|
+
// The edit guidelines live here, read once with the tool, not repeated in every job (they're the most frequent).
|
|
38810
|
+
description: `Waits for the designer to press Send in Pilot, and returns the job to apply (or several, when they were queued: do them all, and report each done). Returns "no edits yet" after a few minutes: call it again to keep waiting. Call pilot_launch first.
|
|
38811
|
+
|
|
38812
|
+
Guidelines for every design-edits job (the job doesn't repeat them):
|
|
38813
|
+
${EDIT_GUIDELINES.join("\n")}`,
|
|
38814
|
+
inputSchema: {}
|
|
38815
|
+
},
|
|
38816
|
+
async (_args, extra) => {
|
|
38817
|
+
if (!origin) return text("Call pilot_launch with the page's URL first.", true);
|
|
38818
|
+
const token = extra._meta?.progressToken;
|
|
38819
|
+
let progress = 0;
|
|
38820
|
+
const ticker = token !== void 0 ? setInterval(() => {
|
|
38821
|
+
extra.sendNotification({
|
|
38822
|
+
method: "notifications/progress",
|
|
38823
|
+
params: { progressToken: token, progress: ++progress, message: "Waiting for the designer to send edits" }
|
|
38824
|
+
}).catch(() => {
|
|
38825
|
+
});
|
|
38826
|
+
}, PROGRESS_MS) : null;
|
|
38827
|
+
try {
|
|
38828
|
+
const { job } = await bridge.wait(origin, waitMs, extra.signal);
|
|
38829
|
+
if (!job) return text("No edits yet. Call pilot_wait_for_edits again to keep waiting (the designer can keep editing meanwhile).");
|
|
38830
|
+
const jobs = [job, ...await takeQueued(job, () => bridge.wait(origin, 0, extra.signal))];
|
|
38831
|
+
const parts = await Promise.all(
|
|
38832
|
+
jobs.map(async (taken) => {
|
|
38833
|
+
const j = withComponentFiles(taken, project);
|
|
38834
|
+
return {
|
|
38835
|
+
// Where its elements' code probably is: found here, in the project, so the agent can go straight to the edit.
|
|
38836
|
+
text: jobPrompt(j, j.attempt === 2 ? "" : whereSection(j, project)),
|
|
38837
|
+
// A comment's images and text files come with it, so the agent sees them without opening files.
|
|
38838
|
+
blocks: await attachmentBlocks(j)
|
|
38839
|
+
};
|
|
38840
|
+
})
|
|
38841
|
+
);
|
|
38842
|
+
if (parts.length === 1) return { content: [{ type: "text", text: parts[0]?.text ?? "" }, ...parts[0]?.blocks ?? []], isError: false };
|
|
38843
|
+
return {
|
|
38844
|
+
content: [
|
|
38845
|
+
{ type: "text", text: batchIntro(jobs) },
|
|
38846
|
+
...parts.flatMap((p, i) => [{ type: "text", text: `## Job ${i + 1} of ${jobs.length}
|
|
38847
|
+
|
|
38848
|
+
${p.text}` }, ...p.blocks])
|
|
38849
|
+
],
|
|
38850
|
+
isError: false
|
|
38851
|
+
};
|
|
38852
|
+
} catch (error62) {
|
|
38853
|
+
return text(`Pilot's bridge failed while waiting: ${error62.message}. Call pilot_wait_for_edits again.`, true);
|
|
38854
|
+
} finally {
|
|
38855
|
+
if (ticker) clearInterval(ticker);
|
|
38856
|
+
}
|
|
38857
|
+
}
|
|
38858
|
+
);
|
|
38859
|
+
server.registerTool(
|
|
38860
|
+
"pilot_done",
|
|
38861
|
+
{
|
|
38862
|
+
title: "Report a job done",
|
|
38863
|
+
description: "Tells Pilot you applied a job. Pilot then checks each change against the page's real CSS; a change that didn't land comes back to you once as a follow-up. Then call pilot_wait_for_edits again. When part of the job needs the designer's decision (they changed only some copies of shared code), apply the rest, leave that part, and ask with `question`: Pilot shows it in a comment on the element, with one-click `choices`, holds the job until they answer, and their answer comes back to you as this job again. You go on with other jobs meanwhile. A job asks once.",
|
|
38864
|
+
inputSchema: {
|
|
38865
|
+
jobId: external_exports.string().describe("The job's id, from pilot_wait_for_edits."),
|
|
38866
|
+
notes: external_exports.string().optional().describe("Short notes for the designer: values you approximated (e.g. 22px \u2192 pt-6, 24px), anything done differently."),
|
|
38867
|
+
question: external_exports.object({
|
|
38868
|
+
text: external_exports.string().describe(`One short sentence, the component's name in **bold** (it's shown as markdown), e.g. "This title comes from the shared **Card**: change every card, or only this one?"`),
|
|
38869
|
+
choices: external_exports.array(external_exports.string()).max(MAX_CHOICES).optional().describe(
|
|
38870
|
+
`One-click answers, a few words each (they sit on one line), your suggestion first (it's the main button). For shared code: "${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}". The designer can also write their own.`
|
|
38871
|
+
)
|
|
38872
|
+
}).optional().describe("Only when part of the job needs the designer's decision: see the description.")
|
|
38873
|
+
}
|
|
38874
|
+
},
|
|
38875
|
+
async ({ jobId, notes, question }) => {
|
|
38876
|
+
try {
|
|
38877
|
+
const asked = questionOf(question);
|
|
38878
|
+
const job = await bridge.done(jobId, notes, asked);
|
|
38879
|
+
if (!job) return text(`Pilot doesn't know job ${jobId} (or the designer cancelled it). Call pilot_wait_for_edits for the next one.`);
|
|
38880
|
+
if (asked && job.question)
|
|
38881
|
+
return text("Done. Pilot shows your question to the designer; their answer comes back as this job. Call pilot_wait_for_edits for the next job meanwhile.");
|
|
38882
|
+
if (asked) return text("Done. This job was answered already, so the question wasn't asked: Pilot is checking the changes. Say it in your notes next time. Call pilot_wait_for_edits for the next job.");
|
|
38883
|
+
return text("Done. Pilot is checking the changes in the page. Call pilot_wait_for_edits for the next job.");
|
|
38884
|
+
} catch (error62) {
|
|
38885
|
+
return text(`Pilot couldn't report the job done: ${error62.message}`, true);
|
|
38886
|
+
}
|
|
38887
|
+
}
|
|
38888
|
+
);
|
|
38889
|
+
server.registerTool(
|
|
38890
|
+
"pilot_check_widths",
|
|
38891
|
+
{
|
|
38892
|
+
title: "Check an element at every width",
|
|
38893
|
+
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.",
|
|
38894
|
+
inputSchema: {
|
|
38895
|
+
jobId: external_exports.string().describe("The Make responsive or Break and fix job's id, from pilot_wait_for_edits.")
|
|
38896
|
+
}
|
|
38897
|
+
},
|
|
38898
|
+
async ({ jobId }) => {
|
|
38899
|
+
try {
|
|
38900
|
+
const check2 = await bridge.check(jobId);
|
|
38901
|
+
if (!check2) {
|
|
38902
|
+
return text(
|
|
38903
|
+
`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.`,
|
|
38904
|
+
true
|
|
38905
|
+
);
|
|
38906
|
+
}
|
|
38907
|
+
return text(formatWidthCheck(check2));
|
|
38908
|
+
} catch (error62) {
|
|
38909
|
+
return text(`Pilot couldn't run the width check: ${error62.message}`, true);
|
|
38910
|
+
}
|
|
38911
|
+
}
|
|
38912
|
+
);
|
|
38913
|
+
return { server, bridge, agent };
|
|
38914
|
+
}
|
|
38915
|
+
|
|
38916
|
+
// src/update.ts
|
|
38917
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
38918
|
+
import { existsSync as existsSync6, lstatSync, readFileSync as readFileSync3 } from "fs";
|
|
38919
|
+
import { homedir as homedir3 } from "os";
|
|
38920
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
38921
|
+
async function update(options = {}) {
|
|
38922
|
+
const cwd = options.cwd ?? process.cwd();
|
|
38923
|
+
const run = options.run ?? runCommand2;
|
|
38924
|
+
const home = options.home ?? homedir3();
|
|
38925
|
+
const pkg = readJson2(join5(cwd, "package.json"));
|
|
38926
|
+
const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
38927
|
+
if (!pkg || !deps.usepilot) {
|
|
38928
|
+
return `# Pilot isn't installed here
|
|
38929
|
+
|
|
38930
|
+
Run this in your app's folder, the one where Pilot was set up. To set Pilot up in this one, run \`npx usepilot@latest init\` instead.
|
|
38931
|
+
`;
|
|
38932
|
+
}
|
|
38933
|
+
const root = projectRoot(cwd);
|
|
38934
|
+
const before = installedVersion(cwd, root);
|
|
38935
|
+
const oldBridge = bridgeOf(cwd, root);
|
|
38936
|
+
const pm = packageManager(cwd, root);
|
|
38937
|
+
const args = installArgs(pm, "usepilot@latest");
|
|
38938
|
+
const installed = run(pm, args, cwd);
|
|
38939
|
+
const after = installed ? installedVersion(cwd, root) ?? VERSION : before;
|
|
38940
|
+
const skills = [];
|
|
38941
|
+
for (const folder of skillFolders(root, home)) {
|
|
38942
|
+
if (!existsSync6(folder) || isLink2(folder)) continue;
|
|
38943
|
+
await writeSkill(folder);
|
|
38944
|
+
skills.push(folder.startsWith(home) ? `~${folder.slice(home.length)}` : folder);
|
|
38945
|
+
}
|
|
38946
|
+
if (!installed) {
|
|
38947
|
+
return `# Pilot: not updated
|
|
38948
|
+
|
|
38949
|
+
Installing the latest Pilot didn't work (the output is above). Run this in ${cwd}, then \`npx usepilot@latest update\` again:
|
|
38950
|
+
|
|
38951
|
+
\`\`\`
|
|
38952
|
+
${pm} ${args.join(" ")}
|
|
38953
|
+
\`\`\`
|
|
38954
|
+
`;
|
|
38955
|
+
}
|
|
38956
|
+
const changed = !!before && !!after && olderThan(before, after);
|
|
38957
|
+
const agents = agentsWithPilot(root, home, options.platform);
|
|
38958
|
+
const steps = [
|
|
38959
|
+
"Restart your app's dev server, so the page loads the new Pilot.",
|
|
38960
|
+
...agents.length ? agents.map((a) => RESTART[a]) : [RESTART.other],
|
|
38961
|
+
"Then, in a new chat, ask your agent to launch Pilot (or run `/pilot`)."
|
|
38962
|
+
];
|
|
38963
|
+
if (oldBridge !== null && oldBridge !== BRIDGE_VERSION) {
|
|
38964
|
+
steps.push(
|
|
38965
|
+
"Update Pilot in your other projects too (`npx usepilot@latest update` in each): this version can't share its connection with older ones."
|
|
38966
|
+
);
|
|
38967
|
+
}
|
|
38968
|
+
const headline = changed ? `# Pilot updated: ${before} \u2192 ${after}` : `# Pilot is up to date (${after ?? VERSION})`;
|
|
38969
|
+
const skillLine = skills.length ? `
|
|
38970
|
+
The \`pilot\` skill is updated too (${skills.map((s) => `\`${s}\``).join(", ")}).
|
|
38971
|
+
` : "";
|
|
38972
|
+
return `${headline}
|
|
38973
|
+
${skillLine}
|
|
38974
|
+
${changed ? `Next:
|
|
38975
|
+
${steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
38976
|
+
` : "Nothing else to do.\n"}`;
|
|
38977
|
+
}
|
|
38978
|
+
function bridgeOf(cwd, root) {
|
|
38979
|
+
for (let dir = cwd; ; dir = dirname3(dir)) {
|
|
38980
|
+
const file2 = join5(dir, "node_modules", "usepilot", "cli", "index.js");
|
|
38981
|
+
if (existsSync6(file2)) {
|
|
38982
|
+
const match = /BRIDGE_VERSION = (\d+)/.exec(readFileSync3(file2, "utf8"));
|
|
38983
|
+
return match ? Number(match[1]) : null;
|
|
38984
|
+
}
|
|
38985
|
+
if (dir === root || dirname3(dir) === dir) return null;
|
|
38986
|
+
}
|
|
38987
|
+
}
|
|
38988
|
+
function isLink2(path) {
|
|
38989
|
+
try {
|
|
38990
|
+
return lstatSync(path).isSymbolicLink();
|
|
38991
|
+
} catch {
|
|
38992
|
+
return false;
|
|
38993
|
+
}
|
|
38994
|
+
}
|
|
38995
|
+
function readJson2(file2) {
|
|
38996
|
+
try {
|
|
38997
|
+
return JSON.parse(readFileSync3(file2, "utf8"));
|
|
38998
|
+
} catch {
|
|
38999
|
+
return null;
|
|
39000
|
+
}
|
|
39001
|
+
}
|
|
39002
|
+
function runCommand2(command2, args, cwd) {
|
|
39003
|
+
const result = spawnSync2(command2, args, { cwd, stdio: ["ignore", "inherit", "inherit"], shell: process.platform === "win32" });
|
|
39004
|
+
return result.status === 0;
|
|
39005
|
+
}
|
|
39006
|
+
|
|
38714
39007
|
// src/index.ts
|
|
38715
|
-
var HELP = `usepilot:
|
|
39008
|
+
var HELP = `usepilot: design in your running app, your agents write the code
|
|
38716
39009
|
|
|
38717
39010
|
Usage: npx usepilot <command>
|
|
38718
39011
|
|
|
@@ -38724,6 +39017,9 @@ Usage: npx usepilot <command>
|
|
|
38724
39017
|
--project: connect the agent in this repo (files to commit, for a
|
|
38725
39018
|
team) instead of once for every project on this machine
|
|
38726
39019
|
--no-install: print the install command instead of running it
|
|
39020
|
+
update Update Pilot in this project: the latest usepilot, and the pilot
|
|
39021
|
+
skill wherever init put it. Prints what's left (restart the app,
|
|
39022
|
+
open a new chat). Run it in the app's folder.
|
|
38727
39023
|
setup Set up /pilot in Claude Code, for every project on this machine
|
|
38728
39024
|
(--project: for this repo, to commit, so everyone gets it)
|
|
38729
39025
|
mcp Run the MCP server (stdio) agents connect to, and the bridge the
|
|
@@ -38779,6 +39075,15 @@ switch (command) {
|
|
|
38779
39075
|
);
|
|
38780
39076
|
} catch (error62) {
|
|
38781
39077
|
process.stderr.write(`usepilot init: ${error62.message}
|
|
39078
|
+
`);
|
|
39079
|
+
process.exitCode = 1;
|
|
39080
|
+
}
|
|
39081
|
+
break;
|
|
39082
|
+
case "update":
|
|
39083
|
+
try {
|
|
39084
|
+
process.stdout.write(await update());
|
|
39085
|
+
} catch (error62) {
|
|
39086
|
+
process.stderr.write(`usepilot update: ${error62.message}
|
|
38782
39087
|
`);
|
|
38783
39088
|
process.exitCode = 1;
|
|
38784
39089
|
}
|