neon 3.0.0 → 3.1.1

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 (207) hide show
  1. package/README.md +70 -5
  2. package/dist/_chunks/auth_selection-DGgq6ifc.js +83 -0
  3. package/dist/_chunks/cmd_pipeline-CUbBO9U_.js +2818 -0
  4. package/dist/_chunks/credentials-MYdHdKah.js +188 -0
  5. package/dist/_chunks/env-NbA61JR3.js +585 -0
  6. package/dist/_chunks/env_services-Tz9G4JeT.js +531 -0
  7. package/dist/_chunks/paths-DMq0Lt7a.js +151 -0
  8. package/dist/_chunks/profiles-Ir29rqns.js +217 -0
  9. package/dist/_chunks/psql-DWH-kc69.js +2169 -0
  10. package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +13 -0
  11. package/dist/_chunks/secure_file-BucZj4yQ.js +39 -0
  12. package/dist/analytics.js +163 -207
  13. package/dist/api.js +815 -758
  14. package/dist/auth.js +121 -141
  15. package/dist/auth_context.js +39 -53
  16. package/dist/cli.js +4 -7
  17. package/dist/commands/api.js +220 -250
  18. package/dist/commands/api_keys.js +251 -314
  19. package/dist/commands/auth.js +283 -328
  20. package/dist/commands/bootstrap.js +372 -437
  21. package/dist/commands/branches.js +304 -455
  22. package/dist/commands/bucket.js +374 -514
  23. package/dist/commands/checkout.js +213 -298
  24. package/dist/commands/config.js +573 -690
  25. package/dist/commands/connection_string.js +137 -165
  26. package/dist/commands/data_api.js +238 -260
  27. package/dist/commands/databases.js +67 -76
  28. package/dist/commands/deploy.js +31 -25
  29. package/dist/commands/dev.js +639 -719
  30. package/dist/commands/diff.js +156 -200
  31. package/dist/commands/env.js +255 -305
  32. package/dist/commands/functions.js +275 -355
  33. package/dist/commands/index.js +70 -65
  34. package/dist/commands/init.js +84 -119
  35. package/dist/commands/inspect.js +55 -55
  36. package/dist/commands/ip_allow.js +88 -120
  37. package/dist/commands/link.js +874 -1019
  38. package/dist/commands/logs.js +291 -0
  39. package/dist/commands/neon_auth.js +725 -933
  40. package/dist/commands/operations.js +34 -25
  41. package/dist/commands/orgs.js +28 -18
  42. package/dist/commands/profile.js +615 -846
  43. package/dist/commands/projects.js +313 -373
  44. package/dist/commands/psql.js +60 -58
  45. package/dist/commands/roles.js +55 -58
  46. package/dist/commands/schema_diff.js +87 -131
  47. package/dist/commands/set_context.js +34 -26
  48. package/dist/commands/snapshots.js +288 -413
  49. package/dist/commands/status.js +41 -37
  50. package/dist/commands/user.js +21 -10
  51. package/dist/commands/vpc_endpoints.js +85 -113
  52. package/dist/config.js +7 -6
  53. package/dist/config_format.js +50 -66
  54. package/dist/config_template.js +128 -157
  55. package/dist/context.js +183 -235
  56. package/dist/current_branch_fast_path.js +40 -49
  57. package/dist/dev/env.js +2 -446
  58. package/dist/dev/functions.js +54 -68
  59. package/dist/dev/inputs.js +46 -58
  60. package/dist/dev/runtime.js +135 -164
  61. package/dist/dev/websocket.js +766 -959
  62. package/dist/env.js +27 -33
  63. package/dist/env_file.js +118 -132
  64. package/dist/env_services.js +2 -51
  65. package/dist/errors.js +57 -68
  66. package/dist/functions_api.js +45 -43
  67. package/dist/help.js +189 -140
  68. package/dist/index.js +182 -257
  69. package/dist/init/agents.js +137 -118
  70. package/dist/init/auth.js +58 -68
  71. package/dist/init/bootstrap.js +325 -396
  72. package/dist/init/build_config.js +4 -2
  73. package/dist/init/detect_agent.js +56 -101
  74. package/dist/init/editors.js +35 -52
  75. package/dist/init/enrich_output.js +51 -66
  76. package/dist/init/extension.js +134 -171
  77. package/dist/init/inspect.js +179 -266
  78. package/dist/init/interactive.js +510 -622
  79. package/dist/init/neonctl.js +117 -168
  80. package/dist/init/orchestrate.js +157 -173
  81. package/dist/init/phases/auth.js +188 -202
  82. package/dist/init/phases/cleanup.js +23 -23
  83. package/dist/init/phases/db.js +251 -277
  84. package/dist/init/phases/getting_started.js +213 -223
  85. package/dist/init/phases/mcp.js +174 -224
  86. package/dist/init/phases/migrations.js +247 -248
  87. package/dist/init/phases/neon_auth.js +114 -133
  88. package/dist/init/phases/setup.js +546 -703
  89. package/dist/init/phases/skills.js +75 -86
  90. package/dist/init/phases/status.js +72 -67
  91. package/dist/init/resolve_context.js +102 -99
  92. package/dist/init/route_command.js +91 -98
  93. package/dist/init/skills.js +174 -218
  94. package/dist/init/vsix.js +77 -99
  95. package/dist/log.js +17 -16
  96. package/dist/neon_services.js +104 -129
  97. package/dist/parameters.gen.js +481 -471
  98. package/dist/pkg.js +17 -19
  99. package/dist/profile_keys.js +44 -47
  100. package/dist/psql/cli.js +44 -47
  101. package/dist/psql/command/cmd_cond.js +231 -406
  102. package/dist/psql/command/cmd_connect.js +557 -764
  103. package/dist/psql/command/cmd_copy.js +728 -984
  104. package/dist/psql/command/cmd_describe.js +1499 -1688
  105. package/dist/psql/command/cmd_format.js +733 -905
  106. package/dist/psql/command/cmd_io.js +2 -2193
  107. package/dist/psql/command/cmd_lo.js +297 -359
  108. package/dist/psql/command/cmd_meta.js +727 -878
  109. package/dist/psql/command/cmd_misc.js +138 -172
  110. package/dist/psql/command/cmd_pipeline.js +2 -1148
  111. package/dist/psql/command/cmd_restrict.js +119 -155
  112. package/dist/psql/command/cmd_show.js +529 -688
  113. package/dist/psql/command/dispatch.js +260 -325
  114. package/dist/psql/command/inputQueue.js +35 -33
  115. package/dist/psql/command/shared.js +49 -63
  116. package/dist/psql/complete/filenames.js +90 -133
  117. package/dist/psql/complete/index.js +59 -97
  118. package/dist/psql/complete/matcher.js +236 -300
  119. package/dist/psql/complete/psqlVars.js +218 -223
  120. package/dist/psql/complete/queries.js +159 -177
  121. package/dist/psql/complete/rules.js +1493 -2299
  122. package/dist/psql/core/common.js +2 -1253
  123. package/dist/psql/core/help.js +456 -546
  124. package/dist/psql/core/mainloop.js +692 -1303
  125. package/dist/psql/core/prompt.js +391 -408
  126. package/dist/psql/core/settings.js +429 -644
  127. package/dist/psql/core/sqlHelp.js +480 -554
  128. package/dist/psql/core/startup.js +2 -846
  129. package/dist/psql/core/syncVars.js +67 -110
  130. package/dist/psql/core/variables.js +156 -278
  131. package/dist/psql/describe/formatters.js +884 -1285
  132. package/dist/psql/describe/processNamePattern.js +173 -260
  133. package/dist/psql/describe/queries.js +1368 -2403
  134. package/dist/psql/describe/versionGate.js +32 -41
  135. package/dist/psql/index.js +2 -2030
  136. package/dist/psql/io/history.js +232 -271
  137. package/dist/psql/io/input.js +103 -108
  138. package/dist/psql/io/lineEditor/buffer.js +238 -319
  139. package/dist/psql/io/lineEditor/complete.js +135 -213
  140. package/dist/psql/io/lineEditor/filename.js +139 -148
  141. package/dist/psql/io/lineEditor/index.js +653 -870
  142. package/dist/psql/io/lineEditor/keymap.js +544 -702
  143. package/dist/psql/io/lineEditor/vt100.js +294 -341
  144. package/dist/psql/io/pgpass.js +158 -187
  145. package/dist/psql/io/pgservice.js +146 -183
  146. package/dist/psql/io/psqlrc.js +328 -403
  147. package/dist/psql/print/aligned.js +1020 -1683
  148. package/dist/psql/print/asciidoc.js +180 -214
  149. package/dist/psql/print/crosstab.js +281 -442
  150. package/dist/psql/print/csv.js +48 -70
  151. package/dist/psql/print/html.js +195 -226
  152. package/dist/psql/print/json.js +75 -88
  153. package/dist/psql/print/latex.js +291 -364
  154. package/dist/psql/print/pager.js +171 -242
  155. package/dist/psql/print/troff.js +194 -226
  156. package/dist/psql/print/unaligned.js +69 -95
  157. package/dist/psql/print/units.js +167 -169
  158. package/dist/psql/scanner/slash.js +428 -483
  159. package/dist/psql/scanner/sql.js +445 -889
  160. package/dist/psql/scanner/stringutils.js +309 -379
  161. package/dist/psql/types/index.js +8 -7
  162. package/dist/psql/types/scanner.js +25 -22
  163. package/dist/psql/wire/connection.js +2042 -2803
  164. package/dist/psql/wire/copy.js +84 -100
  165. package/dist/psql/wire/notify.js +39 -59
  166. package/dist/psql/wire/pipeline.js +305 -518
  167. package/dist/psql/wire/protocol.js +349 -417
  168. package/dist/psql/wire/sasl.js +180 -265
  169. package/dist/psql/wire/tls.js +400 -561
  170. package/dist/storage_api.js +115 -129
  171. package/dist/test_utils/fixtures.js +94 -113
  172. package/dist/test_utils/oauth_server.js +10 -7
  173. package/dist/test_utils/project_dir.js +33 -0
  174. package/dist/utils/ai_gateway_notice.js +131 -162
  175. package/dist/utils/api_enums.js +21 -28
  176. package/dist/utils/auth.js +10 -4
  177. package/dist/utils/branch_notice.js +20 -19
  178. package/dist/utils/branch_picker.js +83 -89
  179. package/dist/utils/cli_name.js +15 -12
  180. package/dist/utils/compute_units.js +20 -27
  181. package/dist/utils/config_diff.js +127 -158
  182. package/dist/utils/enrichers.js +95 -148
  183. package/dist/utils/esbuild.js +130 -189
  184. package/dist/utils/flags.js +35 -47
  185. package/dist/utils/formats.js +8 -15
  186. package/dist/utils/git_diff.js +69 -80
  187. package/dist/utils/inspect_db.js +101 -143
  188. package/dist/utils/inspect_queries.js +179 -142
  189. package/dist/utils/middlewares.js +39 -45
  190. package/dist/utils/openapi.js +87 -99
  191. package/dist/utils/package_manager.js +312 -110
  192. package/dist/utils/point_in_time.js +49 -53
  193. package/dist/utils/psql.js +89 -106
  194. package/dist/utils/service_picker.js +55 -58
  195. package/dist/utils/string.js +5 -5
  196. package/dist/utils/ui.js +38 -55
  197. package/dist/utils/write_sync.js +26 -35
  198. package/dist/utils/zip.js +4 -3
  199. package/dist/writer.js +67 -87
  200. package/package.json +11 -6
  201. package/dist/_shared/auth_selection.js +0 -86
  202. package/dist/_shared/credentials.js +0 -209
  203. package/dist/_shared/env-core/env.js +0 -558
  204. package/dist/_shared/env-core/reuse-secrets.js +0 -223
  205. package/dist/_shared/paths.js +0 -148
  206. package/dist/_shared/profiles.js +0 -276
  207. package/dist/_shared/secure_file.js +0 -43
@@ -1,228 +1,218 @@
1
+ import { DO_NOT_SUBSTITUTE_HINT, MISSING_BINARY_HINT, formatExecCommand, formatInstallCommand, resolvePackageManager } from "../../utils/package_manager.js";
1
2
  import { neonctlCmd } from "../neonctl.js";
2
- import { ensureSkillsUpToDate, SKILL_REFERENCE_URLS } from "../skills.js";
3
+ import { SKILL_REFERENCE_URLS, ensureSkillsUpToDate } from "../skills.js";
4
+ //#region src/init/phases/getting_started.ts
3
5
  /**
4
- * Initiates the "Get started with Neon" workflow.
5
- *
6
- * Steps are concrete and executable — each has a CLI command to run
7
- * or a specific file operation. The agent should attempt each step
8
- * in order and actually perform the action using the Neon CLI.
9
- */
10
- export async function handleGettingStartedPhase(options) {
11
- // Ensure skills are up to date (no-op if recently updated)
12
- if (options.agent) {
13
- await ensureSkillsUpToDate(options.agent);
14
- }
15
- const steps = [];
16
- if (!options.hasConnectionString) {
17
- if (options.preview) {
18
- // Public beta: platform features are only in AWS us-east-2 for now
19
- steps.push({
20
- id: "select_org",
21
- description: [
22
- "List the user's Neon organizations using the CLI command below.",
23
- "If only one org exists, use it automatically.",
24
- "If multiple orgs exist, ask the user which one to use.",
25
- "Remember the selected org ID for the next steps.",
26
- ].join(" "),
27
- command: `${neonctlCmd()} orgs list --output json`,
28
- }, {
29
- id: "select_or_create_project",
30
- description: [
31
- "List existing Neon projects in the selected organization using the CLI command below (replace <org-id> with the selected org ID).",
32
- "IMPORTANT: Neon features (Functions, Object Storage, and AI Gateway) are currently in beta and only available in the AWS us-east-2 region (more regions coming shortly). Projects must have region_id 'aws-us-east-2' and be created on or after 2026-06-15.",
33
- "Filter the project list to ONLY show projects where region_id is 'aws-us-east-2' AND created_at is on or after '2026-06-15'.",
34
- "If eligible projects exist, present them alongside a 'Create new project' option.",
35
- "If no eligible projects exist, tell the user and proceed directly to creating a new one.",
36
- "IMPORTANT: Always include --org-id when creating a project to avoid interactive prompts.",
37
- ].join(" "),
38
- command: `${neonctlCmd()} projects list --org-id <org-id> --output json`,
39
- }, {
40
- id: "create_project_if_needed",
41
- description: [
42
- "If the user chose to create a new project, create it in the AWS us-east-2 region using the CLI command below (replace <org-id> and <project-name>).",
43
- "Ask the user for a project name (suggest the current directory name).",
44
- "If the user chose an existing eligible project, skip this step.",
45
- ].join(" "),
46
- command: `${neonctlCmd()} projects create --name <project-name> --org-id <org-id> --region-id aws-us-east-2 --output json`,
47
- });
48
- }
49
- else {
50
- // Standard mode: let user choose existing or create new
51
- steps.push({
52
- id: "select_org",
53
- description: [
54
- "List the user's Neon organizations using the CLI command below.",
55
- "If only one org exists, use it automatically.",
56
- "If multiple orgs exist, ask the user which one to use.",
57
- "Remember the selected org ID for the next steps.",
58
- ].join(" "),
59
- command: `${neonctlCmd()} orgs list --output json`,
60
- }, {
61
- id: "select_or_create_project",
62
- description: [
63
- "List existing Neon projects in the selected organization using the CLI command below (replace <org-id> with the selected org ID).",
64
- "Ask the user whether they want to use an existing project or create a new one.",
65
- "If creating new, ask the user for a project name (suggest the current directory name).",
66
- "IMPORTANT: Always include --org-id when creating a project to avoid interactive prompts.",
67
- ].join(" "),
68
- command: `${neonctlCmd()} projects list --org-id <org-id> --output json`,
69
- }, {
70
- id: "create_project_if_needed",
71
- description: [
72
- "If the user chose to create a new project, create it using the CLI command below (replace <org-id> and <project-name>).",
73
- "If the user chose an existing project, skip this step.",
74
- ].join(" "),
75
- command: `${neonctlCmd()} projects create --name <project-name> --org-id <org-id> --output json`,
76
- });
77
- }
78
- // Create/update .neon context file
79
- steps.push({
80
- id: "create_neon_context",
81
- description: [
82
- "Update the .neon context file in the project root with the selected org and project IDs.",
83
- "IMPORTANT: If a .neon file already exists, you MUST read it first, then merge the new orgId and projectId into the existing content. Do NOT overwrite the file — other fields (like _init, branch, etc.) must be preserved.",
84
- "If no .neon file exists, create one.",
85
- 'The file is JSON. Add/update only the orgId and projectId fields: {"orgId": "<org-id>", "projectId": "<project-id>", ...existing fields}.',
86
- "This file is safe to commit — it contains no secrets.",
87
- ].join(" "),
88
- });
89
- // Install project dependencies (required before env pull — config files may import packages)
90
- steps.push({
91
- id: "install_dependencies",
92
- description: [
93
- "Check if node_modules exists in the project root.",
94
- "If not, install project dependencies using the appropriate package manager (check for pnpm-lock.yaml, yarn.lock, bun.lockb, or default to npm).",
95
- "This must be done before `neon env pull` because the project's Neon config file may import packages that need to be installed first.",
96
- ].join(" "),
97
- command: "npm install",
98
- });
99
- // Pull environment variables (connection string, etc.) from Neon
100
- steps.push({
101
- id: "pull_env",
102
- description: [
103
- "Now that the .neon context file is in place and dependencies are installed, run `neon env pull` to populate the project's environment variables.",
104
- "This automatically writes the database connection string (and any other Neon-managed env vars) to the correct env file.",
105
- "It reads the .neon context file to determine the project, and writes to the appropriate env file for the project.",
106
- "Ensure the target env file is listed in .gitignore.",
107
- ].join(" "),
108
- command: `${neonctlCmd()} env pull`,
109
- });
110
- // Step 6: Install Neon serverless driver if needed
111
- if (options.orm === "prisma") {
112
- steps.push({
113
- id: "install_driver",
114
- description: [
115
- "Install the @neondatabase/serverless driver adapter for Prisma.",
116
- "This enables Prisma to use Neon's serverless driver for edge/serverless deployments.",
117
- ].join(" "),
118
- command: "npm install @neondatabase/serverless @prisma/adapter-neon",
119
- });
120
- }
121
- else if (options.orm === "drizzle" || options.orm === "drizzle-orm") {
122
- steps.push({
123
- id: "install_driver",
124
- description: "Install the Neon serverless driver for Drizzle.",
125
- command: "npm install @neondatabase/serverless",
126
- });
127
- }
128
- else if (!options.orm || options.orm === "none") {
129
- steps.push({
130
- id: "install_driver",
131
- description: "Install the Neon serverless driver for direct database access.",
132
- command: "npm install @neondatabase/serverless",
133
- });
134
- }
135
- }
136
- // Run migrations if applicable
137
- if (options.migrationTool && options.migrationTool !== "none") {
138
- const tool = options.migrationTool.toLowerCase();
139
- const migrationDir = options.migrationDir;
140
- const hasMigrationDir = migrationDir && migrationDir !== "none";
141
- if (tool === "drizzle") {
142
- steps.push({
143
- id: "run_migrations",
144
- description: [
145
- hasMigrationDir
146
- ? `Check if the ${migrationDir} directory contains .sql migration files.`
147
- : "Check if a drizzle migrations directory exists with .sql files.",
148
- "If .sql files exist, apply them with `npx drizzle-kit migrate`.",
149
- "If the directory is empty or missing but a drizzle schema file exists (e.g. src/db/schema.ts, drizzle/schema.ts), run `npx drizzle-kit generate` first to create migrations, then `npx drizzle-kit migrate` to apply them.",
150
- "If neither schema nor migrations exist, skip this step.",
151
- ].join(" "),
152
- command: "npx drizzle-kit migrate",
153
- });
154
- }
155
- else if (tool === "prisma") {
156
- steps.push({
157
- id: "run_migrations",
158
- description: [
159
- hasMigrationDir
160
- ? `Check if the ${migrationDir} directory contains migration folders.`
161
- : "Check if prisma/migrations contains migration folders.",
162
- "If migrations exist, apply them with `npx prisma migrate deploy`.",
163
- "If the migrations directory is empty or missing but prisma/schema.prisma has models defined, run `npx prisma migrate dev --name init` to create and apply the initial migration.",
164
- "If no models are defined, skip this step.",
165
- ].join(" "),
166
- command: "npx prisma migrate deploy",
167
- });
168
- }
169
- else if (tool === "knex") {
170
- steps.push({
171
- id: "run_migrations",
172
- description: `Apply existing knex migrations to the Neon database.`,
173
- command: "npx knex migrate:latest",
174
- });
175
- }
176
- }
177
- else if (options.preview) {
178
- // Bootstrap flow: migration tool wasn't detected because the project was
179
- // inspected before scaffolding. Detect and run migrations from the scaffolded template.
180
- steps.push({
181
- id: "run_migrations",
182
- description: [
183
- "Check the scaffolded project for a migration tool and schema.",
184
- "Look for: drizzle.config.ts/js (Drizzle), prisma/schema.prisma (Prisma), or knexfile.ts/js (Knex).",
185
- "If Drizzle is found: check if a drizzle migrations directory exists with .sql files. If .sql files exist, run `npx drizzle-kit migrate`. If the directory is empty or missing but a schema file exists, run `npx drizzle-kit generate` first, then `npx drizzle-kit migrate`.",
186
- "If Prisma is found: check if prisma/migrations contains migration folders. If yes, run `npx prisma migrate deploy`. If not but models exist, run `npx prisma migrate dev --name init`.",
187
- "If no migration tool is found, skip this step.",
188
- ].join(" "),
189
- });
190
- }
191
- // Verify the connection
192
- steps.push({
193
- id: "verify_connection",
194
- description: [
195
- "Verify the database connection works by running a SQL query against the Neon database.",
196
- "Write and run a short script that connects using DATABASE_URL from the project's env file and executes `SELECT 1` (or queries a table from the migration if migrations were run).",
197
- "Do NOT use the Neon CLI or MCP tools for this — use a direct database connection to verify end-to-end connectivity.",
198
- ].join(" "),
199
- });
200
- return {
201
- phase: "setup",
202
- status: "getting_started",
203
- nextAction: {
204
- type: "agent_action",
205
- prerequisite: SKILL_REFERENCE_URLS.gettingStarted,
206
- steps,
207
- onComplete: buildOnComplete(options),
208
- },
209
- };
6
+ * Initiates the "Get started with Neon" workflow.
7
+ *
8
+ * Steps are concrete and executable — each has a CLI command to run
9
+ * or a specific file operation. The agent should attempt each step
10
+ * in order and actually perform the action using the Neon CLI.
11
+ */
12
+ async function handleGettingStartedPhase(options) {
13
+ if (options.agent) await ensureSkillsUpToDate(options.agent);
14
+ const steps = [];
15
+ const installPm = resolvePackageManager(options.cwd);
16
+ if (!options.hasConnectionString) {
17
+ if (options.preview) steps.push({
18
+ id: "select_org",
19
+ description: [
20
+ "List the user's Neon organizations using the CLI command below.",
21
+ "If only one org exists, use it automatically.",
22
+ "If multiple orgs exist, ask the user which one to use.",
23
+ "Remember the selected org ID for the next steps."
24
+ ].join(" "),
25
+ command: `${neonctlCmd()} orgs list --output json`
26
+ }, {
27
+ id: "select_or_create_project",
28
+ description: [
29
+ "List existing Neon projects in the selected organization using the CLI command below (replace <org-id> with the selected org ID).",
30
+ "IMPORTANT: Neon features (Functions, Object Storage, and AI Gateway) are currently in beta and only available in the AWS us-east-2 region (more regions coming shortly). Projects must have region_id 'aws-us-east-2' and be created on or after 2026-06-15.",
31
+ "Filter the project list to ONLY show projects where region_id is 'aws-us-east-2' AND created_at is on or after '2026-06-15'.",
32
+ "If eligible projects exist, present them alongside a 'Create new project' option.",
33
+ "If no eligible projects exist, tell the user and proceed directly to creating a new one.",
34
+ "IMPORTANT: Always include --org-id when creating a project to avoid interactive prompts."
35
+ ].join(" "),
36
+ command: `${neonctlCmd()} projects list --org-id <org-id> --output json`
37
+ }, {
38
+ id: "create_project_if_needed",
39
+ description: [
40
+ "If the user chose to create a new project, create it in the AWS us-east-2 region using the CLI command below (replace <org-id> and <project-name>).",
41
+ "Ask the user for a project name (suggest the current directory name).",
42
+ "If the user chose an existing eligible project, skip this step."
43
+ ].join(" "),
44
+ command: `${neonctlCmd()} projects create --name <project-name> --org-id <org-id> --region-id aws-us-east-2 --output json`
45
+ });
46
+ else steps.push({
47
+ id: "select_org",
48
+ description: [
49
+ "List the user's Neon organizations using the CLI command below.",
50
+ "If only one org exists, use it automatically.",
51
+ "If multiple orgs exist, ask the user which one to use.",
52
+ "Remember the selected org ID for the next steps."
53
+ ].join(" "),
54
+ command: `${neonctlCmd()} orgs list --output json`
55
+ }, {
56
+ id: "select_or_create_project",
57
+ description: [
58
+ "List existing Neon projects in the selected organization using the CLI command below (replace <org-id> with the selected org ID).",
59
+ "Ask the user whether they want to use an existing project or create a new one.",
60
+ "If creating new, ask the user for a project name (suggest the current directory name).",
61
+ "IMPORTANT: Always include --org-id when creating a project to avoid interactive prompts."
62
+ ].join(" "),
63
+ command: `${neonctlCmd()} projects list --org-id <org-id> --output json`
64
+ }, {
65
+ id: "create_project_if_needed",
66
+ description: ["If the user chose to create a new project, create it using the CLI command below (replace <org-id> and <project-name>).", "If the user chose an existing project, skip this step."].join(" "),
67
+ command: `${neonctlCmd()} projects create --name <project-name> --org-id <org-id> --output json`
68
+ });
69
+ steps.push({
70
+ id: "create_neon_context",
71
+ description: [
72
+ "Update the .neon context file in the project root with the selected org and project IDs.",
73
+ "IMPORTANT: If a .neon file already exists, you MUST read it first, then merge the new orgId and projectId into the existing content. Do NOT overwrite the file — other fields (like _init, branch, etc.) must be preserved.",
74
+ "If no .neon file exists, create one.",
75
+ "The file is JSON. Add/update only the orgId and projectId fields: {\"orgId\": \"<org-id>\", \"projectId\": \"<project-id>\", ...existing fields}.",
76
+ "This file is safe to commit — it contains no secrets."
77
+ ].join(" ")
78
+ });
79
+ steps.push({
80
+ id: "install_dependencies",
81
+ description: [
82
+ "Check if node_modules exists in the project root. If not, install the project's dependencies.",
83
+ DO_NOT_SUBSTITUTE_HINT,
84
+ "This must be done before `neon env pull` because the project's Neon config file may import packages that need to be installed first."
85
+ ].join(" "),
86
+ command: formatInstallCommand(installPm)
87
+ });
88
+ steps.push({
89
+ id: "pull_env",
90
+ description: [
91
+ "Now that the .neon context file is in place and dependencies are installed, run `neon env pull` to populate the project's environment variables.",
92
+ "This automatically writes the database connection string (and any other Neon-managed env vars) to the correct env file.",
93
+ "It reads the .neon context file to determine the project, and writes to the appropriate env file for the project.",
94
+ "Ensure the target env file is listed in .gitignore."
95
+ ].join(" "),
96
+ command: `${neonctlCmd()} env pull`
97
+ });
98
+ if (options.orm === "prisma") steps.push({
99
+ id: "install_driver",
100
+ description: [
101
+ "Install the @neondatabase/serverless driver adapter for Prisma.",
102
+ "This enables Prisma to use Neon's serverless driver for edge/serverless deployments.",
103
+ DO_NOT_SUBSTITUTE_HINT
104
+ ].join(" "),
105
+ command: formatInstallCommand(installPm, ["@neondatabase/serverless", "@prisma/adapter-neon"])
106
+ });
107
+ else if (options.orm === "drizzle" || options.orm === "drizzle-orm") steps.push({
108
+ id: "install_driver",
109
+ description: `Install the Neon serverless driver for Drizzle. ${DO_NOT_SUBSTITUTE_HINT}`,
110
+ command: formatInstallCommand(installPm, ["@neondatabase/serverless"])
111
+ });
112
+ else if (!options.orm || options.orm === "none") steps.push({
113
+ id: "install_driver",
114
+ description: `Install the Neon serverless driver for direct database access. ${DO_NOT_SUBSTITUTE_HINT}`,
115
+ command: formatInstallCommand(installPm, ["@neondatabase/serverless"])
116
+ });
117
+ }
118
+ if (options.migrationTool && options.migrationTool !== "none") {
119
+ const tool = options.migrationTool.toLowerCase();
120
+ const migrationDir = options.migrationDir;
121
+ const hasMigrationDir = migrationDir && migrationDir !== "none";
122
+ if (tool === "drizzle") {
123
+ const migrate = formatExecCommand(installPm, "drizzle-kit", ["migrate"]);
124
+ const generate = formatExecCommand(installPm, "drizzle-kit", ["generate"]);
125
+ steps.push({
126
+ id: "run_migrations",
127
+ description: [
128
+ hasMigrationDir ? `Check if the ${migrationDir} directory contains .sql migration files.` : "Check if a drizzle migrations directory exists with .sql files.",
129
+ `If .sql files exist, apply them with \`${migrate}\`.`,
130
+ `If the directory is empty or missing but a drizzle schema file exists (e.g. src/db/schema.ts, drizzle/schema.ts), run \`${generate}\` first to create migrations, then \`${migrate}\` to apply them.`,
131
+ "If neither schema nor migrations exist, skip this step.",
132
+ MISSING_BINARY_HINT
133
+ ].join(" "),
134
+ command: migrate
135
+ });
136
+ } else if (tool === "prisma") {
137
+ const deploy = formatExecCommand(installPm, "prisma", ["migrate", "deploy"]);
138
+ steps.push({
139
+ id: "run_migrations",
140
+ description: [
141
+ hasMigrationDir ? `Check if the ${migrationDir} directory contains migration folders.` : "Check if prisma/migrations contains migration folders.",
142
+ `If migrations exist, apply them with \`${deploy}\`.`,
143
+ `If the migrations directory is empty or missing but prisma/schema.prisma has models defined, run \`${formatExecCommand(installPm, "prisma", [
144
+ "migrate",
145
+ "dev",
146
+ "--name",
147
+ "init"
148
+ ])}\` to create and apply the initial migration.`,
149
+ "If no models are defined, skip this step.",
150
+ MISSING_BINARY_HINT
151
+ ].join(" "),
152
+ command: deploy
153
+ });
154
+ } else if (tool === "knex") steps.push({
155
+ id: "run_migrations",
156
+ description: `Apply existing knex migrations to the Neon database. ${MISSING_BINARY_HINT}`,
157
+ command: formatExecCommand(installPm, "knex", ["migrate:latest"])
158
+ });
159
+ } else if (options.preview) steps.push({
160
+ id: "run_migrations",
161
+ description: [
162
+ "Check the scaffolded project for a migration tool and schema.",
163
+ "Look for: drizzle.config.ts/js (Drizzle), prisma/schema.prisma (Prisma), or knexfile.ts/js (Knex).",
164
+ `If Drizzle is found: check if a drizzle migrations directory exists with .sql files. If .sql files exist, run \`${formatExecCommand(installPm, "drizzle-kit", ["migrate"])}\`. If the directory is empty or missing but a schema file exists, run \`${formatExecCommand(installPm, "drizzle-kit", ["generate"])}\` first, then \`${formatExecCommand(installPm, "drizzle-kit", ["migrate"])}\`.`,
165
+ `If Prisma is found: check if prisma/migrations contains migration folders. If yes, run \`${formatExecCommand(installPm, "prisma", ["migrate", "deploy"])}\`. If not but models exist, run \`${formatExecCommand(installPm, "prisma", [
166
+ "migrate",
167
+ "dev",
168
+ "--name",
169
+ "init"
170
+ ])}\`.`,
171
+ "If no migration tool is found, skip this step.",
172
+ MISSING_BINARY_HINT
173
+ ].join(" ")
174
+ });
175
+ steps.push({
176
+ id: "verify_connection",
177
+ description: [
178
+ "Verify the database connection works by running a SQL query against the Neon database.",
179
+ "Write and run a short script that connects using DATABASE_URL from the project's env file and executes `SELECT 1` (or queries a table from the migration if migrations were run).",
180
+ "Do NOT use the Neon CLI or MCP tools for this — use a direct database connection to verify end-to-end connectivity."
181
+ ].join(" ")
182
+ });
183
+ return {
184
+ phase: "setup",
185
+ status: "getting_started",
186
+ nextAction: {
187
+ type: "agent_action",
188
+ prerequisite: SKILL_REFERENCE_URLS.gettingStarted,
189
+ steps,
190
+ onComplete: buildOnComplete(options)
191
+ }
192
+ };
210
193
  }
211
194
  function buildOnComplete(options) {
212
- const agentArgs = options.agent ? ["--agent", options.agent] : [];
213
- const features = options.features ?? [];
214
- const hasFeatureRequirements = features.length > 0;
215
- // If features are specified and auth is not required, go to finalize
216
- if (hasFeatureRequirements && !features.includes("auth")) {
217
- return {
218
- type: "run_neon_init",
219
- args: ["finalize", "--json", ...agentArgs],
220
- };
221
- }
222
- // Chain to neon-auth — if user already selected auth via features, go straight to setup
223
- const authSetup = hasFeatureRequirements && features.includes("auth") ? ["--setup"] : [];
224
- return {
225
- type: "run_neon_init",
226
- args: ["neon-auth", "--json", ...agentArgs, ...authSetup],
227
- };
195
+ const agentArgs = options.agent ? ["--agent", options.agent] : [];
196
+ const features = options.features ?? [];
197
+ const hasFeatureRequirements = features.length > 0;
198
+ if (hasFeatureRequirements && !features.includes("auth")) return {
199
+ type: "run_neon_init",
200
+ args: [
201
+ "finalize",
202
+ "--json",
203
+ ...agentArgs
204
+ ]
205
+ };
206
+ const authSetup = hasFeatureRequirements && features.includes("auth") ? ["--setup"] : [];
207
+ return {
208
+ type: "run_neon_init",
209
+ args: [
210
+ "neon-auth",
211
+ "--json",
212
+ ...agentArgs,
213
+ ...authSetup
214
+ ]
215
+ };
228
216
  }
217
+ //#endregion
218
+ export { handleGettingStartedPhase };