neon 2.45.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.
Files changed (52) hide show
  1. package/README.md +62 -1
  2. package/dist/_shared/paths.js +3 -4
  3. package/dist/commands/bootstrap.js +12 -11
  4. package/dist/commands/checkout.js +7 -6
  5. package/dist/commands/config.js +2 -1
  6. package/dist/commands/data_api.js +4 -3
  7. package/dist/commands/env.js +5 -4
  8. package/dist/commands/functions.js +3 -2
  9. package/dist/commands/init.js +82 -37
  10. package/dist/commands/ip_allow.js +3 -2
  11. package/dist/commands/link.js +17 -16
  12. package/dist/commands/projects.js +3 -2
  13. package/dist/commands/set_context.js +5 -4
  14. package/dist/current_branch_fast_path.js +2 -1
  15. package/dist/dev/env.js +8 -7
  16. package/dist/index.js +2 -2
  17. package/dist/init/agents.js +127 -0
  18. package/dist/init/auth.js +77 -0
  19. package/dist/init/bootstrap.js +448 -0
  20. package/dist/init/build_config.js +2 -0
  21. package/dist/init/detect_agent.js +108 -0
  22. package/dist/init/editors.js +62 -0
  23. package/dist/init/enrich_output.js +71 -0
  24. package/dist/init/extension.js +191 -0
  25. package/dist/init/inspect.js +287 -0
  26. package/dist/init/interactive.js +651 -0
  27. package/dist/init/neonctl.js +184 -0
  28. package/dist/init/orchestrate.js +190 -0
  29. package/dist/init/phases/auth.js +209 -0
  30. package/dist/init/phases/cleanup.js +27 -0
  31. package/dist/init/phases/db.js +283 -0
  32. package/dist/init/phases/getting_started.js +228 -0
  33. package/dist/init/phases/mcp.js +227 -0
  34. package/dist/init/phases/migrations.js +251 -0
  35. package/dist/init/phases/neon_auth.js +135 -0
  36. package/dist/init/phases/setup.js +729 -0
  37. package/dist/init/phases/skills.js +89 -0
  38. package/dist/init/phases/status.js +70 -0
  39. package/dist/init/resolve_context.js +107 -0
  40. package/dist/init/route_command.js +100 -0
  41. package/dist/init/skills.js +248 -0
  42. package/dist/init/types.js +1 -0
  43. package/dist/init/vsix.js +111 -0
  44. package/dist/psql/command/cmd_meta.js +2 -2
  45. package/dist/psql/core/mainloop.js +1 -1
  46. package/dist/psql/core/startup.js +1 -1
  47. package/dist/psql/core/syncVars.js +3 -3
  48. package/dist/psql/index.js +1 -1
  49. package/dist/utils/cli_name.js +14 -0
  50. package/dist/utils/esbuild.js +1 -1
  51. package/dist/utils/write_sync.js +39 -0
  52. package/package.json +18 -12
@@ -0,0 +1,191 @@
1
+ import { existsSync } from "node:fs";
2
+ import { unlink } from "node:fs/promises";
3
+ import { execa } from "execa";
4
+ import { downloadVsix, NEON_EXTENSION_ID } from "./vsix.js";
5
+ /**
6
+ * Uses macOS mdfind to locate an app by bundle identifier
7
+ */
8
+ async function findAppWithMdfind(bundleId) {
9
+ try {
10
+ const result = await execa("mdfind", [`kMDItemCFBundleIdentifier == '${bundleId}'`], { timeout: 5000 });
11
+ const paths = result.stdout.trim().split("\n").filter(Boolean);
12
+ return paths[0] || null;
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ }
18
+ /**
19
+ * Known installation paths for VS Code CLI
20
+ */
21
+ function getVSCodePaths() {
22
+ const platform = process.platform;
23
+ const home = process.env.HOME || "";
24
+ if (platform === "darwin") {
25
+ return [
26
+ "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code",
27
+ "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code-insiders",
28
+ `${home}/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code`,
29
+ `${home}/Downloads/Visual Studio Code.app/Contents/Resources/app/bin/code`,
30
+ ];
31
+ }
32
+ if (platform === "linux") {
33
+ return [
34
+ "/usr/share/code/bin/code",
35
+ "/usr/bin/code",
36
+ "/snap/bin/code",
37
+ "/usr/share/code-insiders/bin/code-insiders",
38
+ ];
39
+ }
40
+ if (platform === "win32") {
41
+ const localAppData = process.env.LOCALAPPDATA || "";
42
+ const programFiles = process.env.PROGRAMFILES || "C:\\Program Files";
43
+ return [
44
+ `${localAppData}\\Programs\\Microsoft VS Code\\bin\\code.cmd`,
45
+ `${programFiles}\\Microsoft VS Code\\bin\\code.cmd`,
46
+ `${localAppData}\\Programs\\Microsoft VS Code Insiders\\bin\\code-insiders.cmd`,
47
+ ];
48
+ }
49
+ return [];
50
+ }
51
+ /**
52
+ * Known installation paths for Cursor CLI
53
+ */
54
+ function getCursorPaths() {
55
+ const platform = process.platform;
56
+ const home = process.env.HOME || "";
57
+ if (platform === "darwin") {
58
+ return [
59
+ "/Applications/Cursor.app/Contents/Resources/app/bin/cursor",
60
+ `${home}/Applications/Cursor.app/Contents/Resources/app/bin/cursor`,
61
+ `${home}/Downloads/Cursor.app/Contents/Resources/app/bin/cursor`,
62
+ ];
63
+ }
64
+ if (platform === "linux") {
65
+ return [
66
+ "/usr/share/cursor/bin/cursor",
67
+ "/usr/bin/cursor",
68
+ `${home}/.local/bin/cursor`,
69
+ "/opt/cursor/bin/cursor",
70
+ ];
71
+ }
72
+ if (platform === "win32") {
73
+ const localAppData = process.env.LOCALAPPDATA || "";
74
+ const programFiles = process.env.PROGRAMFILES || "C:\\Program Files";
75
+ return [
76
+ `${localAppData}\\Programs\\Cursor\\resources\\app\\bin\\cursor.cmd`,
77
+ `${localAppData}\\cursor\\Cursor.exe`,
78
+ `${programFiles}\\Cursor\\resources\\app\\bin\\cursor.cmd`,
79
+ ];
80
+ }
81
+ return [];
82
+ }
83
+ /**
84
+ * Finds the CLI command for an editor by checking known installation paths
85
+ * On macOS, also uses mdfind to locate the app if standard paths fail
86
+ * Falls back to the simple command name if no full path is found (in case it's in PATH)
87
+ */
88
+ export async function findEditorCommand(editor) {
89
+ let paths;
90
+ let fallbackCommand;
91
+ let bundleId = null;
92
+ if (editor === "VS Code") {
93
+ paths = getVSCodePaths();
94
+ fallbackCommand = "code";
95
+ bundleId = "com.microsoft.VSCode";
96
+ }
97
+ else if (editor === "Cursor") {
98
+ paths = getCursorPaths();
99
+ fallbackCommand = "cursor";
100
+ bundleId = "com.todesktop.230313mzl4w4u92";
101
+ }
102
+ else {
103
+ return null;
104
+ }
105
+ for (const path of paths) {
106
+ if (existsSync(path)) {
107
+ return path;
108
+ }
109
+ }
110
+ // On macOS, try mdfind to locate the app dynamically
111
+ if (process.platform === "darwin" && bundleId) {
112
+ const appPath = await findAppWithMdfind(bundleId);
113
+ if (appPath) {
114
+ const cliPath = `${appPath}/Contents/Resources/app/bin/${fallbackCommand}`;
115
+ if (existsSync(cliPath)) {
116
+ return cliPath;
117
+ }
118
+ }
119
+ }
120
+ return fallbackCommand;
121
+ }
122
+ /**
123
+ * Checks if the extension is installed by querying the editor's extension list
124
+ */
125
+ export async function isExtensionInstalled(editor) {
126
+ const command = await findEditorCommand(editor);
127
+ if (!command) {
128
+ return false;
129
+ }
130
+ try {
131
+ const result = await execa(command, ["--list-extensions"], {
132
+ timeout: 5000,
133
+ });
134
+ return result.stdout.includes(NEON_EXTENSION_ID);
135
+ }
136
+ catch {
137
+ return false;
138
+ }
139
+ }
140
+ /**
141
+ * Installs the Neon Local Connect extension for VS Code or Cursor.
142
+ *
143
+ * Strategy:
144
+ * 1. Try `--install-extension <id>` directly (uses the editor's configured marketplace)
145
+ * 2. If that fails, download .vsix (from proxy or Open VSX) and install locally
146
+ * 3. Set NEON_VSX_GALLERY_URL to use a corporate proxy for the download
147
+ */
148
+ export async function installExtension(editor) {
149
+ const command = await findEditorCommand(editor);
150
+ if (!command) {
151
+ return false;
152
+ }
153
+ // Try direct marketplace install first
154
+ try {
155
+ await execa(command, ["--install-extension", NEON_EXTENSION_ID], {
156
+ stdio: "pipe",
157
+ timeout: 60000,
158
+ });
159
+ return true;
160
+ }
161
+ catch {
162
+ // Fall through to VSIX download
163
+ }
164
+ // Download .vsix and install locally
165
+ const vsixPath = await downloadVsix();
166
+ if (!vsixPath) {
167
+ return false;
168
+ }
169
+ try {
170
+ await execa(command, ["--install-extension", vsixPath], {
171
+ stdio: "pipe",
172
+ timeout: 60000,
173
+ });
174
+ return true;
175
+ }
176
+ catch {
177
+ return false;
178
+ }
179
+ finally {
180
+ try {
181
+ await unlink(vsixPath);
182
+ }
183
+ catch { }
184
+ }
185
+ }
186
+ /**
187
+ * Returns the editor types that should use extension installation (vs MCP)
188
+ */
189
+ export function usesExtension(editor) {
190
+ return editor === "VS Code" || editor === "Cursor";
191
+ }
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Filesystem-based project inspection for interactive (agentless) mode.
3
+ * Replaces the "agent_check" pattern — instead of asking an agent to look,
4
+ * we examine the filesystem directly.
5
+ */
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ import { resolve } from "node:path";
8
+ /**
9
+ * Runs filesystem checks based on the agent_check descriptors.
10
+ * Maps check IDs to concrete inspection functions.
11
+ */
12
+ export async function inspectProject(checks) {
13
+ const results = {};
14
+ const cwd = process.cwd();
15
+ for (const check of checks) {
16
+ switch (check.id) {
17
+ case "mcp_server": {
18
+ const mcpScope = checkMcpServer(cwd);
19
+ results.mcpConfigured = mcpScope !== false;
20
+ results.mcpScope = mcpScope;
21
+ break;
22
+ }
23
+ case "connection_string":
24
+ results.connectionString = checkConnectionString(cwd);
25
+ break;
26
+ case "database_url":
27
+ results.databaseUrl = checkDatabaseUrl(cwd);
28
+ break;
29
+ case "project_stack": {
30
+ const stack = detectProjectStack(cwd);
31
+ results.framework = stack.framework;
32
+ results.orm = stack.orm;
33
+ break;
34
+ }
35
+ case "migrations": {
36
+ const migrations = detectMigrations(cwd);
37
+ results.migrationTool = migrations.tool;
38
+ results.migrationDir = migrations.dir;
39
+ break;
40
+ }
41
+ case "skills": {
42
+ const skillsScope = checkSkillsInstalled(cwd);
43
+ results.skillsInstalled = skillsScope !== false;
44
+ results.skillsScope = skillsScope;
45
+ break;
46
+ }
47
+ case "ide_type":
48
+ results.isVscodeIde = checkVscodeIde();
49
+ break;
50
+ case "has_app":
51
+ results.hasApp = checkHasApp(cwd);
52
+ break;
53
+ case "agent_type":
54
+ // Handled by the interactive runner (prompt or env detection)
55
+ break;
56
+ }
57
+ }
58
+ return results;
59
+ }
60
+ // ---------------------------------------------------------------------------
61
+ // Individual check implementations
62
+ // ---------------------------------------------------------------------------
63
+ function checkMcpServer(cwd) {
64
+ const home = process.env.HOME || process.env.USERPROFILE || "";
65
+ // Check project-level configs first
66
+ const projectConfigs = [
67
+ resolve(cwd, ".cursor", "mcp.json"),
68
+ resolve(cwd, ".vscode", "settings.json"),
69
+ ];
70
+ for (const configPath of projectConfigs) {
71
+ if (existsSync(configPath)) {
72
+ try {
73
+ const content = readFileSync(configPath, "utf-8");
74
+ if (content.includes("neon") ||
75
+ content.includes("mcp.neon.tech")) {
76
+ return "project";
77
+ }
78
+ }
79
+ catch { }
80
+ }
81
+ }
82
+ // Check global configs
83
+ const globalConfigs = [
84
+ resolve(home, ".cursor", "mcp.json"),
85
+ // Claude Code config (add-mcp writes to settings.local.json)
86
+ resolve(home, ".claude", "settings.local.json"),
87
+ resolve(home, ".claude", "settings.json"),
88
+ ];
89
+ for (const configPath of globalConfigs) {
90
+ if (existsSync(configPath)) {
91
+ try {
92
+ const content = readFileSync(configPath, "utf-8");
93
+ if (content.includes("neon") ||
94
+ content.includes("mcp.neon.tech")) {
95
+ return "global";
96
+ }
97
+ }
98
+ catch { }
99
+ }
100
+ }
101
+ return false;
102
+ }
103
+ function checkConnectionString(cwd) {
104
+ for (const envFile of [".env", ".env.local"]) {
105
+ const envPath = resolve(cwd, envFile);
106
+ if (existsSync(envPath)) {
107
+ try {
108
+ const content = readFileSync(envPath, "utf-8");
109
+ if (/^DATABASE_URL=.*neon/m.test(content) ||
110
+ /^PGHOST=.*neon/m.test(content)) {
111
+ return true;
112
+ }
113
+ }
114
+ catch { }
115
+ }
116
+ }
117
+ return false;
118
+ }
119
+ function detectProjectStack(cwd) {
120
+ const result = { framework: "none", orm: "none" };
121
+ const pkgPath = resolve(cwd, "package.json");
122
+ if (!existsSync(pkgPath))
123
+ return result;
124
+ try {
125
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
126
+ const allDeps = {
127
+ ...pkg.dependencies,
128
+ ...pkg.devDependencies,
129
+ };
130
+ // Framework detection
131
+ if (allDeps.next)
132
+ result.framework = "next";
133
+ else if (allDeps.remix || allDeps["@remix-run/node"])
134
+ result.framework = "remix";
135
+ else if (allDeps.express)
136
+ result.framework = "express";
137
+ else if (allDeps.hono)
138
+ result.framework = "hono";
139
+ else if (allDeps.fastify)
140
+ result.framework = "fastify";
141
+ else if (allDeps["@sveltejs/kit"])
142
+ result.framework = "sveltekit";
143
+ else if (allDeps.nuxt)
144
+ result.framework = "nuxt";
145
+ else if (allDeps.astro)
146
+ result.framework = "astro";
147
+ // ORM detection
148
+ if (allDeps.prisma || allDeps["@prisma/client"])
149
+ result.orm = "prisma";
150
+ else if (allDeps["drizzle-orm"])
151
+ result.orm = "drizzle";
152
+ else if (allDeps.knex)
153
+ result.orm = "knex";
154
+ else if (allDeps.typeorm)
155
+ result.orm = "typeorm";
156
+ else if (allDeps.sequelize)
157
+ result.orm = "sequelize";
158
+ else if (allDeps["@neondatabase/serverless"])
159
+ result.orm = "neon-serverless";
160
+ }
161
+ catch { }
162
+ return result;
163
+ }
164
+ function detectMigrations(cwd) {
165
+ // Prisma
166
+ if (existsSync(resolve(cwd, "prisma", "schema.prisma"))) {
167
+ const migrationsDir = resolve(cwd, "prisma", "migrations");
168
+ return {
169
+ tool: "prisma",
170
+ dir: existsSync(migrationsDir) ? "prisma/migrations" : "none",
171
+ };
172
+ }
173
+ // Drizzle
174
+ if (existsSync(resolve(cwd, "drizzle.config.ts")) ||
175
+ existsSync(resolve(cwd, "drizzle.config.js"))) {
176
+ const drizzleDir = resolve(cwd, "drizzle");
177
+ return {
178
+ tool: "drizzle",
179
+ dir: existsSync(drizzleDir) ? "drizzle" : "none",
180
+ };
181
+ }
182
+ // Knex
183
+ if (existsSync(resolve(cwd, "knexfile.js")) ||
184
+ existsSync(resolve(cwd, "knexfile.ts"))) {
185
+ const migrationsDir = resolve(cwd, "migrations");
186
+ return {
187
+ tool: "knex",
188
+ dir: existsSync(migrationsDir) ? "migrations" : "none",
189
+ };
190
+ }
191
+ return { tool: "none", dir: "none" };
192
+ }
193
+ function checkDatabaseUrl(cwd) {
194
+ const envPath = resolve(cwd, ".env");
195
+ if (existsSync(envPath)) {
196
+ try {
197
+ const content = readFileSync(envPath, "utf-8");
198
+ if (/^DATABASE_URL=/m.test(content))
199
+ return true;
200
+ }
201
+ catch { }
202
+ }
203
+ return false;
204
+ }
205
+ function checkSkillsInstalled(cwd) {
206
+ const home = process.env.HOME || process.env.USERPROFILE || "";
207
+ const skillNames = ["neon", "neon-postgres"];
208
+ // Check project-level skill directories — ALL base skills must exist
209
+ const projectDirs = [
210
+ resolve(cwd, ".cursor", "skills"),
211
+ resolve(cwd, ".claude", "skills"),
212
+ resolve(cwd, ".agents", "skills"),
213
+ ];
214
+ const allProjectSkills = skillNames.every((skill) => projectDirs.some((dir) => existsSync(resolve(dir, skill, "SKILL.md"))));
215
+ if (allProjectSkills)
216
+ return "project";
217
+ // Check CLAUDE.md for neon skill references (injected by skills CLI)
218
+ // Only counts as installed if both skill names are referenced
219
+ const claudeMd = resolve(cwd, "CLAUDE.md");
220
+ if (existsSync(claudeMd)) {
221
+ try {
222
+ const content = readFileSync(claudeMd, "utf-8");
223
+ if (content.includes("neon-postgres") &&
224
+ content.includes("neon/SKILL.md"))
225
+ return "project";
226
+ }
227
+ catch { }
228
+ }
229
+ // Check global skill directories — ALL base skills must exist
230
+ const globalDirs = [
231
+ resolve(home, ".cursor", "skills"),
232
+ resolve(home, ".claude", "skills"),
233
+ resolve(home, ".agents", "skills"),
234
+ ];
235
+ const allGlobalSkills = skillNames.every((skill) => globalDirs.some((dir) => existsSync(resolve(dir, skill, "SKILL.md"))));
236
+ if (allGlobalSkills)
237
+ return "global";
238
+ // Check for partial installations — ANY skill exists
239
+ const anyProjectSkill = skillNames.some((skill) => projectDirs.some((dir) => existsSync(resolve(dir, skill, "SKILL.md"))));
240
+ if (anyProjectSkill)
241
+ return "project-partial";
242
+ const anyGlobalSkill = skillNames.some((skill) => globalDirs.some((dir) => existsSync(resolve(dir, skill, "SKILL.md"))));
243
+ if (anyGlobalSkill)
244
+ return "global-partial";
245
+ return false;
246
+ }
247
+ function checkVscodeIde() {
248
+ const env = process.env;
249
+ return !!(env.TERM_PROGRAM === "vscode" ||
250
+ env.TERM_PROGRAM === "cursor" ||
251
+ env.TERM_PROGRAM === "windsurf" ||
252
+ env.VSCODE_PID ||
253
+ env.VSCODE_CWD);
254
+ }
255
+ /**
256
+ * Detects whether the current directory contains an application.
257
+ * Returns true if package.json has dependencies or common source directories exist.
258
+ */
259
+ function checkHasApp(cwd) {
260
+ const pkgPath = resolve(cwd, "package.json");
261
+ if (existsSync(pkgPath)) {
262
+ try {
263
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
264
+ const deps = Object.keys(pkg.dependencies ?? {});
265
+ const devDeps = Object.keys(pkg.devDependencies ?? {});
266
+ if (deps.length > 0 || devDeps.length > 0)
267
+ return true;
268
+ }
269
+ catch { }
270
+ }
271
+ // Check for common source directories / entry files
272
+ const indicators = [
273
+ "src",
274
+ "app",
275
+ "pages",
276
+ "lib",
277
+ "index.ts",
278
+ "index.js",
279
+ "main.ts",
280
+ "main.js",
281
+ ];
282
+ for (const indicator of indicators) {
283
+ if (existsSync(resolve(cwd, indicator)))
284
+ return true;
285
+ }
286
+ return false;
287
+ }