neon 2.44.0 → 2.46.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 +62 -1
- package/dist/_shared/paths.js +3 -4
- package/dist/commands/bootstrap.js +12 -11
- package/dist/commands/checkout.js +7 -6
- package/dist/commands/config.js +2 -1
- package/dist/commands/data_api.js +4 -3
- package/dist/commands/env.js +5 -4
- package/dist/commands/functions.js +3 -2
- package/dist/commands/init.js +82 -37
- package/dist/commands/ip_allow.js +3 -2
- package/dist/commands/link.js +17 -16
- package/dist/commands/projects.js +3 -2
- package/dist/commands/set_context.js +5 -4
- package/dist/current_branch_fast_path.js +2 -1
- package/dist/dev/env.js +8 -7
- package/dist/dev/runtime.js +45 -1
- package/dist/dev/websocket.js +1031 -0
- package/dist/index.js +2 -2
- package/dist/init/agents.js +127 -0
- package/dist/init/auth.js +77 -0
- package/dist/init/bootstrap.js +448 -0
- package/dist/init/build_config.js +2 -0
- package/dist/init/detect_agent.js +108 -0
- package/dist/init/editors.js +62 -0
- package/dist/init/enrich_output.js +71 -0
- package/dist/init/extension.js +191 -0
- package/dist/init/inspect.js +287 -0
- package/dist/init/interactive.js +651 -0
- package/dist/init/neonctl.js +184 -0
- package/dist/init/orchestrate.js +190 -0
- package/dist/init/phases/auth.js +209 -0
- package/dist/init/phases/cleanup.js +27 -0
- package/dist/init/phases/db.js +283 -0
- package/dist/init/phases/getting_started.js +228 -0
- package/dist/init/phases/mcp.js +227 -0
- package/dist/init/phases/migrations.js +251 -0
- package/dist/init/phases/neon_auth.js +135 -0
- package/dist/init/phases/setup.js +729 -0
- package/dist/init/phases/skills.js +89 -0
- package/dist/init/phases/status.js +70 -0
- package/dist/init/resolve_context.js +107 -0
- package/dist/init/route_command.js +100 -0
- package/dist/init/skills.js +248 -0
- package/dist/init/types.js +1 -0
- package/dist/init/vsix.js +111 -0
- package/dist/psql/command/cmd_meta.js +2 -2
- package/dist/psql/core/mainloop.js +1 -1
- package/dist/psql/core/startup.js +1 -1
- package/dist/psql/core/syncVars.js +3 -3
- package/dist/psql/index.js +1 -1
- package/dist/utils/cli_name.js +14 -0
- package/dist/utils/esbuild.js +1 -1
- package/dist/utils/write_sync.js +39 -0
- package/package.json +18 -12
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive v2 CLI — purpose-built guided flow for humans.
|
|
3
|
+
* Uses the same underlying install functions but with a clean clack-based UX.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { SelectPrompt } from "@clack/core";
|
|
8
|
+
import { confirm, isCancel, log, multiselect, outro, select, spinner, } from "@clack/prompts";
|
|
9
|
+
import { execa } from "execa";
|
|
10
|
+
import { bold, dim, gray, italic } from "yoctocolors";
|
|
11
|
+
import { ALL_CONFIGURABLE_AGENTS, getAddMcpAgentId } from "./agents.js";
|
|
12
|
+
import { ensureNeonctlAuth, isAuthenticated } from "./auth.js";
|
|
13
|
+
import { FALLBACK_TEMPLATES, fetchTemplates, scaffoldTemplate, } from "./bootstrap.js";
|
|
14
|
+
import { detectAgent, detectIde } from "./detect_agent.js";
|
|
15
|
+
import { detectAvailableEditors } from "./editors.js";
|
|
16
|
+
import { installExtension, isExtensionInstalled, usesExtension, } from "./extension.js";
|
|
17
|
+
import { inspectProject } from "./inspect.js";
|
|
18
|
+
import { ensureNeonctl } from "./neonctl.js";
|
|
19
|
+
import { ensureSkillsUpToDate, installAgentSkills } from "./skills.js";
|
|
20
|
+
function wordWrap(text, width) {
|
|
21
|
+
return text
|
|
22
|
+
.split("\n")
|
|
23
|
+
.map((line) => {
|
|
24
|
+
if (line.length <= width)
|
|
25
|
+
return line;
|
|
26
|
+
const words = line.split(" ");
|
|
27
|
+
const lines = [];
|
|
28
|
+
let current = "";
|
|
29
|
+
for (const word of words) {
|
|
30
|
+
if (current.length + word.length + 1 > width &&
|
|
31
|
+
current.length > 0) {
|
|
32
|
+
lines.push(current);
|
|
33
|
+
current = word;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
current = current.length > 0 ? `${current} ${word}` : word;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (current.length > 0)
|
|
40
|
+
lines.push(current);
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
})
|
|
43
|
+
.join("\n");
|
|
44
|
+
}
|
|
45
|
+
// Patch picocolors (used by @clack/prompts) to use Neon green instead of cyan/magenta.
|
|
46
|
+
// clack hardcodes picocolors.cyan() with no theme API, so this is the least invasive override.
|
|
47
|
+
import picocolors from "picocolors";
|
|
48
|
+
const neonGreenFn = (s) => `\x1b[38;2;75;181;120m${s}\x1b[39m`;
|
|
49
|
+
const originalCyan = picocolors.cyan;
|
|
50
|
+
const originalMagenta = picocolors.magenta;
|
|
51
|
+
function patchClackColors() {
|
|
52
|
+
const pc = picocolors;
|
|
53
|
+
pc.cyan = neonGreenFn;
|
|
54
|
+
pc.magenta = neonGreenFn;
|
|
55
|
+
return () => {
|
|
56
|
+
pc.cyan = originalCyan;
|
|
57
|
+
pc.magenta = originalMagenta;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// clack box-drawing glyphs, mirrored from @clack/prompts so our custom
|
|
61
|
+
// template picker lines up with every other step in the flow.
|
|
62
|
+
const S_BAR = "│";
|
|
63
|
+
const S_BAR_END = "└";
|
|
64
|
+
const S_STEP_ACTIVE = "◆";
|
|
65
|
+
const S_STEP_SUBMIT = "◇";
|
|
66
|
+
const S_STEP_CANCEL = "■";
|
|
67
|
+
const S_RADIO_ACTIVE = "●";
|
|
68
|
+
const S_RADIO_INACTIVE = "○";
|
|
69
|
+
const SENTINEL_NONE = "none";
|
|
70
|
+
/**
|
|
71
|
+
* Bespoke template picker built on @clack/core's `SelectPrompt`.
|
|
72
|
+
*
|
|
73
|
+
* The stock `@clack/prompts` `select` can only render an option on a single
|
|
74
|
+
* line (title + a parenthesized hint on the focused row), which can't express
|
|
75
|
+
* what we want here: a clean title-only list, and a focused row that expands to
|
|
76
|
+
* `Title (tools)` with the description on its own italic line beneath. Driving
|
|
77
|
+
* the core prompt directly lets us own the frame, so we emit a second
|
|
78
|
+
* gutter-aligned line for the active option only.
|
|
79
|
+
*/
|
|
80
|
+
async function selectTemplate(templates, message) {
|
|
81
|
+
const options = [
|
|
82
|
+
...templates.map((t) => ({
|
|
83
|
+
value: t.id,
|
|
84
|
+
label: t.title,
|
|
85
|
+
tools: t.tools,
|
|
86
|
+
description: t.description,
|
|
87
|
+
})),
|
|
88
|
+
{
|
|
89
|
+
value: SENTINEL_NONE,
|
|
90
|
+
label: "No thanks — continue without scaffolding",
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
const green = neonGreenFn;
|
|
94
|
+
// Title sits at column 6 ("│ ● "), so wrapped description lines indent four
|
|
95
|
+
// spaces past the gutter to line up under it.
|
|
96
|
+
const descIndent = " ";
|
|
97
|
+
const descWidth = Math.max(24, (process.stdout.columns || 80) - 8);
|
|
98
|
+
const renderActive = (option) => {
|
|
99
|
+
const tools = option.tools && option.tools.length > 0
|
|
100
|
+
? ` ${dim(`(${option.tools.join(", ")})`)}`
|
|
101
|
+
: "";
|
|
102
|
+
const head = `${green(S_RADIO_ACTIVE)} ${option.label}${tools}`;
|
|
103
|
+
if (!option.description)
|
|
104
|
+
return head;
|
|
105
|
+
const body = wordWrap(option.description, descWidth)
|
|
106
|
+
.split("\n")
|
|
107
|
+
.map((line) => `${green(S_BAR)}${descIndent}${italic(dim(line))}`)
|
|
108
|
+
.join("\n");
|
|
109
|
+
return `${head}\n${body}`;
|
|
110
|
+
};
|
|
111
|
+
const prompt = new SelectPrompt({
|
|
112
|
+
options,
|
|
113
|
+
initialValue: options[0]?.value,
|
|
114
|
+
render() {
|
|
115
|
+
const active = this.options[this.cursor];
|
|
116
|
+
const heading = (symbol) => `${gray(S_BAR)}\n${symbol} ${message}\n`;
|
|
117
|
+
if (this.state === "submit") {
|
|
118
|
+
return `${heading(green(S_STEP_SUBMIT))}${gray(S_BAR)} ${dim(active?.label ?? "")}`;
|
|
119
|
+
}
|
|
120
|
+
if (this.state === "cancel") {
|
|
121
|
+
return `${heading(green(S_STEP_CANCEL))}${gray(S_BAR)} ${dim(active?.label ?? "")}\n${gray(S_BAR)}`;
|
|
122
|
+
}
|
|
123
|
+
const body = this.options
|
|
124
|
+
.map((option) => option === active
|
|
125
|
+
? renderActive(option)
|
|
126
|
+
: `${dim(S_RADIO_INACTIVE)} ${dim(option.label)}`)
|
|
127
|
+
.join(`\n${green(S_BAR)} `);
|
|
128
|
+
return `${heading(green(S_STEP_ACTIVE))}${green(S_BAR)} ${body}\n${green(S_BAR_END)}\n`;
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
return prompt.prompt();
|
|
132
|
+
}
|
|
133
|
+
export async function interactiveInit(options = {}) {
|
|
134
|
+
const restoreColors = patchClackColors();
|
|
135
|
+
try {
|
|
136
|
+
await interactiveInitInner(options);
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
restoreColors();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function interactiveInitInner(options) {
|
|
143
|
+
// Written straight to stdout rather than through `log`, which prefixes
|
|
144
|
+
// every line with a level and goes to stderr — this is the banner of an
|
|
145
|
+
// interactive session, not a diagnostic.
|
|
146
|
+
process.stdout.write(`\n\x1b[38;2;75;181;120m${[
|
|
147
|
+
" ██╗ ██╗██████╗ ██████╗ ██╗ ██╗",
|
|
148
|
+
" ███╗ ██║██╔═══╝ ██╔═══██╗███╗ ██║",
|
|
149
|
+
" ████╗██║██████╗ ██║ ██║████╗██║",
|
|
150
|
+
" ██╔████║██╔═══╝ ██║ ██║██╔████║",
|
|
151
|
+
" ██║╚███║██████╗ ╚██████╔╝██║╚███║",
|
|
152
|
+
" ╚═╝ ╚══╝╚═════╝ ╚═════╝ ╚═╝ ╚══╝",
|
|
153
|
+
].join("\n")}\x1b[0m\n`);
|
|
154
|
+
process.stdout.write(`${dim(wordWrap("\nLet's get your project set up with Neon. We'll install the MCP server, agent skills, and IDE extension, then connect your app to a database.\n", process.stdout.columns || 80))}\n`);
|
|
155
|
+
const detectedAgentId = detectAgent();
|
|
156
|
+
const detectedEditor = detectedAgentId
|
|
157
|
+
? agentIdToEditor(detectedAgentId)
|
|
158
|
+
: null;
|
|
159
|
+
// -----------------------------------------------------------------------
|
|
160
|
+
// Step 1: Inspect what's already in place
|
|
161
|
+
// -----------------------------------------------------------------------
|
|
162
|
+
const inspectSpinner = spinner();
|
|
163
|
+
inspectSpinner.start("Checking existing configuration...");
|
|
164
|
+
const inspection = await inspectProject([
|
|
165
|
+
{ id: "has_app", description: "", lookFor: [] },
|
|
166
|
+
{ id: "mcp_server", description: "", lookFor: [] },
|
|
167
|
+
{ id: "skills", description: "", lookFor: [] },
|
|
168
|
+
{ id: "connection_string", description: "", lookFor: [] },
|
|
169
|
+
{ id: "project_stack", description: "", lookFor: [] },
|
|
170
|
+
{ id: "migrations", description: "", lookFor: [] },
|
|
171
|
+
{ id: "ide_type", description: "", lookFor: [] },
|
|
172
|
+
]);
|
|
173
|
+
inspectSpinner.stop(dim("Configuration checked ✓"));
|
|
174
|
+
const hasApp = inspection.hasApp === true;
|
|
175
|
+
let selectedFeatures = [];
|
|
176
|
+
let selectedTemplate = null;
|
|
177
|
+
// Preview mode: bootstrap from template if no app detected
|
|
178
|
+
if (options.preview && !hasApp) {
|
|
179
|
+
let templates = FALLBACK_TEMPLATES;
|
|
180
|
+
try {
|
|
181
|
+
const fetched = await fetchTemplates();
|
|
182
|
+
if (fetched && fetched.length > 0)
|
|
183
|
+
templates = fetched;
|
|
184
|
+
}
|
|
185
|
+
catch { }
|
|
186
|
+
const templateResult = await selectTemplate(templates, "No application detected. Would you like to scaffold a new project from a template?");
|
|
187
|
+
if (isCancel(templateResult)) {
|
|
188
|
+
outro("Setup cancelled.");
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (templateResult !== "none") {
|
|
192
|
+
selectedTemplate =
|
|
193
|
+
templates.find((t) => t.id === templateResult) ?? null;
|
|
194
|
+
if (selectedTemplate) {
|
|
195
|
+
selectedFeatures = selectedTemplate.requires;
|
|
196
|
+
const bootstrapS = spinner();
|
|
197
|
+
bootstrapS.start(`Scaffolding project from template "${selectedTemplate.title}"...`);
|
|
198
|
+
try {
|
|
199
|
+
await scaffoldTemplate(selectedTemplate, ".", {
|
|
200
|
+
onWarn: (message) => log.warn(message),
|
|
201
|
+
});
|
|
202
|
+
bootstrapS.stop(dim(`Scaffolded project from "${selectedTemplate.title}" ✓`));
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
206
|
+
bootstrapS.stop("Failed to scaffold project");
|
|
207
|
+
log.error(msg);
|
|
208
|
+
outro("Setup failed.");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// For brownfield flows (existing app), ask which features to enable
|
|
215
|
+
if (!selectedTemplate && hasApp) {
|
|
216
|
+
const featuresResult = await select({
|
|
217
|
+
message: "Which Neon features would you like to enable for this project?",
|
|
218
|
+
options: [
|
|
219
|
+
{ value: "database", label: "Database" },
|
|
220
|
+
{
|
|
221
|
+
value: "database,auth",
|
|
222
|
+
label: "Database + Neon Auth (adds authentication via Neon)",
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
initialValue: "database",
|
|
226
|
+
});
|
|
227
|
+
if (isCancel(featuresResult)) {
|
|
228
|
+
outro("Setup cancelled.");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
selectedFeatures = featuresResult.split(",");
|
|
232
|
+
}
|
|
233
|
+
// Write _init metadata to .neon
|
|
234
|
+
if (selectedFeatures.length > 0) {
|
|
235
|
+
const neonPath = resolve(process.cwd(), ".neon");
|
|
236
|
+
let existing = {};
|
|
237
|
+
if (existsSync(neonPath)) {
|
|
238
|
+
try {
|
|
239
|
+
existing = JSON.parse(readFileSync(neonPath, "utf-8"));
|
|
240
|
+
}
|
|
241
|
+
catch { }
|
|
242
|
+
}
|
|
243
|
+
existing._init = { features: selectedFeatures };
|
|
244
|
+
writeFileSync(neonPath, `${JSON.stringify(existing, null, 2)}\n`);
|
|
245
|
+
}
|
|
246
|
+
const mcpAlready = inspection.mcpConfigured === true;
|
|
247
|
+
// If we bootstrapped, skills come from the template
|
|
248
|
+
const skillsAlready = inspection.skillsInstalled === true || selectedTemplate !== null;
|
|
249
|
+
const hasNeonConnection = inspection.connectionString === true;
|
|
250
|
+
let needsMcp = !mcpAlready;
|
|
251
|
+
const needsSkills = !skillsAlready;
|
|
252
|
+
const needsInstall = needsMcp || needsSkills;
|
|
253
|
+
// Check if .neon context file exists
|
|
254
|
+
const neonContextPath = resolve(process.cwd(), ".neon");
|
|
255
|
+
const hasNeonContext = existsSync(neonContextPath) &&
|
|
256
|
+
(() => {
|
|
257
|
+
try {
|
|
258
|
+
const content = JSON.parse(readFileSync(neonContextPath, "utf-8"));
|
|
259
|
+
return !!content.projectId;
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
})();
|
|
265
|
+
// Check if Neon Auth is configured
|
|
266
|
+
const hasNeonAuth = (() => {
|
|
267
|
+
for (const envFile of [".env", ".env.local"]) {
|
|
268
|
+
const envPath = resolve(process.cwd(), envFile);
|
|
269
|
+
if (existsSync(envPath)) {
|
|
270
|
+
try {
|
|
271
|
+
const content = readFileSync(envPath, "utf-8");
|
|
272
|
+
if (/^NEON_AUTH_/m.test(content))
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
catch { }
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
})();
|
|
280
|
+
// Check if extension is installed for the detected editor
|
|
281
|
+
let extensionAlready = false;
|
|
282
|
+
if (detectedEditor && usesExtension(detectedEditor)) {
|
|
283
|
+
extensionAlready = await isExtensionInstalled(detectedEditor);
|
|
284
|
+
}
|
|
285
|
+
// If tooling + database are configured, check if there's anything left to do
|
|
286
|
+
if (mcpAlready && skillsAlready && hasNeonConnection && hasNeonContext) {
|
|
287
|
+
log.step(dim(`Neon MCP server already configured (${inspection.mcpScope || "detected"}) ✓`));
|
|
288
|
+
log.step(dim(`Neon agent skills already installed (${inspection.skillsScope || "detected"}) ✓`));
|
|
289
|
+
if (extensionAlready)
|
|
290
|
+
log.step(dim("Neon editor extension installed ✓"));
|
|
291
|
+
log.step(dim("Neon database connected ✓"));
|
|
292
|
+
if (hasNeonAuth) {
|
|
293
|
+
log.step(dim("Neon Auth configured ✓"));
|
|
294
|
+
outro(dim("Your project is fully configured with Neon. Nothing to do."));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
// Neon Auth not configured — ask if they want it
|
|
298
|
+
const authResult = await select({
|
|
299
|
+
message: "Would you like to set up Neon Auth for user authentication?",
|
|
300
|
+
options: [
|
|
301
|
+
{ value: "yes", label: "Yes, set up Neon Auth" },
|
|
302
|
+
{ value: "no", label: "No, skip for now" },
|
|
303
|
+
],
|
|
304
|
+
initialValue: "no",
|
|
305
|
+
});
|
|
306
|
+
if (isCancel(authResult) || authResult === "no") {
|
|
307
|
+
outro(dim(`Your project is configured with Neon. You can set up Neon Auth later by having your agent run: neon init --agent --data '{"step":"neon-auth"}'`));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
// Read .neon for project context
|
|
311
|
+
let projectId = null;
|
|
312
|
+
try {
|
|
313
|
+
const neonCtx = JSON.parse(readFileSync(neonContextPath, "utf-8"));
|
|
314
|
+
projectId = neonCtx.projectId ?? null;
|
|
315
|
+
}
|
|
316
|
+
catch { }
|
|
317
|
+
log.step("Next steps");
|
|
318
|
+
const promptLines = ["Set up Neon Auth for this project."];
|
|
319
|
+
if (projectId)
|
|
320
|
+
promptLines.push(`Project ID: ${projectId}.`);
|
|
321
|
+
log.message(dim("Copy the following into your agent chat:"));
|
|
322
|
+
log.message(promptLines.map((line) => bold(neonGreenFn(line))).join("\n"));
|
|
323
|
+
outro(dim("Have feedback? Email us at feedback@neon.tech"));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// Log what's already in place
|
|
327
|
+
if (mcpAlready)
|
|
328
|
+
log.step(dim(`Neon MCP server already configured (${inspection.mcpScope || "detected"}) ✓`));
|
|
329
|
+
if (skillsAlready)
|
|
330
|
+
log.step(dim(`Neon agent skills already installed (${inspection.skillsScope || "detected"}) ✓`));
|
|
331
|
+
// -----------------------------------------------------------------------
|
|
332
|
+
// Step 3–5: Install what's missing (skip entirely if everything is configured)
|
|
333
|
+
// -----------------------------------------------------------------------
|
|
334
|
+
if (needsInstall) {
|
|
335
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
336
|
+
if (!homeDir) {
|
|
337
|
+
log.error("Could not determine home directory.");
|
|
338
|
+
outro("Setup failed.");
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
let selectedEditors;
|
|
342
|
+
if (detectedEditor) {
|
|
343
|
+
selectedEditors = [detectedEditor];
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
const availableEditors = await detectAvailableEditors(homeDir);
|
|
347
|
+
const editorResponse = await multiselect({
|
|
348
|
+
message: "Which editor(s) would you like to configure?",
|
|
349
|
+
options: ALL_CONFIGURABLE_AGENTS.map((agent) => ({
|
|
350
|
+
value: agent.editor,
|
|
351
|
+
label: agent.editor,
|
|
352
|
+
hint: agent.hint,
|
|
353
|
+
})),
|
|
354
|
+
initialValues: availableEditors,
|
|
355
|
+
required: true,
|
|
356
|
+
});
|
|
357
|
+
if (isCancel(editorResponse)) {
|
|
358
|
+
outro("Setup cancelled.");
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
selectedEditors = editorResponse;
|
|
362
|
+
if (selectedEditors.length === 0) {
|
|
363
|
+
log.warn("No editors selected.");
|
|
364
|
+
outro("Setup cancelled.");
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// Check extension status
|
|
369
|
+
const vscodeEditors = selectedEditors.filter(usesExtension);
|
|
370
|
+
let extensionAlreadyInstalled = false;
|
|
371
|
+
if (vscodeEditors.length > 0) {
|
|
372
|
+
const checks = await Promise.all(vscodeEditors.map((e) => isExtensionInstalled(e)));
|
|
373
|
+
extensionAlreadyInstalled = checks.every(Boolean);
|
|
374
|
+
if (extensionAlreadyInstalled) {
|
|
375
|
+
log.step(dim("Neon editor extension already installed ✓"));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const canInstallExtension = vscodeEditors.length > 0 && !extensionAlreadyInstalled;
|
|
379
|
+
let doInstallExtension = false;
|
|
380
|
+
// Build hint showing only what needs installing
|
|
381
|
+
const hintParts = [];
|
|
382
|
+
if (needsMcp)
|
|
383
|
+
hintParts.push("MCP server (global)");
|
|
384
|
+
if (needsSkills)
|
|
385
|
+
hintParts.push("agent skills (project)");
|
|
386
|
+
// Installation preferences
|
|
387
|
+
let mcpScope = "global";
|
|
388
|
+
let skillsScope = "project";
|
|
389
|
+
let modeResult;
|
|
390
|
+
while (true) {
|
|
391
|
+
const editorName = selectedEditors.join(", ");
|
|
392
|
+
const result = await select({
|
|
393
|
+
message: `Configure ${editorName} for Neon:`,
|
|
394
|
+
options: [
|
|
395
|
+
{
|
|
396
|
+
value: "defaults",
|
|
397
|
+
label: "Install with defaults",
|
|
398
|
+
hint: hintParts.join(", "),
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
value: "customize",
|
|
402
|
+
label: "Customize installation",
|
|
403
|
+
hint: canInstallExtension
|
|
404
|
+
? "choose scopes and optional editor extension"
|
|
405
|
+
: "choose scopes and options",
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
value: "change_editor",
|
|
409
|
+
label: "Configure a different editor",
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
initialValue: "defaults",
|
|
413
|
+
});
|
|
414
|
+
if (isCancel(result)) {
|
|
415
|
+
outro("Setup cancelled.");
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (result === "change_editor") {
|
|
419
|
+
const availableEditors = await detectAvailableEditors(homeDir);
|
|
420
|
+
const editorResponse = await multiselect({
|
|
421
|
+
message: "Which editor(s) would you like to configure?",
|
|
422
|
+
options: ALL_CONFIGURABLE_AGENTS.map((agent) => ({
|
|
423
|
+
value: agent.editor,
|
|
424
|
+
label: agent.editor,
|
|
425
|
+
hint: agent.hint,
|
|
426
|
+
})),
|
|
427
|
+
initialValues: availableEditors,
|
|
428
|
+
required: true,
|
|
429
|
+
});
|
|
430
|
+
if (isCancel(editorResponse)) {
|
|
431
|
+
outro("Setup cancelled.");
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
selectedEditors = editorResponse;
|
|
435
|
+
if (selectedEditors.length === 0) {
|
|
436
|
+
outro("Setup cancelled.");
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
modeResult = result;
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
if (modeResult === "customize") {
|
|
445
|
+
if (needsMcp) {
|
|
446
|
+
const scopeResult = await select({
|
|
447
|
+
message: "Where should the Neon MCP server be configured?",
|
|
448
|
+
options: [
|
|
449
|
+
{
|
|
450
|
+
value: "global",
|
|
451
|
+
label: "Global (available in all projects)",
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
value: "project",
|
|
455
|
+
label: "Project-level (this project only)",
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
value: "none",
|
|
459
|
+
label: "Skip — do not install the MCP server",
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
});
|
|
463
|
+
if (isCancel(scopeResult)) {
|
|
464
|
+
outro("Setup cancelled.");
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
mcpScope = scopeResult;
|
|
468
|
+
if (mcpScope === "none")
|
|
469
|
+
needsMcp = false;
|
|
470
|
+
}
|
|
471
|
+
if (needsSkills) {
|
|
472
|
+
const skillsScopeResult = await select({
|
|
473
|
+
message: "Where should Neon agent skills be installed?",
|
|
474
|
+
options: [
|
|
475
|
+
{
|
|
476
|
+
value: "global",
|
|
477
|
+
label: "Global (available in all projects)",
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
value: "project",
|
|
481
|
+
label: "Project-level (this project only)",
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
initialValue: "project",
|
|
485
|
+
});
|
|
486
|
+
if (isCancel(skillsScopeResult)) {
|
|
487
|
+
outro("Setup cancelled.");
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
skillsScope = skillsScopeResult;
|
|
491
|
+
}
|
|
492
|
+
if (canInstallExtension) {
|
|
493
|
+
const extResult = await confirm({
|
|
494
|
+
message: `Install the Neon extension for ${vscodeEditors.join(", ")}?`,
|
|
495
|
+
});
|
|
496
|
+
if (isCancel(extResult)) {
|
|
497
|
+
outro("Setup cancelled.");
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
doInstallExtension = extResult;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
// Auth check before install
|
|
504
|
+
const installAuthed = await isAuthenticated();
|
|
505
|
+
if (!installAuthed) {
|
|
506
|
+
const authS = spinner();
|
|
507
|
+
authS.start("Authenticating with Neon...");
|
|
508
|
+
const authSuccess = await ensureNeonctlAuth();
|
|
509
|
+
if (!authSuccess) {
|
|
510
|
+
authS.stop("Authentication failed.");
|
|
511
|
+
outro("Run `neon init` again after signing in.");
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
authS.stop("Authenticated.");
|
|
515
|
+
}
|
|
516
|
+
// Ensure the Neon CLI is installed and up to date
|
|
517
|
+
const nctlS = spinner();
|
|
518
|
+
nctlS.start("Checking Neon CLI...");
|
|
519
|
+
const nctlResult = await ensureNeonctl();
|
|
520
|
+
switch (nctlResult.status) {
|
|
521
|
+
case "already_current":
|
|
522
|
+
nctlS.stop(dim(`Neon CLI is up to date (v${nctlResult.version}) ✓`));
|
|
523
|
+
break;
|
|
524
|
+
case "installed":
|
|
525
|
+
nctlS.stop(dim(`Installed Neon CLI (v${nctlResult.version}) ✓`));
|
|
526
|
+
break;
|
|
527
|
+
case "updated":
|
|
528
|
+
nctlS.stop(dim(`Updated Neon CLI to v${nctlResult.version} ✓`));
|
|
529
|
+
break;
|
|
530
|
+
case "failed":
|
|
531
|
+
nctlS.stop("Failed to install Neon CLI");
|
|
532
|
+
log.warn("The Neon CLI could not be installed automatically. The setup will continue using npx.");
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
// Install only what's missing
|
|
536
|
+
for (const editor of selectedEditors) {
|
|
537
|
+
if (needsMcp) {
|
|
538
|
+
const mcpAgentId = getAddMcpAgentId(editor);
|
|
539
|
+
const mcpArgs = [
|
|
540
|
+
"-y",
|
|
541
|
+
"add-mcp",
|
|
542
|
+
"https://mcp.neon.tech/mcp",
|
|
543
|
+
"-n",
|
|
544
|
+
"Neon",
|
|
545
|
+
"-y",
|
|
546
|
+
"-a",
|
|
547
|
+
mcpAgentId,
|
|
548
|
+
];
|
|
549
|
+
if (mcpScope === "global")
|
|
550
|
+
mcpArgs.splice(5, 0, "-g");
|
|
551
|
+
const mcpS = spinner();
|
|
552
|
+
mcpS.start(`Installing Neon MCP server for ${editor}...`);
|
|
553
|
+
try {
|
|
554
|
+
await execa("npx", mcpArgs, {
|
|
555
|
+
stdio: "pipe",
|
|
556
|
+
timeout: 60000,
|
|
557
|
+
});
|
|
558
|
+
mcpS.stop(dim(`Neon MCP server configured for ${editor} (${mcpScope}) ✓`));
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
562
|
+
mcpS.stop(`Failed to configure MCP server for ${editor}`);
|
|
563
|
+
log.error(msg);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (needsSkills) {
|
|
567
|
+
await installAgentSkills([editor], {
|
|
568
|
+
scope: skillsScope,
|
|
569
|
+
preview: options.preview,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
if (doInstallExtension && usesExtension(editor)) {
|
|
573
|
+
const extS = spinner();
|
|
574
|
+
extS.start(`Installing Neon extension for ${editor}...`);
|
|
575
|
+
const extOk = await installExtension(editor);
|
|
576
|
+
if (extOk) {
|
|
577
|
+
extS.stop(dim(`Neon extension installed for ${editor} ✓`));
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
extS.stop(`Extension install failed — install manually from the extensions panel.`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// Ensure all required skills are present (fills in any missing ones).
|
|
586
|
+
// detectAgent() returns null in a human terminal (TTY), so fall back
|
|
587
|
+
// to IDE detection which works regardless of TTY.
|
|
588
|
+
const ide = detectIde();
|
|
589
|
+
const agentForSkills = detectAgent() ??
|
|
590
|
+
(ide === "Cursor"
|
|
591
|
+
? "cursor"
|
|
592
|
+
: ide === "VS Code"
|
|
593
|
+
? "vscode"
|
|
594
|
+
: ide === "Windsurf"
|
|
595
|
+
? "windsurf"
|
|
596
|
+
: null);
|
|
597
|
+
if (agentForSkills) {
|
|
598
|
+
const detectedSkillsScope = inspection.skillsScope === "global" ? "global" : undefined;
|
|
599
|
+
await ensureSkillsUpToDate(agentForSkills, detectedSkillsScope, options.preview);
|
|
600
|
+
}
|
|
601
|
+
// -----------------------------------------------------------------------
|
|
602
|
+
// Step 6: Done — build prompt for the agent to continue
|
|
603
|
+
// -----------------------------------------------------------------------
|
|
604
|
+
// Build the getting-started data payload (same as agent mode)
|
|
605
|
+
const gettingStartedData = {};
|
|
606
|
+
if (hasNeonConnection)
|
|
607
|
+
gettingStartedData.hasConnectionString = true;
|
|
608
|
+
if (inspection.framework && inspection.framework !== "none")
|
|
609
|
+
gettingStartedData.framework = inspection.framework;
|
|
610
|
+
if (inspection.orm && inspection.orm !== "none")
|
|
611
|
+
gettingStartedData.orm = inspection.orm;
|
|
612
|
+
if (inspection.migrationTool && inspection.migrationTool !== "none")
|
|
613
|
+
gettingStartedData.migrationTool = inspection.migrationTool;
|
|
614
|
+
if (inspection.migrationDir && inspection.migrationDir !== "none")
|
|
615
|
+
gettingStartedData.migrationDir = inspection.migrationDir;
|
|
616
|
+
if (selectedFeatures.length > 0)
|
|
617
|
+
gettingStartedData.features = selectedFeatures;
|
|
618
|
+
if (options.preview)
|
|
619
|
+
gettingStartedData.preview = true;
|
|
620
|
+
// Build a prompt for the user to paste into their agent chat
|
|
621
|
+
const cmd = `neon init --agent --data '${JSON.stringify({ step: "getting-started", ...gettingStartedData })}'`;
|
|
622
|
+
// Account for clack's "│ " prefix (3 chars) when wrapping
|
|
623
|
+
const cols = (process.stdout.columns || 80) - 3;
|
|
624
|
+
const promptText = `To finish setting up Neon using Neon's agent-guided onboarding experience, have your agent run this shell command: ${cmd}`;
|
|
625
|
+
log.step("Next steps");
|
|
626
|
+
log.message(dim("Copy the following into your agent chat:"));
|
|
627
|
+
log.message(wordWrap(promptText, cols)
|
|
628
|
+
.split("\n")
|
|
629
|
+
.map((line) => bold(neonGreenFn(line)))
|
|
630
|
+
.join("\n"));
|
|
631
|
+
outro(dim("Have feedback? Email us at feedback@neon.tech"));
|
|
632
|
+
}
|
|
633
|
+
function agentIdToEditor(agentId) {
|
|
634
|
+
switch (agentId) {
|
|
635
|
+
case "cursor":
|
|
636
|
+
return "Cursor";
|
|
637
|
+
case "vscode":
|
|
638
|
+
return "VS Code";
|
|
639
|
+
case "claude-code":
|
|
640
|
+
return "Claude CLI";
|
|
641
|
+
case "windsurf":
|
|
642
|
+
// Windsurf not in Editor type yet — fall back to prompt
|
|
643
|
+
return null;
|
|
644
|
+
case "codex":
|
|
645
|
+
return "Codex";
|
|
646
|
+
case "cline":
|
|
647
|
+
return "Cline";
|
|
648
|
+
default:
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
}
|