usepilot 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.js +695 -231
- package/dist/{mount-D38Ob6ds.js → mount-C1Ukrf6F.js} +5156 -3458
- 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 = resolve3.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 resolve3(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 resolve3(baseURI, relativeURI, options) {
|
|
3880
3880
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
3881
3881
|
const {
|
|
3882
3882
|
parsed: baseParsed,
|
|
@@ -3912,50 +3912,50 @@ var require_fast_uri = __commonJS({
|
|
|
3912
3912
|
schemelessOptions.skipEscape = true;
|
|
3913
3913
|
return serialize(resolved, schemelessOptions);
|
|
3914
3914
|
}
|
|
3915
|
-
function resolveComponent(base,
|
|
3915
|
+
function resolveComponent(base, relative6, options, skipNormalization) {
|
|
3916
3916
|
const target = {};
|
|
3917
3917
|
if (!skipNormalization) {
|
|
3918
3918
|
base = parse3(serialize(base, options), options);
|
|
3919
|
-
|
|
3919
|
+
relative6 = parse3(serialize(relative6, options), options);
|
|
3920
3920
|
}
|
|
3921
3921
|
options = options || {};
|
|
3922
|
-
if (!options.tolerant &&
|
|
3923
|
-
target.scheme =
|
|
3924
|
-
target.userinfo =
|
|
3925
|
-
target.host =
|
|
3926
|
-
target.port =
|
|
3927
|
-
target.path = removeDotSegments(
|
|
3928
|
-
target.query =
|
|
3922
|
+
if (!options.tolerant && relative6.scheme) {
|
|
3923
|
+
target.scheme = relative6.scheme;
|
|
3924
|
+
target.userinfo = relative6.userinfo;
|
|
3925
|
+
target.host = relative6.host;
|
|
3926
|
+
target.port = relative6.port;
|
|
3927
|
+
target.path = removeDotSegments(relative6.path || "");
|
|
3928
|
+
target.query = relative6.query;
|
|
3929
3929
|
} else {
|
|
3930
|
-
if (
|
|
3931
|
-
target.userinfo =
|
|
3932
|
-
target.host =
|
|
3933
|
-
target.port =
|
|
3934
|
-
target.path = removeDotSegments(
|
|
3935
|
-
target.query =
|
|
3930
|
+
if (relative6.userinfo !== void 0 || relative6.host !== void 0 || relative6.port !== void 0) {
|
|
3931
|
+
target.userinfo = relative6.userinfo;
|
|
3932
|
+
target.host = relative6.host;
|
|
3933
|
+
target.port = relative6.port;
|
|
3934
|
+
target.path = removeDotSegments(relative6.path || "");
|
|
3935
|
+
target.query = relative6.query;
|
|
3936
3936
|
} else {
|
|
3937
|
-
if (!
|
|
3937
|
+
if (!relative6.path) {
|
|
3938
3938
|
target.path = base.path;
|
|
3939
|
-
if (
|
|
3940
|
-
target.query =
|
|
3939
|
+
if (relative6.query !== void 0) {
|
|
3940
|
+
target.query = relative6.query;
|
|
3941
3941
|
} else {
|
|
3942
3942
|
target.query = base.query;
|
|
3943
3943
|
}
|
|
3944
3944
|
} else {
|
|
3945
|
-
if (
|
|
3946
|
-
target.path = removeDotSegments(
|
|
3945
|
+
if (relative6.path[0] === "/") {
|
|
3946
|
+
target.path = removeDotSegments(relative6.path);
|
|
3947
3947
|
} else {
|
|
3948
3948
|
const baseHasAuthority = base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0;
|
|
3949
3949
|
if (baseHasAuthority && !base.path) {
|
|
3950
|
-
target.path = "/" +
|
|
3950
|
+
target.path = "/" + relative6.path;
|
|
3951
3951
|
} else if (!base.path) {
|
|
3952
|
-
target.path =
|
|
3952
|
+
target.path = relative6.path;
|
|
3953
3953
|
} else {
|
|
3954
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
3954
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative6.path;
|
|
3955
3955
|
}
|
|
3956
3956
|
target.path = base.scheme === void 0 && !baseHasAuthority && target.path[0] !== "/" ? removeDotSegmentsRelative(target.path) : removeDotSegments(target.path);
|
|
3957
3957
|
}
|
|
3958
|
-
target.query =
|
|
3958
|
+
target.query = relative6.query;
|
|
3959
3959
|
}
|
|
3960
3960
|
target.userinfo = base.userinfo;
|
|
3961
3961
|
target.host = base.host;
|
|
@@ -3963,7 +3963,7 @@ var require_fast_uri = __commonJS({
|
|
|
3963
3963
|
}
|
|
3964
3964
|
target.scheme = base.scheme;
|
|
3965
3965
|
}
|
|
3966
|
-
target.fragment =
|
|
3966
|
+
target.fragment = relative6.fragment;
|
|
3967
3967
|
return target;
|
|
3968
3968
|
}
|
|
3969
3969
|
function equal(uriA, uriB, options) {
|
|
@@ -4267,7 +4267,7 @@ var require_fast_uri = __commonJS({
|
|
|
4267
4267
|
var fastUri = {
|
|
4268
4268
|
SCHEMES,
|
|
4269
4269
|
normalize,
|
|
4270
|
-
resolve:
|
|
4270
|
+
resolve: resolve3,
|
|
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, resolve3) {
|
|
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, resolve2) {
|
|
|
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, resolve3);
|
|
12340
12340
|
if (answer > result)
|
|
12341
12341
|
result = answer;
|
|
12342
12342
|
}
|
|
@@ -12347,7 +12347,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
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, resolve3) : NONE;
|
|
12351
12351
|
if (child > answer)
|
|
12352
12352
|
answer = child;
|
|
12353
12353
|
}
|
|
@@ -12411,7 +12411,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
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 ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
12415
12415
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
12416
12416
|
break;
|
|
12417
12417
|
}
|
|
@@ -26761,21 +26761,21 @@ function visit(schema, fnOrHandlers) {
|
|
|
26761
26761
|
const h = fnOrHandlers[node2._zod.def.type];
|
|
26762
26762
|
return h ? h(node2, rewritten) : node2;
|
|
26763
26763
|
};
|
|
26764
|
-
const
|
|
26764
|
+
const cache4 = /* @__PURE__ */ new Map();
|
|
26765
26765
|
function run(s) {
|
|
26766
|
-
const cached2 =
|
|
26766
|
+
const cached2 = cache4.get(s);
|
|
26767
26767
|
if (cached2 === RESOLVING) {
|
|
26768
26768
|
return new $ZodLazy({
|
|
26769
26769
|
type: "lazy",
|
|
26770
|
-
getter: () =>
|
|
26770
|
+
getter: () => cache4.get(s)
|
|
26771
26771
|
});
|
|
26772
26772
|
}
|
|
26773
26773
|
if (cached2 !== void 0)
|
|
26774
26774
|
return cached2;
|
|
26775
|
-
|
|
26775
|
+
cache4.set(s, RESOLVING);
|
|
26776
26776
|
const inner = mapInner(s);
|
|
26777
26777
|
const mapped = fn(inner, inner !== s);
|
|
26778
|
-
|
|
26778
|
+
cache4.set(s, mapped);
|
|
26779
26779
|
return mapped;
|
|
26780
26780
|
}
|
|
26781
26781
|
function mapInner(s) {
|
|
@@ -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((resolve3) => {
|
|
28604
28604
|
const json3 = serializeMessage(message);
|
|
28605
28605
|
if (this._stdout.write(json3)) {
|
|
28606
|
-
|
|
28606
|
+
resolve3();
|
|
28607
28607
|
} else {
|
|
28608
|
-
this._stdout.once("drain",
|
|
28608
|
+
this._stdout.once("drain", resolve3);
|
|
28609
28609
|
}
|
|
28610
28610
|
});
|
|
28611
28611
|
}
|
|
@@ -28613,8 +28613,8 @@ var StdioServerTransport = class {
|
|
|
28613
28613
|
|
|
28614
28614
|
// src/mcp.ts
|
|
28615
28615
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
28616
|
-
import { existsSync as
|
|
28617
|
-
import { basename as
|
|
28616
|
+
import { existsSync as existsSync6 } from "fs";
|
|
28617
|
+
import { basename as basename5, isAbsolute as isAbsolute2, resolve as resolve2 } from "path";
|
|
28618
28618
|
import { fileURLToPath } from "url";
|
|
28619
28619
|
|
|
28620
28620
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v3/helpers/util.js
|
|
@@ -34591,7 +34591,7 @@ var Protocol = class {
|
|
|
34591
34591
|
return;
|
|
34592
34592
|
}
|
|
34593
34593
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
34594
|
-
await new Promise((
|
|
34594
|
+
await new Promise((resolve3) => setTimeout(resolve3, pollInterval));
|
|
34595
34595
|
options?.signal?.throwIfAborted();
|
|
34596
34596
|
}
|
|
34597
34597
|
} catch (error62) {
|
|
@@ -34608,7 +34608,7 @@ var Protocol = class {
|
|
|
34608
34608
|
*/
|
|
34609
34609
|
request(request, resultSchema, options) {
|
|
34610
34610
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
34611
|
-
return new Promise((
|
|
34611
|
+
return new Promise((resolve3, reject) => {
|
|
34612
34612
|
const earlyReject = (error62) => {
|
|
34613
34613
|
reject(error62);
|
|
34614
34614
|
};
|
|
@@ -34686,7 +34686,7 @@ var Protocol = class {
|
|
|
34686
34686
|
if (!parseResult.success) {
|
|
34687
34687
|
reject(parseResult.error);
|
|
34688
34688
|
} else {
|
|
34689
|
-
|
|
34689
|
+
resolve3(parseResult.data);
|
|
34690
34690
|
}
|
|
34691
34691
|
} catch (error62) {
|
|
34692
34692
|
reject(error62);
|
|
@@ -34948,12 +34948,12 @@ var Protocol = class {
|
|
|
34948
34948
|
}
|
|
34949
34949
|
} catch {
|
|
34950
34950
|
}
|
|
34951
|
-
return new Promise((
|
|
34951
|
+
return new Promise((resolve3, reject) => {
|
|
34952
34952
|
if (signal.aborted) {
|
|
34953
34953
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
34954
34954
|
return;
|
|
34955
34955
|
}
|
|
34956
|
-
const timeoutId = setTimeout(
|
|
34956
|
+
const timeoutId = setTimeout(resolve3, interval);
|
|
34957
34957
|
signal.addEventListener("abort", () => {
|
|
34958
34958
|
clearTimeout(timeoutId);
|
|
34959
34959
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -36093,7 +36093,7 @@ var McpServer = class {
|
|
|
36093
36093
|
let task = createTaskResult.task;
|
|
36094
36094
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
36095
36095
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
36096
|
-
await new Promise((
|
|
36096
|
+
await new Promise((resolve3) => setTimeout(resolve3, pollInterval));
|
|
36097
36097
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
36098
36098
|
if (!updatedTask) {
|
|
36099
36099
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -36662,8 +36662,9 @@ var EMPTY_COMPLETION_RESULT = {
|
|
|
36662
36662
|
};
|
|
36663
36663
|
|
|
36664
36664
|
// ../protocol/src/types.ts
|
|
36665
|
-
|
|
36666
|
-
|
|
36665
|
+
function mentionText(reference) {
|
|
36666
|
+
return reference.kind === "token" ? reference.name : `@${reference.name}`;
|
|
36667
|
+
}
|
|
36667
36668
|
var ATTACHMENT_TYPES = {
|
|
36668
36669
|
png: "image/png",
|
|
36669
36670
|
jpg: "image/jpeg",
|
|
@@ -36704,7 +36705,8 @@ function requestTargets(request) {
|
|
|
36704
36705
|
function formatPrompt(changeSet, options = {}) {
|
|
36705
36706
|
if (changeSet.request?.kind === "responsive") return formatResponsive(changeSet, changeSet.request);
|
|
36706
36707
|
if (changeSet.request?.kind === "break-and-fix") return formatBreakFix(changeSet, changeSet.request);
|
|
36707
|
-
if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request);
|
|
36708
|
+
if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request, options);
|
|
36709
|
+
if (changeSet.request?.kind === "props") return formatProps(changeSet, changeSet.request);
|
|
36708
36710
|
const { page, edits, note } = changeSet;
|
|
36709
36711
|
const lines = [
|
|
36710
36712
|
"# Pilot design edits",
|
|
@@ -36722,9 +36724,21 @@ function formatPrompt(changeSet, options = {}) {
|
|
|
36722
36724
|
edits.forEach((edit, index) => {
|
|
36723
36725
|
lines.push("", ...formatEdit(edit, index + 1));
|
|
36724
36726
|
});
|
|
36727
|
+
lines.push(...fileTokenLines(changeSet.fileTokens));
|
|
36725
36728
|
return `${lines.join("\n")}
|
|
36726
36729
|
`;
|
|
36727
36730
|
}
|
|
36731
|
+
function fileTokenLines(tokens) {
|
|
36732
|
+
if (!tokens?.length) return [];
|
|
36733
|
+
return [
|
|
36734
|
+
"",
|
|
36735
|
+
"## The project's tokens in these values",
|
|
36736
|
+
"",
|
|
36737
|
+
"Some values use tokens from the project's files, which Pilot previewed as CSS variables of its own: they're not in the code. Write each the way the project uses that token (its utility, its variable, its theme), never the `var(--\u2026)` itself:",
|
|
36738
|
+
"",
|
|
36739
|
+
...tokens.map((t) => `- \`var(${t.variable})\` is \`${t.name}\` in \`${t.file}${t.line ? `:${t.line}` : ""}\` (\`${t.value}\`)`)
|
|
36740
|
+
];
|
|
36741
|
+
}
|
|
36728
36742
|
var ADVANCED_TASK = "**An advanced task: it needs judgment more than speed.** If you can hand work to a more capable model than the one you run on (a subagent, or another model your agent offers), do: give it this whole prompt (with the job id), have it make the changes and run the width check, and report back; then call `pilot_done` with its notes.";
|
|
36729
36743
|
var DESIGN_INTENT = "**These are design instructions, not code**: the designer's intent, shown as plain CSS values. Use your judgment and write production code the way this project already styles things, whatever it uses (Tailwind, CSS or Sass modules, StyleX, vanilla-extract, Panda, styled-components, Emotion, a component library's props\u2026). First look at how each element's component is styled, and follow that: its tokens and scale, its variants and props, and the rule that already styles it rather than a new override.";
|
|
36730
36744
|
var PRODUCTION_CODE = "No inline styles, no `!important`, no hard-coded values where a token or utility fits.";
|
|
@@ -36758,15 +36772,49 @@ var EDIT_GUIDELINES = [
|
|
|
36758
36772
|
"- No screenshots, builds or tests for these edits: hot reload shows them, and Pilot checks the page itself.",
|
|
36759
36773
|
`- 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.`,
|
|
36760
36774
|
"- 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.",
|
|
36762
36775
|
"- 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)."
|
|
36763
36776
|
];
|
|
36764
36777
|
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.";
|
|
36765
36778
|
var PROJECT_CODE = `**Write production code in the project's own styling system**, whatever it uses (Tailwind, CSS or Sass modules, StyleX, styled-components\u2026), following how this element's component is styled: its tokens and scale, the rule that already styles it. ${PRODUCTION_CODE}`;
|
|
36766
36779
|
var ACTION_ASKED = {
|
|
36767
36780
|
responsive: "asked you to make it responsive",
|
|
36768
|
-
"break-and-fix": "asked you to break and fix it"
|
|
36781
|
+
"break-and-fix": "asked you to break and fix it",
|
|
36782
|
+
props: "asked for the component's props"
|
|
36769
36783
|
};
|
|
36784
|
+
function propValue(value) {
|
|
36785
|
+
return value === void 0 ? "*not set*" : `\`${typeof value === "string" ? JSON.stringify(value) : String(value)}\``;
|
|
36786
|
+
}
|
|
36787
|
+
function formatProps(changeSet, request) {
|
|
36788
|
+
const { page, note } = changeSet;
|
|
36789
|
+
const current = Object.entries(request.current);
|
|
36790
|
+
const lines = [
|
|
36791
|
+
"# Pilot: props",
|
|
36792
|
+
"",
|
|
36793
|
+
`A designer selected an instance of the \`${request.component}\` component in the browser with Pilot, to change it through its props from a list. Read the component's code and list its props for them. **Don't change any code.**`,
|
|
36794
|
+
"",
|
|
36795
|
+
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
36796
|
+
"",
|
|
36797
|
+
...elementsSection(request),
|
|
36798
|
+
...request.usedIn ? [`- This instance is written in: \`${request.usedIn}\``] : [],
|
|
36799
|
+
"",
|
|
36800
|
+
"## Its props now (read from the page)",
|
|
36801
|
+
"",
|
|
36802
|
+
...current.length ? current.map(([name, value]) => `- \`${name}\`: ${propValue(value)}`) : ["None that Pilot could read (it reads strings, numbers and on-off values)."],
|
|
36803
|
+
...note?.trim() ? ["", `Designer note: ${note.trim()}`] : [],
|
|
36804
|
+
...request.attachments?.length ? ["", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`)] : [],
|
|
36805
|
+
...request.references?.length ? ["", ...referenceLines(request.references)] : [],
|
|
36806
|
+
"",
|
|
36807
|
+
"## What to list",
|
|
36808
|
+
"",
|
|
36809
|
+
"- **The props that change how it looks or what it shows:** variants, sizes, tones, on-off flags (`disabled`, `loading`), short texts (a label, a title), numbers (a count). Not event handlers, refs, children, class names or styles.",
|
|
36810
|
+
'- **For each:** `name`; `type`: `options` (one of a set of values), `boolean`, `text` or `number`; for `options`, every value it accepts, from its types (a union like `"primary" | "ghost"`), its variants config (cva, tailwind-variants, a variants object), its prop validation (a Vue `validator`, `PropTypes.oneOf`), or how the component uses it; `default` when it has one; `description` in a few words when the name doesn\'t say.',
|
|
36811
|
+
"- The most useful first (the main variant, then the size, then the rest); 12 at most.",
|
|
36812
|
+
"",
|
|
36813
|
+
"Call `pilot_done` with this job's id, the list in `props`, and notes: one short sentence for the designer, like a chat message (\"Button has 3 props you can change\"). Pilot shows the props in the designer's thread, each with its value on this instance; what they pick comes back to you as a comment, a `name: value` line per prop (`tone: dark`), to set where this instance is written. If none is worth listing, say so in the notes and leave `props` out."
|
|
36814
|
+
];
|
|
36815
|
+
return `${lines.join("\n")}
|
|
36816
|
+
`;
|
|
36817
|
+
}
|
|
36770
36818
|
function formatBreakFix(changeSet, request) {
|
|
36771
36819
|
const { page, note } = changeSet;
|
|
36772
36820
|
const { breakpoints } = request;
|
|
@@ -36785,6 +36833,7 @@ function formatBreakFix(changeSet, request) {
|
|
|
36785
36833
|
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
36786
36834
|
if (request.attachments?.length)
|
|
36787
36835
|
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
36836
|
+
if (request.references?.length) lines.push("", ...referenceLines(request.references));
|
|
36788
36837
|
lines.push(
|
|
36789
36838
|
"",
|
|
36790
36839
|
...elementsSection(request),
|
|
@@ -36829,6 +36878,7 @@ function formatResponsive(changeSet, request) {
|
|
|
36829
36878
|
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
36830
36879
|
if (request.attachments?.length)
|
|
36831
36880
|
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
36881
|
+
if (request.references?.length) lines.push("", ...referenceLines(request.references));
|
|
36832
36882
|
lines.push(
|
|
36833
36883
|
"",
|
|
36834
36884
|
...elementsSection(request),
|
|
@@ -36851,8 +36901,8 @@ function formatResponsive(changeSet, request) {
|
|
|
36851
36901
|
return `${lines.join("\n")}
|
|
36852
36902
|
`;
|
|
36853
36903
|
}
|
|
36854
|
-
function formatComment(changeSet, request) {
|
|
36855
|
-
const { page } = changeSet;
|
|
36904
|
+
function formatComment(changeSet, request, options = {}) {
|
|
36905
|
+
const { page, edits } = changeSet;
|
|
36856
36906
|
const { thread, breakpoints } = request;
|
|
36857
36907
|
const several = requestTargets(request).length;
|
|
36858
36908
|
const latest = thread.at(-1);
|
|
@@ -36870,8 +36920,34 @@ function formatComment(changeSet, request) {
|
|
|
36870
36920
|
"",
|
|
36871
36921
|
"## The comment",
|
|
36872
36922
|
"",
|
|
36873
|
-
|
|
36923
|
+
// Props set from the thread, with no words: the props are the comment.
|
|
36924
|
+
...latest?.props && !latest.text.trim() && !latest.attachments?.length ? ["The designer set props on this instance (below), with no words."] : commentLines(latest)
|
|
36874
36925
|
];
|
|
36926
|
+
if (latest?.props?.set.length) {
|
|
36927
|
+
const { component, usedIn, set: set2 } = latest.props;
|
|
36928
|
+
lines.push(
|
|
36929
|
+
"",
|
|
36930
|
+
"## Props to set",
|
|
36931
|
+
"",
|
|
36932
|
+
`The designer picked new values for this \`${component}\` instance's props from the list you gave (the \`name: value\` lines in their comment):`,
|
|
36933
|
+
"",
|
|
36934
|
+
...set2.map((c) => `- \`${c.name}\`: ${propValue(c.from)} \u2192 ${propValue(c.to)}`),
|
|
36935
|
+
"",
|
|
36936
|
+
`Set them where this instance is written${usedIn ? ` (\`${usedIn}\`, its \`<${component} \u2026>\`)` : ` (its \`<${component} \u2026>\`)`}, not in the component itself: only this instance changes. If that line renders several instances (a loop over data) or the value comes from data or a variable, ask with \`pilot_done\`'s question and choices before changing it for all of them. Pilot reads the instance's props on the page when you're done.`
|
|
36937
|
+
);
|
|
36938
|
+
}
|
|
36939
|
+
if (edits.length) {
|
|
36940
|
+
lines.push(
|
|
36941
|
+
"",
|
|
36942
|
+
"## The designer's edits, sent with the comment",
|
|
36943
|
+
"",
|
|
36944
|
+
`Before writing it, the designer changed these in Pilot's editor: apply them too, exactly, as design edits. The comment may be about them ("like this, on mobile too"). Pilot checks them on the page when you're done.`,
|
|
36945
|
+
"",
|
|
36946
|
+
...options.guidelines === false ? [EDIT_GUIDELINES_REMINDER] : ["Guidelines:", ...EDIT_GUIDELINES]
|
|
36947
|
+
);
|
|
36948
|
+
edits.forEach((edit, index) => lines.push("", ...formatEdit(edit, index + 1).map((l) => l.startsWith("## ") ? `#${l}` : l)));
|
|
36949
|
+
lines.push(...fileTokenLines(changeSet.fileTokens));
|
|
36950
|
+
}
|
|
36875
36951
|
if (earlier.length) {
|
|
36876
36952
|
lines.push("", "## The thread so far (you already did what it asked)", "");
|
|
36877
36953
|
for (const m of earlier) {
|
|
@@ -36900,6 +36976,8 @@ function commentLines(message) {
|
|
|
36900
36976
|
const text = message?.text.trim() ?? "";
|
|
36901
36977
|
const files = message?.attachments ?? [];
|
|
36902
36978
|
const out = text ? [quote(text)] : [];
|
|
36979
|
+
const references = message?.references ?? [];
|
|
36980
|
+
if (references.length) out.push("", ...referenceLines(references));
|
|
36903
36981
|
if (!files.length) return out.length ? out : ["> (empty)"];
|
|
36904
36982
|
const one = files.length === 1;
|
|
36905
36983
|
if (out.length) out.push("");
|
|
@@ -36910,6 +36988,32 @@ function commentLines(message) {
|
|
|
36910
36988
|
);
|
|
36911
36989
|
return out;
|
|
36912
36990
|
}
|
|
36991
|
+
function referenceLines(references) {
|
|
36992
|
+
const picked = references.some((r) => r.kind !== "unlisted");
|
|
36993
|
+
return [
|
|
36994
|
+
picked ? "What it mentions with `@`, each as it reads in the comment (the ones picked from Pilot's list are exact: use them, don't look for others):" : "What it mentions with `@`, as it reads in the comment:",
|
|
36995
|
+
"",
|
|
36996
|
+
...references.map(referenceLine)
|
|
36997
|
+
];
|
|
36998
|
+
}
|
|
36999
|
+
function referenceLine(reference) {
|
|
37000
|
+
const as = `- \`${mentionText(reference)}\`:`;
|
|
37001
|
+
if (reference.kind === "token" && reference.source)
|
|
37002
|
+
return `${as} a design token from the project's files (\`${reference.source.file}${reference.source.line ? `:${reference.source.line}` : ""}\`), now \`${reference.value}\`. Use this token the way the project does (its utility, its variable, its theme); it isn't a CSS variable on the page.`;
|
|
37003
|
+
if (reference.kind === "token")
|
|
37004
|
+
return `${as} a design token (a CSS variable on the page), now \`${reference.value}\`. Use this token (\`var(${reference.name})\`, or the project's form of it).`;
|
|
37005
|
+
if (reference.kind === "unlisted")
|
|
37006
|
+
return `${as} a name the designer typed that Pilot didn't find on the page or among the project's components: probably a component or a part of the page. Search the project for \`${reference.name}\`, and ask in your reply if it's unclear what it is.`;
|
|
37007
|
+
if (reference.kind === "component") {
|
|
37008
|
+
const t = reference.target;
|
|
37009
|
+
const source = reference.source ?? (t?.source?.file ? { file: t.source.file, line: t.source.line } : void 0);
|
|
37010
|
+
const where = source ? `, declared in \`${source.file}${source.line ? `:${source.line}` : ""}\`` : `; find its declaration (\`function ${reference.name}\`, \`const ${reference.name} =\`, \`class ${reference.name}\`, or a \`${reference.name}.vue\` or \`.svelte\` file)`;
|
|
37011
|
+
return t ? `${as} the \`${reference.name}\` component${where}; one of its instances on the page: \`${t.selector}\`.` : `${as} the \`${reference.name}\` component${where}. It isn't on this page.`;
|
|
37012
|
+
}
|
|
37013
|
+
const el = reference.target;
|
|
37014
|
+
const component = el.source?.component ? `, inside the \`${el.source.component}\` component` : "";
|
|
37015
|
+
return `${as} an element on the page: \`${el.path}\`, selector \`${el.selector}\`${el.text ? `, text "${el.text}"` : ""}${component}.`;
|
|
37016
|
+
}
|
|
36913
37017
|
function attachmentLines(files, intro) {
|
|
36914
37018
|
const lines = files.map((file2) => {
|
|
36915
37019
|
const kind = attachmentKind(file2.id);
|
|
@@ -36947,15 +37051,8 @@ function targetLines(target) {
|
|
|
36947
37051
|
return out;
|
|
36948
37052
|
}
|
|
36949
37053
|
function formatEdit(edit, n) {
|
|
36950
|
-
const { target, changes, texts
|
|
36951
|
-
const out =
|
|
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));
|
|
37054
|
+
const { target, changes, texts } = edit;
|
|
37055
|
+
const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
|
|
36959
37056
|
if (texts?.length) out.push("", "Text (from \u2192 to):", "", ...texts.map((t) => `- ${JSON.stringify(t.from)} \u2192 ${JSON.stringify(t.to)}`));
|
|
36960
37057
|
if (!changes.length) return out;
|
|
36961
37058
|
const withStates = changes.some((c) => c.states?.length);
|
|
@@ -36974,11 +37071,6 @@ function formatEdit(edit, n) {
|
|
|
36974
37071
|
if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
|
|
36975
37072
|
return out;
|
|
36976
37073
|
}
|
|
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
|
-
}
|
|
36982
37074
|
function describeStates(states) {
|
|
36983
37075
|
return states?.length ? states.join(", ") : "\u2014";
|
|
36984
37076
|
}
|
|
@@ -37033,7 +37125,7 @@ function formatWidthCheck(check2) {
|
|
|
37033
37125
|
}
|
|
37034
37126
|
|
|
37035
37127
|
// ../protocol/src/bridge.ts
|
|
37036
|
-
var BRIDGE_VERSION =
|
|
37128
|
+
var BRIDGE_VERSION = 6;
|
|
37037
37129
|
var DEFAULT_BRIDGE_PORT = 4747 + BRIDGE_VERSION;
|
|
37038
37130
|
var MAX_CHOICES = 4;
|
|
37039
37131
|
function questionOf(value) {
|
|
@@ -37042,6 +37134,28 @@ function questionOf(value) {
|
|
|
37042
37134
|
const choices = (Array.isArray(q.choices) ? q.choices : []).filter((c) => typeof c === "string").map((c) => c.trim().slice(0, 60)).filter(Boolean).slice(0, MAX_CHOICES);
|
|
37043
37135
|
return { text: q.text.trim().slice(0, 500), ...choices.length ? { choices } : {} };
|
|
37044
37136
|
}
|
|
37137
|
+
var MAX_PROPS = 20;
|
|
37138
|
+
function propsOf(value) {
|
|
37139
|
+
if (!Array.isArray(value)) return void 0;
|
|
37140
|
+
const scalar = (v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
37141
|
+
const props = value.flatMap((p) => {
|
|
37142
|
+
const name = typeof p?.name === "string" ? p.name.trim().slice(0, 60) : "";
|
|
37143
|
+
const type = ["options", "boolean", "text", "number"].includes(p?.type) ? p.type : null;
|
|
37144
|
+
if (!name || !type) return [];
|
|
37145
|
+
const options = Array.isArray(p.options) ? [...new Set(p.options.filter(scalar).map(String))].slice(0, 30) : [];
|
|
37146
|
+
if (type === "options" && !options.length) return [];
|
|
37147
|
+
return [
|
|
37148
|
+
{
|
|
37149
|
+
name,
|
|
37150
|
+
type,
|
|
37151
|
+
...type === "options" ? { options } : {},
|
|
37152
|
+
...scalar(p.default) ? { default: p.default } : {},
|
|
37153
|
+
...typeof p.description === "string" && p.description.trim() ? { description: p.description.trim().slice(0, 120) } : {}
|
|
37154
|
+
}
|
|
37155
|
+
];
|
|
37156
|
+
});
|
|
37157
|
+
return props.length ? props.slice(0, MAX_PROPS) : void 0;
|
|
37158
|
+
}
|
|
37045
37159
|
function originOf(url2) {
|
|
37046
37160
|
try {
|
|
37047
37161
|
const u = new URL(url2.includes("://") ? url2 : `http://${url2}`);
|
|
@@ -37173,6 +37287,284 @@ async function sweepAttachments(dir = attachmentsDir(), now = Date.now()) {
|
|
|
37173
37287
|
}
|
|
37174
37288
|
}
|
|
37175
37289
|
|
|
37290
|
+
// src/components.ts
|
|
37291
|
+
import { existsSync as existsSync2, readdirSync, readFileSync, statSync } from "fs";
|
|
37292
|
+
import { basename as basename2, dirname as dirname2, extname, join as join2, relative } from "path";
|
|
37293
|
+
var SKIP = /* @__PURE__ */ new Set([
|
|
37294
|
+
"node_modules",
|
|
37295
|
+
"dist",
|
|
37296
|
+
"build",
|
|
37297
|
+
"out",
|
|
37298
|
+
"coverage",
|
|
37299
|
+
"vendor",
|
|
37300
|
+
".git",
|
|
37301
|
+
".next",
|
|
37302
|
+
".nuxt",
|
|
37303
|
+
".svelte-kit",
|
|
37304
|
+
".output",
|
|
37305
|
+
".vercel",
|
|
37306
|
+
".turbo",
|
|
37307
|
+
".cache",
|
|
37308
|
+
"storybook-static",
|
|
37309
|
+
"__tests__",
|
|
37310
|
+
"__mocks__"
|
|
37311
|
+
]);
|
|
37312
|
+
var EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx", ".js", ".vue", ".svelte"]);
|
|
37313
|
+
var NOT_COMPONENTS = /\.(test|spec|stories|story|d)\.[jt]sx?$/;
|
|
37314
|
+
var ROUTE_FILES = /^(page|layout|template|loading|error|not-found|default|route|_app|_document)\.[jt]sx?$/;
|
|
37315
|
+
var MAX_FILES = 8e3;
|
|
37316
|
+
var MAX_FILE_BYTES = 512e3;
|
|
37317
|
+
var BUDGET_MS = 1500;
|
|
37318
|
+
var cache = /* @__PURE__ */ new Map();
|
|
37319
|
+
function projectComponents(folders) {
|
|
37320
|
+
const roots = [...new Set(folders.map(workspaceRoot))];
|
|
37321
|
+
const out = [];
|
|
37322
|
+
const seen = /* @__PURE__ */ new Set();
|
|
37323
|
+
const deadline = Date.now() + BUDGET_MS;
|
|
37324
|
+
for (const root of roots) {
|
|
37325
|
+
for (const c of scan(root, deadline)) {
|
|
37326
|
+
const key = `${c.name} ${c.file}`;
|
|
37327
|
+
if (!seen.has(key)) {
|
|
37328
|
+
seen.add(key);
|
|
37329
|
+
out.push(c);
|
|
37330
|
+
}
|
|
37331
|
+
}
|
|
37332
|
+
}
|
|
37333
|
+
return out;
|
|
37334
|
+
}
|
|
37335
|
+
function workspaceRoot(folder) {
|
|
37336
|
+
let dir = folder;
|
|
37337
|
+
for (; ; ) {
|
|
37338
|
+
if (isWorkspace(dir)) return dir;
|
|
37339
|
+
const parent = dirname2(dir);
|
|
37340
|
+
if (existsSync2(join2(dir, ".git")) || parent === dir) return folder;
|
|
37341
|
+
dir = parent;
|
|
37342
|
+
}
|
|
37343
|
+
}
|
|
37344
|
+
function isWorkspace(dir) {
|
|
37345
|
+
if (["pnpm-workspace.yaml", "lerna.json", "nx.json", "turbo.json"].some((f) => existsSync2(join2(dir, f)))) return true;
|
|
37346
|
+
try {
|
|
37347
|
+
return "workspaces" in JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
37348
|
+
} catch {
|
|
37349
|
+
return false;
|
|
37350
|
+
}
|
|
37351
|
+
}
|
|
37352
|
+
function scan(root, deadline) {
|
|
37353
|
+
const known = cache.get(root) ?? /* @__PURE__ */ new Map();
|
|
37354
|
+
const now = /* @__PURE__ */ new Map();
|
|
37355
|
+
const out = [];
|
|
37356
|
+
const walk = (dir) => {
|
|
37357
|
+
let entries;
|
|
37358
|
+
try {
|
|
37359
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
37360
|
+
} catch {
|
|
37361
|
+
return;
|
|
37362
|
+
}
|
|
37363
|
+
for (const entry of entries) {
|
|
37364
|
+
if (now.size >= MAX_FILES || Date.now() > deadline) return;
|
|
37365
|
+
const name = entry.name;
|
|
37366
|
+
if (SKIP.has(name) || name.startsWith(".")) continue;
|
|
37367
|
+
const path = join2(dir, name);
|
|
37368
|
+
if (entry.isDirectory()) {
|
|
37369
|
+
walk(path);
|
|
37370
|
+
continue;
|
|
37371
|
+
}
|
|
37372
|
+
if (!entry.isFile() || !EXTENSIONS.has(extname(name)) || NOT_COMPONENTS.test(name) || ROUTE_FILES.test(name)) continue;
|
|
37373
|
+
let stat2;
|
|
37374
|
+
try {
|
|
37375
|
+
stat2 = statSync(path);
|
|
37376
|
+
} catch {
|
|
37377
|
+
continue;
|
|
37378
|
+
}
|
|
37379
|
+
if (stat2.size > MAX_FILE_BYTES) continue;
|
|
37380
|
+
const before = known.get(path);
|
|
37381
|
+
const cached2 = before && before.mtime === stat2.mtimeMs ? before : { mtime: stat2.mtimeMs, components: read(path) };
|
|
37382
|
+
now.set(path, cached2);
|
|
37383
|
+
const file2 = relative(root, path);
|
|
37384
|
+
for (const c of cached2.components) out.push({ name: c.name, file: file2, line: c.line });
|
|
37385
|
+
}
|
|
37386
|
+
};
|
|
37387
|
+
walk(root);
|
|
37388
|
+
cache.set(root, now);
|
|
37389
|
+
return out;
|
|
37390
|
+
}
|
|
37391
|
+
function fileComponentName(path) {
|
|
37392
|
+
return basename2(path, extname(path)).split(/[-_.\s]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join("");
|
|
37393
|
+
}
|
|
37394
|
+
var NAME = "[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*";
|
|
37395
|
+
var FUNCTION = new RegExp(`^\\s*(export\\s+)?(?:default\\s+)?(?:async\\s+)?function\\s+(${NAME})\\b`);
|
|
37396
|
+
var CONSTANT = new RegExp(`^\\s*(export\\s+)?(?:const|let|var)\\s+(${NAME})\\s*(?::[^=]+)?=\\s*(.*)$`);
|
|
37397
|
+
var COMPONENT_VALUE = /^(?:\(|async\s*\(|function\b|[A-Za-z_$][\w$]*\s*=>|(?:React\.)?(?:forwardRef|memo|lazy)\b|styled[.(]|defineComponent\b|component\$)/;
|
|
37398
|
+
function read(path) {
|
|
37399
|
+
const ext = extname(path);
|
|
37400
|
+
if (ext === ".vue" || ext === ".svelte") return [{ name: fileComponentName(path), line: 1 }];
|
|
37401
|
+
let source;
|
|
37402
|
+
try {
|
|
37403
|
+
source = readFileSync(path, "utf8");
|
|
37404
|
+
} catch {
|
|
37405
|
+
return [];
|
|
37406
|
+
}
|
|
37407
|
+
if (!/<[A-Za-z]|styled[.(]/.test(source)) return [];
|
|
37408
|
+
const found = [];
|
|
37409
|
+
const lines = source.split("\n");
|
|
37410
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37411
|
+
const line = lines[i];
|
|
37412
|
+
const fn = FUNCTION.exec(line);
|
|
37413
|
+
const constant = fn ? null : CONSTANT.exec(line);
|
|
37414
|
+
const m = fn ?? constant;
|
|
37415
|
+
if (!m) continue;
|
|
37416
|
+
const name = m[2];
|
|
37417
|
+
if (constant && !COMPONENT_VALUE.test((constant[3] ?? "").trim())) continue;
|
|
37418
|
+
const exported = !!m[1] || new RegExp(`export\\s+default\\s+${name}\\b|export\\s*\\{[^}]*\\b${name}\\b[^}]*\\}`).test(source);
|
|
37419
|
+
if (exported && !found.some((f) => f.name === name)) found.push({ name, line: i + 1 });
|
|
37420
|
+
}
|
|
37421
|
+
return found;
|
|
37422
|
+
}
|
|
37423
|
+
|
|
37424
|
+
// src/tokenFiles.ts
|
|
37425
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
37426
|
+
import { basename as basename3, dirname as dirname3, join as join3, relative as relative2 } from "path";
|
|
37427
|
+
var MAX_FILES2 = 8e3;
|
|
37428
|
+
var MAX_FILE_BYTES2 = 512e3;
|
|
37429
|
+
var MAX_TOKENS = 1e3;
|
|
37430
|
+
var BUDGET_MS2 = 1500;
|
|
37431
|
+
function isTokenJson(path) {
|
|
37432
|
+
const name = basename3(path).toLowerCase();
|
|
37433
|
+
if (!name.endsWith(".json") || name === "package.json" || name.startsWith("tsconfig")) return false;
|
|
37434
|
+
return /(^|[.-])(design-)?tokens?\.json$/.test(name) || /(^|\/)(design-)?tokens?$/.test(dirname3(path).toLowerCase());
|
|
37435
|
+
}
|
|
37436
|
+
function isTokenSass(path) {
|
|
37437
|
+
const name = basename3(path).toLowerCase();
|
|
37438
|
+
return /\.s[ac]ss$/.test(name) && /(token|variable|vars?\b|theme|colou?r|spacing|typograph|radius|radii|shadow|breakpoint)/.test(name);
|
|
37439
|
+
}
|
|
37440
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
37441
|
+
function fileTokens(folders) {
|
|
37442
|
+
const out = [];
|
|
37443
|
+
const seen = /* @__PURE__ */ new Set();
|
|
37444
|
+
const deadline = Date.now() + BUDGET_MS2;
|
|
37445
|
+
for (const root of new Set(folders.map(workspaceRoot))) {
|
|
37446
|
+
for (const t of scan2(root, deadline)) {
|
|
37447
|
+
if (out.length >= MAX_TOKENS) return out;
|
|
37448
|
+
if (!seen.has(t.name)) {
|
|
37449
|
+
seen.add(t.name);
|
|
37450
|
+
out.push(t);
|
|
37451
|
+
}
|
|
37452
|
+
}
|
|
37453
|
+
}
|
|
37454
|
+
return out;
|
|
37455
|
+
}
|
|
37456
|
+
function scan2(root, deadline) {
|
|
37457
|
+
const known = cache2.get(root) ?? /* @__PURE__ */ new Map();
|
|
37458
|
+
const now = /* @__PURE__ */ new Map();
|
|
37459
|
+
const out = [];
|
|
37460
|
+
let files = 0;
|
|
37461
|
+
const walk = (dir) => {
|
|
37462
|
+
let entries;
|
|
37463
|
+
try {
|
|
37464
|
+
entries = readdirSync2(dir, { withFileTypes: true });
|
|
37465
|
+
} catch {
|
|
37466
|
+
return;
|
|
37467
|
+
}
|
|
37468
|
+
for (const entry of entries) {
|
|
37469
|
+
if (files >= MAX_FILES2 || Date.now() > deadline) return;
|
|
37470
|
+
const name = entry.name;
|
|
37471
|
+
if (SKIP.has(name) || name.startsWith(".")) continue;
|
|
37472
|
+
const path = join3(dir, name);
|
|
37473
|
+
if (entry.isDirectory()) {
|
|
37474
|
+
walk(path);
|
|
37475
|
+
continue;
|
|
37476
|
+
}
|
|
37477
|
+
files++;
|
|
37478
|
+
const json3 = isTokenJson(path);
|
|
37479
|
+
if (!entry.isFile() || !(json3 || isTokenSass(path))) continue;
|
|
37480
|
+
let stat2;
|
|
37481
|
+
try {
|
|
37482
|
+
stat2 = statSync2(path);
|
|
37483
|
+
} catch {
|
|
37484
|
+
continue;
|
|
37485
|
+
}
|
|
37486
|
+
if (stat2.size > MAX_FILE_BYTES2) continue;
|
|
37487
|
+
const before = known.get(path);
|
|
37488
|
+
const file2 = relative2(root, path);
|
|
37489
|
+
const cached2 = before && before.mtime === stat2.mtimeMs ? before : { mtime: stat2.mtimeMs, tokens: read2(path, file2, json3) };
|
|
37490
|
+
now.set(path, cached2);
|
|
37491
|
+
out.push(...cached2.tokens);
|
|
37492
|
+
}
|
|
37493
|
+
};
|
|
37494
|
+
walk(root);
|
|
37495
|
+
cache2.set(root, now);
|
|
37496
|
+
return out;
|
|
37497
|
+
}
|
|
37498
|
+
function read2(path, file2, json3) {
|
|
37499
|
+
let text;
|
|
37500
|
+
try {
|
|
37501
|
+
text = readFileSync2(path, "utf8");
|
|
37502
|
+
} catch {
|
|
37503
|
+
return [];
|
|
37504
|
+
}
|
|
37505
|
+
return json3 ? jsonTokens(text, file2) : sassTokens(text, file2);
|
|
37506
|
+
}
|
|
37507
|
+
function jsonTokens(text, file2) {
|
|
37508
|
+
let data;
|
|
37509
|
+
try {
|
|
37510
|
+
data = JSON.parse(text);
|
|
37511
|
+
} catch {
|
|
37512
|
+
return [];
|
|
37513
|
+
}
|
|
37514
|
+
const raw = /* @__PURE__ */ new Map();
|
|
37515
|
+
const walk = (node2, path) => {
|
|
37516
|
+
if (!node2 || typeof node2 !== "object" || Array.isArray(node2)) return;
|
|
37517
|
+
const n = node2;
|
|
37518
|
+
const value = "$value" in n ? n.$value : "value" in n && typeof n.value !== "object" ? n.value : void 0;
|
|
37519
|
+
if (value !== void 0) {
|
|
37520
|
+
if ((typeof value === "string" || typeof value === "number") && path.length) raw.set(path.join("."), String(value));
|
|
37521
|
+
return;
|
|
37522
|
+
}
|
|
37523
|
+
for (const [key, child] of Object.entries(n)) if (!key.startsWith("$")) walk(child, [...path, key]);
|
|
37524
|
+
};
|
|
37525
|
+
walk(data, []);
|
|
37526
|
+
const lines = text.split("\n");
|
|
37527
|
+
const out = [];
|
|
37528
|
+
for (const [name, value] of raw) {
|
|
37529
|
+
const resolved = resolve(value, (ref) => raw.get(ref), /\{([^{}]+)\}/g);
|
|
37530
|
+
if (resolved === null) continue;
|
|
37531
|
+
const last = name.split(".").at(-1);
|
|
37532
|
+
const at = lines.findIndex((l) => l.includes(`"${last}"`));
|
|
37533
|
+
out.push({ name, value: resolved, file: file2, ...at >= 0 ? { line: at + 1 } : {} });
|
|
37534
|
+
}
|
|
37535
|
+
return out;
|
|
37536
|
+
}
|
|
37537
|
+
function sassTokens(text, file2) {
|
|
37538
|
+
const raw = /* @__PURE__ */ new Map();
|
|
37539
|
+
text.split("\n").forEach((line, i) => {
|
|
37540
|
+
const m = /^\s*\$([\w-]+)\s*:\s*([^;]+?)\s*(?:!default|!global)*\s*;/.exec(line);
|
|
37541
|
+
if (m && !raw.has(m[1])) raw.set(m[1], { value: m[2], line: i + 1 });
|
|
37542
|
+
});
|
|
37543
|
+
const out = [];
|
|
37544
|
+
for (const [name, { value, line }] of raw) {
|
|
37545
|
+
if (/[\w-]\([^)]*\$|map-get|\bif\(|^\(/.test(value)) continue;
|
|
37546
|
+
const resolved = resolve(value, (ref) => raw.get(ref)?.value, /\$([\w-]+)/g);
|
|
37547
|
+
if (resolved === null || resolved.includes("$")) continue;
|
|
37548
|
+
out.push({ name: `$${name}`, value: resolved, file: file2, line });
|
|
37549
|
+
}
|
|
37550
|
+
return out;
|
|
37551
|
+
}
|
|
37552
|
+
function resolve(value, get, pattern) {
|
|
37553
|
+
let v = value;
|
|
37554
|
+
for (let depth = 0; depth < 8; depth++) {
|
|
37555
|
+
let missing = false;
|
|
37556
|
+
const next = v.replace(pattern, (_, ref) => {
|
|
37557
|
+
const found = get(ref);
|
|
37558
|
+
if (found === void 0) missing = true;
|
|
37559
|
+
return found ?? "";
|
|
37560
|
+
});
|
|
37561
|
+
if (missing) return null;
|
|
37562
|
+
if (next === v) return v.trim();
|
|
37563
|
+
v = next;
|
|
37564
|
+
}
|
|
37565
|
+
return null;
|
|
37566
|
+
}
|
|
37567
|
+
|
|
37176
37568
|
// src/hub.ts
|
|
37177
37569
|
import { randomUUID } from "crypto";
|
|
37178
37570
|
var AGENT_TTL = 3e4;
|
|
@@ -37191,7 +37583,8 @@ var Hub = class {
|
|
|
37191
37583
|
register(info, origin) {
|
|
37192
37584
|
const key = originKey(origin);
|
|
37193
37585
|
const known = this.agents.get(info.id);
|
|
37194
|
-
|
|
37586
|
+
const { folder, ...shown } = info;
|
|
37587
|
+
this.agents.set(info.id, { info: shown, origin: key, seen: this.now(), folder: folder ?? known?.folder });
|
|
37195
37588
|
if (!known || known.origin !== key) {
|
|
37196
37589
|
if (known) this.notifyAgents(known.origin);
|
|
37197
37590
|
this.notifyAgents(key);
|
|
@@ -37213,6 +37606,15 @@ var Hub = class {
|
|
|
37213
37606
|
this.notifyAgents(agent.origin);
|
|
37214
37607
|
this.dispatch(agent.origin);
|
|
37215
37608
|
}
|
|
37609
|
+
/** An agent's info as pages see it (no folder). */
|
|
37610
|
+
shown(info) {
|
|
37611
|
+
return this.agents.get(info.id)?.info ?? { id: info.id, label: info.label };
|
|
37612
|
+
}
|
|
37613
|
+
/** The project folders of the agents working on pages of `origin`: where its components are read from. */
|
|
37614
|
+
folders(origin) {
|
|
37615
|
+
const key = originKey(origin);
|
|
37616
|
+
return [...new Set([...this.agents.values()].filter((a) => a.origin === key && a.folder).map((a) => a.folder))];
|
|
37617
|
+
}
|
|
37216
37618
|
/** Drops agents not heard from in AGENT_TTL (`keep`: the ones in this process, always alive). */
|
|
37217
37619
|
sweep(keep = /* @__PURE__ */ new Set()) {
|
|
37218
37620
|
const cutoff = this.now() - AGENT_TTL;
|
|
@@ -37223,7 +37625,7 @@ var Hub = class {
|
|
|
37223
37625
|
/** An agent ran /pilot: registers it and tells the open pages of `origin` to launch Pilot. Returns how many pages got it. */
|
|
37224
37626
|
launch(info, origin) {
|
|
37225
37627
|
this.register(info, origin);
|
|
37226
|
-
return this.sendTo(originKey(origin), { type: "launch", agent: info });
|
|
37628
|
+
return this.sendTo(originKey(origin), { type: "launch", agent: this.shown(info) });
|
|
37227
37629
|
}
|
|
37228
37630
|
/**
|
|
37229
37631
|
* The agent's next job for its origin: the oldest queued one right away, or
|
|
@@ -37234,15 +37636,15 @@ var Hub = class {
|
|
|
37234
37636
|
this.register(info, origin);
|
|
37235
37637
|
const key = originKey(origin);
|
|
37236
37638
|
const queued = this.oldestQueued(key);
|
|
37237
|
-
if (queued) return Promise.resolve({ job: this.take(queued, info) });
|
|
37238
|
-
return new Promise((
|
|
37639
|
+
if (queued) return Promise.resolve({ job: this.take(queued, this.shown(info)) });
|
|
37640
|
+
return new Promise((resolve3) => {
|
|
37239
37641
|
const waiter = {
|
|
37240
37642
|
agentId: info.id,
|
|
37241
37643
|
origin: key,
|
|
37242
37644
|
resolve: (job) => {
|
|
37243
37645
|
clearTimeout(timer);
|
|
37244
37646
|
signal?.removeEventListener("abort", onAbort);
|
|
37245
|
-
|
|
37647
|
+
resolve3({ job });
|
|
37246
37648
|
}
|
|
37247
37649
|
};
|
|
37248
37650
|
const timer = setTimeout(() => this.endWait(waiter, null), timeoutMs);
|
|
@@ -37258,12 +37660,20 @@ var Hub = class {
|
|
|
37258
37660
|
* the answer, see answer). A job asks once: a question on an answered job
|
|
37259
37661
|
* is dropped. Null for a job the hub doesn't know.
|
|
37260
37662
|
*/
|
|
37261
|
-
done(agentId, jobId, notes, question) {
|
|
37663
|
+
done(agentId, jobId, notes, question, props) {
|
|
37262
37664
|
const job = this.jobs.get(jobId);
|
|
37263
37665
|
if (!job || job.status === "cancelled") return null;
|
|
37264
37666
|
const agent = this.agents.get(agentId)?.info ?? job.agent;
|
|
37265
37667
|
const asks = question && !job.answer ? { question } : {};
|
|
37266
|
-
|
|
37668
|
+
const listed = props?.length && job.changeSet.request?.kind === "props" ? { props } : {};
|
|
37669
|
+
this.update(job, {
|
|
37670
|
+
status: "done",
|
|
37671
|
+
agent,
|
|
37672
|
+
notes: notes?.trim() || void 0,
|
|
37673
|
+
doneAt: new Date(this.now()).toISOString(),
|
|
37674
|
+
...asks,
|
|
37675
|
+
...listed
|
|
37676
|
+
});
|
|
37267
37677
|
return job;
|
|
37268
37678
|
}
|
|
37269
37679
|
/**
|
|
@@ -37288,12 +37698,12 @@ var Hub = class {
|
|
|
37288
37698
|
const job = this.jobs.get(jobId);
|
|
37289
37699
|
if (!job) return Promise.resolve(null);
|
|
37290
37700
|
const requestId = randomUUID();
|
|
37291
|
-
return new Promise((
|
|
37701
|
+
return new Promise((resolve3) => {
|
|
37292
37702
|
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
37293
37703
|
const finish = (check2) => {
|
|
37294
37704
|
clearTimeout(timer);
|
|
37295
37705
|
this.checks.delete(requestId);
|
|
37296
|
-
|
|
37706
|
+
resolve3(check2);
|
|
37297
37707
|
};
|
|
37298
37708
|
this.checks.set(requestId, { origin: job.origin, resolve: finish });
|
|
37299
37709
|
if (!this.sendTo(job.origin, { type: "check", requestId, jobId })) finish(null);
|
|
@@ -37438,14 +37848,14 @@ function startHub(port, hub = new Hub(), options = {}) {
|
|
|
37438
37848
|
});
|
|
37439
37849
|
const sweep = setInterval(() => hub.sweep(localAgents), 5e3);
|
|
37440
37850
|
sweep.unref();
|
|
37441
|
-
return new Promise((
|
|
37851
|
+
return new Promise((resolve3, reject) => {
|
|
37442
37852
|
server.once("error", (error62) => {
|
|
37443
37853
|
clearInterval(sweep);
|
|
37444
37854
|
reject(error62);
|
|
37445
37855
|
});
|
|
37446
37856
|
server.listen(port, "127.0.0.1", () => {
|
|
37447
37857
|
const address = server.address();
|
|
37448
|
-
|
|
37858
|
+
resolve3({
|
|
37449
37859
|
hub,
|
|
37450
37860
|
server,
|
|
37451
37861
|
port: typeof address === "object" && address ? address.port : port,
|
|
@@ -37482,6 +37892,8 @@ async function handle(hub, req, res, attachments) {
|
|
|
37482
37892
|
if (path === "/events" && req.method === "GET") return events(hub, origin, req, res);
|
|
37483
37893
|
if (req.method !== "POST") return json2(res, 405, { error: "POST only" });
|
|
37484
37894
|
if (!hub.hasAgents(origin)) return json2(res, 403, { error: "no agent works on this page: run /pilot in your agent" });
|
|
37895
|
+
if (path === "/components") return json2(res, 200, { components: projectComponents(hub.folders(origin)) });
|
|
37896
|
+
if (path === "/tokens") return json2(res, 200, { tokens: fileTokens(hub.folders(origin)) });
|
|
37485
37897
|
if (path === "/attachments") {
|
|
37486
37898
|
const type = req.headers["content-type"] ?? "";
|
|
37487
37899
|
if (!extensionOf(type)) return json2(res, 415, { error: "images (png, jpeg, gif, webp), text files (txt, md, csv, json) and PDFs only" });
|
|
@@ -37555,7 +37967,7 @@ async function handleAgent(hub, action, data, req, res) {
|
|
|
37555
37967
|
}
|
|
37556
37968
|
case "done":
|
|
37557
37969
|
if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
|
|
37558
|
-
return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes, questionOf(d.question)) });
|
|
37970
|
+
return json2(res, 200, { job: hub.done(d.agent.id, d.jobId, d.notes, questionOf(d.question), propsOf(d.props)) });
|
|
37559
37971
|
case "check": {
|
|
37560
37972
|
if (!d.jobId) return json2(res, 400, { error: "jobId needed" });
|
|
37561
37973
|
const check2 = await hub.check(d.jobId, Math.min(d.timeoutMs ?? CHECK_TIMEOUT, 2 * 6e4));
|
|
@@ -37578,7 +37990,7 @@ function json2(res, status, data) {
|
|
|
37578
37990
|
res.end(JSON.stringify(data));
|
|
37579
37991
|
}
|
|
37580
37992
|
function rawBody(req, max) {
|
|
37581
|
-
return new Promise((
|
|
37993
|
+
return new Promise((resolve3, reject) => {
|
|
37582
37994
|
const chunks = [];
|
|
37583
37995
|
let size = 0;
|
|
37584
37996
|
let over = false;
|
|
@@ -37587,20 +37999,20 @@ function rawBody(req, max) {
|
|
|
37587
37999
|
size += chunk.length;
|
|
37588
38000
|
if (size > max) {
|
|
37589
38001
|
over = true;
|
|
37590
|
-
|
|
38002
|
+
resolve3(null);
|
|
37591
38003
|
req.resume();
|
|
37592
38004
|
return;
|
|
37593
38005
|
}
|
|
37594
38006
|
chunks.push(chunk);
|
|
37595
38007
|
});
|
|
37596
38008
|
req.on("end", () => {
|
|
37597
|
-
if (!over)
|
|
38009
|
+
if (!over) resolve3(Buffer.concat(chunks));
|
|
37598
38010
|
});
|
|
37599
38011
|
req.on("error", reject);
|
|
37600
38012
|
});
|
|
37601
38013
|
}
|
|
37602
38014
|
function body(req) {
|
|
37603
|
-
return new Promise((
|
|
38015
|
+
return new Promise((resolve3, reject) => {
|
|
37604
38016
|
let text = "";
|
|
37605
38017
|
req.setEncoding("utf8");
|
|
37606
38018
|
req.on("data", (chunk) => {
|
|
@@ -37609,9 +38021,9 @@ function body(req) {
|
|
|
37609
38021
|
});
|
|
37610
38022
|
req.on("end", () => {
|
|
37611
38023
|
try {
|
|
37612
|
-
|
|
38024
|
+
resolve3(text ? JSON.parse(text) : {});
|
|
37613
38025
|
} catch {
|
|
37614
|
-
|
|
38026
|
+
resolve3({});
|
|
37615
38027
|
}
|
|
37616
38028
|
});
|
|
37617
38029
|
req.on("error", reject);
|
|
@@ -37636,8 +38048,8 @@ var LocalApi = class {
|
|
|
37636
38048
|
localAgents.add(agent.id);
|
|
37637
38049
|
return this.hub.wait(agent, origin, timeoutMs, signal);
|
|
37638
38050
|
}
|
|
37639
|
-
async done(agent, jobId, notes, question) {
|
|
37640
|
-
return this.hub.done(agent.id, jobId, notes, question);
|
|
38051
|
+
async done(agent, jobId, notes, question, props) {
|
|
38052
|
+
return this.hub.done(agent.id, jobId, notes, question, props);
|
|
37641
38053
|
}
|
|
37642
38054
|
check(_agent, jobId, timeoutMs) {
|
|
37643
38055
|
return this.hub.check(jobId, timeoutMs);
|
|
@@ -37671,8 +38083,8 @@ var RemoteApi = class {
|
|
|
37671
38083
|
wait(agent, origin, timeoutMs, signal) {
|
|
37672
38084
|
return this.post("wait", { agent, origin, timeoutMs }, signal);
|
|
37673
38085
|
}
|
|
37674
|
-
async done(agent, jobId, notes, question) {
|
|
37675
|
-
return (await this.post("done", { agent, jobId, notes, question })).job;
|
|
38086
|
+
async done(agent, jobId, notes, question, props) {
|
|
38087
|
+
return (await this.post("done", { agent, jobId, notes, question, props })).job;
|
|
37676
38088
|
}
|
|
37677
38089
|
async check(agent, jobId, timeoutMs) {
|
|
37678
38090
|
return (await this.post("check", { agent, jobId, timeoutMs })).check;
|
|
@@ -37720,8 +38132,8 @@ var Bridge = class {
|
|
|
37720
38132
|
}
|
|
37721
38133
|
}
|
|
37722
38134
|
}
|
|
37723
|
-
done(jobId, notes, question) {
|
|
37724
|
-
return this.call((api) => api.done(this.agent, jobId, notes, question));
|
|
38135
|
+
done(jobId, notes, question, props) {
|
|
38136
|
+
return this.call((api) => api.done(this.agent, jobId, notes, question, props));
|
|
37725
38137
|
}
|
|
37726
38138
|
/** Pilot's width check of a task's element, measured by the page (null: no page answered). */
|
|
37727
38139
|
check(jobId, timeoutMs = CHECK_TIMEOUT) {
|
|
@@ -37813,9 +38225,9 @@ function isConnectionError(error62) {
|
|
|
37813
38225
|
}
|
|
37814
38226
|
|
|
37815
38227
|
// src/locate.ts
|
|
37816
|
-
import { existsSync as
|
|
37817
|
-
import { basename as
|
|
37818
|
-
var
|
|
38228
|
+
import { existsSync as existsSync3, readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync3 } from "fs";
|
|
38229
|
+
import { basename as basename4, extname as extname3, isAbsolute, join as join4, relative as relative3 } from "path";
|
|
38230
|
+
var SKIP2 = /* @__PURE__ */ new Set([
|
|
37819
38231
|
"node_modules",
|
|
37820
38232
|
"dist",
|
|
37821
38233
|
"build",
|
|
@@ -37831,7 +38243,7 @@ var SKIP = /* @__PURE__ */ new Set([
|
|
|
37831
38243
|
".turbo",
|
|
37832
38244
|
".cache"
|
|
37833
38245
|
]);
|
|
37834
|
-
var
|
|
38246
|
+
var EXTENSIONS2 = /* @__PURE__ */ new Set([
|
|
37835
38247
|
".html",
|
|
37836
38248
|
".htm",
|
|
37837
38249
|
".jsx",
|
|
@@ -37850,40 +38262,40 @@ var EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
37850
38262
|
".liquid",
|
|
37851
38263
|
".twig"
|
|
37852
38264
|
]);
|
|
37853
|
-
var
|
|
37854
|
-
var
|
|
37855
|
-
var
|
|
37856
|
-
var
|
|
38265
|
+
var MAX_FILES3 = 4e3;
|
|
38266
|
+
var MAX_FILE_BYTES3 = 512e3;
|
|
38267
|
+
var BUDGET_MS3 = 800;
|
|
38268
|
+
var cache3 = null;
|
|
37857
38269
|
function sourceFiles(root) {
|
|
37858
|
-
if (
|
|
38270
|
+
if (cache3 && cache3.root === root && Date.now() - cache3.at < 3e4) return cache3.files;
|
|
37859
38271
|
const files = [];
|
|
37860
38272
|
const walk = (dir) => {
|
|
37861
38273
|
let names;
|
|
37862
38274
|
try {
|
|
37863
|
-
names =
|
|
38275
|
+
names = readdirSync3(dir);
|
|
37864
38276
|
} catch {
|
|
37865
38277
|
return;
|
|
37866
38278
|
}
|
|
37867
38279
|
for (const name of names) {
|
|
37868
|
-
if (files.length >=
|
|
37869
|
-
if (
|
|
37870
|
-
const path =
|
|
38280
|
+
if (files.length >= MAX_FILES3) return;
|
|
38281
|
+
if (SKIP2.has(name) || name.startsWith(".") && name !== ".") continue;
|
|
38282
|
+
const path = join4(dir, name);
|
|
37871
38283
|
let stat2;
|
|
37872
38284
|
try {
|
|
37873
|
-
stat2 =
|
|
38285
|
+
stat2 = statSync3(path);
|
|
37874
38286
|
} catch {
|
|
37875
38287
|
continue;
|
|
37876
38288
|
}
|
|
37877
38289
|
if (stat2.isDirectory()) walk(path);
|
|
37878
|
-
else if (
|
|
38290
|
+
else if (EXTENSIONS2.has(extname3(name)) && stat2.size <= MAX_FILE_BYTES3) files.push(path);
|
|
37879
38291
|
}
|
|
37880
38292
|
};
|
|
37881
38293
|
walk(root);
|
|
37882
|
-
|
|
38294
|
+
cache3 = { root, at: Date.now(), files };
|
|
37883
38295
|
return files;
|
|
37884
38296
|
}
|
|
37885
38297
|
function searchable(cwd) {
|
|
37886
|
-
return
|
|
38298
|
+
return existsSync3(join4(cwd, "package.json")) || existsSync3(join4(cwd, ".git"));
|
|
37887
38299
|
}
|
|
37888
38300
|
var escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37889
38301
|
function needles(target) {
|
|
@@ -37898,12 +38310,12 @@ function needles(target) {
|
|
|
37898
38310
|
tag: new RegExp(`<${escape2(target.tag)}[\\s>/]`, "i")
|
|
37899
38311
|
};
|
|
37900
38312
|
}
|
|
37901
|
-
function locate(target, root, deadline = Date.now() +
|
|
38313
|
+
function locate(target, root, deadline = Date.now() + BUDGET_MS3) {
|
|
37902
38314
|
const n = needles(target);
|
|
37903
38315
|
const known = target.source?.file && target.source.line ? sourcePath(target.source.file, root) : null;
|
|
37904
38316
|
if (known && target.source?.line) {
|
|
37905
38317
|
try {
|
|
37906
|
-
const lines =
|
|
38318
|
+
const lines = readFileSync3(join4(root, known), "utf8").split("\n");
|
|
37907
38319
|
const from = target.source.line - 1;
|
|
37908
38320
|
const own2 = bestLine(n, lines, from);
|
|
37909
38321
|
const index = own2 && own2.score >= 2 ? own2.index : from;
|
|
@@ -37917,7 +38329,7 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS) {
|
|
|
37917
38329
|
if (Date.now() > deadline) break;
|
|
37918
38330
|
let content;
|
|
37919
38331
|
try {
|
|
37920
|
-
content =
|
|
38332
|
+
content = readFileSync3(file2, "utf8");
|
|
37921
38333
|
} catch {
|
|
37922
38334
|
continue;
|
|
37923
38335
|
}
|
|
@@ -37930,7 +38342,7 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS) {
|
|
|
37930
38342
|
}
|
|
37931
38343
|
const enough = best && (best.score >= 6 || n.classes.length >= 3 && best.score >= n.classes.length + 2);
|
|
37932
38344
|
if (!best || !enough) return null;
|
|
37933
|
-
return { file:
|
|
38345
|
+
return { file: relative3(root, best.file), line: best.line + 1, snippet: snippetAt(best.lines, best.line) };
|
|
37934
38346
|
}
|
|
37935
38347
|
function bestLine(n, lines, from = 0) {
|
|
37936
38348
|
const classesOn = (i) => lines[i] === void 0 ? 0 : n.classes.filter((re) => re.test(lines[i])).length;
|
|
@@ -37954,23 +38366,23 @@ function snippetAt(lines, index) {
|
|
|
37954
38366
|
return lines.slice(Math.max(0, index - 2), index + 3).map((l) => l.length > 160 ? `${l.slice(0, 159)}\u2026` : l).join("\n");
|
|
37955
38367
|
}
|
|
37956
38368
|
function sourcePath(file2, root) {
|
|
37957
|
-
const rel = isAbsolute(file2) ?
|
|
38369
|
+
const rel = isAbsolute(file2) ? relative3(root, file2) : file2.replace(/^\.\//, "");
|
|
37958
38370
|
if (rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
37959
|
-
return
|
|
38371
|
+
return existsSync3(join4(root, rel)) ? rel : null;
|
|
37960
38372
|
}
|
|
37961
|
-
function componentFile(name, root, deadline = Date.now() +
|
|
38373
|
+
function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
|
|
37962
38374
|
if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null;
|
|
37963
38375
|
const declaration = new RegExp(
|
|
37964
38376
|
`^\\s*(export\\s+(?:default\\s+)?)?(?:(?:async\\s+)?function\\s*\\*?\\s+${name}\\b|class\\s+${name}\\b|(?:const|let|var)\\s+${name}\\s*[:=])`
|
|
37965
38377
|
);
|
|
37966
38378
|
let best = null;
|
|
37967
|
-
const files = within ? [
|
|
38379
|
+
const files = within ? [join4(root, within)] : sourceFiles(root);
|
|
37968
38380
|
for (const file2 of files) {
|
|
37969
38381
|
if (Date.now() > deadline) break;
|
|
37970
38382
|
if (!/\.[jt]sx?$|\.mjs$/.test(file2)) continue;
|
|
37971
38383
|
let content;
|
|
37972
38384
|
try {
|
|
37973
|
-
content =
|
|
38385
|
+
content = readFileSync3(file2, "utf8");
|
|
37974
38386
|
} catch {
|
|
37975
38387
|
continue;
|
|
37976
38388
|
}
|
|
@@ -37979,16 +38391,16 @@ function componentFile(name, root, deadline = Date.now() + BUDGET_MS, within) {
|
|
|
37979
38391
|
for (let i = 0; i < lines.length; i++) {
|
|
37980
38392
|
const m = declaration.exec(lines[i]);
|
|
37981
38393
|
if (!m) continue;
|
|
37982
|
-
const score = (
|
|
38394
|
+
const score = (basename4(file2).replace(/\.[^.]+$/, "") === name ? 2 : 0) + (m[1] ? 1 : 0);
|
|
37983
38395
|
if (!best || score > best.score) best = { file: file2, line: i + 1, score };
|
|
37984
38396
|
break;
|
|
37985
38397
|
}
|
|
37986
38398
|
}
|
|
37987
|
-
return best ? { file:
|
|
38399
|
+
return best ? { file: relative3(root, best.file), line: best.line } : null;
|
|
37988
38400
|
}
|
|
37989
38401
|
function withComponentFiles(job, root) {
|
|
37990
38402
|
if (!searchable(root)) return job;
|
|
37991
|
-
const deadline = Date.now() +
|
|
38403
|
+
const deadline = Date.now() + BUDGET_MS3;
|
|
37992
38404
|
const fill = (target) => {
|
|
37993
38405
|
const source = target.source;
|
|
37994
38406
|
if (!source?.component || source.line) return target;
|
|
@@ -37997,6 +38409,32 @@ function withComponentFiles(job, root) {
|
|
|
37997
38409
|
const found = componentFile(source.component, root, deadline, known ?? void 0);
|
|
37998
38410
|
return found ? { ...target, source: { ...source, file: found.file, line: found.line } } : target;
|
|
37999
38411
|
};
|
|
38412
|
+
const workspace = workspaceRoot(root);
|
|
38413
|
+
const declared = (name) => {
|
|
38414
|
+
const found = componentFile(name, workspace, deadline);
|
|
38415
|
+
return found ? { file: relative3(root, join4(workspace, found.file)), line: found.line } : null;
|
|
38416
|
+
};
|
|
38417
|
+
const local = (file2) => {
|
|
38418
|
+
const path = join4(workspace, file2);
|
|
38419
|
+
return existsSync3(path) ? relative3(root, path) : file2;
|
|
38420
|
+
};
|
|
38421
|
+
const mention = (r) => {
|
|
38422
|
+
if (r.kind === "token") return r.source ? { ...r, source: { ...r.source, file: local(r.source.file) } } : r;
|
|
38423
|
+
if (r.kind === "element") return { ...r, target: fill(r.target) };
|
|
38424
|
+
if (r.kind === "unlisted") {
|
|
38425
|
+
const source2 = declared(r.name);
|
|
38426
|
+
return source2 ? { kind: "component", name: r.name, source: source2 } : r;
|
|
38427
|
+
}
|
|
38428
|
+
if (r.kind !== "component") return r;
|
|
38429
|
+
if (r.source) {
|
|
38430
|
+
const path = join4(workspace, r.source.file);
|
|
38431
|
+
return existsSync3(path) ? { ...r, source: { ...r.source, file: relative3(root, path) } } : r;
|
|
38432
|
+
}
|
|
38433
|
+
if (r.target?.source?.file) return { ...r, target: fill(r.target) };
|
|
38434
|
+
const source = declared(r.name);
|
|
38435
|
+
return source ? { ...r, source } : r;
|
|
38436
|
+
};
|
|
38437
|
+
const mentions = (refs) => refs?.length ? { references: refs.map(mention) } : {};
|
|
38000
38438
|
const { changeSet } = job;
|
|
38001
38439
|
const request = changeSet.request;
|
|
38002
38440
|
return {
|
|
@@ -38004,11 +38442,13 @@ function withComponentFiles(job, root) {
|
|
|
38004
38442
|
changeSet: {
|
|
38005
38443
|
...changeSet,
|
|
38006
38444
|
edits: changeSet.edits.map((e) => ({ ...e, target: fill(e.target) })),
|
|
38445
|
+
...changeSet.fileTokens ? { fileTokens: changeSet.fileTokens.map((t) => ({ ...t, file: local(t.file) })) } : {},
|
|
38007
38446
|
...request ? {
|
|
38008
38447
|
request: {
|
|
38009
38448
|
...request,
|
|
38010
38449
|
target: fill(request.target),
|
|
38011
|
-
...request.others ? { others: request.others.map(fill) } : {}
|
|
38450
|
+
...request.others ? { others: request.others.map(fill) } : {},
|
|
38451
|
+
...request.kind === "comment" ? { thread: request.thread.map((m) => ({ ...m, ...mentions(m.references) })) } : mentions(request.references)
|
|
38012
38452
|
}
|
|
38013
38453
|
} : {}
|
|
38014
38454
|
}
|
|
@@ -38017,12 +38457,12 @@ function withComponentFiles(job, root) {
|
|
|
38017
38457
|
function whereSection(job, root) {
|
|
38018
38458
|
if (!searchable(root)) return "";
|
|
38019
38459
|
const targets = job.changeSet.request ? requestTargets(job.changeSet.request) : job.changeSet.edits.map((e) => e.target);
|
|
38020
|
-
const deadline = Date.now() +
|
|
38460
|
+
const deadline = Date.now() + BUDGET_MS3;
|
|
38021
38461
|
const found = [];
|
|
38022
38462
|
for (const target of targets) {
|
|
38023
38463
|
const at = locate(target, root, deadline);
|
|
38024
38464
|
if (!at) continue;
|
|
38025
|
-
const lang =
|
|
38465
|
+
const lang = extname3(at.file).slice(1) || "text";
|
|
38026
38466
|
found.push(
|
|
38027
38467
|
`- \`${target.path}\` \u2192 \`${at.file}:${at.line}\`:`,
|
|
38028
38468
|
"",
|
|
@@ -38060,16 +38500,16 @@ function clientOf(name) {
|
|
|
38060
38500
|
|
|
38061
38501
|
// src/init.ts
|
|
38062
38502
|
import { spawnSync } from "child_process";
|
|
38063
|
-
import { existsSync as
|
|
38503
|
+
import { existsSync as existsSync5, readdirSync as readdirSync4, readFileSync as readFileSync4 } from "fs";
|
|
38064
38504
|
import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
38065
38505
|
import { homedir as homedir2 } from "os";
|
|
38066
|
-
import { dirname as
|
|
38506
|
+
import { dirname as dirname4, join as join6, relative as relative5 } from "path";
|
|
38067
38507
|
|
|
38068
38508
|
// src/setup.ts
|
|
38069
|
-
import { existsSync as
|
|
38509
|
+
import { existsSync as existsSync4 } from "fs";
|
|
38070
38510
|
import { lstat, mkdir as mkdir2, readFile as readFile2, unlink, writeFile as writeFile2 } from "fs/promises";
|
|
38071
38511
|
import { homedir } from "os";
|
|
38072
|
-
import { join as
|
|
38512
|
+
import { join as join5, relative as relative4 } from "path";
|
|
38073
38513
|
|
|
38074
38514
|
// ../../skills/pilot/SKILL.md
|
|
38075
38515
|
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";
|
|
@@ -38080,7 +38520,7 @@ async function setup(options = {}) {
|
|
|
38080
38520
|
return options.project ? setupProject(options.cwd ?? process.cwd()) : setupMachine(options.home ?? homedir());
|
|
38081
38521
|
}
|
|
38082
38522
|
async function setupMachine(home) {
|
|
38083
|
-
const file2 = await writeSkill(
|
|
38523
|
+
const file2 = await writeSkill(join5(home, ".claude", "skills", "pilot"));
|
|
38084
38524
|
return `Installed the /pilot skill: ${file2}
|
|
38085
38525
|
|
|
38086
38526
|
Now register Pilot's MCP server with Claude Code, once, for every project:
|
|
@@ -38092,11 +38532,11 @@ Then, in any Claude Code chat: /pilot
|
|
|
38092
38532
|
`;
|
|
38093
38533
|
}
|
|
38094
38534
|
async function setupProject(cwd) {
|
|
38095
|
-
const skillFile = await writeSkill(
|
|
38096
|
-
const mcpFile =
|
|
38535
|
+
const skillFile = await writeSkill(join5(cwd, ".claude", "skills", "pilot"));
|
|
38536
|
+
const mcpFile = join5(cwd, ".mcp.json");
|
|
38097
38537
|
const { added } = await addMcpServer(mcpFile);
|
|
38098
|
-
const rel = (f) =>
|
|
38099
|
-
const app =
|
|
38538
|
+
const rel = (f) => relative4(cwd, f);
|
|
38539
|
+
const app = existsSync4(join5(cwd, "package.json")) ? "" : "\nNo package.json here: run this in the project's root folder, where the app is.\n";
|
|
38100
38540
|
const width = rel(skillFile).length + 2;
|
|
38101
38541
|
return `Set up /pilot for this repo:
|
|
38102
38542
|
${rel(skillFile).padEnd(width)}the /pilot skill
|
|
@@ -38115,7 +38555,7 @@ Then, in a Claude Code chat in this folder: /pilot
|
|
|
38115
38555
|
async function writeSkill(dir) {
|
|
38116
38556
|
if (await isLink(dir)) await unlink(dir);
|
|
38117
38557
|
await mkdir2(dir, { recursive: true });
|
|
38118
|
-
const file2 =
|
|
38558
|
+
const file2 = join5(dir, "SKILL.md");
|
|
38119
38559
|
await writeFile2(file2, SKILL_default);
|
|
38120
38560
|
return file2;
|
|
38121
38561
|
}
|
|
@@ -38128,7 +38568,7 @@ async function isLink(path) {
|
|
|
38128
38568
|
}
|
|
38129
38569
|
async function addMcpServer(file2) {
|
|
38130
38570
|
let config2 = {};
|
|
38131
|
-
if (
|
|
38571
|
+
if (existsSync4(file2)) {
|
|
38132
38572
|
const text = await readFile2(file2, "utf8");
|
|
38133
38573
|
try {
|
|
38134
38574
|
config2 = text.trim() ? JSON.parse(text) : {};
|
|
@@ -38145,7 +38585,7 @@ async function addMcpServer(file2) {
|
|
|
38145
38585
|
}
|
|
38146
38586
|
|
|
38147
38587
|
// src/version.ts
|
|
38148
|
-
var VERSION = "0.
|
|
38588
|
+
var VERSION = "0.10.0";
|
|
38149
38589
|
function olderThan(a, b) {
|
|
38150
38590
|
const parts = (v) => v.replace(/^[^\d]*/, "").split(/[.-]/).slice(0, 3).map((n) => Number.parseInt(n, 10) || 0);
|
|
38151
38591
|
const [x, y] = [parts(a), parts(b)];
|
|
@@ -38161,15 +38601,15 @@ var AGENTS = [
|
|
|
38161
38601
|
id: "claude-code",
|
|
38162
38602
|
name: "Claude Code",
|
|
38163
38603
|
mcp: { file: ".mcp.json", key: "mcpServers", entry: MCP_SERVER },
|
|
38164
|
-
skills:
|
|
38604
|
+
skills: join6(".claude", "skills"),
|
|
38165
38605
|
invoke: "`/pilot`",
|
|
38166
38606
|
signals: [".mcp.json", ".claude"]
|
|
38167
38607
|
},
|
|
38168
38608
|
{
|
|
38169
38609
|
id: "cursor",
|
|
38170
38610
|
name: "Cursor",
|
|
38171
|
-
mcp: { file:
|
|
38172
|
-
skills:
|
|
38611
|
+
mcp: { file: join6(".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
|
|
38612
|
+
skills: join6(".cursor", "skills"),
|
|
38173
38613
|
invoke: "`/pilot`",
|
|
38174
38614
|
signals: [".cursor"],
|
|
38175
38615
|
// Cursor sees a project's new MCP server but leaves it off: it never starts until the user turns it on.
|
|
@@ -38178,16 +38618,16 @@ var AGENTS = [
|
|
|
38178
38618
|
{
|
|
38179
38619
|
id: "vscode",
|
|
38180
38620
|
name: "VS Code",
|
|
38181
|
-
mcp: { file:
|
|
38182
|
-
skills:
|
|
38621
|
+
mcp: { file: join6(".vscode", "mcp.json"), key: "servers", entry: { type: "stdio", ...MCP_SERVER } },
|
|
38622
|
+
skills: join6(".github", "skills"),
|
|
38183
38623
|
invoke: "`/pilot`",
|
|
38184
|
-
signals: [
|
|
38624
|
+
signals: [join6(".vscode", "mcp.json"), join6(".github", "skills"), join6(".github", "copilot-instructions.md")]
|
|
38185
38625
|
},
|
|
38186
38626
|
{
|
|
38187
38627
|
id: "codex",
|
|
38188
38628
|
name: "Codex",
|
|
38189
38629
|
register: `\`codex mcp add pilot -- ${COMMAND}\``,
|
|
38190
|
-
skills:
|
|
38630
|
+
skills: join6(".agents", "skills"),
|
|
38191
38631
|
invoke: "`$pilot`",
|
|
38192
38632
|
signals: [".codex"]
|
|
38193
38633
|
},
|
|
@@ -38196,7 +38636,7 @@ var AGENTS = [
|
|
|
38196
38636
|
name: "your agent",
|
|
38197
38637
|
register: `in your MCP settings: a server named \`pilot\`, running \`${COMMAND}\``,
|
|
38198
38638
|
// The open skills folder, read by many agents.
|
|
38199
|
-
skills:
|
|
38639
|
+
skills: join6(".agents", "skills"),
|
|
38200
38640
|
invoke: "the `pilot` skill",
|
|
38201
38641
|
signals: []
|
|
38202
38642
|
}
|
|
@@ -38207,35 +38647,35 @@ var MACHINE = {
|
|
|
38207
38647
|
command: {
|
|
38208
38648
|
cmd: "claude",
|
|
38209
38649
|
args: ["mcp", "add", "--scope", "user", "pilot", "--", ...MCP_SERVER_ARGV],
|
|
38210
|
-
has: (home) => !!readJson(
|
|
38650
|
+
has: (home) => !!readJson(join6(home, ".claude.json"))?.mcpServers?.pilot
|
|
38211
38651
|
},
|
|
38212
|
-
skills: (home) =>
|
|
38652
|
+
skills: (home) => join6(home, ".claude", "skills")
|
|
38213
38653
|
},
|
|
38214
38654
|
cursor: {
|
|
38215
|
-
mcp: { file: (home) =>
|
|
38216
|
-
skills: (home) =>
|
|
38655
|
+
mcp: { file: (home) => join6(home, ".cursor", "mcp.json"), key: "mcpServers", entry: MCP_SERVER },
|
|
38656
|
+
skills: (home) => join6(home, ".cursor", "skills")
|
|
38217
38657
|
},
|
|
38218
38658
|
vscode: {
|
|
38219
38659
|
mcp: {
|
|
38220
|
-
file: (home, platform) =>
|
|
38660
|
+
file: (home, platform) => join6(vscodeUserDir(home, platform), "mcp.json"),
|
|
38221
38661
|
key: "servers",
|
|
38222
38662
|
entry: { type: "stdio", ...MCP_SERVER }
|
|
38223
38663
|
},
|
|
38224
|
-
skills: (home) =>
|
|
38664
|
+
skills: (home) => join6(home, ".copilot", "skills")
|
|
38225
38665
|
},
|
|
38226
38666
|
codex: {
|
|
38227
38667
|
command: {
|
|
38228
38668
|
cmd: "codex",
|
|
38229
38669
|
args: ["mcp", "add", "pilot", "--", ...MCP_SERVER_ARGV],
|
|
38230
|
-
has: (home) => /\[mcp_servers\.pilot\]/.test(readText(
|
|
38670
|
+
has: (home) => /\[mcp_servers\.pilot\]/.test(readText(join6(home, ".codex", "config.toml")))
|
|
38231
38671
|
},
|
|
38232
|
-
skills: (home) =>
|
|
38672
|
+
skills: (home) => join6(home, ".agents", "skills")
|
|
38233
38673
|
},
|
|
38234
|
-
other: { skills: (home) =>
|
|
38674
|
+
other: { skills: (home) => join6(home, ".agents", "skills") }
|
|
38235
38675
|
};
|
|
38236
38676
|
function skillFolders(root, home) {
|
|
38237
|
-
const machine = AGENT_IDS.map((id) =>
|
|
38238
|
-
const project = AGENTS.map((a) =>
|
|
38677
|
+
const machine = AGENT_IDS.map((id) => join6(MACHINE[id].skills(home), "pilot"));
|
|
38678
|
+
const project = AGENTS.map((a) => join6(root, a.skills, "pilot"));
|
|
38239
38679
|
return [.../* @__PURE__ */ new Set([...machine, ...project])];
|
|
38240
38680
|
}
|
|
38241
38681
|
function agentsWithPilot(root, home, platform = process.platform) {
|
|
@@ -38245,24 +38685,24 @@ function agentsWithPilot(root, home, platform = process.platform) {
|
|
|
38245
38685
|
const machine = MACHINE[a.id];
|
|
38246
38686
|
if (machine.mcp && hasServer(machine.mcp.file(home, platform), machine.mcp.key)) return true;
|
|
38247
38687
|
if (machine.command?.has(home)) return true;
|
|
38248
|
-
if (a.mcp && hasServer(
|
|
38249
|
-
return a.id !== "codex" &&
|
|
38688
|
+
if (a.mcp && hasServer(join6(root, a.mcp.file), a.mcp.key)) return true;
|
|
38689
|
+
return a.id !== "codex" && existsSync5(join6(machine.skills(home), "pilot"));
|
|
38250
38690
|
}).map((a) => a.id);
|
|
38251
38691
|
}
|
|
38252
38692
|
function installArgs(pm, spec = "usepilot") {
|
|
38253
38693
|
return pm === "npm" ? ["install", "-D", spec] : pm === "bun" ? ["add", "-d", spec] : ["add", "-D", spec];
|
|
38254
38694
|
}
|
|
38255
38695
|
function installedVersion(cwd, root) {
|
|
38256
|
-
for (let dir = cwd; ; dir =
|
|
38257
|
-
const version2 = readJson(
|
|
38696
|
+
for (let dir = cwd; ; dir = dirname4(dir)) {
|
|
38697
|
+
const version2 = readJson(join6(dir, "node_modules", "usepilot", "package.json"))?.version;
|
|
38258
38698
|
if (version2) return version2;
|
|
38259
|
-
if (dir === root ||
|
|
38699
|
+
if (dir === root || dirname4(dir) === dir) return null;
|
|
38260
38700
|
}
|
|
38261
38701
|
}
|
|
38262
38702
|
function vscodeUserDir(home, platform) {
|
|
38263
|
-
if (platform === "darwin") return
|
|
38264
|
-
if (platform === "win32") return
|
|
38265
|
-
return
|
|
38703
|
+
if (platform === "darwin") return join6(home, "Library", "Application Support", "Code", "User");
|
|
38704
|
+
if (platform === "win32") return join6(process.env.APPDATA ?? join6(home, "AppData", "Roaming"), "Code", "User");
|
|
38705
|
+
return join6(home, ".config", "Code", "User");
|
|
38266
38706
|
}
|
|
38267
38707
|
function tilde(path, home) {
|
|
38268
38708
|
return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
@@ -38276,8 +38716,8 @@ function detectAgent(env) {
|
|
|
38276
38716
|
async function init(options = {}) {
|
|
38277
38717
|
const cwd = options.cwd ?? process.cwd();
|
|
38278
38718
|
const run = options.run ?? runCommand;
|
|
38279
|
-
const pkgFile =
|
|
38280
|
-
if (!
|
|
38719
|
+
const pkgFile = join6(cwd, "package.json");
|
|
38720
|
+
if (!existsSync5(pkgFile)) {
|
|
38281
38721
|
return `# Pilot: not set up
|
|
38282
38722
|
|
|
38283
38723
|
There's no package.json in ${cwd}. Run \`npx usepilot@latest init\` again in the app's folder: the one with the package.json of the web app the user works on.
|
|
@@ -38333,16 +38773,16 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
|
38333
38773
|
} else if (agent.register) {
|
|
38334
38774
|
todo.push(`**Register Pilot's MCP server with yourself**, for every project: ${agent.register}.`);
|
|
38335
38775
|
}
|
|
38336
|
-
const skill =
|
|
38776
|
+
const skill = join6(machine.skills(home), "pilot");
|
|
38337
38777
|
await writeSkill(skill);
|
|
38338
38778
|
parts.push(`the \`pilot\` skill (\`${tilde(skill, home)}/\`)`);
|
|
38339
38779
|
done.push(`Connected ${agent.name} to Pilot, once for every project on this machine: ${list(parts)}. Nothing was added to the repo.`);
|
|
38340
38780
|
} else if (named) {
|
|
38341
|
-
const present = AGENTS.filter((a) => a.id !== named && a.signals.some((p) =>
|
|
38781
|
+
const present = AGENTS.filter((a) => a.id !== named && a.signals.some((p) => existsSync5(join6(root, p))));
|
|
38342
38782
|
for (const agent of [...AGENTS.filter((a) => a.id === named), ...present]) {
|
|
38343
38783
|
const parts = [];
|
|
38344
38784
|
if (agent.mcp) {
|
|
38345
|
-
const file2 =
|
|
38785
|
+
const file2 = join6(root, agent.mcp.file);
|
|
38346
38786
|
if (await addServer(file2, agent.mcp.key, agent.mcp.entry) === "invalid") {
|
|
38347
38787
|
todo.push(
|
|
38348
38788
|
`\`${agent.mcp.file}\` isn't valid JSON, so Pilot wasn't added to it: fix it, and add the \`pilot\` server (\`${COMMAND}\`).`
|
|
@@ -38352,8 +38792,8 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
|
38352
38792
|
written.push(`\`${agent.mcp.file}\``);
|
|
38353
38793
|
}
|
|
38354
38794
|
}
|
|
38355
|
-
const skill =
|
|
38356
|
-
await writeSkill(
|
|
38795
|
+
const skill = join6(agent.skills, "pilot");
|
|
38796
|
+
await writeSkill(join6(root, skill));
|
|
38357
38797
|
parts.push(`the \`pilot\` skill (\`${skill}/\`)`);
|
|
38358
38798
|
if (!written.includes(`\`${skill}/\``)) written.push(`\`${skill}/\``);
|
|
38359
38799
|
done.push(`Set Pilot up for ${agent.name} in this project: ${list(parts)}.`);
|
|
@@ -38364,7 +38804,7 @@ ${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
|
38364
38804
|
`**Connect yourself:** run \`npx usepilot@latest init --agent <you>\` in ${cwd}, with \`<you>\` the agent you are: ${AGENT_IDS.map((a) => `\`${a}\``).join(", ")}.`
|
|
38365
38805
|
);
|
|
38366
38806
|
}
|
|
38367
|
-
if (framework.loads) done.push(`The app already loads Pilot (\`${
|
|
38807
|
+
if (framework.loads) done.push(`The app already loads Pilot (\`${relative5(cwd, framework.loads)}\`).`);
|
|
38368
38808
|
else todo.push(loadStep(framework, cwd));
|
|
38369
38809
|
const me = AGENTS.find((a) => a.id === named);
|
|
38370
38810
|
const enable = project && me?.enable ? `Before that, ${me.enable}. ` : "";
|
|
@@ -38381,23 +38821,23 @@ ${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
|
|
|
38381
38821
|
`;
|
|
38382
38822
|
}
|
|
38383
38823
|
function projectRoot(cwd) {
|
|
38384
|
-
for (let dir = cwd; ; dir =
|
|
38385
|
-
if (
|
|
38386
|
-
if (
|
|
38824
|
+
for (let dir = cwd; ; dir = dirname4(dir)) {
|
|
38825
|
+
if (existsSync5(join6(dir, ".git"))) return dir;
|
|
38826
|
+
if (dirname4(dir) === dir) return cwd;
|
|
38387
38827
|
}
|
|
38388
38828
|
}
|
|
38389
38829
|
function packageManager(cwd, root) {
|
|
38390
|
-
for (let dir = cwd; ; dir =
|
|
38391
|
-
if (
|
|
38392
|
-
if (
|
|
38393
|
-
if (
|
|
38394
|
-
if (
|
|
38395
|
-
if (dir === root ||
|
|
38830
|
+
for (let dir = cwd; ; dir = dirname4(dir)) {
|
|
38831
|
+
if (existsSync5(join6(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
38832
|
+
if (existsSync5(join6(dir, "yarn.lock"))) return "yarn";
|
|
38833
|
+
if (existsSync5(join6(dir, "bun.lock")) || existsSync5(join6(dir, "bun.lockb"))) return "bun";
|
|
38834
|
+
if (existsSync5(join6(dir, "package-lock.json"))) return "npm";
|
|
38835
|
+
if (dir === root || dirname4(dir) === dir) return "npm";
|
|
38396
38836
|
}
|
|
38397
38837
|
}
|
|
38398
38838
|
function detectFramework(cwd, deps) {
|
|
38399
38839
|
const has = (name) => name in deps;
|
|
38400
|
-
const first = (...files) => files.map((f) =>
|
|
38840
|
+
const first = (...files) => files.map((f) => join6(cwd, f)).find((f) => existsSync5(f));
|
|
38401
38841
|
const loads = findLoader(cwd);
|
|
38402
38842
|
const result = (kind, file2) => ({ kind, file: file2, loads });
|
|
38403
38843
|
if (has("next")) {
|
|
@@ -38419,8 +38859,8 @@ function detectFramework(cwd, deps) {
|
|
|
38419
38859
|
if (has("vite") || Object.keys(deps).some((d) => d.startsWith("@vitejs/"))) {
|
|
38420
38860
|
const entry = viteEntry(cwd);
|
|
38421
38861
|
if (entry) return result("vite", entry);
|
|
38422
|
-
if (
|
|
38423
|
-
const config2 = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) =>
|
|
38862
|
+
if (existsSync5(join6(cwd, "index.html"))) {
|
|
38863
|
+
const config2 = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) => join6(cwd, f)).find((f) => existsSync5(f));
|
|
38424
38864
|
return result("vite-html", config2);
|
|
38425
38865
|
}
|
|
38426
38866
|
return result("vite");
|
|
@@ -38434,16 +38874,16 @@ function detectFramework(cwd, deps) {
|
|
|
38434
38874
|
return { kind: "unknown", loads };
|
|
38435
38875
|
}
|
|
38436
38876
|
function viteEntry(cwd) {
|
|
38437
|
-
const html =
|
|
38438
|
-
if (
|
|
38439
|
-
for (const tag of
|
|
38877
|
+
const html = join6(cwd, "index.html");
|
|
38878
|
+
if (existsSync5(html)) {
|
|
38879
|
+
for (const tag of readFileSync4(html, "utf8").match(/<script\b[^>]*>/gi) ?? []) {
|
|
38440
38880
|
if (!/type=["']module["']/i.test(tag)) continue;
|
|
38441
38881
|
const src = /src=["']\/?([^"'?#]+)/i.exec(tag)?.[1];
|
|
38442
|
-
if (src &&
|
|
38882
|
+
if (src && existsSync5(join6(cwd, src))) return join6(cwd, src);
|
|
38443
38883
|
}
|
|
38444
38884
|
return void 0;
|
|
38445
38885
|
}
|
|
38446
|
-
return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) =>
|
|
38886
|
+
return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) => join6(cwd, f)).find((f) => existsSync5(f));
|
|
38447
38887
|
}
|
|
38448
38888
|
var SOURCE_DIRS = ["src", "app", "pages", "plugins", "components", "lib"];
|
|
38449
38889
|
var SOURCE_FILE = /\.(m?[jt]sx?|vue|svelte|astro|html)$/;
|
|
@@ -38452,13 +38892,13 @@ function findLoader(cwd) {
|
|
|
38452
38892
|
const walk = (dir, depth) => {
|
|
38453
38893
|
let names;
|
|
38454
38894
|
try {
|
|
38455
|
-
names =
|
|
38895
|
+
names = readdirSync4(dir);
|
|
38456
38896
|
} catch {
|
|
38457
38897
|
return void 0;
|
|
38458
38898
|
}
|
|
38459
38899
|
for (const name of names) {
|
|
38460
38900
|
if (budget-- <= 0 || name === "node_modules" || name.startsWith(".")) continue;
|
|
38461
|
-
const path =
|
|
38901
|
+
const path = join6(dir, name);
|
|
38462
38902
|
if (SOURCE_FILE.test(name)) {
|
|
38463
38903
|
if (/["']usepilot(\/auto)?["']/.test(readText(path))) return path;
|
|
38464
38904
|
} else if (depth > 0 && !name.includes(".")) {
|
|
@@ -38469,40 +38909,40 @@ function findLoader(cwd) {
|
|
|
38469
38909
|
return void 0;
|
|
38470
38910
|
};
|
|
38471
38911
|
for (const name of ["index.html", "vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"]) {
|
|
38472
|
-
const file2 =
|
|
38473
|
-
if (
|
|
38912
|
+
const file2 = join6(cwd, name);
|
|
38913
|
+
if (existsSync5(file2) && /usepilot/.test(readText(file2))) return file2;
|
|
38474
38914
|
}
|
|
38475
38915
|
for (const dir of SOURCE_DIRS) {
|
|
38476
|
-
const found = walk(
|
|
38916
|
+
const found = walk(join6(cwd, dir), 6);
|
|
38477
38917
|
if (found) return found;
|
|
38478
38918
|
}
|
|
38479
38919
|
return void 0;
|
|
38480
38920
|
}
|
|
38481
38921
|
function readText(file2) {
|
|
38482
38922
|
try {
|
|
38483
|
-
return
|
|
38923
|
+
return readFileSync4(file2, "utf8");
|
|
38484
38924
|
} catch {
|
|
38485
38925
|
return "";
|
|
38486
38926
|
}
|
|
38487
38927
|
}
|
|
38488
38928
|
function isWorkspaceRoot(cwd, pkg) {
|
|
38489
|
-
return !!pkg.workspaces ||
|
|
38929
|
+
return !!pkg.workspaces || existsSync5(join6(cwd, "pnpm-workspace.yaml"));
|
|
38490
38930
|
}
|
|
38491
38931
|
function workspaceApps(cwd) {
|
|
38492
38932
|
const found = [];
|
|
38493
38933
|
for (const group of ["apps", "packages", "examples", "sites"]) {
|
|
38494
|
-
const dir =
|
|
38495
|
-
if (!
|
|
38496
|
-
for (const name of
|
|
38497
|
-
const pkg = readJson(
|
|
38498
|
-
if (pkg && detectFramework(
|
|
38499
|
-
found.push(
|
|
38934
|
+
const dir = join6(cwd, group);
|
|
38935
|
+
if (!existsSync5(dir)) continue;
|
|
38936
|
+
for (const name of readdirSync4(dir)) {
|
|
38937
|
+
const pkg = readJson(join6(dir, name, "package.json"));
|
|
38938
|
+
if (pkg && detectFramework(join6(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
|
|
38939
|
+
found.push(join6(group, name));
|
|
38500
38940
|
}
|
|
38501
38941
|
}
|
|
38502
38942
|
return found;
|
|
38503
38943
|
}
|
|
38504
38944
|
function loadStep(framework, cwd) {
|
|
38505
|
-
const at = (file2, otherwise) => file2 ? `\`${
|
|
38945
|
+
const at = (file2, otherwise) => file2 ? `\`${relative5(cwd, file2)}\`` : otherwise;
|
|
38506
38946
|
const code = (lang, text) => `
|
|
38507
38947
|
|
|
38508
38948
|
\`\`\`${lang}
|
|
@@ -38572,7 +39012,7 @@ export function Pilot() {
|
|
|
38572
39012
|
}
|
|
38573
39013
|
async function addServer(file2, key, entry) {
|
|
38574
39014
|
let config2 = {};
|
|
38575
|
-
if (
|
|
39015
|
+
if (existsSync5(file2)) {
|
|
38576
39016
|
const text = await readFile3(file2, "utf8");
|
|
38577
39017
|
try {
|
|
38578
39018
|
config2 = text.trim() ? JSON.parse(text) : {};
|
|
@@ -38584,14 +39024,14 @@ async function addServer(file2, key, entry) {
|
|
|
38584
39024
|
const servers = config2[key] ?? {};
|
|
38585
39025
|
const result = "pilot" in servers ? "updated" : "added";
|
|
38586
39026
|
config2[key] = { ...servers, pilot: entry };
|
|
38587
|
-
await mkdir3(
|
|
39027
|
+
await mkdir3(dirname4(file2), { recursive: true });
|
|
38588
39028
|
await writeFile3(file2, `${JSON.stringify(config2, null, 2)}
|
|
38589
39029
|
`);
|
|
38590
39030
|
return result;
|
|
38591
39031
|
}
|
|
38592
39032
|
function readJson(file2) {
|
|
38593
39033
|
try {
|
|
38594
|
-
return JSON.parse(
|
|
39034
|
+
return JSON.parse(readFileSync4(file2, "utf8"));
|
|
38595
39035
|
} catch {
|
|
38596
39036
|
return null;
|
|
38597
39037
|
}
|
|
@@ -38633,7 +39073,7 @@ function agentLabel(clientName, cwd) {
|
|
|
38633
39073
|
codex: "Codex"
|
|
38634
39074
|
};
|
|
38635
39075
|
const app = clientName && (names[clientName.toLowerCase()] ?? clientName) || "Agent";
|
|
38636
|
-
return `${app} \xB7 ${
|
|
39076
|
+
return `${app} \xB7 ${basename5(cwd)}`;
|
|
38637
39077
|
}
|
|
38638
39078
|
function jobPrompt(job, where = "") {
|
|
38639
39079
|
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 });
|
|
@@ -38673,9 +39113,7 @@ function followUp(job) {
|
|
|
38673
39113
|
for (const d of job.differences ?? []) {
|
|
38674
39114
|
const edit = job.changeSet.edits.find((e) => e.target.selector === d.selector);
|
|
38675
39115
|
const where = edit ? `\`${edit.target.path}\` (selector \`${d.selector}\`${edit.target.text ? `, text "${edit.target.text}"` : ""})` : `\`${d.selector}\``;
|
|
38676
|
-
|
|
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 ?? "?"}\`.`);
|
|
39116
|
+
lines.push(`- ${where}: \`${d.property}\` should be \`${d.expected}\`, the page gives \`${d.actual ?? "?"}\`.`);
|
|
38679
39117
|
}
|
|
38680
39118
|
lines.push(
|
|
38681
39119
|
"",
|
|
@@ -38685,7 +39123,7 @@ function followUp(job) {
|
|
|
38685
39123
|
}
|
|
38686
39124
|
var MAX_BATCH = 6;
|
|
38687
39125
|
async function takeQueued(first, take) {
|
|
38688
|
-
const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment";
|
|
39126
|
+
const advanced = (j) => !!j.changeSet.request && j.changeSet.request.kind !== "comment" && j.changeSet.request.kind !== "props";
|
|
38689
39127
|
if (advanced(first)) return [];
|
|
38690
39128
|
const more = [];
|
|
38691
39129
|
while (more.length < MAX_BATCH - 1) {
|
|
@@ -38709,6 +39147,8 @@ function notesFor(job) {
|
|
|
38709
39147
|
return "what changed at which widths, anything left for the designer";
|
|
38710
39148
|
case "break-and-fix":
|
|
38711
39149
|
return "what broke and how you fixed it, anything for the designer to decide";
|
|
39150
|
+
case "props":
|
|
39151
|
+
return "one short sentence for the designer, like a chat message; the props go in `props`";
|
|
38712
39152
|
default:
|
|
38713
39153
|
return "values you approximated, anything you did differently";
|
|
38714
39154
|
}
|
|
@@ -38716,6 +39156,20 @@ function notesFor(job) {
|
|
|
38716
39156
|
function taskFollowUp(job) {
|
|
38717
39157
|
const request = job.changeSet.request;
|
|
38718
39158
|
const target = `\`${request?.target.path ?? "the element"}\``;
|
|
39159
|
+
if (request?.kind === "comment")
|
|
39160
|
+
return [
|
|
39161
|
+
"# Pilot: props, follow-up",
|
|
39162
|
+
"",
|
|
39163
|
+
`You set the props the designer picked on ${target}, but Pilot read the instance on the page after hot reload, and these aren't what they picked yet:`,
|
|
39164
|
+
"",
|
|
39165
|
+
...(job.issues ?? []).map((i) => `- ${i}`),
|
|
39166
|
+
"",
|
|
39167
|
+
"Fix them where this instance is written: the usual causes are another instance's line, a value the parent passes from a variable or data, or a default the prop falls back to. If one can't be set there, say why in your notes. Pilot takes what the code gives after this.",
|
|
39168
|
+
"",
|
|
39169
|
+
"The comment, for reference:",
|
|
39170
|
+
"",
|
|
39171
|
+
formatPrompt(job.changeSet, { guidelines: false })
|
|
39172
|
+
].join("\n");
|
|
38719
39173
|
const breakFix = request?.kind === "break-and-fix";
|
|
38720
39174
|
const lines = [
|
|
38721
39175
|
breakFix ? "# Pilot: break and fix, follow-up" : "# Pilot: make responsive, follow-up",
|
|
@@ -38743,8 +39197,8 @@ function projectFolder(candidate) {
|
|
|
38743
39197
|
}
|
|
38744
39198
|
}
|
|
38745
39199
|
if (!isAbsolute2(path)) return null;
|
|
38746
|
-
path =
|
|
38747
|
-
return
|
|
39200
|
+
path = resolve2(path);
|
|
39201
|
+
return existsSync6(path) && searchable(path) ? path : null;
|
|
38748
39202
|
}
|
|
38749
39203
|
function createPilotServer(options = {}) {
|
|
38750
39204
|
const port = options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT);
|
|
@@ -38753,12 +39207,13 @@ function createPilotServer(options = {}) {
|
|
|
38753
39207
|
let client;
|
|
38754
39208
|
let waitMs = options.waitMs ?? waitMsFor(void 0);
|
|
38755
39209
|
const server = new McpServer({ name: "pilot", version: VERSION }, { instructions: INSTRUCTIONS });
|
|
38756
|
-
const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd) };
|
|
39210
|
+
const agent = { id: randomUUID2(), label: agentLabel(void 0, cwd), ...searchable(cwd) ? { folder: cwd } : {} };
|
|
38757
39211
|
const bridge = new Bridge(agent, port);
|
|
38758
39212
|
let origin = null;
|
|
38759
39213
|
const useProject = (folder) => {
|
|
38760
39214
|
project = folder;
|
|
38761
39215
|
agent.label = agentLabel(client, folder);
|
|
39216
|
+
agent.folder = folder;
|
|
38762
39217
|
};
|
|
38763
39218
|
server.server.oninitialized = () => {
|
|
38764
39219
|
client = server.server.getClientVersion()?.name;
|
|
@@ -38860,7 +39315,7 @@ ${p.text}` }, ...p.blocks])
|
|
|
38860
39315
|
"pilot_done",
|
|
38861
39316
|
{
|
|
38862
39317
|
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.",
|
|
39318
|
+
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. For a props job (`/props`), pass the component's props in `props`: Pilot shows them to the designer to pick values from.",
|
|
38864
39319
|
inputSchema: {
|
|
38865
39320
|
jobId: external_exports.string().describe("The job's id, from pilot_wait_for_edits."),
|
|
38866
39321
|
notes: external_exports.string().optional().describe("Short notes for the designer: values you approximated (e.g. 22px \u2192 pt-6, 24px), anything done differently."),
|
|
@@ -38869,13 +39324,22 @@ ${p.text}` }, ...p.blocks])
|
|
|
38869
39324
|
choices: external_exports.array(external_exports.string()).max(MAX_CHOICES).optional().describe(
|
|
38870
39325
|
`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
39326
|
)
|
|
38872
|
-
}).optional().describe("Only when part of the job needs the designer's decision: see the description.")
|
|
39327
|
+
}).optional().describe("Only when part of the job needs the designer's decision: see the description."),
|
|
39328
|
+
props: external_exports.array(
|
|
39329
|
+
external_exports.object({
|
|
39330
|
+
name: external_exports.string().describe("The prop's name, as the code has it (`variant`)."),
|
|
39331
|
+
type: external_exports.enum(["options", "boolean", "text", "number"]).describe("`options`: one of a set of values; `boolean`: on or off; `text` or `number`: typed."),
|
|
39332
|
+
options: external_exports.array(external_exports.string()).optional().describe("For `options`: every value it accepts, in the code's order."),
|
|
39333
|
+
default: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()]).optional().describe("Its default value, when it has one."),
|
|
39334
|
+
description: external_exports.string().optional().describe("What it does, in a few words, when the name doesn't say.")
|
|
39335
|
+
})
|
|
39336
|
+
).max(MAX_PROPS).optional().describe("Only for a props job (`/props`): the component's props the designer can set, the most useful first.")
|
|
38873
39337
|
}
|
|
38874
39338
|
},
|
|
38875
|
-
async ({ jobId, notes, question }) => {
|
|
39339
|
+
async ({ jobId, notes, question, props }) => {
|
|
38876
39340
|
try {
|
|
38877
39341
|
const asked = questionOf(question);
|
|
38878
|
-
const job = await bridge.done(jobId, notes, asked);
|
|
39342
|
+
const job = await bridge.done(jobId, notes, asked, propsOf(props));
|
|
38879
39343
|
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
39344
|
if (asked && job.question)
|
|
38881
39345
|
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.");
|
|
@@ -38915,14 +39379,14 @@ ${p.text}` }, ...p.blocks])
|
|
|
38915
39379
|
|
|
38916
39380
|
// src/update.ts
|
|
38917
39381
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
38918
|
-
import { existsSync as
|
|
39382
|
+
import { existsSync as existsSync7, lstatSync, readFileSync as readFileSync5 } from "fs";
|
|
38919
39383
|
import { homedir as homedir3 } from "os";
|
|
38920
|
-
import { dirname as
|
|
39384
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
38921
39385
|
async function update(options = {}) {
|
|
38922
39386
|
const cwd = options.cwd ?? process.cwd();
|
|
38923
39387
|
const run = options.run ?? runCommand2;
|
|
38924
39388
|
const home = options.home ?? homedir3();
|
|
38925
|
-
const pkg = readJson2(
|
|
39389
|
+
const pkg = readJson2(join7(cwd, "package.json"));
|
|
38926
39390
|
const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
38927
39391
|
if (!pkg || !deps.usepilot) {
|
|
38928
39392
|
return `# Pilot isn't installed here
|
|
@@ -38939,7 +39403,7 @@ Run this in your app's folder, the one where Pilot was set up. To set Pilot up i
|
|
|
38939
39403
|
const after = installed ? installedVersion(cwd, root) ?? VERSION : before;
|
|
38940
39404
|
const skills = [];
|
|
38941
39405
|
for (const folder of skillFolders(root, home)) {
|
|
38942
|
-
if (!
|
|
39406
|
+
if (!existsSync7(folder) || isLink2(folder)) continue;
|
|
38943
39407
|
await writeSkill(folder);
|
|
38944
39408
|
skills.push(folder.startsWith(home) ? `~${folder.slice(home.length)}` : folder);
|
|
38945
39409
|
}
|
|
@@ -38976,13 +39440,13 @@ ${steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
|
38976
39440
|
` : "Nothing else to do.\n"}`;
|
|
38977
39441
|
}
|
|
38978
39442
|
function bridgeOf(cwd, root) {
|
|
38979
|
-
for (let dir = cwd; ; dir =
|
|
38980
|
-
const file2 =
|
|
38981
|
-
if (
|
|
38982
|
-
const match = /BRIDGE_VERSION = (\d+)/.exec(
|
|
39443
|
+
for (let dir = cwd; ; dir = dirname5(dir)) {
|
|
39444
|
+
const file2 = join7(dir, "node_modules", "usepilot", "cli", "index.js");
|
|
39445
|
+
if (existsSync7(file2)) {
|
|
39446
|
+
const match = /BRIDGE_VERSION = (\d+)/.exec(readFileSync5(file2, "utf8"));
|
|
38983
39447
|
return match ? Number(match[1]) : null;
|
|
38984
39448
|
}
|
|
38985
|
-
if (dir === root ||
|
|
39449
|
+
if (dir === root || dirname5(dir) === dir) return null;
|
|
38986
39450
|
}
|
|
38987
39451
|
}
|
|
38988
39452
|
function isLink2(path) {
|
|
@@ -38994,7 +39458,7 @@ function isLink2(path) {
|
|
|
38994
39458
|
}
|
|
38995
39459
|
function readJson2(file2) {
|
|
38996
39460
|
try {
|
|
38997
|
-
return JSON.parse(
|
|
39461
|
+
return JSON.parse(readFileSync5(file2, "utf8"));
|
|
38998
39462
|
} catch {
|
|
38999
39463
|
return null;
|
|
39000
39464
|
}
|