usepilot 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/cli/index.js +1124 -946
- package/dist/{mount-BiOBwGgJ.js → mount-CLRI4wJ5.js} +2059 -1971
- package/dist/pilot-auto.js +1 -1
- package/dist/pilot.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +7 -2
package/cli/index.js
CHANGED
|
@@ -56,22 +56,25 @@ var AGENTS = {
|
|
|
56
56
|
install: "curl -fsSL https://claude.ai/install.sh | bash",
|
|
57
57
|
signIn: "claude auth login",
|
|
58
58
|
status: { args: ["auth", "status"], ok: (out) => /"loggedIn"\s*:\s*true/.test(out) },
|
|
59
|
-
//
|
|
59
|
+
// The designer's own settings (allow rules, MCP servers, skills), edits in the project accepted.
|
|
60
|
+
// A run can't prompt: `-p` refuses what would ask (checked; `--permission-prompts none` says the
|
|
61
|
+
// same, but older versions don't know it). Reading the user's skills is allowed, read-only: its
|
|
62
|
+
// chat would ask before a skill reads its other files there, and a run can't answer.
|
|
60
63
|
args: ({ resume, readDirs = [] }) => [
|
|
61
64
|
"-p",
|
|
62
65
|
"--output-format",
|
|
63
66
|
"stream-json",
|
|
64
67
|
"--verbose",
|
|
65
|
-
"--restricted",
|
|
66
|
-
"--strict-mcp-config",
|
|
67
|
-
"--tools",
|
|
68
|
-
"Read,Edit,Write,Glob,Grep",
|
|
69
68
|
"--permission-mode",
|
|
70
69
|
"acceptEdits",
|
|
70
|
+
"--allowedTools",
|
|
71
|
+
"Read(~/.claude/skills/**)",
|
|
71
72
|
...readDirs.flatMap((d) => ["--add-dir", d]),
|
|
72
73
|
...resume ? ["--resume", resume] : []
|
|
73
74
|
],
|
|
74
|
-
parse: parseStream
|
|
75
|
+
parse: parseStream,
|
|
76
|
+
skills: { project: [".claude/skills"], home: [".claude/skills"] },
|
|
77
|
+
invokeSkill: (name) => `/${name}`
|
|
75
78
|
},
|
|
76
79
|
codex: {
|
|
77
80
|
kind: "codex",
|
|
@@ -80,22 +83,23 @@ var AGENTS = {
|
|
|
80
83
|
install: "npm install -g @openai/codex",
|
|
81
84
|
signIn: "codex login",
|
|
82
85
|
status: { args: ["login", "status"], ok: (_out, code) => code === 0 },
|
|
83
|
-
// Its sandbox
|
|
86
|
+
// Its sandbox in the mode its chat uses for a project (writes in the project), with the designer's
|
|
87
|
+
// own settings for the rest (network, web search, rules). `exec` never asks: what would is refused.
|
|
84
88
|
// On Windows the sandbox needs a mode, or a run is read-only; "unelevated" needs no admin rights.
|
|
85
89
|
args: ({ resume, images = [], platform = process.platform }) => [
|
|
86
90
|
"exec",
|
|
87
91
|
"--json",
|
|
88
92
|
"-s",
|
|
89
93
|
"workspace-write",
|
|
90
|
-
"-c",
|
|
91
|
-
'web_search="disabled"',
|
|
92
94
|
...platform === "win32" ? ["-c", 'windows.sandbox="unelevated"'] : [],
|
|
93
95
|
"--skip-git-repo-check",
|
|
94
96
|
...images.flatMap((i) => ["-i", i]),
|
|
95
97
|
...resume ? ["resume", resume] : [],
|
|
96
98
|
"-"
|
|
97
99
|
],
|
|
98
|
-
parse: parseCodex
|
|
100
|
+
parse: parseCodex,
|
|
101
|
+
skills: { project: [".agents/skills"], home: [".agents/skills", ".codex/skills"] },
|
|
102
|
+
invokeSkill: (name) => "$" + name
|
|
99
103
|
},
|
|
100
104
|
cursor: {
|
|
101
105
|
kind: "cursor",
|
|
@@ -109,7 +113,9 @@ var AGENTS = {
|
|
|
109
113
|
// default AppArmor settings. Without `--force`, a run is refused what the user's allowlist doesn't
|
|
110
114
|
// allow (it can't ask): writes outside the project, web fetches, shell commands. Checked on all three.
|
|
111
115
|
args: ({ resume }) => ["-p", "--output-format", "stream-json", "--trust", "--sandbox", "disabled", ...resume ? ["--resume", resume] : []],
|
|
112
|
-
parse: parseStream
|
|
116
|
+
parse: parseStream,
|
|
117
|
+
skills: { project: [".agents/skills", ".cursor/skills"], home: [".cursor/skills"] },
|
|
118
|
+
invokeSkill: (name) => `/${name}`
|
|
113
119
|
}
|
|
114
120
|
};
|
|
115
121
|
function isAgentKind(value) {
|
|
@@ -132,6 +138,12 @@ function findBin(names, env = process.env, platform = process.platform, home = h
|
|
|
132
138
|
}
|
|
133
139
|
return null;
|
|
134
140
|
}
|
|
141
|
+
function agentFromEnv(env = process.env) {
|
|
142
|
+
if (env.CLAUDECODE || env.CLAUDE_CODE_ENTRYPOINT) return "claude";
|
|
143
|
+
if (env.CURSOR_AGENT || env.CURSOR_TRACE_ID) return "cursor";
|
|
144
|
+
if (env.CODEX_SANDBOX || env.CODEX_SANDBOX_NETWORK_DISABLED || env.CODEX_MANAGED_BY_NPM || env.CODEX_THREAD_ID) return "codex";
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
135
147
|
async function detectAgents(kinds = AGENT_KINDS) {
|
|
136
148
|
const found = await Promise.all(
|
|
137
149
|
kinds.map(async (kind) => {
|
|
@@ -214,960 +226,1007 @@ import { dirname as dirname2, join as join4, relative } from "path";
|
|
|
214
226
|
// src/config.ts
|
|
215
227
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
216
228
|
import { homedir as homedir2 } from "os";
|
|
217
|
-
import { dirname, join as join2, resolve } from "path";
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
function read(file) {
|
|
223
|
-
try {
|
|
224
|
-
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
225
|
-
return data && typeof data === "object" ? data : {};
|
|
226
|
-
} catch {
|
|
227
|
-
return {};
|
|
228
|
-
}
|
|
229
|
+
import { basename, dirname, join as join2, resolve } from "path";
|
|
230
|
+
|
|
231
|
+
// ../protocol/src/types.ts
|
|
232
|
+
function mentionText(reference) {
|
|
233
|
+
return reference.kind === "token" ? reference.name : `@${reference.name}`;
|
|
229
234
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
var ATTACHMENT_TYPES = {
|
|
236
|
+
png: "image/png",
|
|
237
|
+
jpg: "image/jpeg",
|
|
238
|
+
gif: "image/gif",
|
|
239
|
+
webp: "image/webp",
|
|
240
|
+
pdf: "application/pdf",
|
|
241
|
+
txt: "text/plain",
|
|
242
|
+
md: "text/markdown",
|
|
243
|
+
csv: "text/csv",
|
|
244
|
+
json: "application/json"
|
|
245
|
+
};
|
|
246
|
+
var ATTACHMENT_ID = /^[a-f0-9]{64}\.(png|jpg|gif|webp|pdf|txt|md|csv|json)$/;
|
|
247
|
+
function attachmentKind(name) {
|
|
248
|
+
const ext = name.split(".").pop()?.toLowerCase();
|
|
249
|
+
return ext === "pdf" ? "pdf" : ext === "png" || ext === "jpg" || ext === "jpeg" || ext === "gif" || ext === "webp" ? "image" : "text";
|
|
233
250
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
251
|
+
var BY_EXTENSION = {
|
|
252
|
+
png: "image/png",
|
|
253
|
+
jpg: "image/jpeg",
|
|
254
|
+
jpeg: "image/jpeg",
|
|
255
|
+
gif: "image/gif",
|
|
256
|
+
webp: "image/webp",
|
|
257
|
+
pdf: "application/pdf",
|
|
258
|
+
txt: "text/plain",
|
|
259
|
+
log: "text/plain",
|
|
260
|
+
text: "text/plain",
|
|
261
|
+
md: "text/markdown",
|
|
262
|
+
markdown: "text/markdown",
|
|
263
|
+
csv: "text/csv",
|
|
264
|
+
json: "application/json"
|
|
265
|
+
};
|
|
266
|
+
var ATTACHMENT_ACCEPT = [...new Set(Object.values(ATTACHMENT_TYPES))].join(",") + "," + Object.keys(BY_EXTENSION).map((e) => `.${e}`).join(",");
|
|
267
|
+
function requestTargets(request) {
|
|
268
|
+
return [request.target, ...request.others ?? []];
|
|
240
269
|
}
|
|
241
270
|
|
|
242
|
-
// src/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
271
|
+
// ../protocol/src/format.ts
|
|
272
|
+
function formatPrompt(changeSet) {
|
|
273
|
+
if (changeSet.request?.kind === "responsive") return formatResponsive(changeSet, changeSet.request);
|
|
274
|
+
if (changeSet.request?.kind === "break-and-fix") return formatBreakFix(changeSet, changeSet.request);
|
|
275
|
+
if (changeSet.request?.kind === "comment") return formatComment(changeSet, changeSet.request);
|
|
276
|
+
if (changeSet.request?.kind === "props") return formatProps(changeSet, changeSet.request);
|
|
277
|
+
const { page, edits, note } = changeSet;
|
|
278
|
+
const lines = [
|
|
279
|
+
"# Pilot design edits",
|
|
280
|
+
"",
|
|
281
|
+
"A designer adjusted the UI below in the browser with Pilot. Apply these changes to the source code.",
|
|
282
|
+
"",
|
|
283
|
+
"Guidelines:",
|
|
284
|
+
...editGuidelines(),
|
|
285
|
+
"",
|
|
286
|
+
`Page: ${page.url} (${page.title || "untitled"}) at ${page.viewport.width}x${page.viewport.height}`
|
|
253
287
|
];
|
|
288
|
+
if (note?.trim()) {
|
|
289
|
+
lines.push("", `Designer note: ${note.trim()}`);
|
|
290
|
+
}
|
|
291
|
+
edits.forEach((edit, index) => {
|
|
292
|
+
lines.push("", ...formatEdit(edit, index + 1));
|
|
293
|
+
});
|
|
294
|
+
lines.push(...fileTokenLines(changeSet.fileTokens));
|
|
295
|
+
return `${lines.join("\n")}
|
|
296
|
+
`;
|
|
254
297
|
}
|
|
255
|
-
function
|
|
298
|
+
function fileTokenLines(tokens) {
|
|
299
|
+
if (!tokens?.length) return [];
|
|
256
300
|
return [
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
join3(root, ".github", "skills", "pilot"),
|
|
264
|
-
join3(root, ".agents", "skills", "pilot")
|
|
301
|
+
"",
|
|
302
|
+
"## The project's tokens in these values",
|
|
303
|
+
"",
|
|
304
|
+
"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:",
|
|
305
|
+
"",
|
|
306
|
+
...tokens.map((t) => `- \`var(${t.variable})\` is \`${t.name}\` in \`${t.file}${t.line ? `:${t.line}` : ""}\` (\`${t.value}\`)`)
|
|
265
307
|
];
|
|
266
308
|
}
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
if (!e || typeof e.command !== "string") return false;
|
|
270
|
-
const args = Array.isArray(e.args) ? e.args.map(String) : [];
|
|
271
|
-
const line = [e.command, ...args].join(" ");
|
|
272
|
-
return args.includes("mcp") && /usepilot|packages\/cli\/dist\/index\.js/.test(line);
|
|
273
|
-
}
|
|
274
|
-
async function removeOldSetup(root, home, platform, run2) {
|
|
275
|
-
const removed = [];
|
|
276
|
-
for (const { file, key } of serverConfigs(root, home, platform)) {
|
|
277
|
-
let config;
|
|
278
|
-
try {
|
|
279
|
-
config = JSON.parse(await readFile(file, "utf8"));
|
|
280
|
-
} catch {
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
const servers = config?.[key];
|
|
284
|
-
if (!servers || !isPilotServer(servers.pilot)) continue;
|
|
285
|
-
delete servers.pilot;
|
|
286
|
-
await writeFile(file, `${JSON.stringify(config, null, 2)}
|
|
287
|
-
`);
|
|
288
|
-
removed.push(tilde(file, home));
|
|
289
|
-
}
|
|
290
|
-
const claude = readJson(join3(home, ".claude.json"))?.mcpServers?.pilot;
|
|
291
|
-
if (isPilotServer(claude) && run2("claude", ["mcp", "remove", "--scope", "user", "pilot"], home)) removed.push("Claude Code's `pilot` server");
|
|
292
|
-
if (/\[mcp_servers\.pilot\][^[]*usepilot/.test(readText(join3(home, ".codex", "config.toml"))) && run2("codex", ["mcp", "remove", "pilot"], home))
|
|
293
|
-
removed.push("Codex's `pilot` server");
|
|
294
|
-
for (const folder of skillFolders(root, home)) {
|
|
295
|
-
if (!await removeSkill(folder)) continue;
|
|
296
|
-
removed.push(tilde(folder, home));
|
|
297
|
-
}
|
|
298
|
-
return removed;
|
|
309
|
+
function advancedTask() {
|
|
310
|
+
return "**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, have it make the changes, and report back with what it did.";
|
|
299
311
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
312
|
+
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.";
|
|
313
|
+
var PRODUCTION_CODE = "No inline styles, no `!important`, no hard-coded values where a token or utility fits.";
|
|
314
|
+
var SHARED_CHOICES = {
|
|
315
|
+
all: { label: "All of them", means: "change the component (or the shared code) itself, so every instance gets it." },
|
|
316
|
+
one: {
|
|
317
|
+
label: "Only this",
|
|
318
|
+
means: "change it where this instance is used, with what the component already accepts: classes passed through its `className` (merged the way the project does, `cn`, `twMerge`), or one of its props. If it accepts neither, add the smallest pass-through (accept a `className`), not a variant. Never inline styles."
|
|
319
|
+
},
|
|
320
|
+
variant: {
|
|
321
|
+
label: "New variant",
|
|
322
|
+
means: "add a named option to the component, the way it defines its variants (a `cva` variant, a `variant` or `size` prop, a modifier class), named for its purpose, and use it here. Say its name in your notes."
|
|
306
323
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
function vscodeUserDir(home, platform) {
|
|
313
|
-
if (platform === "darwin") return join3(home, "Library", "Application Support", "Code", "User");
|
|
314
|
-
if (platform === "win32") return join3(process.env.APPDATA ?? join3(home, "AppData", "Roaming"), "Code", "User");
|
|
315
|
-
return join3(home, ".config", "Code", "User");
|
|
324
|
+
};
|
|
325
|
+
function sharedChoiceMeaning(answer) {
|
|
326
|
+
const said = answer.trim().toLowerCase();
|
|
327
|
+
const choice = Object.values(SHARED_CHOICES).find((c) => c.label.toLowerCase() === said);
|
|
328
|
+
return choice ? `**${choice.label}**: ${choice.means}` : null;
|
|
316
329
|
}
|
|
317
|
-
function
|
|
318
|
-
return
|
|
330
|
+
function sharedCode() {
|
|
331
|
+
return [
|
|
332
|
+
`**Shared code, only some copies:** an element's "Look-alikes" line counts the elements like it that this job leaves out (other instances of its component, or the same part of other copies). If they come from the same code (a shared component, a loop over data), and the designer didn't say which they meant, don't guess: do the rest of the job, leave that part, and ask in one short sentence, the component's name in **bold**, with three choices, your suggestion first: "${SHARED_CHOICES.all.label}", "${SHARED_CHOICES.one.label}", "${SHARED_CHOICES.variant.label}" (as the question in your reply's \`pilot\` block). Their answer comes back to you as this job.`,
|
|
333
|
+
...Object.values(SHARED_CHOICES).map((c) => `**${c.label}**: ${c.means}`),
|
|
334
|
+
`Don't ask when the designer already said (in the comment or note: "only here", "every card", "as a variant"), when every copy is in the job, or when nothing else uses that code: just change it.`
|
|
335
|
+
].join(" ");
|
|
319
336
|
}
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
337
|
+
function editGuidelines() {
|
|
338
|
+
return [
|
|
339
|
+
`- ${DESIGN_INTENT}`,
|
|
340
|
+
`- ${PRODUCTION_CODE} Prefer an existing token or utility when it matches the value (or is within a pixel or two): utility classes take the closest one in the project's scale or theme (\`padding-top: 24px\` \u2192 \`pt-6\`), arbitrary values only when nothing fits. Mention any value you had to approximate.`,
|
|
341
|
+
"- Find each element by its selector, DOM path and text, then the component that renders it. Change only the listed elements.",
|
|
342
|
+
`- ${sharedCode()}`,
|
|
343
|
+
"- A removed property means the element shouldn't declare it at all: not `0` or `none`, the declaration gone.",
|
|
344
|
+
"- No screenshots, builds or tests for these edits: hot reload shows them, and Pilot checks the page itself.",
|
|
345
|
+
`- 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.`,
|
|
346
|
+
"- 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.",
|
|
347
|
+
"- 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)."
|
|
348
|
+
];
|
|
326
349
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
350
|
+
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}`;
|
|
351
|
+
var ACTION_ASKED = {
|
|
352
|
+
responsive: "asked you to make it responsive",
|
|
353
|
+
"break-and-fix": "asked you to break and fix it",
|
|
354
|
+
props: "asked for the component's props"
|
|
355
|
+
};
|
|
356
|
+
function propValue(value) {
|
|
357
|
+
return value === void 0 ? "*not set*" : `\`${typeof value === "string" ? JSON.stringify(value) : String(value)}\``;
|
|
333
358
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
359
|
+
function formatProps(changeSet, request) {
|
|
360
|
+
const { page, note } = changeSet;
|
|
361
|
+
const current = Object.entries(request.current);
|
|
362
|
+
const lines = [
|
|
363
|
+
"# Pilot: props",
|
|
364
|
+
"",
|
|
365
|
+
`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.**`,
|
|
366
|
+
"",
|
|
367
|
+
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
368
|
+
"",
|
|
369
|
+
...elementsSection(request),
|
|
370
|
+
...request.usedIn ? [`- This instance is written in: \`${request.usedIn}\``] : [],
|
|
371
|
+
"",
|
|
372
|
+
"## Its props now (read from the page)",
|
|
373
|
+
"",
|
|
374
|
+
...current.length ? current.map(([name, value]) => `- \`${name}\`: ${propValue(value)}`) : ["None that Pilot could read (it reads strings, numbers and on-off values)."],
|
|
375
|
+
...note?.trim() ? ["", `Designer note: ${note.trim()}`] : [],
|
|
376
|
+
...request.attachments?.length ? ["", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`)] : [],
|
|
377
|
+
...request.references?.length ? ["", ...referenceLines(request.references)] : [],
|
|
378
|
+
"",
|
|
379
|
+
"## What to list",
|
|
380
|
+
"",
|
|
381
|
+
"- **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.",
|
|
382
|
+
'- **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.',
|
|
383
|
+
"- The most useful first (the main variant, then the size, then the rest); 12 at most.",
|
|
384
|
+
"",
|
|
385
|
+
"Reply with one short sentence for the designer, like a chat message (\"Button has 3 props you can change\"), and the list as `props` in your reply's `pilot` block. 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 and leave the block out."
|
|
386
|
+
];
|
|
387
|
+
return `${lines.join("\n")}
|
|
388
|
+
`;
|
|
342
389
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
|
|
390
|
+
function formatBreakFix(changeSet, request) {
|
|
391
|
+
const { page, note } = changeSet;
|
|
392
|
+
const { breakpoints } = request;
|
|
393
|
+
const several = requestTargets(request).length;
|
|
394
|
+
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
395
|
+
const lines = [
|
|
396
|
+
"# Pilot: break and fix",
|
|
397
|
+
"",
|
|
398
|
+
several > 1 ? `A designer selected the ${several} elements below together in the browser with Pilot and asked you to stress-test each of them: make sure they hold up with real-world content, not only the placeholder values they were built with, and fix what breaks. Content should never break the layout.` : "A designer selected the element below in the browser with Pilot and asked you to stress-test it: make sure it holds up with real-world content, not only the placeholder values it was built with, and fix what breaks. Content should never break the layout.",
|
|
399
|
+
"",
|
|
400
|
+
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
401
|
+
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
402
|
+
"",
|
|
403
|
+
advancedTask()
|
|
404
|
+
];
|
|
405
|
+
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
406
|
+
if (request.attachments?.length)
|
|
407
|
+
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
408
|
+
if (request.references?.length) lines.push("", ...referenceLines(request.references));
|
|
409
|
+
lines.push(
|
|
410
|
+
"",
|
|
411
|
+
...elementsSection(request),
|
|
412
|
+
"",
|
|
413
|
+
"## How to do it",
|
|
414
|
+
"",
|
|
415
|
+
"1. **Find the element's component and where its content comes from**: props, data, a CMS or an API, translations. List what can vary: each text, how many repeated items there are, optional parts (an image, a subtitle, a badge), numbers, names, URLs.",
|
|
416
|
+
"2. **Think of the odd but realistic content each can get**: text far longer than the placeholder (a 120-character title, a long person or product name) and much shorter or empty; long words with no spaces (URLs, emails, IDs, compound words); optional parts missing (no image, no subtitle, an empty list) and many repeated items instead of a few; big numbers and prices; the longer strings of other languages; images (and background images) in odd shapes, very wide, very tall, tiny or low-resolution, and images that fail to load.",
|
|
417
|
+
"3. **Find where it breaks**: for each kind of odd content, read the layout code and work out what it would do: content sticking out of the viewport, spilling out of its parent, clipped, or overlapping; items that shrink when they shouldn't (an icon or avatar squeezed by flex), buttons that stretch, rows that misalign, text wrapping under an icon, images stretched or squashed. If trying it helps, put the content in temporarily and take it out again; no browser or screenshots.",
|
|
418
|
+
"4. **Fix what breaks, without changing how it looks with its usual content**, the way this project does it (its utilities, its components):",
|
|
419
|
+
" - **Long text:** truncate it with an ellipsis (`truncate`, `text-overflow: ellipsis`) where one line matters, or clamp it to a few lines (`line-clamp-*`) where it can wrap; when the full text is lost, show it on hover (`title`, or the project's tooltip).",
|
|
420
|
+
" - **Flex and grid:** `min-width: 0` (`min-w-0`) on items holding text so they can shrink; `flex-shrink: 0` (`shrink-0`) on icons, avatars and buttons that mustn't; `minmax(0, 1fr)` columns; wrapping rows (`flex-wrap`) instead of overflowing ones.",
|
|
421
|
+
" - **Long words:** `overflow-wrap: anywhere` (`break-words`) where text must wrap.",
|
|
422
|
+
" - **Images:** `object-fit: cover` for photos that should fill their frame, `contain` where cropping would lose something (logos, product shots); for background images, `background-size: cover` (or `contain`) with a sensible `background-position`. A fixed `aspect-ratio` (or size) on the frame, so the layout doesn't jump while an image loads or when its shape is odd, and a fallback when it fails or is missing (a plain background, initials, an icon), never a broken-image box.",
|
|
423
|
+
" - **Missing parts:** no gap or empty box left behind; a simple empty state only where one is clearly needed.",
|
|
424
|
+
" In the check, an ellipsis on your deliberately long text is the fix working, not a problem.",
|
|
425
|
+
"5. **Put the real content back.** Remove every temporary value you added: nothing of the test may stay in the code. With its usual content, the element must look as it did at the designer's width.",
|
|
426
|
+
`6. **Report** in your notes, in a line or two, what broke and how you fixed it, and anything for the designer to decide (a content limit to agree on, an empty state to design). When you report it done, Pilot runs the width check once more, with the usual content: problems come back to you once, as a follow-up.`,
|
|
427
|
+
"",
|
|
428
|
+
several > 1 ? `Change only these elements and what they need (their children, their containers). If they come from a shared component, fix it there, so every instance gets sturdier, as long as its usual look doesn't change; ask before anything that would. ${firstChecked()}` : "Change only this element and what it needs (its children, its container). If it's a shared component, fix it there, so every instance gets sturdier, as long as its usual look doesn't change; ask before anything that would.",
|
|
429
|
+
"",
|
|
430
|
+
PROJECT_CODE
|
|
431
|
+
);
|
|
432
|
+
return `${lines.join("\n")}
|
|
433
|
+
`;
|
|
348
434
|
}
|
|
349
|
-
function
|
|
350
|
-
|
|
435
|
+
function formatResponsive(changeSet, request) {
|
|
436
|
+
const { page, note } = changeSet;
|
|
437
|
+
const { breakpoints } = request;
|
|
438
|
+
const several = requestTargets(request).length;
|
|
439
|
+
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
440
|
+
const lines = [
|
|
441
|
+
"# Pilot: make responsive",
|
|
442
|
+
"",
|
|
443
|
+
several > 1 ? `A designer selected the ${several} elements below together in the browser with Pilot and asked you to make each of them work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.` : "A designer selected the element below in the browser with Pilot and asked you to make it work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.",
|
|
444
|
+
"",
|
|
445
|
+
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
446
|
+
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
447
|
+
"",
|
|
448
|
+
advancedTask()
|
|
449
|
+
];
|
|
450
|
+
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
451
|
+
if (request.attachments?.length)
|
|
452
|
+
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
453
|
+
if (request.references?.length) lines.push("", ...referenceLines(request.references));
|
|
454
|
+
lines.push(
|
|
455
|
+
"",
|
|
456
|
+
...elementsSection(request),
|
|
457
|
+
"",
|
|
458
|
+
"## How to do it",
|
|
459
|
+
"",
|
|
460
|
+
"1. **Find the element's component** and the layout around it (its parent and siblings): a fix often belongs to the container, not the element.",
|
|
461
|
+
"2. **Learn how this project does responsive**: its breakpoints and their names (Tailwind config or theme, CSS variables, existing media queries), whether components respond to their container instead (container queries, `@container`), and whether it writes mobile-first (min-width) or desktop-first (max-width). Use its breakpoints; don't invent new ones.",
|
|
462
|
+
"3. **Find similar components** that already have responsive rules (other cards, lists, headers, forms in this project) and follow the same patterns, so this one behaves like its siblings.",
|
|
463
|
+
"4. **Make the smallest changes that work**, in the project's conventions (Tailwind variants like `md:`, the media queries it already uses, its tokens): layout first (stacking, wrapping, columns, flex direction), then spacing and type size. Hide content only as a last resort, and say so. Don't change how it looks at the width the designer is working at unless that width has a problem too. Never leave inline styles.",
|
|
464
|
+
"5. **Check every width from the code**: work out how the element lays out at a phone width (375px), each breakpoint and 1px below it, and a wide desktop (1440px), and fix what wouldn't fit. No browser or screenshots: when you're done, Pilot loads the page at those widths, measures the element (sticking out of the viewport, spilling out of its parent, clipped content, overlaps, anything changed at the designer's width) and sends back what it finds, once.",
|
|
465
|
+
`6. **Report** in your notes what changed at which widths, in a line or two, and anything you left for the designer to decide. When you report it done, Pilot runs the width check once more: problems come back to you once, as a follow-up.`,
|
|
466
|
+
"",
|
|
467
|
+
several > 1 ? `Change only these elements and what their layout needs (their containers, their children). ${firstChecked()}` : "Change only this element and what its layout needs (its container, its children).",
|
|
468
|
+
"",
|
|
469
|
+
sharedCode(),
|
|
470
|
+
"",
|
|
471
|
+
PROJECT_CODE
|
|
472
|
+
);
|
|
473
|
+
return `${lines.join("\n")}
|
|
474
|
+
`;
|
|
351
475
|
}
|
|
352
|
-
function
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
476
|
+
function formatComment(changeSet, request) {
|
|
477
|
+
const { page, edits } = changeSet;
|
|
478
|
+
const { thread, breakpoints } = request;
|
|
479
|
+
const several = requestTargets(request).length;
|
|
480
|
+
const latest = thread.at(-1);
|
|
481
|
+
const earlier = thread.slice(0, -1);
|
|
482
|
+
const widths = breakpoints.length ? breakpoints.map((b) => `${b}px`).join(", ") : "none found (it may use container queries, or none yet)";
|
|
483
|
+
const lines = [
|
|
484
|
+
"# Pilot: comment",
|
|
485
|
+
"",
|
|
486
|
+
several > 1 ? `A designer left a comment on the ${several} elements below, selected together in the browser with Pilot: it's about each of them. Do what it asks in the source code (or, if it's a question, answer it).` : "A designer left a comment on the element below, in the browser with Pilot. Do what it asks in the source code (or, if it's a question, answer it).",
|
|
487
|
+
"",
|
|
488
|
+
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
489
|
+
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
490
|
+
"",
|
|
491
|
+
...elementsSection(request),
|
|
492
|
+
"",
|
|
493
|
+
"## The comment",
|
|
494
|
+
"",
|
|
495
|
+
// Props set from the thread, with no words: the props are the comment.
|
|
496
|
+
...latest?.props && !latest.text.trim() && !latest.attachments?.length ? ["The designer set props on this instance (below), with no words."] : latest?.skill && !latest.text.trim() && !latest.attachments?.length ? [`The designer picked the skill \`${latest.skill}\` (below), with no words: use it on ${several > 1 ? "these elements" : "this element"}.`] : commentLines(latest)
|
|
497
|
+
];
|
|
498
|
+
if (latest?.skill) {
|
|
499
|
+
lines.push(
|
|
500
|
+
"",
|
|
501
|
+
"## The skill to use",
|
|
502
|
+
"",
|
|
503
|
+
`The designer asked you to use their skill \`${latest.skill}\` for this comment: load it the way you load skills, and follow it for ${several > 1 ? "these elements" : "this element"}. Where it and the guidelines below differ, the skill wins; what it doesn't say, they cover. If a step needs something you can't do in this run (a permission you don't have, a tool that isn't there), skip it and say so in your reply. If there's no skill by that name, say so and don't guess what it does.`
|
|
504
|
+
);
|
|
357
505
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
done: [],
|
|
371
|
-
todo: [
|
|
372
|
-
it ? `**Tell the user** to sign in to ${cli.label}'s command-line tool: \`${cli.signIn}\` in a terminal.` : `**Tell the user** to install ${cli.label}'s command-line tool and sign in: \`${cli.install}\`, then \`${cli.signIn}\`.`
|
|
373
|
-
]
|
|
374
|
-
};
|
|
506
|
+
if (latest?.props?.set.length) {
|
|
507
|
+
const { component, usedIn, set } = latest.props;
|
|
508
|
+
lines.push(
|
|
509
|
+
"",
|
|
510
|
+
"## Props to set",
|
|
511
|
+
"",
|
|
512
|
+
`The designer picked new values for this \`${component}\` instance's props from the list you gave (the \`name: value\` lines in their comment):`,
|
|
513
|
+
"",
|
|
514
|
+
...set.map((c) => `- \`${c.name}\`: ${propValue(c.from)} \u2192 ${propValue(c.to)}`),
|
|
515
|
+
"",
|
|
516
|
+
`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 (the question in your reply's \`pilot\` block) before changing it for all of them. Pilot reads the instance's props on the page when you're done.`
|
|
517
|
+
);
|
|
375
518
|
}
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const cwd = options.cwd ?? process.cwd();
|
|
389
|
-
const run2 = options.run ?? runCommand;
|
|
390
|
-
const pkgFile = join4(cwd, "package.json");
|
|
391
|
-
if (!existsSync2(pkgFile)) {
|
|
392
|
-
return `# Pilot: not set up
|
|
393
|
-
|
|
394
|
-
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.
|
|
395
|
-
`;
|
|
519
|
+
if (edits.length) {
|
|
520
|
+
lines.push(
|
|
521
|
+
"",
|
|
522
|
+
"## The designer's edits, sent with the comment",
|
|
523
|
+
"",
|
|
524
|
+
`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.`,
|
|
525
|
+
"",
|
|
526
|
+
"Guidelines:",
|
|
527
|
+
...editGuidelines()
|
|
528
|
+
);
|
|
529
|
+
edits.forEach((edit, index) => lines.push("", ...formatEdit(edit, index + 1).map((l) => l.startsWith("## ") ? `#${l}` : l)));
|
|
530
|
+
lines.push(...fileTokenLines(changeSet.fileTokens));
|
|
396
531
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
${cwd} is a monorepo's root, not an app. Run \`npx usepilot@latest init\` again in the folder of the web app the user works on${apps.length ? `, one of:
|
|
406
|
-
|
|
407
|
-
${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
408
|
-
`;
|
|
532
|
+
if (earlier.length) {
|
|
533
|
+
lines.push("", "## The thread so far (you already did what it asked)", "");
|
|
534
|
+
for (const m of earlier) {
|
|
535
|
+
const files = m.attachments?.length ? ` (${countFiles(m.attachments.length)})` : "";
|
|
536
|
+
const action = m.action ? ` (${ACTION_ASKED[m.action]})` : m.skill ? ` (with the skill \`${m.skill}\`)` : "";
|
|
537
|
+
lines.push(`- **${m.from === "designer" ? "Designer" : "You"}:**${action}${files} ${m.text.replace(/\s*\n\s*/g, " ")}`.trimEnd());
|
|
538
|
+
}
|
|
409
539
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
done.push(`Installed \`usepilot\` as a dev dependency (\`${install}\`).`);
|
|
423
|
-
else todo.push(`Install Pilot as a dev dependency: run \`${install}\` in ${cwd}.`);
|
|
424
|
-
const wanted = agentKindOf(options.agent);
|
|
425
|
-
const found = await (options.detect ?? detectAgents)();
|
|
426
|
-
const agents = agentLines(found, wanted);
|
|
427
|
-
done.push(...agents.done);
|
|
428
|
-
todo.push(...agents.todo);
|
|
429
|
-
if (wanted && found.some((a) => a.kind === wanted && a.signedIn)) saveAgent(cwd, wanted, options.configFile);
|
|
430
|
-
const home = options.home ?? homedir3();
|
|
431
|
-
const removed = await removeOldSetup(root, home, options.platform ?? process.platform, run2);
|
|
432
|
-
if (removed.length) done.push(`Removed Pilot's old chat setup (its MCP server and \`/pilot\` skill): ${removed.map((r) => `\`${r}\``).join(", ")}. Pilot runs the agent itself now.`);
|
|
433
|
-
if (framework.loads) done.push(`The app already loads Pilot (\`${relative(cwd, framework.loads)}\`).`);
|
|
434
|
-
else todo.push(loadStep(framework, cwd));
|
|
435
|
-
todo.push(
|
|
436
|
-
`**Tell the user**, in a few lines: Pilot is set up. To use it, run \`npx usepilot\` in ${cwd}, in a terminal beside the app's dev server, and open the app: Pilot opens on every page. They design and press Send (or comment on an element), Pilot runs their agent for each job, and the terminal shows what it does. No chat needs to stay open; without \`npx usepilot\` running, the toolbar says so.`
|
|
540
|
+
lines.push(
|
|
541
|
+
"",
|
|
542
|
+
"## How to do it",
|
|
543
|
+
"",
|
|
544
|
+
"- **A specific, small ask** (a color, a size, a spacing, a text): make it right away, in the project's conventions (its tokens, utilities, components). Speed matters: no screenshots or builds.",
|
|
545
|
+
"- **An open-ended ask that needs design judgment** (make it calmer, rework this layout): it's an advanced task. If you can hand work to a more capable model than the one you run on (a subagent, or another model your agent offers), do: give it this prompt (with the job id), and report back with its notes.",
|
|
546
|
+
`- The designer was looking at the page ${page.viewport.width}px wide. If the comment is about how it looks at that width only, scope the change with the project's breakpoints; otherwise it's for every width.`,
|
|
547
|
+
`- ${PROJECT_CODE}`,
|
|
548
|
+
several > 1 ? "- Change only what the comment is about, on each of these elements." : "- Change only what the comment is about.",
|
|
549
|
+
`- ${sharedCode()}`,
|
|
550
|
+
"- **A question, not a change:** answer it, and change nothing.",
|
|
551
|
+
latest?.skill ? "- **Your notes are your reply in the designer's thread:** reply as the skill says (findings, a report, options to pick from), as long as it needs to be. Markdown shows (lists, bold, inline `code`, code blocks); headings show as bold lines." : "- **Your notes are your reply in the designer's thread, a small chat box for quick design back-and-forth:** keep it concise, like a chat message: what you changed, or your answer, or what you need from them, in a few short sentences at most. No headings, and not a report: the designer sees the result on the page."
|
|
437
552
|
);
|
|
438
|
-
return
|
|
439
|
-
|
|
440
|
-
Done:
|
|
441
|
-
${done.map((d) => `- ${d}`).join("\n")}
|
|
442
|
-
|
|
443
|
-
Left for you (the agent), in order:
|
|
444
|
-
${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
|
|
553
|
+
return `${lines.join("\n")}
|
|
445
554
|
`;
|
|
446
555
|
}
|
|
447
|
-
function
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
556
|
+
function commentLines(message) {
|
|
557
|
+
const text = message?.text.trim() ?? "";
|
|
558
|
+
const files = message?.attachments ?? [];
|
|
559
|
+
const out = text ? [quote(text)] : [];
|
|
560
|
+
const references = message?.references ?? [];
|
|
561
|
+
if (references.length) out.push("", ...referenceLines(references));
|
|
562
|
+
if (!files.length) return out.length ? out : ["> (empty)"];
|
|
563
|
+
const one = files.length === 1;
|
|
564
|
+
if (out.length) out.push("");
|
|
565
|
+
out.push(
|
|
566
|
+
text ? `The designer attached ${countFiles(files.length)} to it:` : `The comment is ${countFiles(files.length)}, with no words. ${one ? "It" : "They"} may hold the instructions: a screenshot, a sketch, notes, a spec. If it's unclear what to do, ask in your reply instead of guessing.`,
|
|
567
|
+
"",
|
|
568
|
+
...attachmentLines(files)
|
|
569
|
+
);
|
|
570
|
+
return out;
|
|
452
571
|
}
|
|
453
|
-
function
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
572
|
+
function referenceLines(references) {
|
|
573
|
+
const picked = references.some((r) => r.kind !== "unlisted");
|
|
574
|
+
return [
|
|
575
|
+
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:",
|
|
576
|
+
"",
|
|
577
|
+
...references.map(referenceLine)
|
|
578
|
+
];
|
|
461
579
|
}
|
|
462
|
-
function
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
return
|
|
475
|
-
"next-pages",
|
|
476
|
-
first("src/pages/_app.tsx", "src/pages/_app.jsx", "src/pages/_app.js", "pages/_app.tsx", "pages/_app.jsx", "pages/_app.js")
|
|
477
|
-
);
|
|
580
|
+
function referenceLine(reference) {
|
|
581
|
+
const as = `- \`${mentionText(reference)}\`:`;
|
|
582
|
+
if (reference.kind === "token" && reference.source)
|
|
583
|
+
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.`;
|
|
584
|
+
if (reference.kind === "token")
|
|
585
|
+
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).`;
|
|
586
|
+
if (reference.kind === "unlisted")
|
|
587
|
+
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.`;
|
|
588
|
+
if (reference.kind === "component") {
|
|
589
|
+
const t = reference.target;
|
|
590
|
+
const source = reference.source ?? (t?.source?.file ? { file: t.source.file, line: t.source.line } : void 0);
|
|
591
|
+
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)`;
|
|
592
|
+
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.`;
|
|
478
593
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
594
|
+
const el = reference.target;
|
|
595
|
+
const component = el.source?.component ? `, inside the \`${el.source.component}\` component` : "";
|
|
596
|
+
return `${as} an element on the page: \`${el.path}\`, selector \`${el.selector}\`${el.text ? `, text "${el.text}"` : ""}${component}.`;
|
|
597
|
+
}
|
|
598
|
+
function attachmentLines(files, intro) {
|
|
599
|
+
const lines = files.map((file) => {
|
|
600
|
+
const kind = attachmentKind(file.id);
|
|
601
|
+
const how = kind === "pdf" ? "a PDF: open it at this path" : kind === "image" ? "an image, shown with this job" : "a text file, its contents shown with this job";
|
|
602
|
+
return `- ${file.name ? `${file.name} ` : ""}(${how}): \`${file.path ?? file.id}\``;
|
|
603
|
+
});
|
|
604
|
+
return intro ? [intro, "", ...lines] : lines;
|
|
605
|
+
}
|
|
606
|
+
function countFiles(n) {
|
|
607
|
+
return n === 1 ? "a file" : `${n} files`;
|
|
608
|
+
}
|
|
609
|
+
function quote(text) {
|
|
610
|
+
return text.trim().split("\n").map((l) => `> ${l}`).join("\n");
|
|
611
|
+
}
|
|
612
|
+
function firstChecked() {
|
|
613
|
+
return "Pilot's width check after you're done measures the first of them; read the code for the others.";
|
|
614
|
+
}
|
|
615
|
+
function elementsSection(request) {
|
|
616
|
+
const targets = requestTargets(request);
|
|
617
|
+
if (targets.length === 1) return [`## \`${request.target.path}\``, "", ...targetLines(request.target)];
|
|
618
|
+
const out = [`## The elements (${targets.length})`];
|
|
619
|
+
targets.forEach((target, i) => out.push("", `### ${i + 1}. \`${target.path}\``, "", ...targetLines(target)));
|
|
620
|
+
return out;
|
|
621
|
+
}
|
|
622
|
+
function targetLines(target) {
|
|
623
|
+
const out = [`- Selector: \`${target.selector}\``];
|
|
624
|
+
if (target.text) out.push(`- Text: "${target.text}"`);
|
|
625
|
+
if (target.source?.component || target.source?.file) {
|
|
626
|
+
const { component, file, line } = target.source;
|
|
627
|
+
const where = [component && `\`${component}\``, file && `\`${file}${line ? `:${line}` : ""}\``].filter(Boolean).join(", in ");
|
|
628
|
+
out.push(`- Component: ${where}`);
|
|
491
629
|
}
|
|
492
|
-
if (
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
first("src/index.tsx", "src/index.ts", "src/index.jsx", "src/index.js", "src/main.tsx", "src/main.ts", "src/main.js")
|
|
496
|
-
);
|
|
630
|
+
if (target.lookAlikes) {
|
|
631
|
+
const of = target.lookAlikesOf ? `other instances of \`${target.lookAlikesOf}\`, the same part of each` : "the same part of other copies";
|
|
632
|
+
out.push(`- Look-alikes: ${target.lookAlikes} more on the page (${of}), not in this job`);
|
|
497
633
|
}
|
|
498
|
-
return
|
|
634
|
+
return out;
|
|
499
635
|
}
|
|
500
|
-
function
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
636
|
+
function formatEdit(edit, n) {
|
|
637
|
+
const { target, changes, texts } = edit;
|
|
638
|
+
const out = [`## ${n}. \`${target.path}\``, "", ...targetLines(target)];
|
|
639
|
+
if (texts?.length) out.push("", "Text (from \u2192 to):", "", ...texts.map((t) => `- ${JSON.stringify(t.from)} \u2192 ${JSON.stringify(t.to)}`));
|
|
640
|
+
if (!changes.length) return out;
|
|
641
|
+
const withStates = changes.some((c) => c.states?.length);
|
|
642
|
+
out.push(
|
|
643
|
+
"",
|
|
644
|
+
withStates ? "| Property | From | To | Widths | State |" : "| Property | From | To | Widths |",
|
|
645
|
+
withStates ? "| --- | --- | --- | --- | --- |" : "| --- | --- | --- | --- |"
|
|
646
|
+
);
|
|
647
|
+
for (const c of changes) {
|
|
648
|
+
const to = c.removed ? "*removed*" : `\`${c.to}\``;
|
|
649
|
+
const from = c.from ? `\`${c.from}\`` : "*not set*";
|
|
650
|
+
const widths = c.widths ? describeWidths(c.widths) : "every width";
|
|
651
|
+
out.push(`| \`${c.property}\` | ${from} | ${to} | ${widths} |${withStates ? ` ${describeStates(c.states)} |` : ""}`);
|
|
509
652
|
}
|
|
510
|
-
|
|
653
|
+
const notes = changes.flatMap((c) => [c.removed && removalNote(c), mediaNote(c)].filter((n2) => !!n2));
|
|
654
|
+
if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
|
|
655
|
+
return out;
|
|
511
656
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
657
|
+
function describeStates(states) {
|
|
658
|
+
return states?.length ? states.join(", ") : "\u2014";
|
|
659
|
+
}
|
|
660
|
+
function describeWidths({ min, max }) {
|
|
661
|
+
if (min !== void 0 && min === max) return `${min}px only`;
|
|
662
|
+
if (min !== void 0 && max !== void 0) return `${min}\u2013${max}px`;
|
|
663
|
+
if (min !== void 0) return `from ${min}px`;
|
|
664
|
+
if (max !== void 0) return `to ${max}px`;
|
|
665
|
+
return "every width";
|
|
666
|
+
}
|
|
667
|
+
function mediaNote(c) {
|
|
668
|
+
const media = c.source?.kind === "rule" ? c.source.media : void 0;
|
|
669
|
+
if (!media) return null;
|
|
670
|
+
const today = `\`${c.property}\` is set inside \`@media ${media}\` today.`;
|
|
671
|
+
return c.widths ? `${today} The change is for ${describeWidths(c.widths)}.` : `${today} The change is for every width, so that media query shouldn't override it.`;
|
|
672
|
+
}
|
|
673
|
+
function removalNote(c) {
|
|
674
|
+
const note = `\`${c.property}\` is removed: this element shouldn't set it (not \`0\` or \`none\`), so it gets what the cascade gives without it (another rule, the inherited value, or the default).`;
|
|
675
|
+
const source = c.source;
|
|
676
|
+
if (!source) return note;
|
|
677
|
+
if (source.kind === "inline") return `${note} It's set in the element's own \`style\` attribute.`;
|
|
678
|
+
const shared = source.elements && source.elements > 1 ? `, which matches ${source.elements} elements on the page: remove it for this element only, unless the designer's note says otherwise` : "";
|
|
679
|
+
return `${note} It comes from \`${source.selector}\`${shared}.`;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// ../protocol/src/bridge.ts
|
|
683
|
+
var BRIDGE_VERSION = 8;
|
|
684
|
+
var DEFAULT_BRIDGE_PORT = 4747 + BRIDGE_VERSION;
|
|
685
|
+
var SKILL_NAME = /^[A-Za-z0-9][\w.:-]{0,63}$/;
|
|
686
|
+
var MAX_CHOICES = 4;
|
|
687
|
+
function questionOf(value) {
|
|
688
|
+
const q = value;
|
|
689
|
+
if (typeof q?.text !== "string" || !q.text.trim()) return void 0;
|
|
690
|
+
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);
|
|
691
|
+
return { text: q.text.trim().slice(0, 500), ...choices.length ? { choices } : {} };
|
|
692
|
+
}
|
|
693
|
+
function sessionOf(value) {
|
|
694
|
+
const s = value;
|
|
695
|
+
if (typeof s?.agent !== "string" || !/^[a-z]{1,20}$/.test(s.agent)) return void 0;
|
|
696
|
+
if (typeof s.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9-]{7,99}$/.test(s.id)) return void 0;
|
|
697
|
+
return { agent: s.agent, id: s.id };
|
|
698
|
+
}
|
|
699
|
+
function jobErrorOf(value) {
|
|
700
|
+
const e = value;
|
|
701
|
+
if (typeof e?.title !== "string" || !e.title.trim()) return void 0;
|
|
702
|
+
return { title: e.title.trim().slice(0, 200), detail: typeof e.detail === "string" ? e.detail.trim().slice(0, 1e3) : "" };
|
|
703
|
+
}
|
|
704
|
+
var MAX_PROPS = 20;
|
|
705
|
+
function propsOf(value) {
|
|
706
|
+
if (!Array.isArray(value)) return void 0;
|
|
707
|
+
const scalar = (v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
708
|
+
const props = value.flatMap((p) => {
|
|
709
|
+
const name = typeof p?.name === "string" ? p.name.trim().slice(0, 60) : "";
|
|
710
|
+
const type = ["options", "boolean", "text", "number"].includes(p?.type) ? p.type : null;
|
|
711
|
+
if (!name || !type) return [];
|
|
712
|
+
const options = Array.isArray(p.options) ? [...new Set(p.options.filter(scalar).map(String))].slice(0, 30) : [];
|
|
713
|
+
if (type === "options" && !options.length) return [];
|
|
714
|
+
return [
|
|
715
|
+
{
|
|
716
|
+
name,
|
|
717
|
+
type,
|
|
718
|
+
...type === "options" ? { options } : {},
|
|
719
|
+
...scalar(p.default) ? { default: p.default } : {},
|
|
720
|
+
...typeof p.description === "string" && p.description.trim() ? { description: p.description.trim().slice(0, 120) } : {}
|
|
721
|
+
}
|
|
722
|
+
];
|
|
723
|
+
});
|
|
724
|
+
return props.length ? props.slice(0, MAX_PROPS) : void 0;
|
|
544
725
|
}
|
|
545
|
-
function
|
|
726
|
+
function projectNameOf(value) {
|
|
727
|
+
return typeof value === "string" && /^[\w@./-]{1,120}$/.test(value.trim()) ? value.trim() : void 0;
|
|
728
|
+
}
|
|
729
|
+
function originOf(url) {
|
|
546
730
|
try {
|
|
547
|
-
|
|
731
|
+
const u = new URL(url.includes("://") ? url : `http://${url}`);
|
|
732
|
+
return u.protocol === "http:" || u.protocol === "https:" ? u.origin : null;
|
|
548
733
|
} catch {
|
|
549
|
-
return
|
|
734
|
+
return null;
|
|
550
735
|
}
|
|
551
736
|
}
|
|
552
|
-
function
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const pkg = readJson2(join4(dir, name, "package.json"));
|
|
562
|
-
if (pkg && detectFramework(join4(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
|
|
563
|
-
found.push(join4(group, name));
|
|
564
|
-
}
|
|
737
|
+
function isLocalHost(hostname) {
|
|
738
|
+
const h = hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
739
|
+
if (!h) return false;
|
|
740
|
+
if (h === "localhost" || h === "0.0.0.0" || h === "::1" || h === "::") return true;
|
|
741
|
+
if (/\.(localhost|local|test|internal|lan|home\.arpa)$/.test(h)) return true;
|
|
742
|
+
const v4 = /^(\d{1,3})\.(\d{1,3})\.\d{1,3}\.\d{1,3}$/.exec(h);
|
|
743
|
+
if (v4) {
|
|
744
|
+
const [a, b] = [Number(v4[1]), Number(v4[2])];
|
|
745
|
+
return a === 127 || a === 10 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 169 && b === 254;
|
|
565
746
|
}
|
|
566
|
-
return
|
|
747
|
+
if (h.includes(":")) return /^f[cd][0-9a-f]{2}:/.test(h) || /^fe[89ab][0-9a-f]:/.test(h);
|
|
748
|
+
return !h.includes(".");
|
|
749
|
+
}
|
|
750
|
+
function originKey(origin) {
|
|
751
|
+
return origin.replace(/^(https?:\/\/)(?:127\.0\.0\.1|\[::1\])(?=[:/]|$)/, "$1localhost").replace(/\/$/, "");
|
|
567
752
|
}
|
|
568
|
-
function loadStep(framework, cwd) {
|
|
569
|
-
const at = (file, otherwise) => file ? `\`${relative(cwd, file)}\`` : otherwise;
|
|
570
|
-
const code = (lang, text) => `
|
|
571
|
-
|
|
572
|
-
\`\`\`${lang}
|
|
573
|
-
${text.replace(/^(?=.)/gm, " ")}
|
|
574
|
-
\`\`\``;
|
|
575
|
-
const intro = "**Load Pilot in the app, in development only** (it must never reach production), the way this project writes code.";
|
|
576
|
-
switch (framework.kind) {
|
|
577
|
-
case "vite":
|
|
578
|
-
return `${intro} It's a Vite app: in its entry module, ${at(framework.file, 'the module its HTML page loads (`<script type="module" src=\u2026>`)')}, add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
579
|
-
case "vite-html":
|
|
580
|
-
return `${intro} It's a Vite app whose pages load no module of their own (classic scripts only, which Vite doesn't process), and its HTML may be deployed as it is. So don't edit the HTML: inject Pilot from ${at(framework.file, "its Vite config (create `vite.config.js` if there's none)")}, only while Vite serves. Add this plugin to its \`plugins\` (keep any that are there):${code(
|
|
581
|
-
"js",
|
|
582
|
-
`{
|
|
583
|
-
name: "pilot",
|
|
584
|
-
apply: "serve", // development only: builds never get it
|
|
585
|
-
transformIndexHtml: {
|
|
586
|
-
order: "pre", // before Vite's own processing, so it resolves the package
|
|
587
|
-
handler: () => [{ tag: "script", attrs: { type: "module" }, children: 'import("usepilot/auto");', injectTo: "body" }],
|
|
588
|
-
},
|
|
589
|
-
}`
|
|
590
|
-
)}
|
|
591
|
-
|
|
592
|
-
It's added to every HTML page Vite serves.`;
|
|
593
|
-
case "next-app":
|
|
594
|
-
return `${intro} It's Next.js (App Router): add a client component, and render it in ${at(framework.file, "the root layout")}, inside \`<body>\`:${code(
|
|
595
|
-
"tsx",
|
|
596
|
-
`"use client";
|
|
597
|
-
import { useEffect } from "react";
|
|
598
753
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return null;
|
|
604
|
-
}`
|
|
605
|
-
)}`;
|
|
606
|
-
case "next-pages":
|
|
607
|
-
return `${intro} It's Next.js (Pages Router): in ${at(framework.file, "the custom App, `pages/_app` (create it if there's none)")}, in the App component:${code(
|
|
608
|
-
"tsx",
|
|
609
|
-
`useEffect(() => {
|
|
610
|
-
if (process.env.NODE_ENV === "development") import("usepilot/auto");
|
|
611
|
-
}, []);`
|
|
612
|
-
)}`;
|
|
613
|
-
case "nuxt":
|
|
614
|
-
return `${intro} It's Nuxt: add a client plugin, \`plugins/pilot.client.ts\` (\`app/plugins/\` in Nuxt 4's layout):${code(
|
|
615
|
-
"ts",
|
|
616
|
-
`export default defineNuxtPlugin(() => {
|
|
617
|
-
if (import.meta.dev) import("usepilot/auto");
|
|
618
|
-
});`
|
|
619
|
-
)}`;
|
|
620
|
-
case "sveltekit":
|
|
621
|
-
return `${intro} It's SvelteKit: in ${at(framework.file, "`src/hooks.client.ts`")} (create it if there's none), add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
622
|
-
case "astro":
|
|
623
|
-
return `${intro} It's Astro: in the layout every page uses, add:${code("astro", '<script>\n if (import.meta.env.DEV) import("usepilot/auto");\n</script>')}`;
|
|
624
|
-
case "react-router":
|
|
625
|
-
return `${intro} It's React Router (or Remix): in ${at(framework.file, "the root route module (`root.tsx` in the app folder)")}, in the root component:${code(
|
|
626
|
-
"tsx",
|
|
627
|
-
`useEffect(() => {
|
|
628
|
-
if (import.meta.env.DEV) import("usepilot/auto");
|
|
629
|
-
}, []);`
|
|
630
|
-
)}`;
|
|
631
|
-
case "webpack":
|
|
632
|
-
return `${intro} In the app's entry file, ${at(framework.file, "the one its bundler config starts from")}, add:${code("js", 'if (process.env.NODE_ENV === "development") import("usepilot/auto");')}`;
|
|
633
|
-
default:
|
|
634
|
-
return `${intro} With no bundler Pilot knows (a server-rendered site: PHP, Rails, Django, plain HTML), add it to the layout every page shares (Pilot works on every page), as one tag pointing at Pilot's file where the dev server serves it: \`<script type="module" src="\u2026/node_modules/usepilot/dist/pilot-auto.js"></script>\`. **It must never be output on a server, whatever a request says.** Print it only when both hold: Pilot's own file is on disk (\`node_modules/usepilot/dist/pilot-auto.js\`: a dev dependency, never on a server, as long as the deploy leaves \`node_modules\` out or installs without dev dependencies: check the project's deploy rules, and ask the user if you can't tell), and the project's own development setting says so (an environment variable like \`APP_ENV=local\`, or the local config file that isn't deployed; ask the user if there's none). Never decide from the request (the Host header, the client's IP): a proxy or a client can make them say anything. For example, in PHP:${code(
|
|
635
|
-
"php",
|
|
636
|
-
`<?php if (is_file(__DIR__ . '/node_modules/usepilot/dist/pilot-auto.js') && getenv('APP_ENV') === 'local') { ?>
|
|
637
|
-
<script type="module" src="/node_modules/usepilot/dist/pilot-auto.js"></script>
|
|
638
|
-
<?php } ?>`
|
|
639
|
-
)}
|
|
640
|
-
With a bundler, import \`usepilot/auto\` from the browser code, only in development (\`import.meta.env.DEV\` with Vite, \`process.env.NODE_ENV === "development"\` with webpack). Either way Pilot itself won't run on a public address.`;
|
|
641
|
-
}
|
|
754
|
+
// src/config.ts
|
|
755
|
+
function configFile(env = process.env, platform = process.platform, home = homedir2()) {
|
|
756
|
+
const base = platform === "win32" ? env.APPDATA ?? join2(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME ?? join2(home, ".config");
|
|
757
|
+
return join2(base, "usepilot", "projects.json");
|
|
642
758
|
}
|
|
643
|
-
function
|
|
759
|
+
function read(file) {
|
|
644
760
|
try {
|
|
645
|
-
|
|
761
|
+
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
762
|
+
return data && typeof data === "object" ? data : {};
|
|
646
763
|
} catch {
|
|
647
|
-
return
|
|
764
|
+
return {};
|
|
648
765
|
}
|
|
649
766
|
}
|
|
650
|
-
function
|
|
651
|
-
const
|
|
652
|
-
return
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// src/run.ts
|
|
656
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
657
|
-
import { existsSync as existsSync6 } from "fs";
|
|
658
|
-
import { basename as basename5 } from "path";
|
|
659
|
-
|
|
660
|
-
// ../protocol/src/types.ts
|
|
661
|
-
function mentionText(reference) {
|
|
662
|
-
return reference.kind === "token" ? reference.name : `@${reference.name}`;
|
|
767
|
+
function savedAgent(folder, file = configFile()) {
|
|
768
|
+
const agent = read(file)[resolve(folder)]?.agent;
|
|
769
|
+
return isAgentKind(agent) ? agent : void 0;
|
|
663
770
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
txt: "text/plain",
|
|
671
|
-
md: "text/markdown",
|
|
672
|
-
csv: "text/csv",
|
|
673
|
-
json: "application/json"
|
|
674
|
-
};
|
|
675
|
-
var ATTACHMENT_ID = /^[a-f0-9]{64}\.(png|jpg|gif|webp|pdf|txt|md|csv|json)$/;
|
|
676
|
-
function attachmentKind(name) {
|
|
677
|
-
const ext = name.split(".").pop()?.toLowerCase();
|
|
678
|
-
return ext === "pdf" ? "pdf" : ext === "png" || ext === "jpg" || ext === "jpeg" || ext === "gif" || ext === "webp" ? "image" : "text";
|
|
771
|
+
function saveAgent(folder, agent, file = configFile()) {
|
|
772
|
+
const projects = read(file);
|
|
773
|
+
projects[resolve(folder)] = { ...projects[resolve(folder)], agent };
|
|
774
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
775
|
+
writeFileSync(file, `${JSON.stringify(projects, null, 2)}
|
|
776
|
+
`);
|
|
679
777
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
txt: "text/plain",
|
|
688
|
-
log: "text/plain",
|
|
689
|
-
text: "text/plain",
|
|
690
|
-
md: "text/markdown",
|
|
691
|
-
markdown: "text/markdown",
|
|
692
|
-
csv: "text/csv",
|
|
693
|
-
json: "application/json"
|
|
694
|
-
};
|
|
695
|
-
var ATTACHMENT_ACCEPT = [...new Set(Object.values(ATTACHMENT_TYPES))].join(",") + "," + Object.keys(BY_EXTENSION).map((e) => `.${e}`).join(",");
|
|
696
|
-
function requestTargets(request) {
|
|
697
|
-
return [request.target, ...request.others ?? []];
|
|
778
|
+
function projectName(folder) {
|
|
779
|
+
try {
|
|
780
|
+
const name = projectNameOf(JSON.parse(readFileSync(join2(folder, "package.json"), "utf8")).name);
|
|
781
|
+
if (name) return name;
|
|
782
|
+
} catch {
|
|
783
|
+
}
|
|
784
|
+
return projectNameOf(basename(resolve(folder))) ?? "project";
|
|
698
785
|
}
|
|
699
786
|
|
|
700
|
-
//
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
"",
|
|
710
|
-
|
|
711
|
-
"",
|
|
712
|
-
"Guidelines:",
|
|
713
|
-
...editGuidelines(),
|
|
714
|
-
"",
|
|
715
|
-
`Page: ${page.url} (${page.title || "untitled"}) at ${page.viewport.width}x${page.viewport.height}`
|
|
787
|
+
// src/legacy.ts
|
|
788
|
+
import { existsSync, lstatSync, readFileSync as readFileSync2 } from "fs";
|
|
789
|
+
import { readFile, rm, unlink, writeFile } from "fs/promises";
|
|
790
|
+
import { join as join3 } from "path";
|
|
791
|
+
function serverConfigs(root, home, platform) {
|
|
792
|
+
return [
|
|
793
|
+
{ file: join3(home, ".cursor", "mcp.json"), key: "mcpServers" },
|
|
794
|
+
{ file: join3(vscodeUserDir(home, platform), "mcp.json"), key: "servers" },
|
|
795
|
+
{ file: join3(root, ".mcp.json"), key: "mcpServers" },
|
|
796
|
+
{ file: join3(root, ".cursor", "mcp.json"), key: "mcpServers" },
|
|
797
|
+
{ file: join3(root, ".vscode", "mcp.json"), key: "servers" }
|
|
716
798
|
];
|
|
717
|
-
|
|
718
|
-
|
|
799
|
+
}
|
|
800
|
+
function skillFolders(root, home) {
|
|
801
|
+
return [
|
|
802
|
+
join3(home, ".claude", "skills", "pilot"),
|
|
803
|
+
join3(home, ".cursor", "skills", "pilot"),
|
|
804
|
+
join3(home, ".copilot", "skills", "pilot"),
|
|
805
|
+
join3(home, ".agents", "skills", "pilot"),
|
|
806
|
+
join3(root, ".claude", "skills", "pilot"),
|
|
807
|
+
join3(root, ".cursor", "skills", "pilot"),
|
|
808
|
+
join3(root, ".github", "skills", "pilot"),
|
|
809
|
+
join3(root, ".agents", "skills", "pilot")
|
|
810
|
+
];
|
|
811
|
+
}
|
|
812
|
+
function isPilotServer(entry) {
|
|
813
|
+
const e = entry;
|
|
814
|
+
if (!e || typeof e.command !== "string") return false;
|
|
815
|
+
const args = Array.isArray(e.args) ? e.args.map(String) : [];
|
|
816
|
+
const line = [e.command, ...args].join(" ");
|
|
817
|
+
return args.includes("mcp") && /usepilot|packages\/cli\/dist\/index\.js/.test(line);
|
|
818
|
+
}
|
|
819
|
+
async function removeOldSetup(root, home, platform, run2) {
|
|
820
|
+
const removed = [];
|
|
821
|
+
for (const { file, key } of serverConfigs(root, home, platform)) {
|
|
822
|
+
let config;
|
|
823
|
+
try {
|
|
824
|
+
config = JSON.parse(await readFile(file, "utf8"));
|
|
825
|
+
} catch {
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
const servers = config?.[key];
|
|
829
|
+
if (!servers || !isPilotServer(servers.pilot)) continue;
|
|
830
|
+
delete servers.pilot;
|
|
831
|
+
await writeFile(file, `${JSON.stringify(config, null, 2)}
|
|
832
|
+
`);
|
|
833
|
+
removed.push(tilde(file, home));
|
|
834
|
+
}
|
|
835
|
+
const claude = readJson(join3(home, ".claude.json"))?.mcpServers?.pilot;
|
|
836
|
+
if (isPilotServer(claude) && run2("claude", ["mcp", "remove", "--scope", "user", "pilot"], home)) removed.push("Claude Code's `pilot` server");
|
|
837
|
+
if (/\[mcp_servers\.pilot\][^[]*usepilot/.test(readText(join3(home, ".codex", "config.toml"))) && run2("codex", ["mcp", "remove", "pilot"], home))
|
|
838
|
+
removed.push("Codex's `pilot` server");
|
|
839
|
+
for (const folder of skillFolders(root, home)) {
|
|
840
|
+
if (!await removeSkill(folder)) continue;
|
|
841
|
+
removed.push(tilde(folder, home));
|
|
719
842
|
}
|
|
720
|
-
|
|
721
|
-
lines.push("", ...formatEdit(edit, index + 1));
|
|
722
|
-
});
|
|
723
|
-
lines.push(...fileTokenLines(changeSet.fileTokens));
|
|
724
|
-
return `${lines.join("\n")}
|
|
725
|
-
`;
|
|
843
|
+
return removed;
|
|
726
844
|
}
|
|
727
|
-
function
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
845
|
+
async function removeSkill(folder) {
|
|
846
|
+
let link = false;
|
|
847
|
+
try {
|
|
848
|
+
link = lstatSync(folder).isSymbolicLink();
|
|
849
|
+
} catch {
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
if (!/^name:\s*pilot\s*$/m.test(readText(join3(folder, "SKILL.md")))) return false;
|
|
853
|
+
if (link) await unlink(folder);
|
|
854
|
+
else await rm(folder, { recursive: true, force: true });
|
|
855
|
+
return true;
|
|
737
856
|
}
|
|
738
|
-
function
|
|
739
|
-
|
|
857
|
+
function vscodeUserDir(home, platform) {
|
|
858
|
+
if (platform === "darwin") return join3(home, "Library", "Application Support", "Code", "User");
|
|
859
|
+
if (platform === "win32") return join3(process.env.APPDATA ?? join3(home, "AppData", "Roaming"), "Code", "User");
|
|
860
|
+
return join3(home, ".config", "Code", "User");
|
|
740
861
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
variant: {
|
|
750
|
-
label: "New variant",
|
|
751
|
-
means: "add a named option to the component, the way it defines its variants (a `cva` variant, a `variant` or `size` prop, a modifier class), named for its purpose, and use it here. Say its name in your notes."
|
|
862
|
+
function tilde(path, home) {
|
|
863
|
+
return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
864
|
+
}
|
|
865
|
+
function readText(file) {
|
|
866
|
+
try {
|
|
867
|
+
return existsSync(file) ? readFileSync2(file, "utf8") : "";
|
|
868
|
+
} catch {
|
|
869
|
+
return "";
|
|
752
870
|
}
|
|
753
|
-
};
|
|
754
|
-
function sharedChoiceMeaning(answer) {
|
|
755
|
-
const said = answer.trim().toLowerCase();
|
|
756
|
-
const choice = Object.values(SHARED_CHOICES).find((c) => c.label.toLowerCase() === said);
|
|
757
|
-
return choice ? `**${choice.label}**: ${choice.means}` : null;
|
|
758
871
|
}
|
|
759
|
-
function
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
872
|
+
function readJson(file) {
|
|
873
|
+
try {
|
|
874
|
+
return JSON.parse(readText(file));
|
|
875
|
+
} catch {
|
|
876
|
+
return null;
|
|
877
|
+
}
|
|
765
878
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
`- 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.`,
|
|
775
|
-
"- 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.",
|
|
776
|
-
"- 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)."
|
|
777
|
-
];
|
|
879
|
+
|
|
880
|
+
// src/version.ts
|
|
881
|
+
var VERSION = "0.15.0";
|
|
882
|
+
function olderThan(a, b) {
|
|
883
|
+
const parts = (v) => v.replace(/^[^\d]*/, "").split(/[.-]/).slice(0, 3).map((n) => Number.parseInt(n, 10) || 0);
|
|
884
|
+
const [x, y] = [parts(a), parts(b)];
|
|
885
|
+
for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) < (y[i] ?? 0);
|
|
886
|
+
return false;
|
|
778
887
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
};
|
|
785
|
-
function propValue(value) {
|
|
786
|
-
return value === void 0 ? "*not set*" : `\`${typeof value === "string" ? JSON.stringify(value) : String(value)}\``;
|
|
888
|
+
|
|
889
|
+
// src/init.ts
|
|
890
|
+
function agentKindOf(value) {
|
|
891
|
+
const v = value?.toLowerCase().replace(/^claude-code$/, "claude");
|
|
892
|
+
return isAgentKind(v) ? v : void 0;
|
|
787
893
|
}
|
|
788
|
-
function
|
|
789
|
-
|
|
790
|
-
const current = Object.entries(request.current);
|
|
791
|
-
const lines = [
|
|
792
|
-
"# Pilot: props",
|
|
793
|
-
"",
|
|
794
|
-
`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.**`,
|
|
795
|
-
"",
|
|
796
|
-
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
797
|
-
"",
|
|
798
|
-
...elementsSection(request),
|
|
799
|
-
...request.usedIn ? [`- This instance is written in: \`${request.usedIn}\``] : [],
|
|
800
|
-
"",
|
|
801
|
-
"## Its props now (read from the page)",
|
|
802
|
-
"",
|
|
803
|
-
...current.length ? current.map(([name, value]) => `- \`${name}\`: ${propValue(value)}`) : ["None that Pilot could read (it reads strings, numbers and on-off values)."],
|
|
804
|
-
...note?.trim() ? ["", `Designer note: ${note.trim()}`] : [],
|
|
805
|
-
...request.attachments?.length ? ["", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`)] : [],
|
|
806
|
-
...request.references?.length ? ["", ...referenceLines(request.references)] : [],
|
|
807
|
-
"",
|
|
808
|
-
"## What to list",
|
|
809
|
-
"",
|
|
810
|
-
"- **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.",
|
|
811
|
-
'- **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.',
|
|
812
|
-
"- The most useful first (the main variant, then the size, then the rest); 12 at most.",
|
|
813
|
-
"",
|
|
814
|
-
"Reply with one short sentence for the designer, like a chat message (\"Button has 3 props you can change\"), and the list as `props` in your reply's `pilot` block. 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 and leave the block out."
|
|
815
|
-
];
|
|
816
|
-
return `${lines.join("\n")}
|
|
817
|
-
`;
|
|
894
|
+
function agentsToInstall() {
|
|
895
|
+
return Object.values(AGENTS).map((cli) => `${cli.label}: \`${cli.install}\`, then \`${cli.signIn}\``).join("; ");
|
|
818
896
|
}
|
|
819
|
-
function
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
897
|
+
function installedVersion(cwd, root) {
|
|
898
|
+
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
899
|
+
const version = readJson2(join4(dir, "node_modules", "usepilot", "package.json"))?.version;
|
|
900
|
+
if (version) return version;
|
|
901
|
+
if (dir === root || dirname2(dir) === dir) return null;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
function installArgs(pm, spec = "usepilot") {
|
|
905
|
+
return pm === "npm" ? ["install", "-D", spec] : pm === "bun" ? ["add", "-d", spec] : ["add", "-D", spec];
|
|
906
|
+
}
|
|
907
|
+
function agentLines(found, wanted) {
|
|
908
|
+
const ready = found.filter((a) => a.signedIn);
|
|
909
|
+
const label = (kind) => AGENTS[kind].label;
|
|
910
|
+
if (wanted) {
|
|
911
|
+
const it = found.find((a) => a.kind === wanted);
|
|
912
|
+
const cli = AGENTS[wanted];
|
|
913
|
+
if (it?.signedIn) return { done: [`Pilot will run ${cli.label} for this project (signed in).`], todo: [] };
|
|
914
|
+
return {
|
|
915
|
+
done: [],
|
|
916
|
+
todo: [
|
|
917
|
+
it ? `**Tell the user** to sign in to ${cli.label}'s command-line tool: \`${cli.signIn}\` in a terminal.` : `**Tell the user** to install ${cli.label}'s command-line tool and sign in: \`${cli.install}\`, then \`${cli.signIn}\`.`
|
|
918
|
+
]
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
if (ready.length === 1) return { done: [`Pilot will run ${label(ready[0].kind)}, signed in here, for each job.`], todo: [] };
|
|
922
|
+
if (ready.length > 1)
|
|
923
|
+
return { done: [`Found ${ready.map((a) => label(a.kind)).join(" and ")} signed in: \`npx usepilot\` asks which to run, the first time.`], todo: [] };
|
|
924
|
+
const installed = found.map((a) => `${label(a.kind)} (\`${AGENTS[a.kind].signIn}\`)`);
|
|
925
|
+
return {
|
|
926
|
+
done: [],
|
|
927
|
+
todo: [
|
|
928
|
+
installed.length ? `**Tell the user** Pilot runs their coding agent's command-line tool for each job, and it isn't signed in: sign in to ${installed.join(" or ")} in a terminal.` : `**Tell the user** Pilot runs their coding agent's command-line tool for each job, and none is installed here. One of: ${agentsToInstall()}.`
|
|
929
|
+
]
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
async function init(options = {}) {
|
|
933
|
+
const cwd = options.cwd ?? process.cwd();
|
|
934
|
+
const run2 = options.run ?? runCommand;
|
|
935
|
+
const pkgFile = join4(cwd, "package.json");
|
|
936
|
+
if (!existsSync2(pkgFile)) {
|
|
937
|
+
return `# Pilot: not set up
|
|
938
|
+
|
|
939
|
+
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.
|
|
940
|
+
`;
|
|
941
|
+
}
|
|
942
|
+
const pkg = readJson2(pkgFile) ?? {};
|
|
943
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
944
|
+
const root = projectRoot(cwd);
|
|
945
|
+
const framework = detectFramework(cwd, deps);
|
|
946
|
+
if (framework.kind === "unknown" && isWorkspaceRoot(cwd, pkg)) {
|
|
947
|
+
const apps = workspaceApps(cwd);
|
|
948
|
+
return `# Pilot: not set up yet
|
|
949
|
+
|
|
950
|
+
${cwd} is a monorepo's root, not an app. Run \`npx usepilot@latest init\` again in the folder of the web app the user works on${apps.length ? `, one of:
|
|
951
|
+
|
|
952
|
+
${apps.map((a) => `- ${a}`).join("\n")}` : "."}
|
|
953
|
+
`;
|
|
954
|
+
}
|
|
955
|
+
const done = [];
|
|
956
|
+
const todo = [];
|
|
957
|
+
const pm = packageManager(cwd, root);
|
|
958
|
+
const args = installArgs(pm);
|
|
959
|
+
const install = `${pm} ${args.join(" ")}`;
|
|
960
|
+
const installed = deps.usepilot ? installedVersion(cwd, root) : null;
|
|
961
|
+
if (deps.usepilot && installed && olderThan(installed, VERSION))
|
|
962
|
+
todo.push(
|
|
963
|
+
`**Tell the user** Pilot ${installed} is installed here, and ${VERSION} is out: \`npx usepilot@latest update\` updates it (run it now if they ask).`
|
|
964
|
+
);
|
|
965
|
+
if (deps.usepilot) done.push("`usepilot` was already a dependency.");
|
|
966
|
+
else if (options.install !== false && run2(pm, args, cwd))
|
|
967
|
+
done.push(`Installed \`usepilot\` as a dev dependency (\`${install}\`).`);
|
|
968
|
+
else todo.push(`Install Pilot as a dev dependency: run \`${install}\` in ${cwd}.`);
|
|
969
|
+
const wanted = agentKindOf(options.agent) ?? agentFromEnv(options.env ?? process.env) ?? void 0;
|
|
970
|
+
const found = await (options.detect ?? detectAgents)();
|
|
971
|
+
const agents = agentLines(found, wanted);
|
|
972
|
+
done.push(...agents.done);
|
|
973
|
+
todo.push(...agents.todo);
|
|
974
|
+
if (wanted && found.some((a) => a.kind === wanted && a.signedIn)) saveAgent(cwd, wanted, options.configFile);
|
|
975
|
+
const home = options.home ?? homedir3();
|
|
976
|
+
const removed = await removeOldSetup(root, home, options.platform ?? process.platform, run2);
|
|
977
|
+
if (removed.length) done.push(`Removed Pilot's old chat setup (its MCP server and \`/pilot\` skill): ${removed.map((r) => `\`${r}\``).join(", ")}. Pilot runs the agent itself now.`);
|
|
978
|
+
if (framework.loads) {
|
|
979
|
+
const naming = namingStep(framework.loads, cwd);
|
|
980
|
+
if (naming) todo.push(naming);
|
|
981
|
+
else done.push(`The app already loads Pilot (\`${relative(cwd, framework.loads)}\`).`);
|
|
982
|
+
} else todo.push(loadStep(framework, cwd));
|
|
983
|
+
todo.push(
|
|
984
|
+
`**Tell the user**, in a few lines: Pilot is set up. To use it, run \`npx usepilot\` in ${cwd}, in a terminal beside the app's dev server, and open the app: Pilot opens on every page. They design and press Send (or comment on an element), Pilot runs their agent for each job, and the terminal shows what it does. No chat needs to stay open; without \`npx usepilot\` running, the toolbar says so.`
|
|
860
985
|
);
|
|
861
|
-
return
|
|
986
|
+
return `# Pilot: set up
|
|
987
|
+
|
|
988
|
+
Done:
|
|
989
|
+
${done.map((d) => `- ${d}`).join("\n")}
|
|
990
|
+
|
|
991
|
+
Left for you (the agent), in order:
|
|
992
|
+
${todo.map((t, i) => `${i + 1}. ${t}`).join("\n")}
|
|
862
993
|
`;
|
|
863
994
|
}
|
|
864
|
-
function
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
const lines = [
|
|
870
|
-
"# Pilot: make responsive",
|
|
871
|
-
"",
|
|
872
|
-
several > 1 ? `A designer selected the ${several} elements below together in the browser with Pilot and asked you to make each of them work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.` : "A designer selected the element below in the browser with Pilot and asked you to make it work well at every viewport width, from a narrow phone to a wide desktop. Decide the changes yourself and apply them to the source code.",
|
|
873
|
-
"",
|
|
874
|
-
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
875
|
-
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
876
|
-
"",
|
|
877
|
-
advancedTask()
|
|
878
|
-
];
|
|
879
|
-
if (note?.trim()) lines.push("", `Designer note: ${note.trim()}`);
|
|
880
|
-
if (request.attachments?.length)
|
|
881
|
-
lines.push("", ...attachmentLines(request.attachments, `The designer attached ${countFiles(request.attachments.length)}:`));
|
|
882
|
-
if (request.references?.length) lines.push("", ...referenceLines(request.references));
|
|
883
|
-
lines.push(
|
|
884
|
-
"",
|
|
885
|
-
...elementsSection(request),
|
|
886
|
-
"",
|
|
887
|
-
"## How to do it",
|
|
888
|
-
"",
|
|
889
|
-
"1. **Find the element's component** and the layout around it (its parent and siblings): a fix often belongs to the container, not the element.",
|
|
890
|
-
"2. **Learn how this project does responsive**: its breakpoints and their names (Tailwind config or theme, CSS variables, existing media queries), whether components respond to their container instead (container queries, `@container`), and whether it writes mobile-first (min-width) or desktop-first (max-width). Use its breakpoints; don't invent new ones.",
|
|
891
|
-
"3. **Find similar components** that already have responsive rules (other cards, lists, headers, forms in this project) and follow the same patterns, so this one behaves like its siblings.",
|
|
892
|
-
"4. **Make the smallest changes that work**, in the project's conventions (Tailwind variants like `md:`, the media queries it already uses, its tokens): layout first (stacking, wrapping, columns, flex direction), then spacing and type size. Hide content only as a last resort, and say so. Don't change how it looks at the width the designer is working at unless that width has a problem too. Never leave inline styles.",
|
|
893
|
-
"5. **Check every width from the code**: work out how the element lays out at a phone width (375px), each breakpoint and 1px below it, and a wide desktop (1440px), and fix what wouldn't fit. No browser or screenshots: when you're done, Pilot loads the page at those widths, measures the element (sticking out of the viewport, spilling out of its parent, clipped content, overlaps, anything changed at the designer's width) and sends back what it finds, once.",
|
|
894
|
-
`6. **Report** in your notes what changed at which widths, in a line or two, and anything you left for the designer to decide. When you report it done, Pilot runs the width check once more: problems come back to you once, as a follow-up.`,
|
|
895
|
-
"",
|
|
896
|
-
several > 1 ? `Change only these elements and what their layout needs (their containers, their children). ${firstChecked()}` : "Change only this element and what its layout needs (its container, its children).",
|
|
897
|
-
"",
|
|
898
|
-
sharedCode(),
|
|
899
|
-
"",
|
|
900
|
-
PROJECT_CODE
|
|
901
|
-
);
|
|
902
|
-
return `${lines.join("\n")}
|
|
903
|
-
`;
|
|
995
|
+
function projectRoot(cwd) {
|
|
996
|
+
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
997
|
+
if (existsSync2(join4(dir, ".git"))) return dir;
|
|
998
|
+
if (dirname2(dir) === dir) return cwd;
|
|
999
|
+
}
|
|
904
1000
|
}
|
|
905
|
-
function
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const lines = [
|
|
913
|
-
"# Pilot: comment",
|
|
914
|
-
"",
|
|
915
|
-
several > 1 ? `A designer left a comment on the ${several} elements below, selected together in the browser with Pilot: it's about each of them. Do what it asks in the source code (or, if it's a question, answer it).` : "A designer left a comment on the element below, in the browser with Pilot. Do what it asks in the source code (or, if it's a question, answer it).",
|
|
916
|
-
"",
|
|
917
|
-
`Page: ${page.url} (${page.title || "untitled"}), seen at ${page.viewport.width}x${page.viewport.height}`,
|
|
918
|
-
`The page's breakpoints (the widths its media queries test): ${widths}`,
|
|
919
|
-
"",
|
|
920
|
-
...elementsSection(request),
|
|
921
|
-
"",
|
|
922
|
-
"## The comment",
|
|
923
|
-
"",
|
|
924
|
-
// Props set from the thread, with no words: the props are the comment.
|
|
925
|
-
...latest?.props && !latest.text.trim() && !latest.attachments?.length ? ["The designer set props on this instance (below), with no words."] : commentLines(latest)
|
|
926
|
-
];
|
|
927
|
-
if (latest?.props?.set.length) {
|
|
928
|
-
const { component, usedIn, set } = latest.props;
|
|
929
|
-
lines.push(
|
|
930
|
-
"",
|
|
931
|
-
"## Props to set",
|
|
932
|
-
"",
|
|
933
|
-
`The designer picked new values for this \`${component}\` instance's props from the list you gave (the \`name: value\` lines in their comment):`,
|
|
934
|
-
"",
|
|
935
|
-
...set.map((c) => `- \`${c.name}\`: ${propValue(c.from)} \u2192 ${propValue(c.to)}`),
|
|
936
|
-
"",
|
|
937
|
-
`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 (the question in your reply's \`pilot\` block) before changing it for all of them. Pilot reads the instance's props on the page when you're done.`
|
|
938
|
-
);
|
|
1001
|
+
function packageManager(cwd, root) {
|
|
1002
|
+
for (let dir = cwd; ; dir = dirname2(dir)) {
|
|
1003
|
+
if (existsSync2(join4(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1004
|
+
if (existsSync2(join4(dir, "yarn.lock"))) return "yarn";
|
|
1005
|
+
if (existsSync2(join4(dir, "bun.lock")) || existsSync2(join4(dir, "bun.lockb"))) return "bun";
|
|
1006
|
+
if (existsSync2(join4(dir, "package-lock.json"))) return "npm";
|
|
1007
|
+
if (dir === root || dirname2(dir) === dir) return "npm";
|
|
939
1008
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1009
|
+
}
|
|
1010
|
+
function detectFramework(cwd, deps) {
|
|
1011
|
+
const has = (name) => name in deps;
|
|
1012
|
+
const first = (...files) => files.map((f) => join4(cwd, f)).find((f) => existsSync2(f));
|
|
1013
|
+
const loads = findLoader(cwd);
|
|
1014
|
+
const result = (kind, file) => ({ kind, file, loads });
|
|
1015
|
+
if (has("next")) {
|
|
1016
|
+
const app = first("src/app", "app");
|
|
1017
|
+
if (app)
|
|
1018
|
+
return result(
|
|
1019
|
+
"next-app",
|
|
1020
|
+
first("src/app/layout.tsx", "src/app/layout.jsx", "src/app/layout.js", "app/layout.tsx", "app/layout.jsx", "app/layout.js")
|
|
1021
|
+
);
|
|
1022
|
+
return result(
|
|
1023
|
+
"next-pages",
|
|
1024
|
+
first("src/pages/_app.tsx", "src/pages/_app.jsx", "src/pages/_app.js", "pages/_app.tsx", "pages/_app.jsx", "pages/_app.js")
|
|
949
1025
|
);
|
|
950
|
-
edits.forEach((edit, index) => lines.push("", ...formatEdit(edit, index + 1).map((l) => l.startsWith("## ") ? `#${l}` : l)));
|
|
951
|
-
lines.push(...fileTokenLines(changeSet.fileTokens));
|
|
952
1026
|
}
|
|
953
|
-
if (
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1027
|
+
if (has("nuxt")) return result("nuxt", first("plugins/pilot.client.ts", "app/plugins/pilot.client.ts"));
|
|
1028
|
+
if (has("@sveltejs/kit")) return result("sveltekit", first("src/hooks.client.ts", "src/hooks.client.js"));
|
|
1029
|
+
if (has("astro")) return result("astro");
|
|
1030
|
+
if (has("@react-router/dev") || has("@remix-run/react")) return result("react-router", first("app/root.tsx", "app/root.jsx"));
|
|
1031
|
+
if (has("vite") || Object.keys(deps).some((d) => d.startsWith("@vitejs/"))) {
|
|
1032
|
+
const entry = viteEntry(cwd);
|
|
1033
|
+
if (entry) return result("vite", entry);
|
|
1034
|
+
if (existsSync2(join4(cwd, "index.html"))) {
|
|
1035
|
+
const config = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((f) => join4(cwd, f)).find((f) => existsSync2(f));
|
|
1036
|
+
return result("vite-html", config);
|
|
959
1037
|
}
|
|
1038
|
+
return result("vite");
|
|
960
1039
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
"- **An open-ended ask that needs design judgment** (make it calmer, rework this layout): it's an advanced task. If you can hand work to a more capable model than the one you run on (a subagent, or another model your agent offers), do: give it this prompt (with the job id), and report back with its notes.",
|
|
967
|
-
`- The designer was looking at the page ${page.viewport.width}px wide. If the comment is about how it looks at that width only, scope the change with the project's breakpoints; otherwise it's for every width.`,
|
|
968
|
-
`- ${PROJECT_CODE}`,
|
|
969
|
-
several > 1 ? "- Change only what the comment is about, on each of these elements." : "- Change only what the comment is about.",
|
|
970
|
-
`- ${sharedCode()}`,
|
|
971
|
-
"- **A question, not a change:** answer it, and change nothing.",
|
|
972
|
-
"- **Your notes are your reply in the designer's thread, a small chat box for quick design back-and-forth:** keep it to one short sentence, like a chat message (about 120 characters at most): what you changed, or your answer, or the one thing you need from them. No lists, headings or code blocks; inline `code` for a value or a file name at most. Not a report: the designer sees the result on the page."
|
|
973
|
-
);
|
|
974
|
-
return `${lines.join("\n")}
|
|
975
|
-
`;
|
|
976
|
-
}
|
|
977
|
-
function commentLines(message) {
|
|
978
|
-
const text = message?.text.trim() ?? "";
|
|
979
|
-
const files = message?.attachments ?? [];
|
|
980
|
-
const out = text ? [quote(text)] : [];
|
|
981
|
-
const references = message?.references ?? [];
|
|
982
|
-
if (references.length) out.push("", ...referenceLines(references));
|
|
983
|
-
if (!files.length) return out.length ? out : ["> (empty)"];
|
|
984
|
-
const one = files.length === 1;
|
|
985
|
-
if (out.length) out.push("");
|
|
986
|
-
out.push(
|
|
987
|
-
text ? `The designer attached ${countFiles(files.length)} to it:` : `The comment is ${countFiles(files.length)}, with no words. ${one ? "It" : "They"} may hold the instructions: a screenshot, a sketch, notes, a spec. If it's unclear what to do, ask in your reply instead of guessing.`,
|
|
988
|
-
"",
|
|
989
|
-
...attachmentLines(files)
|
|
990
|
-
);
|
|
991
|
-
return out;
|
|
992
|
-
}
|
|
993
|
-
function referenceLines(references) {
|
|
994
|
-
const picked = references.some((r) => r.kind !== "unlisted");
|
|
995
|
-
return [
|
|
996
|
-
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:",
|
|
997
|
-
"",
|
|
998
|
-
...references.map(referenceLine)
|
|
999
|
-
];
|
|
1000
|
-
}
|
|
1001
|
-
function referenceLine(reference) {
|
|
1002
|
-
const as = `- \`${mentionText(reference)}\`:`;
|
|
1003
|
-
if (reference.kind === "token" && reference.source)
|
|
1004
|
-
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.`;
|
|
1005
|
-
if (reference.kind === "token")
|
|
1006
|
-
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).`;
|
|
1007
|
-
if (reference.kind === "unlisted")
|
|
1008
|
-
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.`;
|
|
1009
|
-
if (reference.kind === "component") {
|
|
1010
|
-
const t = reference.target;
|
|
1011
|
-
const source = reference.source ?? (t?.source?.file ? { file: t.source.file, line: t.source.line } : void 0);
|
|
1012
|
-
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)`;
|
|
1013
|
-
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.`;
|
|
1040
|
+
if (has("react-scripts") || has("webpack")) {
|
|
1041
|
+
return result(
|
|
1042
|
+
"webpack",
|
|
1043
|
+
first("src/index.tsx", "src/index.ts", "src/index.jsx", "src/index.js", "src/main.tsx", "src/main.ts", "src/main.js")
|
|
1044
|
+
);
|
|
1014
1045
|
}
|
|
1015
|
-
|
|
1016
|
-
const component = el.source?.component ? `, inside the \`${el.source.component}\` component` : "";
|
|
1017
|
-
return `${as} an element on the page: \`${el.path}\`, selector \`${el.selector}\`${el.text ? `, text "${el.text}"` : ""}${component}.`;
|
|
1018
|
-
}
|
|
1019
|
-
function attachmentLines(files, intro) {
|
|
1020
|
-
const lines = files.map((file) => {
|
|
1021
|
-
const kind = attachmentKind(file.id);
|
|
1022
|
-
const how = kind === "pdf" ? "a PDF: open it at this path" : kind === "image" ? "an image, shown with this job" : "a text file, its contents shown with this job";
|
|
1023
|
-
return `- ${file.name ? `${file.name} ` : ""}(${how}): \`${file.path ?? file.id}\``;
|
|
1024
|
-
});
|
|
1025
|
-
return intro ? [intro, "", ...lines] : lines;
|
|
1026
|
-
}
|
|
1027
|
-
function countFiles(n) {
|
|
1028
|
-
return n === 1 ? "a file" : `${n} files`;
|
|
1029
|
-
}
|
|
1030
|
-
function quote(text) {
|
|
1031
|
-
return text.trim().split("\n").map((l) => `> ${l}`).join("\n");
|
|
1032
|
-
}
|
|
1033
|
-
function firstChecked() {
|
|
1034
|
-
return "Pilot's width check after you're done measures the first of them; read the code for the others.";
|
|
1046
|
+
return { kind: "unknown", loads };
|
|
1035
1047
|
}
|
|
1036
|
-
function
|
|
1037
|
-
const
|
|
1038
|
-
if (
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1048
|
+
function viteEntry(cwd) {
|
|
1049
|
+
const html = join4(cwd, "index.html");
|
|
1050
|
+
if (existsSync2(html)) {
|
|
1051
|
+
for (const tag of readFileSync3(html, "utf8").match(/<script\b[^>]*>/gi) ?? []) {
|
|
1052
|
+
if (!/type=["']module["']/i.test(tag)) continue;
|
|
1053
|
+
const src = /src=["']\/?([^"'?#]+)/i.exec(tag)?.[1];
|
|
1054
|
+
if (src && existsSync2(join4(cwd, src))) return join4(cwd, src);
|
|
1055
|
+
}
|
|
1056
|
+
return void 0;
|
|
1057
|
+
}
|
|
1058
|
+
return ["src/main.tsx", "src/main.ts", "src/main.jsx", "src/main.js", "src/index.tsx", "src/index.ts"].map((f) => join4(cwd, f)).find((f) => existsSync2(f));
|
|
1042
1059
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1060
|
+
var SOURCE_DIRS = ["src", "app", "pages", "plugins", "components", "lib"];
|
|
1061
|
+
var SOURCE_FILE = /\.(m?[jt]sx?|vue|svelte|astro|html)$/;
|
|
1062
|
+
function findLoader(cwd) {
|
|
1063
|
+
let budget = 3e3;
|
|
1064
|
+
const walk = (dir, depth) => {
|
|
1065
|
+
let names;
|
|
1066
|
+
try {
|
|
1067
|
+
names = readdirSync(dir);
|
|
1068
|
+
} catch {
|
|
1069
|
+
return void 0;
|
|
1070
|
+
}
|
|
1071
|
+
for (const name of names) {
|
|
1072
|
+
if (budget-- <= 0 || name === "node_modules" || name.startsWith(".")) continue;
|
|
1073
|
+
const path = join4(dir, name);
|
|
1074
|
+
if (SOURCE_FILE.test(name)) {
|
|
1075
|
+
if (/["']usepilot(\/auto)?["']/.test(readText2(path))) return path;
|
|
1076
|
+
} else if (depth > 0 && !name.includes(".")) {
|
|
1077
|
+
const found = walk(path, depth - 1);
|
|
1078
|
+
if (found) return found;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return void 0;
|
|
1082
|
+
};
|
|
1083
|
+
for (const name of ["index.html", "vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"]) {
|
|
1084
|
+
const file = join4(cwd, name);
|
|
1085
|
+
if (existsSync2(file) && /usepilot/.test(readText2(file))) return file;
|
|
1050
1086
|
}
|
|
1051
|
-
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1087
|
+
for (const dir of SOURCE_DIRS) {
|
|
1088
|
+
const found = walk(join4(cwd, dir), 6);
|
|
1089
|
+
if (found) return found;
|
|
1054
1090
|
}
|
|
1055
|
-
return
|
|
1091
|
+
return void 0;
|
|
1056
1092
|
}
|
|
1057
|
-
function
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
const withStates = changes.some((c) => c.states?.length);
|
|
1063
|
-
out.push(
|
|
1064
|
-
"",
|
|
1065
|
-
withStates ? "| Property | From | To | Widths | State |" : "| Property | From | To | Widths |",
|
|
1066
|
-
withStates ? "| --- | --- | --- | --- | --- |" : "| --- | --- | --- | --- |"
|
|
1067
|
-
);
|
|
1068
|
-
for (const c of changes) {
|
|
1069
|
-
const to = c.removed ? "*removed*" : `\`${c.to}\``;
|
|
1070
|
-
const from = c.from ? `\`${c.from}\`` : "*not set*";
|
|
1071
|
-
const widths = c.widths ? describeWidths(c.widths) : "every width";
|
|
1072
|
-
out.push(`| \`${c.property}\` | ${from} | ${to} | ${widths} |${withStates ? ` ${describeStates(c.states)} |` : ""}`);
|
|
1093
|
+
function readText2(file) {
|
|
1094
|
+
try {
|
|
1095
|
+
return readFileSync3(file, "utf8");
|
|
1096
|
+
} catch {
|
|
1097
|
+
return "";
|
|
1073
1098
|
}
|
|
1074
|
-
const notes = changes.flatMap((c) => [c.removed && removalNote(c), mediaNote(c)].filter((n2) => !!n2));
|
|
1075
|
-
if (notes.length) out.push("", ...notes.map((n2) => `- ${n2}`));
|
|
1076
|
-
return out;
|
|
1077
|
-
}
|
|
1078
|
-
function describeStates(states) {
|
|
1079
|
-
return states?.length ? states.join(", ") : "\u2014";
|
|
1080
|
-
}
|
|
1081
|
-
function describeWidths({ min, max }) {
|
|
1082
|
-
if (min !== void 0 && min === max) return `${min}px only`;
|
|
1083
|
-
if (min !== void 0 && max !== void 0) return `${min}\u2013${max}px`;
|
|
1084
|
-
if (min !== void 0) return `from ${min}px`;
|
|
1085
|
-
if (max !== void 0) return `to ${max}px`;
|
|
1086
|
-
return "every width";
|
|
1087
1099
|
}
|
|
1088
|
-
function
|
|
1089
|
-
|
|
1090
|
-
if (!media) return null;
|
|
1091
|
-
const today = `\`${c.property}\` is set inside \`@media ${media}\` today.`;
|
|
1092
|
-
return c.widths ? `${today} The change is for ${describeWidths(c.widths)}.` : `${today} The change is for every width, so that media query shouldn't override it.`;
|
|
1100
|
+
function isWorkspaceRoot(cwd, pkg) {
|
|
1101
|
+
return !!pkg.workspaces || existsSync2(join4(cwd, "pnpm-workspace.yaml"));
|
|
1093
1102
|
}
|
|
1094
|
-
function
|
|
1095
|
-
const
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1103
|
+
function workspaceApps(cwd) {
|
|
1104
|
+
const found = [];
|
|
1105
|
+
for (const group of ["apps", "packages", "examples", "sites"]) {
|
|
1106
|
+
const dir = join4(cwd, group);
|
|
1107
|
+
if (!existsSync2(dir)) continue;
|
|
1108
|
+
for (const name of readdirSync(dir)) {
|
|
1109
|
+
const pkg = readJson2(join4(dir, name, "package.json"));
|
|
1110
|
+
if (pkg && detectFramework(join4(dir, name), { ...pkg.dependencies, ...pkg.devDependencies }).kind !== "unknown")
|
|
1111
|
+
found.push(join4(group, name));
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return found;
|
|
1101
1115
|
}
|
|
1116
|
+
function baseLoadStep(framework, cwd) {
|
|
1117
|
+
const at = (file, otherwise) => file ? `\`${relative(cwd, file)}\`` : otherwise;
|
|
1118
|
+
const code = (lang, text) => `
|
|
1102
1119
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1120
|
+
\`\`\`${lang}
|
|
1121
|
+
${text.replace(/^(?=.)/gm, " ")}
|
|
1122
|
+
\`\`\``;
|
|
1123
|
+
const intro = "**Load Pilot in the app, in development only** (it must never reach production), the way this project writes code.";
|
|
1124
|
+
switch (framework.kind) {
|
|
1125
|
+
case "vite":
|
|
1126
|
+
return `${intro} It's a Vite app: in its entry module, ${at(framework.file, 'the module its HTML page loads (`<script type="module" src=\u2026>`)')}, add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
1127
|
+
case "vite-html":
|
|
1128
|
+
return `${intro} It's a Vite app whose pages load no module of their own (classic scripts only, which Vite doesn't process), and its HTML may be deployed as it is. So don't edit the HTML: inject Pilot from ${at(framework.file, "its Vite config (create `vite.config.js` if there's none)")}, only while Vite serves. Add this plugin to its \`plugins\` (keep any that are there):${code(
|
|
1129
|
+
"js",
|
|
1130
|
+
`{
|
|
1131
|
+
name: "pilot",
|
|
1132
|
+
apply: "serve", // development only: builds never get it
|
|
1133
|
+
transformIndexHtml: {
|
|
1134
|
+
order: "pre", // before Vite's own processing, so it resolves the package
|
|
1135
|
+
handler: () => [{ tag: "script", attrs: { type: "module" }, children: 'import("usepilot/auto");', injectTo: "body" }],
|
|
1136
|
+
},
|
|
1137
|
+
}`
|
|
1138
|
+
)}
|
|
1139
|
+
|
|
1140
|
+
It's added to every HTML page Vite serves.`;
|
|
1141
|
+
case "next-app":
|
|
1142
|
+
return `${intro} It's Next.js (App Router): add a client component, and render it in ${at(framework.file, "the root layout")}, inside \`<body>\`:${code(
|
|
1143
|
+
"tsx",
|
|
1144
|
+
`"use client";
|
|
1145
|
+
import { useEffect } from "react";
|
|
1146
|
+
|
|
1147
|
+
export function Pilot() {
|
|
1148
|
+
useEffect(() => {
|
|
1149
|
+
if (process.env.NODE_ENV === "development") import("usepilot/auto");
|
|
1150
|
+
}, []);
|
|
1151
|
+
return null;
|
|
1152
|
+
}`
|
|
1153
|
+
)}`;
|
|
1154
|
+
case "next-pages":
|
|
1155
|
+
return `${intro} It's Next.js (Pages Router): in ${at(framework.file, "the custom App, `pages/_app` (create it if there's none)")}, in the App component:${code(
|
|
1156
|
+
"tsx",
|
|
1157
|
+
`useEffect(() => {
|
|
1158
|
+
if (process.env.NODE_ENV === "development") import("usepilot/auto");
|
|
1159
|
+
}, []);`
|
|
1160
|
+
)}`;
|
|
1161
|
+
case "nuxt":
|
|
1162
|
+
return `${intro} It's Nuxt: add a client plugin, \`plugins/pilot.client.ts\` (\`app/plugins/\` in Nuxt 4's layout):${code(
|
|
1163
|
+
"ts",
|
|
1164
|
+
`export default defineNuxtPlugin(() => {
|
|
1165
|
+
if (import.meta.dev) import("usepilot/auto");
|
|
1166
|
+
});`
|
|
1167
|
+
)}`;
|
|
1168
|
+
case "sveltekit":
|
|
1169
|
+
return `${intro} It's SvelteKit: in ${at(framework.file, "`src/hooks.client.ts`")} (create it if there's none), add:${code("ts", 'if (import.meta.env.DEV) import("usepilot/auto");')}`;
|
|
1170
|
+
case "astro":
|
|
1171
|
+
return `${intro} It's Astro: in the layout every page uses, add:${code("astro", '<script>\n if (import.meta.env.DEV) import("usepilot/auto");\n</script>')}`;
|
|
1172
|
+
case "react-router":
|
|
1173
|
+
return `${intro} It's React Router (or Remix): in ${at(framework.file, "the root route module (`root.tsx` in the app folder)")}, in the root component:${code(
|
|
1174
|
+
"tsx",
|
|
1175
|
+
`useEffect(() => {
|
|
1176
|
+
if (import.meta.env.DEV) import("usepilot/auto");
|
|
1177
|
+
}, []);`
|
|
1178
|
+
)}`;
|
|
1179
|
+
case "webpack":
|
|
1180
|
+
return `${intro} In the app's entry file, ${at(framework.file, "the one its bundler config starts from")}, add:${code("js", 'if (process.env.NODE_ENV === "development") import("usepilot/auto");')}`;
|
|
1181
|
+
default:
|
|
1182
|
+
return `${intro} With no bundler Pilot knows (a server-rendered site: PHP, Rails, Django, plain HTML), add it to the layout every page shares (Pilot works on every page), as one tag pointing at Pilot's file where the dev server serves it: \`<script type="module" src="\u2026/node_modules/usepilot/dist/pilot-auto.js"></script>\`. **It must never be output on a server, whatever a request says.** Print it only when both hold: Pilot's own file is on disk (\`node_modules/usepilot/dist/pilot-auto.js\`: a dev dependency, never on a server, as long as the deploy leaves \`node_modules\` out or installs without dev dependencies: check the project's deploy rules, and ask the user if you can't tell), and the project's own development setting says so (an environment variable like \`APP_ENV=local\`, or the local config file that isn't deployed; ask the user if there's none). Never decide from the request (the Host header, the client's IP): a proxy or a client can make them say anything. For example, in PHP:${code(
|
|
1183
|
+
"php",
|
|
1184
|
+
`<?php if (is_file(__DIR__ . '/node_modules/usepilot/dist/pilot-auto.js') && getenv('APP_ENV') === 'local') { ?>
|
|
1185
|
+
<script type="module" src="/node_modules/usepilot/dist/pilot-auto.js"></script>
|
|
1186
|
+
<?php } ?>`
|
|
1187
|
+
)}
|
|
1188
|
+
With a bundler, import \`usepilot/auto\` from the browser code, only in development (\`import.meta.env.DEV\` with Vite, \`process.env.NODE_ENV === "development"\` with webpack). Either way Pilot itself won't run on a public address.`;
|
|
1189
|
+
}
|
|
1112
1190
|
}
|
|
1113
|
-
function
|
|
1114
|
-
|
|
1115
|
-
if (typeof s?.agent !== "string" || !/^[a-z]{1,20}$/.test(s.agent)) return void 0;
|
|
1116
|
-
if (typeof s.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9-]{7,99}$/.test(s.id)) return void 0;
|
|
1117
|
-
return { agent: s.agent, id: s.id };
|
|
1191
|
+
function loaderCall(name) {
|
|
1192
|
+
return `import("usepilot").then((p) => p.mountPilot({ project: ${JSON.stringify(name)} }))`;
|
|
1118
1193
|
}
|
|
1119
|
-
function
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
return
|
|
1194
|
+
function loadStep(framework, cwd) {
|
|
1195
|
+
const name = projectName(cwd);
|
|
1196
|
+
const json2 = JSON.stringify(name);
|
|
1197
|
+
return baseLoadStep(framework, cwd).replaceAll('import("usepilot/auto")', loaderCall(name)).replaceAll(
|
|
1198
|
+
'<script type="module" src="/node_modules/usepilot/dist/pilot-auto.js"></script>',
|
|
1199
|
+
`<script type="module">import { mountPilot } from "/node_modules/usepilot/dist/pilot.js"; mountPilot({ project: ${json2} });</script>`
|
|
1200
|
+
).replaceAll(
|
|
1201
|
+
'`<script type="module" src="\u2026/node_modules/usepilot/dist/pilot-auto.js"></script>`',
|
|
1202
|
+
`\`<script type="module">import { mountPilot } from "\u2026/node_modules/usepilot/dist/pilot.js"; mountPilot({ project: ${json2} });</script>\``
|
|
1203
|
+
).replaceAll("import `usepilot/auto` from the browser code", `call \`${loaderCall(name)}\` from the browser code`) + `
|
|
1204
|
+
|
|
1205
|
+
The \`project\` (${json2}, this package's name) tells \`npx usepilot\` which pages are this project's: keep it as it is.`;
|
|
1123
1206
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
const name = typeof p?.name === "string" ? p.name.trim().slice(0, 60) : "";
|
|
1130
|
-
const type = ["options", "boolean", "text", "number"].includes(p?.type) ? p.type : null;
|
|
1131
|
-
if (!name || !type) return [];
|
|
1132
|
-
const options = Array.isArray(p.options) ? [...new Set(p.options.filter(scalar).map(String))].slice(0, 30) : [];
|
|
1133
|
-
if (type === "options" && !options.length) return [];
|
|
1134
|
-
return [
|
|
1135
|
-
{
|
|
1136
|
-
name,
|
|
1137
|
-
type,
|
|
1138
|
-
...type === "options" ? { options } : {},
|
|
1139
|
-
...scalar(p.default) ? { default: p.default } : {},
|
|
1140
|
-
...typeof p.description === "string" && p.description.trim() ? { description: p.description.trim().slice(0, 120) } : {}
|
|
1141
|
-
}
|
|
1142
|
-
];
|
|
1143
|
-
});
|
|
1144
|
-
return props.length ? props.slice(0, MAX_PROPS) : void 0;
|
|
1207
|
+
function namingStep(file, cwd) {
|
|
1208
|
+
const name = projectName(cwd);
|
|
1209
|
+
const text = readText2(file);
|
|
1210
|
+
if (new RegExp(`project:\\s*["'\`]${name.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}["'\`]`).test(text)) return null;
|
|
1211
|
+
return `**Name this project in Pilot's loader** (\`${relative(cwd, file)}\`): \`npx usepilot\` runs only for pages that say which project they are. Replace \`import("usepilot/auto")\` with \`${loaderCall(name)}\` (keep its development-only check), or set \`project: ${JSON.stringify(name)}\` where it calls \`mountPilot\`.`;
|
|
1145
1212
|
}
|
|
1146
|
-
function
|
|
1213
|
+
function readJson2(file) {
|
|
1147
1214
|
try {
|
|
1148
|
-
|
|
1149
|
-
return u.protocol === "http:" || u.protocol === "https:" ? u.origin : null;
|
|
1215
|
+
return JSON.parse(readFileSync3(file, "utf8"));
|
|
1150
1216
|
} catch {
|
|
1151
1217
|
return null;
|
|
1152
1218
|
}
|
|
1153
1219
|
}
|
|
1154
|
-
function
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
if (h === "localhost" || h === "0.0.0.0" || h === "::1" || h === "::") return true;
|
|
1158
|
-
if (/\.(localhost|local|test|internal|lan|home\.arpa)$/.test(h)) return true;
|
|
1159
|
-
const v4 = /^(\d{1,3})\.(\d{1,3})\.\d{1,3}\.\d{1,3}$/.exec(h);
|
|
1160
|
-
if (v4) {
|
|
1161
|
-
const [a, b] = [Number(v4[1]), Number(v4[2])];
|
|
1162
|
-
return a === 127 || a === 10 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 169 && b === 254;
|
|
1163
|
-
}
|
|
1164
|
-
if (h.includes(":")) return /^f[cd][0-9a-f]{2}:/.test(h) || /^fe[89ab][0-9a-f]:/.test(h);
|
|
1165
|
-
return !h.includes(".");
|
|
1166
|
-
}
|
|
1167
|
-
function originKey(origin) {
|
|
1168
|
-
return origin.replace(/^(https?:\/\/)(?:127\.0\.0\.1|\[::1\])(?=[:/]|$)/, "$1localhost").replace(/\/$/, "");
|
|
1220
|
+
function runCommand(command2, args, cwd) {
|
|
1221
|
+
const result = spawnSync(command2, args, { cwd, stdio: ["ignore", "inherit", "inherit"], shell: process.platform === "win32" });
|
|
1222
|
+
return result.status === 0;
|
|
1169
1223
|
}
|
|
1170
1224
|
|
|
1225
|
+
// src/run.ts
|
|
1226
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1227
|
+
import { existsSync as existsSync7 } from "fs";
|
|
1228
|
+
import { basename as basename6 } from "path";
|
|
1229
|
+
|
|
1171
1230
|
// src/server.ts
|
|
1172
1231
|
import { createServer } from "http";
|
|
1173
1232
|
|
|
@@ -1176,7 +1235,7 @@ import { createHash } from "crypto";
|
|
|
1176
1235
|
import { existsSync as existsSync3 } from "fs";
|
|
1177
1236
|
import { mkdir, readdir, readFile as readFile2, rm as rm2, stat, writeFile as writeFile2 } from "fs/promises";
|
|
1178
1237
|
import { tmpdir } from "os";
|
|
1179
|
-
import { basename, dirname as dirname3, join as join5 } from "path";
|
|
1238
|
+
import { basename as basename2, dirname as dirname3, join as join5 } from "path";
|
|
1180
1239
|
var FOLDER = "pilot-attachments";
|
|
1181
1240
|
var MAX_ATTACHMENT_BYTES = 1e7;
|
|
1182
1241
|
var MAX_INLINE_IMAGE = 35e5;
|
|
@@ -1247,7 +1306,7 @@ function newAttachments(job) {
|
|
|
1247
1306
|
const lastReply = request.thread.map((m) => m.from).lastIndexOf("agent");
|
|
1248
1307
|
files = request.thread.slice(lastReply + 1).flatMap((m) => m.attachments ?? []);
|
|
1249
1308
|
} else return [];
|
|
1250
|
-
return files.filter((f) => !!f.path &&
|
|
1309
|
+
return files.filter((f) => !!f.path && basename2(dirname3(f.path)) === FOLDER && ATTACHMENT_ID.test(basename2(f.path)));
|
|
1251
1310
|
}
|
|
1252
1311
|
async function attachmentBlocks(job) {
|
|
1253
1312
|
const blocks = [];
|
|
@@ -1259,11 +1318,11 @@ async function attachmentBlocks(job) {
|
|
|
1259
1318
|
const size = (await stat(path)).size;
|
|
1260
1319
|
if (kind === "image") {
|
|
1261
1320
|
if (size > MAX_INLINE_IMAGE) continue;
|
|
1262
|
-
const ext =
|
|
1321
|
+
const ext = basename2(path).split(".").pop();
|
|
1263
1322
|
blocks.push({ type: "image", data: (await readFile2(path)).toString("base64"), mimeType: ATTACHMENT_TYPES[ext] });
|
|
1264
1323
|
} else {
|
|
1265
1324
|
if (size > MAX_INLINE_TEXT) continue;
|
|
1266
|
-
const name = file.name ??
|
|
1325
|
+
const name = file.name ?? basename2(path);
|
|
1267
1326
|
blocks.push({
|
|
1268
1327
|
type: "text",
|
|
1269
1328
|
text: `Attached file ${name}, as the designer sent it:
|
|
@@ -1291,7 +1350,7 @@ async function sweepAttachments(dir = attachmentsDir(), now = Date.now()) {
|
|
|
1291
1350
|
|
|
1292
1351
|
// src/components.ts
|
|
1293
1352
|
import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync4, statSync as statSync2 } from "fs";
|
|
1294
|
-
import { basename as
|
|
1353
|
+
import { basename as basename3, dirname as dirname4, extname, join as join6, relative as relative2 } from "path";
|
|
1295
1354
|
var SKIP = /* @__PURE__ */ new Set([
|
|
1296
1355
|
"node_modules",
|
|
1297
1356
|
"dist",
|
|
@@ -1391,7 +1450,7 @@ function scan(root, deadline) {
|
|
|
1391
1450
|
return out;
|
|
1392
1451
|
}
|
|
1393
1452
|
function fileComponentName(path) {
|
|
1394
|
-
return
|
|
1453
|
+
return basename3(path, extname(path)).split(/[-_.\s]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join("");
|
|
1395
1454
|
}
|
|
1396
1455
|
var NAME = "[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*";
|
|
1397
1456
|
var FUNCTION = new RegExp(`^\\s*(export\\s+)?(?:default\\s+)?(?:async\\s+)?function\\s+(${NAME})\\b`);
|
|
@@ -1423,20 +1482,98 @@ function read2(path) {
|
|
|
1423
1482
|
return found;
|
|
1424
1483
|
}
|
|
1425
1484
|
|
|
1485
|
+
// src/skills.ts
|
|
1486
|
+
import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
|
|
1487
|
+
import { homedir as homedir4 } from "os";
|
|
1488
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
1489
|
+
function skillFolders2(cli, project, home = homedir4()) {
|
|
1490
|
+
const folders = [...projectRoots(project).flatMap((dir) => cli.skills.project.map((rel) => join7(dir, rel))), ...cli.skills.home.map((rel) => join7(home, rel))];
|
|
1491
|
+
return [...new Set(folders)];
|
|
1492
|
+
}
|
|
1493
|
+
function projectRoots(project) {
|
|
1494
|
+
const roots = [project];
|
|
1495
|
+
let dir = project;
|
|
1496
|
+
while (!existsSync5(join7(dir, ".git"))) {
|
|
1497
|
+
const up = dirname5(dir);
|
|
1498
|
+
if (up === dir) return [project];
|
|
1499
|
+
dir = up;
|
|
1500
|
+
roots.push(dir);
|
|
1501
|
+
}
|
|
1502
|
+
return roots;
|
|
1503
|
+
}
|
|
1504
|
+
function findSkills(folders) {
|
|
1505
|
+
const found = /* @__PURE__ */ new Map();
|
|
1506
|
+
for (const folder of folders) {
|
|
1507
|
+
let entries;
|
|
1508
|
+
try {
|
|
1509
|
+
entries = readdirSync3(folder);
|
|
1510
|
+
} catch {
|
|
1511
|
+
continue;
|
|
1512
|
+
}
|
|
1513
|
+
for (const entry of entries.sort()) {
|
|
1514
|
+
if (entry.startsWith(".")) continue;
|
|
1515
|
+
const meta = readSkill(join7(folder, entry, "SKILL.md"));
|
|
1516
|
+
if (!meta) continue;
|
|
1517
|
+
const name = meta.name || entry;
|
|
1518
|
+
if (!SKILL_NAME.test(name) || found.has(name)) continue;
|
|
1519
|
+
found.set(name, { name, ...meta.description ? { description: meta.description } : {} });
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
1523
|
+
}
|
|
1524
|
+
var MAX_SKILL_BYTES = 256e3;
|
|
1525
|
+
var MAX_DESCRIPTION = 300;
|
|
1526
|
+
function readSkill(file) {
|
|
1527
|
+
try {
|
|
1528
|
+
if (statSync3(file).size > MAX_SKILL_BYTES) return null;
|
|
1529
|
+
const meta = frontmatter(readFileSync5(file, "utf8"));
|
|
1530
|
+
const description = meta.description?.replace(/\s+/g, " ").trim();
|
|
1531
|
+
return {
|
|
1532
|
+
name: meta.name?.trim(),
|
|
1533
|
+
description: description && description.length > MAX_DESCRIPTION ? `${description.slice(0, MAX_DESCRIPTION - 1).trimEnd()}\u2026` : description
|
|
1534
|
+
};
|
|
1535
|
+
} catch {
|
|
1536
|
+
return null;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
function frontmatter(text) {
|
|
1540
|
+
const block = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(text)?.[1];
|
|
1541
|
+
if (block === void 0) return {};
|
|
1542
|
+
const lines = block.split(/\r?\n/);
|
|
1543
|
+
const out = {};
|
|
1544
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1545
|
+
const pair = /^([A-Za-z][\w-]*):[ \t]*(.*)$/.exec(lines[i]);
|
|
1546
|
+
if (!pair) continue;
|
|
1547
|
+
const key = pair[1];
|
|
1548
|
+
let value = pair[2].trim();
|
|
1549
|
+
const more = [];
|
|
1550
|
+
while (i + 1 < lines.length && (/^[ \t]+\S/.test(lines[i + 1]) || !lines[i + 1].trim())) more.push(lines[++i].trim());
|
|
1551
|
+
if (/^[>|][+-]?$/.test(value)) value = more.filter(Boolean).join(value.startsWith("|") ? "\n" : " ");
|
|
1552
|
+
else if (more.some(Boolean)) value = [value, ...more].filter(Boolean).join(" ");
|
|
1553
|
+
out[key] = unquote(value);
|
|
1554
|
+
}
|
|
1555
|
+
return out;
|
|
1556
|
+
}
|
|
1557
|
+
function unquote(value) {
|
|
1558
|
+
if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replace(/''/g, "'");
|
|
1559
|
+
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) return value.slice(1, -1).replace(/\\(["\\])/g, "$1").replace(/\\n/g, "\n");
|
|
1560
|
+
return value;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1426
1563
|
// src/tokenFiles.ts
|
|
1427
|
-
import { readdirSync as
|
|
1428
|
-
import { basename as
|
|
1564
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync6, statSync as statSync4 } from "fs";
|
|
1565
|
+
import { basename as basename4, dirname as dirname6, join as join8, relative as relative3 } from "path";
|
|
1429
1566
|
var MAX_FILES2 = 8e3;
|
|
1430
1567
|
var MAX_FILE_BYTES2 = 512e3;
|
|
1431
1568
|
var MAX_TOKENS = 1e3;
|
|
1432
1569
|
var BUDGET_MS2 = 1500;
|
|
1433
1570
|
function isTokenJson(path) {
|
|
1434
|
-
const name =
|
|
1571
|
+
const name = basename4(path).toLowerCase();
|
|
1435
1572
|
if (!name.endsWith(".json") || name === "package.json" || name.startsWith("tsconfig")) return false;
|
|
1436
|
-
return /(^|[.-])(design-)?tokens?\.json$/.test(name) || /(^|\/)(design-)?tokens?$/.test(
|
|
1573
|
+
return /(^|[.-])(design-)?tokens?\.json$/.test(name) || /(^|\/)(design-)?tokens?$/.test(dirname6(path).toLowerCase());
|
|
1437
1574
|
}
|
|
1438
1575
|
function isTokenSass(path) {
|
|
1439
|
-
const name =
|
|
1576
|
+
const name = basename4(path).toLowerCase();
|
|
1440
1577
|
return /\.s[ac]ss$/.test(name) && /(token|variable|vars?\b|theme|colou?r|spacing|typograph|radius|radii|shadow|breakpoint)/.test(name);
|
|
1441
1578
|
}
|
|
1442
1579
|
var cache2 = /* @__PURE__ */ new Map();
|
|
@@ -1463,7 +1600,7 @@ function scan2(root, deadline) {
|
|
|
1463
1600
|
const walk = (dir) => {
|
|
1464
1601
|
let entries;
|
|
1465
1602
|
try {
|
|
1466
|
-
entries =
|
|
1603
|
+
entries = readdirSync4(dir, { withFileTypes: true });
|
|
1467
1604
|
} catch {
|
|
1468
1605
|
return;
|
|
1469
1606
|
}
|
|
@@ -1471,7 +1608,7 @@ function scan2(root, deadline) {
|
|
|
1471
1608
|
if (files >= MAX_FILES2 || Date.now() > deadline) return;
|
|
1472
1609
|
const name = entry.name;
|
|
1473
1610
|
if (SKIP.has(name) || name.startsWith(".")) continue;
|
|
1474
|
-
const path =
|
|
1611
|
+
const path = join8(dir, name);
|
|
1475
1612
|
if (entry.isDirectory()) {
|
|
1476
1613
|
walk(path);
|
|
1477
1614
|
continue;
|
|
@@ -1481,7 +1618,7 @@ function scan2(root, deadline) {
|
|
|
1481
1618
|
if (!entry.isFile() || !(json2 || isTokenSass(path))) continue;
|
|
1482
1619
|
let stat2;
|
|
1483
1620
|
try {
|
|
1484
|
-
stat2 =
|
|
1621
|
+
stat2 = statSync4(path);
|
|
1485
1622
|
} catch {
|
|
1486
1623
|
continue;
|
|
1487
1624
|
}
|
|
@@ -1500,7 +1637,7 @@ function scan2(root, deadline) {
|
|
|
1500
1637
|
function read3(path, file, json2) {
|
|
1501
1638
|
let text;
|
|
1502
1639
|
try {
|
|
1503
|
-
text =
|
|
1640
|
+
text = readFileSync6(path, "utf8");
|
|
1504
1641
|
} catch {
|
|
1505
1642
|
return [];
|
|
1506
1643
|
}
|
|
@@ -1585,8 +1722,14 @@ var Hub = class {
|
|
|
1585
1722
|
register(info, origin) {
|
|
1586
1723
|
const key = originKey(origin);
|
|
1587
1724
|
const known = this.agents.get(info.id);
|
|
1588
|
-
const { folder, ...shown } = info;
|
|
1589
|
-
this.agents.set(info.id, {
|
|
1725
|
+
const { folder, kind, ...shown } = info;
|
|
1726
|
+
this.agents.set(info.id, {
|
|
1727
|
+
info: shown,
|
|
1728
|
+
origin: key,
|
|
1729
|
+
seen: this.now(),
|
|
1730
|
+
folder: folder ?? known?.folder,
|
|
1731
|
+
kind: isAgentKind(kind) ? kind : known?.kind
|
|
1732
|
+
});
|
|
1590
1733
|
if (!known || known.origin !== key) {
|
|
1591
1734
|
if (known) this.notifyAgents(known.origin);
|
|
1592
1735
|
this.notifyAgents(key);
|
|
@@ -1617,6 +1760,12 @@ var Hub = class {
|
|
|
1617
1760
|
const key = originKey(origin);
|
|
1618
1761
|
return [...new Set([...this.agents.values()].filter((a) => a.origin === key && a.folder).map((a) => a.folder))];
|
|
1619
1762
|
}
|
|
1763
|
+
/** Where the agents working on pages of `origin` read their skills from (each agent's own folders, skills.ts): for the `/` list. */
|
|
1764
|
+
skillFolders(origin) {
|
|
1765
|
+
const key = originKey(origin);
|
|
1766
|
+
const agents = [...this.agents.values()].filter((a) => a.origin === key && a.folder && a.kind);
|
|
1767
|
+
return [...new Set(agents.flatMap((a) => skillFolders2(AGENTS[a.kind], a.folder)))];
|
|
1768
|
+
}
|
|
1620
1769
|
/** Drops agents not heard from in AGENT_TTL (`keep`: the ones in this process, always alive). */
|
|
1621
1770
|
sweep(keep = /* @__PURE__ */ new Set()) {
|
|
1622
1771
|
const cutoff = this.now() - AGENT_TTL;
|
|
@@ -1633,11 +1782,17 @@ var Hub = class {
|
|
|
1633
1782
|
this.sendTo(originKey(origin), { type: "quit" });
|
|
1634
1783
|
}
|
|
1635
1784
|
/**
|
|
1636
|
-
* The
|
|
1637
|
-
*
|
|
1785
|
+
* The pages with Pilot open in a browser now, each site and project once,
|
|
1786
|
+
* leaving out the sites Pilot already runs for: where `npx usepilot` looks
|
|
1787
|
+
* for its own project's pages (by their project's name), without a URL.
|
|
1638
1788
|
*/
|
|
1639
|
-
|
|
1640
|
-
|
|
1789
|
+
openPages() {
|
|
1790
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1791
|
+
for (const page of this.pages) {
|
|
1792
|
+
if (this.hasAgents(page.origin)) continue;
|
|
1793
|
+
seen.set(`${page.origin} ${page.project ?? ""}`, { origin: page.origin, ...page.project ? { project: page.project } : {} });
|
|
1794
|
+
}
|
|
1795
|
+
return [...seen.values()];
|
|
1641
1796
|
}
|
|
1642
1797
|
/** Pilot started for a site (`npx usepilot`): registers it and tells the open pages of `origin` to launch Pilot. Returns how many pages got it. */
|
|
1643
1798
|
launch(info, origin) {
|
|
@@ -1910,7 +2065,7 @@ async function handle(hub, req, res, attachments) {
|
|
|
1910
2065
|
res.writeHead(204).end();
|
|
1911
2066
|
return;
|
|
1912
2067
|
}
|
|
1913
|
-
if (path === "/events" && req.method === "GET") return events(hub, origin, req, res);
|
|
2068
|
+
if (path === "/events" && req.method === "GET") return events(hub, origin, req, res, projectNameOf(url.searchParams.get("project")));
|
|
1914
2069
|
if (path === "/quit" && req.method === "POST") {
|
|
1915
2070
|
hub.quit(origin);
|
|
1916
2071
|
return json(res, 200, { ok: true });
|
|
@@ -1919,6 +2074,7 @@ async function handle(hub, req, res, attachments) {
|
|
|
1919
2074
|
if (!hub.hasAgents(origin)) return json(res, 403, { error: "Pilot isn't running for this site: run npx usepilot in your project" });
|
|
1920
2075
|
if (path === "/components") return json(res, 200, { components: projectComponents(hub.folders(origin)) });
|
|
1921
2076
|
if (path === "/tokens") return json(res, 200, { tokens: fileTokens(hub.folders(origin)) });
|
|
2077
|
+
if (path === "/skills") return json(res, 200, { skills: findSkills(hub.skillFolders(origin)) });
|
|
1922
2078
|
if (path === "/attachments") {
|
|
1923
2079
|
const type = req.headers["content-type"] ?? "";
|
|
1924
2080
|
if (!extensionOf(type)) return json(res, 415, { error: "images (png, jpeg, gif, webp), text files (txt, md, csv, json) and PDFs only" });
|
|
@@ -1954,7 +2110,7 @@ async function handle(hub, req, res, attachments) {
|
|
|
1954
2110
|
}
|
|
1955
2111
|
return json(res, 404, { error: "not found" });
|
|
1956
2112
|
}
|
|
1957
|
-
function events(hub, origin, req, res) {
|
|
2113
|
+
function events(hub, origin, req, res, project) {
|
|
1958
2114
|
res.writeHead(200, {
|
|
1959
2115
|
"Content-Type": "text/event-stream",
|
|
1960
2116
|
"Cache-Control": "no-cache",
|
|
@@ -1964,7 +2120,7 @@ function events(hub, origin, req, res) {
|
|
|
1964
2120
|
const send = (event) => res.write(`data: ${JSON.stringify(event)}
|
|
1965
2121
|
|
|
1966
2122
|
`);
|
|
1967
|
-
const remove = hub.addPage({ origin, send });
|
|
2123
|
+
const remove = hub.addPage({ origin, project, send });
|
|
1968
2124
|
const ping = setInterval(() => res.write(": ping\n\n"), 15e3);
|
|
1969
2125
|
req.on("close", () => {
|
|
1970
2126
|
clearInterval(ping);
|
|
@@ -1980,7 +2136,7 @@ async function handleAgent(hub, action, data, req, res) {
|
|
|
1980
2136
|
hub.register(d.agent, d.origin);
|
|
1981
2137
|
return json(res, 200, { ok: true });
|
|
1982
2138
|
case "pages":
|
|
1983
|
-
return json(res, 200, {
|
|
2139
|
+
return json(res, 200, { pages: hub.openPages() });
|
|
1984
2140
|
case "launch":
|
|
1985
2141
|
if (!d.origin) return json(res, 400, { error: "origin needed" });
|
|
1986
2142
|
return json(res, 200, { pages: hub.launch(d.agent, d.origin) });
|
|
@@ -2077,7 +2233,7 @@ var LocalApi = class {
|
|
|
2077
2233
|
return this.hub.launch(agent, origin);
|
|
2078
2234
|
}
|
|
2079
2235
|
async pages() {
|
|
2080
|
-
return this.hub.
|
|
2236
|
+
return this.hub.openPages();
|
|
2081
2237
|
}
|
|
2082
2238
|
wait(agent, origin, timeoutMs, signal) {
|
|
2083
2239
|
localAgents.add(agent.id);
|
|
@@ -2120,7 +2276,7 @@ var RemoteApi = class {
|
|
|
2120
2276
|
}
|
|
2121
2277
|
async pages() {
|
|
2122
2278
|
try {
|
|
2123
|
-
return (await this.post("pages", {})).
|
|
2279
|
+
return (await this.post("pages", {})).pages ?? [];
|
|
2124
2280
|
} catch (error) {
|
|
2125
2281
|
if (isConnectionError(error)) throw error;
|
|
2126
2282
|
return [];
|
|
@@ -2282,8 +2438,8 @@ function isConnectionError(error) {
|
|
|
2282
2438
|
}
|
|
2283
2439
|
|
|
2284
2440
|
// src/locate.ts
|
|
2285
|
-
import { existsSync as
|
|
2286
|
-
import { basename as
|
|
2441
|
+
import { existsSync as existsSync6, readdirSync as readdirSync5, readFileSync as readFileSync7, statSync as statSync5 } from "fs";
|
|
2442
|
+
import { basename as basename5, extname as extname3, isAbsolute, join as join9, relative as relative4 } from "path";
|
|
2287
2443
|
var SKIP2 = /* @__PURE__ */ new Set([
|
|
2288
2444
|
"node_modules",
|
|
2289
2445
|
"dist",
|
|
@@ -2329,17 +2485,17 @@ function sourceFiles(root) {
|
|
|
2329
2485
|
const walk = (dir) => {
|
|
2330
2486
|
let names;
|
|
2331
2487
|
try {
|
|
2332
|
-
names =
|
|
2488
|
+
names = readdirSync5(dir);
|
|
2333
2489
|
} catch {
|
|
2334
2490
|
return;
|
|
2335
2491
|
}
|
|
2336
2492
|
for (const name of names) {
|
|
2337
2493
|
if (files.length >= MAX_FILES3) return;
|
|
2338
2494
|
if (SKIP2.has(name) || name.startsWith(".") && name !== ".") continue;
|
|
2339
|
-
const path =
|
|
2495
|
+
const path = join9(dir, name);
|
|
2340
2496
|
let stat2;
|
|
2341
2497
|
try {
|
|
2342
|
-
stat2 =
|
|
2498
|
+
stat2 = statSync5(path);
|
|
2343
2499
|
} catch {
|
|
2344
2500
|
continue;
|
|
2345
2501
|
}
|
|
@@ -2352,7 +2508,7 @@ function sourceFiles(root) {
|
|
|
2352
2508
|
return files;
|
|
2353
2509
|
}
|
|
2354
2510
|
function searchable(cwd) {
|
|
2355
|
-
return
|
|
2511
|
+
return existsSync6(join9(cwd, "package.json")) || existsSync6(join9(cwd, ".git"));
|
|
2356
2512
|
}
|
|
2357
2513
|
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2358
2514
|
function needles(target) {
|
|
@@ -2372,7 +2528,7 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS3) {
|
|
|
2372
2528
|
const known = target.source?.file && target.source.line ? sourcePath(target.source.file, root) : null;
|
|
2373
2529
|
if (known && target.source?.line) {
|
|
2374
2530
|
try {
|
|
2375
|
-
const lines =
|
|
2531
|
+
const lines = readFileSync7(join9(root, known), "utf8").split("\n");
|
|
2376
2532
|
const from = target.source.line - 1;
|
|
2377
2533
|
const own = bestLine(n, lines, from);
|
|
2378
2534
|
const index = own && own.score >= 2 ? own.index : from;
|
|
@@ -2386,7 +2542,7 @@ function locate(target, root, deadline = Date.now() + BUDGET_MS3) {
|
|
|
2386
2542
|
if (Date.now() > deadline) break;
|
|
2387
2543
|
let content;
|
|
2388
2544
|
try {
|
|
2389
|
-
content =
|
|
2545
|
+
content = readFileSync7(file, "utf8");
|
|
2390
2546
|
} catch {
|
|
2391
2547
|
continue;
|
|
2392
2548
|
}
|
|
@@ -2425,7 +2581,7 @@ function snippetAt(lines, index) {
|
|
|
2425
2581
|
function sourcePath(file, root) {
|
|
2426
2582
|
const rel = isAbsolute(file) ? relative4(root, file) : file.replace(/^\.\//, "");
|
|
2427
2583
|
if (rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
2428
|
-
return
|
|
2584
|
+
return existsSync6(join9(root, rel)) ? rel : null;
|
|
2429
2585
|
}
|
|
2430
2586
|
function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
|
|
2431
2587
|
if (!/^[A-Za-z_$][\w$]*$/.test(name)) return null;
|
|
@@ -2433,13 +2589,13 @@ function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
|
|
|
2433
2589
|
`^\\s*(export\\s+(?:default\\s+)?)?(?:(?:async\\s+)?function\\s*\\*?\\s+${name}\\b|class\\s+${name}\\b|(?:const|let|var)\\s+${name}\\s*[:=])`
|
|
2434
2590
|
);
|
|
2435
2591
|
let best = null;
|
|
2436
|
-
const files = within ? [
|
|
2592
|
+
const files = within ? [join9(root, within)] : sourceFiles(root);
|
|
2437
2593
|
for (const file of files) {
|
|
2438
2594
|
if (Date.now() > deadline) break;
|
|
2439
2595
|
if (!/\.[jt]sx?$|\.mjs$/.test(file)) continue;
|
|
2440
2596
|
let content;
|
|
2441
2597
|
try {
|
|
2442
|
-
content =
|
|
2598
|
+
content = readFileSync7(file, "utf8");
|
|
2443
2599
|
} catch {
|
|
2444
2600
|
continue;
|
|
2445
2601
|
}
|
|
@@ -2448,7 +2604,7 @@ function componentFile(name, root, deadline = Date.now() + BUDGET_MS3, within) {
|
|
|
2448
2604
|
for (let i = 0; i < lines.length; i++) {
|
|
2449
2605
|
const m = declaration.exec(lines[i]);
|
|
2450
2606
|
if (!m) continue;
|
|
2451
|
-
const score = (
|
|
2607
|
+
const score = (basename5(file).replace(/\.[^.]+$/, "") === name ? 2 : 0) + (m[1] ? 1 : 0);
|
|
2452
2608
|
if (!best || score > best.score) best = { file, line: i + 1, score };
|
|
2453
2609
|
break;
|
|
2454
2610
|
}
|
|
@@ -2469,11 +2625,11 @@ function withComponentFiles(job, root) {
|
|
|
2469
2625
|
const workspace = workspaceRoot(root);
|
|
2470
2626
|
const declared = (name) => {
|
|
2471
2627
|
const found = componentFile(name, workspace, deadline);
|
|
2472
|
-
return found ? { file: relative4(root,
|
|
2628
|
+
return found ? { file: relative4(root, join9(workspace, found.file)), line: found.line } : null;
|
|
2473
2629
|
};
|
|
2474
2630
|
const local = (file) => {
|
|
2475
|
-
const path =
|
|
2476
|
-
return
|
|
2631
|
+
const path = join9(workspace, file);
|
|
2632
|
+
return existsSync6(path) ? relative4(root, path) : file;
|
|
2477
2633
|
};
|
|
2478
2634
|
const mention = (r) => {
|
|
2479
2635
|
if (r.kind === "token") return r.source ? { ...r, source: { ...r.source, file: local(r.source.file) } } : r;
|
|
@@ -2484,8 +2640,8 @@ function withComponentFiles(job, root) {
|
|
|
2484
2640
|
}
|
|
2485
2641
|
if (r.kind !== "component") return r;
|
|
2486
2642
|
if (r.source) {
|
|
2487
|
-
const path =
|
|
2488
|
-
return
|
|
2643
|
+
const path = join9(workspace, r.source.file);
|
|
2644
|
+
return existsSync6(path) ? { ...r, source: { ...r.source, file: relative4(root, path) } } : r;
|
|
2489
2645
|
}
|
|
2490
2646
|
if (r.target?.source?.file) return { ...r, target: fill(r.target) };
|
|
2491
2647
|
const source = declared(r.name);
|
|
@@ -2551,7 +2707,7 @@ ${runFooter(job)}
|
|
|
2551
2707
|
function runFooter(job) {
|
|
2552
2708
|
const props = job.changeSet.request?.kind === "props";
|
|
2553
2709
|
return [
|
|
2554
|
-
`When you're done, reply with your notes for the designer: ${notesFor(job)}.
|
|
2710
|
+
skillOf(job) ? `When you're done, reply with your notes for the designer: ${notesFor(job)}. Pilot shows them to the designer in the element's thread.` : `When you're done, reply with your notes for the designer: ${notesFor(job)}. Concise, no headings ("Done." when there's nothing to add): Pilot shows them to the designer in a small box, and checks the page itself, so don't open a browser, start a dev server, or run builds or tests.`,
|
|
2555
2711
|
"",
|
|
2556
2712
|
props ? "Put the props in a block at the very end of your reply, after your notes, as JSON:" : "If you ask the designer a question (only where this job says to), put it in a block at the very end of your reply, after your notes, as JSON:",
|
|
2557
2713
|
"",
|
|
@@ -2601,7 +2757,7 @@ function followUp(job) {
|
|
|
2601
2757
|
function notesFor(job) {
|
|
2602
2758
|
switch (job.changeSet.request?.kind) {
|
|
2603
2759
|
case "comment":
|
|
2604
|
-
return "your reply in the designer's comment thread, a small chat box:
|
|
2760
|
+
return skillOf(job) ? "your reply in the designer's comment thread, as the skill you used says to report (as long as it needs to be; Markdown shows)" : "your reply in the designer's comment thread, a small chat box: concise, like a chat message, a few short sentences at most, with what you changed or your answer";
|
|
2605
2761
|
case "responsive":
|
|
2606
2762
|
return "what changed at which widths, anything left for the designer";
|
|
2607
2763
|
case "break-and-fix":
|
|
@@ -2645,6 +2801,12 @@ function taskFollowUp(job) {
|
|
|
2645
2801
|
];
|
|
2646
2802
|
return lines.join("\n");
|
|
2647
2803
|
}
|
|
2804
|
+
function skillOf(job) {
|
|
2805
|
+
const request = job.changeSet.request;
|
|
2806
|
+
if (request?.kind !== "comment" || job.attempt === 2 || job.answer) return void 0;
|
|
2807
|
+
const skill = request.thread.at(-1)?.skill;
|
|
2808
|
+
return skill && SKILL_NAME.test(skill) ? skill : void 0;
|
|
2809
|
+
}
|
|
2648
2810
|
|
|
2649
2811
|
// src/run.ts
|
|
2650
2812
|
var SLOTS = 3;
|
|
@@ -2662,9 +2824,9 @@ async function startRunner(options) {
|
|
|
2662
2824
|
throw new RunnerError(`${project} isn't a project folder (no package.json or .git). Run npx usepilot in your project's folder.`);
|
|
2663
2825
|
}
|
|
2664
2826
|
const { cli, bin } = await pickAgent(options, choose2, out);
|
|
2665
|
-
const agent = { id: randomUUID2(), label: `${cli.label} \xB7 ${
|
|
2827
|
+
const agent = { id: randomUUID2(), label: `${cli.label} \xB7 ${basename6(project)}`, folder: project, kind: cli.kind };
|
|
2666
2828
|
const bridge = new Bridge(agent, options.port ?? (Number(process.env.PILOT_PORT) || DEFAULT_BRIDGE_PORT));
|
|
2667
|
-
const origin = await pickSite(bridge, options,
|
|
2829
|
+
const origin = await pickSite(bridge, options, out);
|
|
2668
2830
|
await bridge.launch(origin);
|
|
2669
2831
|
out(`Pilot is on ${origin}, every page, with ${cli.label}. Send from the toolbar; jobs show here. Ctrl+C stops.`);
|
|
2670
2832
|
const stop = new AbortController();
|
|
@@ -2726,27 +2888,39 @@ async function pickAgent(options, choose2, out) {
|
|
|
2726
2888
|
if (ready.length > 1) out(`${AGENTS[picked.kind].label} it is, for this project (npx usepilot --agent <name> changes it).`);
|
|
2727
2889
|
return { cli: AGENTS[picked.kind], bin: options.bin ?? picked.bin };
|
|
2728
2890
|
}
|
|
2729
|
-
async function pickSite(bridge, options,
|
|
2891
|
+
async function pickSite(bridge, options, out) {
|
|
2730
2892
|
if (options.url) {
|
|
2731
2893
|
const origin = originOf(options.url);
|
|
2732
2894
|
if (!origin) throw new RunnerError(`"${options.url}" isn't a page address. Pass your dev server's, e.g. http://localhost:5173.`);
|
|
2733
2895
|
return originKey(origin);
|
|
2734
2896
|
}
|
|
2735
|
-
|
|
2897
|
+
const name = projectName(options.cwd);
|
|
2898
|
+
const told = /* @__PURE__ */ new Set();
|
|
2899
|
+
const say = (key, line) => {
|
|
2900
|
+
if (told.has(key)) return;
|
|
2901
|
+
told.add(key);
|
|
2902
|
+
out(line);
|
|
2903
|
+
};
|
|
2736
2904
|
for (; ; ) {
|
|
2737
|
-
const local = (await bridge.pages()).filter((
|
|
2905
|
+
const local = (await bridge.pages()).filter((p) => {
|
|
2738
2906
|
try {
|
|
2739
|
-
return isLocalHost(new URL(
|
|
2907
|
+
return isLocalHost(new URL(p.origin).hostname);
|
|
2740
2908
|
} catch {
|
|
2741
2909
|
return false;
|
|
2742
2910
|
}
|
|
2743
2911
|
});
|
|
2744
|
-
|
|
2745
|
-
if (
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2912
|
+
const mine = local.find((p) => p.project === name);
|
|
2913
|
+
if (mine) return mine.origin;
|
|
2914
|
+
for (const page of local) {
|
|
2915
|
+
if (page.project)
|
|
2916
|
+
say(`${page.origin} ${page.project}`, `Pilot is open on ${page.origin} for ${page.project}, not ${name}: run npx usepilot in that project's folder for it.`);
|
|
2917
|
+
else
|
|
2918
|
+
say(
|
|
2919
|
+
page.origin,
|
|
2920
|
+
`Pilot is open on ${page.origin}, but its loader doesn't say which project it is (set up before 0.15). If it's this one, ask your agent to run npx usepilot@latest update here, or start with npx usepilot --url ${page.origin}.`
|
|
2921
|
+
);
|
|
2749
2922
|
}
|
|
2923
|
+
say("none", `Waiting for a page of ${name}: open your app in the browser (with its dev server running).`);
|
|
2750
2924
|
await sleep(1e3);
|
|
2751
2925
|
}
|
|
2752
2926
|
}
|
|
@@ -2764,7 +2938,7 @@ async function runJob(job, ctx) {
|
|
|
2764
2938
|
});
|
|
2765
2939
|
}, CANCEL_POLL_MS);
|
|
2766
2940
|
try {
|
|
2767
|
-
const prompt = await promptFor(job, ctx.project);
|
|
2941
|
+
const prompt = await promptFor(job, ctx.project, cli);
|
|
2768
2942
|
const resume = sessionToResume(job, cli.kind);
|
|
2769
2943
|
const images = newAttachments(job).map((f) => f.path).filter((p) => /\.(png|jpe?g|gif|webp)$/i.test(p));
|
|
2770
2944
|
let result = await runAgent(ctx, prompt, { resume, images, signal: stop.signal });
|
|
@@ -2801,7 +2975,7 @@ async function runJob(job, ctx) {
|
|
|
2801
2975
|
}
|
|
2802
2976
|
async function runAgent(ctx, prompt, options) {
|
|
2803
2977
|
const { cli } = ctx;
|
|
2804
|
-
if (!
|
|
2978
|
+
if (!existsSync7(ctx.bin)) return { error: `${cli.label}'s command-line tool isn't installed any more.` };
|
|
2805
2979
|
const run2 = await exec(ctx.bin, cli.args({ resume: options.resume, readDirs: [attachmentsDir()], images: options.images }), {
|
|
2806
2980
|
cwd: ctx.project,
|
|
2807
2981
|
input: prompt,
|
|
@@ -2814,11 +2988,12 @@ async function runAgent(ctx, prompt, options) {
|
|
|
2814
2988
|
${run2.stderr.trim().slice(-500)}`;
|
|
2815
2989
|
return parsed;
|
|
2816
2990
|
}
|
|
2817
|
-
async function promptFor(job, project) {
|
|
2991
|
+
async function promptFor(job, project, cli) {
|
|
2818
2992
|
const j = withComponentFiles(job, project);
|
|
2819
2993
|
const where = j.attempt === 2 ? "" : whereSection(j, project);
|
|
2820
2994
|
const texts = (await attachmentBlocks(j)).flatMap((b) => b.type === "text" ? [b.text] : []);
|
|
2821
|
-
|
|
2995
|
+
const skill = skillOf(j);
|
|
2996
|
+
return [...skill ? [cli.invokeSkill(skill)] : [], jobPrompt(j, where), ...texts].join("\n\n");
|
|
2822
2997
|
}
|
|
2823
2998
|
function sessionToResume(job, agent) {
|
|
2824
2999
|
const request = job.changeSet.request;
|
|
@@ -2886,14 +3061,14 @@ function sleep(ms, signal) {
|
|
|
2886
3061
|
|
|
2887
3062
|
// src/update.ts
|
|
2888
3063
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
2889
|
-
import { existsSync as
|
|
2890
|
-
import { homedir as
|
|
2891
|
-
import { dirname as
|
|
3064
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "fs";
|
|
3065
|
+
import { homedir as homedir5 } from "os";
|
|
3066
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
2892
3067
|
async function update(options = {}) {
|
|
2893
3068
|
const cwd = options.cwd ?? process.cwd();
|
|
2894
3069
|
const run2 = options.run ?? runCommand2;
|
|
2895
|
-
const home = options.home ??
|
|
2896
|
-
const pkg = readJson3(
|
|
3070
|
+
const home = options.home ?? homedir5();
|
|
3071
|
+
const pkg = readJson3(join10(cwd, "package.json"));
|
|
2897
3072
|
const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
2898
3073
|
if (!pkg || !deps.usepilot) {
|
|
2899
3074
|
return `# Pilot isn't installed here
|
|
@@ -2919,9 +3094,12 @@ ${pm} ${args.join(" ")}
|
|
|
2919
3094
|
\`\`\`
|
|
2920
3095
|
`;
|
|
2921
3096
|
}
|
|
3097
|
+
const loader = detectFramework(cwd, deps).loads;
|
|
3098
|
+
const unnamed = loader ? !!namingStep(loader, cwd) : oldBridge !== null && oldBridge < 8;
|
|
2922
3099
|
const bumped = !!before && !!after && olderThan(before, after);
|
|
2923
|
-
const changed = bumped || removed.length > 0;
|
|
3100
|
+
const changed = bumped || removed.length > 0 || unnamed;
|
|
2924
3101
|
const steps = [
|
|
3102
|
+
...unnamed ? ["Ask your agent to run `npx usepilot@latest init` in the app's folder: it names this project in Pilot's loader, so `npx usepilot` knows the app's pages are this project's (new in 0.15)."] : [],
|
|
2925
3103
|
"Restart your app's dev server, so the page loads the new Pilot.",
|
|
2926
3104
|
"Restart `npx usepilot` in the app's folder (Ctrl+C, then run it again), so Pilot runs the new version."
|
|
2927
3105
|
];
|
|
@@ -2941,18 +3119,18 @@ ${steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
|
2941
3119
|
` : "Nothing else to do.\n"}`;
|
|
2942
3120
|
}
|
|
2943
3121
|
function bridgeOf(cwd, root) {
|
|
2944
|
-
for (let dir = cwd; ; dir =
|
|
2945
|
-
const file =
|
|
2946
|
-
if (
|
|
2947
|
-
const match = /BRIDGE_VERSION = (\d+)/.exec(
|
|
3122
|
+
for (let dir = cwd; ; dir = dirname7(dir)) {
|
|
3123
|
+
const file = join10(dir, "node_modules", "usepilot", "cli", "index.js");
|
|
3124
|
+
if (existsSync8(file)) {
|
|
3125
|
+
const match = /BRIDGE_VERSION = (\d+)/.exec(readFileSync8(file, "utf8"));
|
|
2948
3126
|
return match ? Number(match[1]) : null;
|
|
2949
3127
|
}
|
|
2950
|
-
if (dir === root ||
|
|
3128
|
+
if (dir === root || dirname7(dir) === dir) return null;
|
|
2951
3129
|
}
|
|
2952
3130
|
}
|
|
2953
3131
|
function readJson3(file) {
|
|
2954
3132
|
try {
|
|
2955
|
-
return JSON.parse(
|
|
3133
|
+
return JSON.parse(readFileSync8(file, "utf8"));
|
|
2956
3134
|
} catch {
|
|
2957
3135
|
return null;
|
|
2958
3136
|
}
|