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,184 @@
1
+ import { lstatSync } from "node:fs";
2
+ import { execa } from "execa";
3
+ /**
4
+ * Returns the Neon CLI command prefix: "CI= npx -y neon".
5
+ *
6
+ * The CLI reads NEON_API_HOST and NEON_OAUTH_HOST from the environment
7
+ * directly, so no extra flags are needed. The `neon` package ships both the
8
+ * `neon` and `neonctl` binaries; we surface the cleaner `neon` command in the
9
+ * examples emitted to users and agents.
10
+ *
11
+ * Usage: `${neonctlCmd()} orgs list --output json`
12
+ */
13
+ export function neonctlCmd() {
14
+ return "CI= npx -y neon";
15
+ }
16
+ /**
17
+ * Detects which package manager was used to invoke the current process.
18
+ * Reads the `npm_config_user_agent` env var set by npm/pnpm/yarn/bun when
19
+ * they spawn child processes (including via `npx`, `pnpx`, `bunx`, etc.).
20
+ *
21
+ * Falls back to "npm" if detection fails.
22
+ */
23
+ export function detectPackageManager() {
24
+ const ua = process.env.npm_config_user_agent;
25
+ if (ua) {
26
+ if (ua.startsWith("pnpm/"))
27
+ return "pnpm";
28
+ if (ua.startsWith("yarn/"))
29
+ return "yarn";
30
+ if (ua.startsWith("bun/"))
31
+ return "bun";
32
+ }
33
+ return "npm";
34
+ }
35
+ /**
36
+ * Returns the global install command for a given package manager.
37
+ */
38
+ function globalInstallArgs(pm, pkg) {
39
+ switch (pm) {
40
+ case "pnpm":
41
+ return { command: "pnpm", args: ["add", "-g", pkg] };
42
+ case "yarn":
43
+ return { command: "yarn", args: ["global", "add", pkg] };
44
+ case "bun":
45
+ return { command: "bun", args: ["add", "-g", pkg] };
46
+ default:
47
+ return { command: "npm", args: ["install", "-g", pkg] };
48
+ }
49
+ }
50
+ /**
51
+ * Gets the currently available neonctl version.
52
+ * Tries the global binary first, then falls back to npx.
53
+ */
54
+ async function getNeonctlVersion() {
55
+ // Try global binary first (fast path)
56
+ try {
57
+ const result = await execa("neonctl", ["--version"], {
58
+ stdio: "pipe",
59
+ timeout: 5000,
60
+ });
61
+ const match = result.stdout.trim().match(/(\d+\.\d+\.\d+)/);
62
+ if (match)
63
+ return match[1];
64
+ }
65
+ catch {
66
+ // Not globally installed — that's fine
67
+ }
68
+ return null;
69
+ }
70
+ /**
71
+ * Checks whether the neonctl CLI is globally installed and whether it's up to date.
72
+ */
73
+ export async function checkNeonctl() {
74
+ const currentVersion = await getNeonctlVersion();
75
+ if (!currentVersion) {
76
+ return {
77
+ installed: false,
78
+ currentVersion: null,
79
+ latestVersion: null,
80
+ needsUpdate: true,
81
+ };
82
+ }
83
+ // Check latest version from npm registry
84
+ let latestVersion = null;
85
+ try {
86
+ const result = await execa("npm", ["view", "neonctl", "version"], {
87
+ stdio: "pipe",
88
+ timeout: 10000,
89
+ });
90
+ latestVersion = result.stdout.trim();
91
+ }
92
+ catch {
93
+ // Can't determine latest — assume current is fine
94
+ return {
95
+ installed: true,
96
+ currentVersion,
97
+ latestVersion: null,
98
+ needsUpdate: false,
99
+ };
100
+ }
101
+ const needsUpdate = currentVersion !== null &&
102
+ latestVersion !== null &&
103
+ currentVersion !== latestVersion &&
104
+ isOlderVersion(currentVersion, latestVersion);
105
+ return { installed: true, currentVersion, latestVersion, needsUpdate };
106
+ }
107
+ function isOlderVersion(current, latest) {
108
+ const c = current.split(".").map(Number);
109
+ const l = latest.split(".").map(Number);
110
+ for (let i = 0; i < 3; i++) {
111
+ if ((c[i] ?? 0) < (l[i] ?? 0))
112
+ return true;
113
+ if ((c[i] ?? 0) > (l[i] ?? 0))
114
+ return false;
115
+ }
116
+ return false;
117
+ }
118
+ /**
119
+ * Checks if neonctl is installed via a local dev symlink.
120
+ * If so, skip install/update — the developer manages it manually.
121
+ */
122
+ function isLocalDevSymlink() {
123
+ try {
124
+ const home = process.env.HOME || process.env.USERPROFILE || "";
125
+ const nvmDir = process.env.NVM_DIR || `${home}/.nvm`;
126
+ // Check common global module locations for a symlink
127
+ const candidates = [
128
+ `${nvmDir}/versions/node/${process.version}/lib/node_modules/neonctl`,
129
+ `${home}/.nvm/versions/node/${process.version}/lib/node_modules/neonctl`,
130
+ ];
131
+ for (const candidate of candidates) {
132
+ try {
133
+ const stat = lstatSync(candidate);
134
+ if (stat.isSymbolicLink())
135
+ return true;
136
+ }
137
+ catch {
138
+ // path doesn't exist
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+ catch {
144
+ return false;
145
+ }
146
+ }
147
+ /**
148
+ * Ensures neonctl is globally installed and up to date.
149
+ * Uses the same package manager that invoked the init command.
150
+ */
151
+ export async function ensureNeonctl() {
152
+ // Skip install for local dev symlinks to avoid permission errors
153
+ if (isLocalDevSymlink()) {
154
+ const version = await getNeonctlVersion();
155
+ return {
156
+ status: "already_current",
157
+ version: version ?? "dev",
158
+ };
159
+ }
160
+ const check = await checkNeonctl();
161
+ if (check.installed && !check.needsUpdate) {
162
+ return {
163
+ status: "already_current",
164
+ version: check.currentVersion ?? undefined,
165
+ };
166
+ }
167
+ const pm = detectPackageManager();
168
+ const { command, args } = globalInstallArgs(pm, "neonctl");
169
+ try {
170
+ await execa(command, args, { stdio: "pipe", timeout: 60000 });
171
+ // Verify installation
172
+ const version = await getNeonctlVersion();
173
+ return {
174
+ status: check.installed ? "updated" : "installed",
175
+ version: version ?? undefined,
176
+ };
177
+ }
178
+ catch (err) {
179
+ return {
180
+ status: "failed",
181
+ error: err instanceof Error ? err.message : "Unknown error",
182
+ };
183
+ }
184
+ }
@@ -0,0 +1,190 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { isAuthenticated } from "./auth.js";
4
+ import { inspectProject } from "./inspect.js";
5
+ import { handleAuthPhase } from "./phases/auth.js";
6
+ import { handleGettingStartedPhase } from "./phases/getting_started.js";
7
+ import { handleMigrationsPhase } from "./phases/migrations.js";
8
+ import { handleNeonAuthPhase } from "./phases/neon_auth.js";
9
+ import { handleSetupPhase } from "./phases/setup.js";
10
+ import { resolveNeonContext } from "./resolve_context.js";
11
+ /**
12
+ * v2 orchestrator: checks phases in order and returns the first that needs attention.
13
+ *
14
+ * Phase order:
15
+ * auth -> setup (if tooling not installed)
16
+ * -> getting-started (if tooling installed but no Neon connection string)
17
+ * -> resolve .neon context (if connection string exists but no .neon file)
18
+ * -> neon_auth (optional) -> complete
19
+ *
20
+ * Each call is stateless — it re-checks everything from the file system and credentials.
21
+ *
22
+ * The orchestrator uses filesystem inspection to decide what to do:
23
+ * - No app detected → bootstrap phase (scaffold from template)
24
+ * - MCP not configured → full setup flow (inspect → install → getting-started)
25
+ * - MCP configured, no connection string → skip install, go to getting-started
26
+ * - MCP configured + connection string → fall through to neon-auth/migrations/complete
27
+ */
28
+ export async function orchestrate(options) {
29
+ // Phase 1: Auth
30
+ const authed = await isAuthenticated();
31
+ if (!authed) {
32
+ return handleAuthPhase({ agent: options.agent });
33
+ }
34
+ const cwd = process.cwd();
35
+ // Phase 2: Inspect what's already in place
36
+ const inspection = await inspectProject([
37
+ { id: "has_app", description: "", lookFor: [] },
38
+ { id: "mcp_server", description: "", lookFor: [] },
39
+ { id: "skills", description: "", lookFor: [] },
40
+ { id: "connection_string", description: "", lookFor: [] },
41
+ { id: "project_stack", description: "", lookFor: [] },
42
+ { id: "migrations", description: "", lookFor: [] },
43
+ ]);
44
+ // Only detect empty projects when --preview is enabled
45
+ const hasApp = options.preview ? inspection.hasApp === true : true;
46
+ // When preview is enabled, check that all preview skills are installed too
47
+ let skillsInstalled = inspection.skillsInstalled;
48
+ if (options.preview && skillsInstalled && inspection.skillsScope) {
49
+ const { getSkillList } = await import("./skills.js");
50
+ const previewSkills = getSkillList(true);
51
+ const { existsSync: exists } = await import("node:fs");
52
+ const { resolve: resolvePath } = await import("node:path");
53
+ const home = process.env.HOME || process.env.USERPROFILE || "";
54
+ const scope = inspection.skillsScope;
55
+ const dirs = scope === "project"
56
+ ? [
57
+ resolvePath(cwd, ".cursor", "skills"),
58
+ resolvePath(cwd, ".claude", "skills"),
59
+ resolvePath(cwd, ".agents", "skills"),
60
+ ]
61
+ : [
62
+ resolvePath(home, ".cursor", "skills"),
63
+ resolvePath(home, ".claude", "skills"),
64
+ resolvePath(home, ".agents", "skills"),
65
+ ];
66
+ const allPresent = previewSkills.every((skill) => dirs.some((dir) => exists(resolvePath(dir, skill, "SKILL.md"))));
67
+ if (!allPresent) {
68
+ skillsInstalled = false;
69
+ // Mark as partial so setup auto-completes to the same scope
70
+ inspection.skillsScope =
71
+ `${inspection.skillsScope}-partial`;
72
+ }
73
+ }
74
+ const toolingInstalled = inspection.mcpConfigured && skillsInstalled;
75
+ const hasNeonConnection = inspection.connectionString === true;
76
+ // Phase 3a: No app or tooling not installed → setup flow
77
+ // When !hasApp (preview mode), setup will offer template selection before asking about tooling.
78
+ // Clean up any stale _init state from a previous run.
79
+ if (!hasApp || !toolingInstalled) {
80
+ cleanupInitState(resolve(cwd, ".neon"));
81
+ return handleSetupPhase({
82
+ agent: options.agent,
83
+ preview: options.preview,
84
+ hasApp,
85
+ mcpConfigured: inspection.mcpConfigured ?? null,
86
+ mcpScope: inspection.mcpScope || undefined,
87
+ skillsInstalled: skillsInstalled ?? null,
88
+ skillsScope: inspection.skillsScope || undefined,
89
+ });
90
+ }
91
+ // Read .neon context early — needed for feature-based routing
92
+ const neonContextPath = resolve(cwd, ".neon");
93
+ const neonContext = readNeonContext(neonContextPath);
94
+ const initState = typeof neonContext._init === "object" && neonContext._init !== null
95
+ ? neonContext._init
96
+ : {};
97
+ const features = Array.isArray(initState.features)
98
+ ? initState.features
99
+ : [];
100
+ // Phase 3b: Tooling installed but no Neon connection string → getting-started
101
+ if (!hasNeonConnection) {
102
+ return handleGettingStartedPhase({
103
+ agent: options.agent,
104
+ hasConnectionString: false,
105
+ framework: inspection.framework,
106
+ orm: inspection.orm,
107
+ migrationTool: inspection.migrationTool,
108
+ migrationDir: inspection.migrationDir,
109
+ features,
110
+ preview: options.preview,
111
+ });
112
+ }
113
+ // Phase 3c: Neon connection exists but no .neon context file → resolve project
114
+ if (!neonContext.projectId) {
115
+ // Resolve the project from the connection string and merge into .neon
116
+ try {
117
+ const resolved = await resolveNeonContext(cwd);
118
+ if (resolved) {
119
+ const merged = { ...neonContext };
120
+ if (resolved.orgId)
121
+ merged.orgId = resolved.orgId;
122
+ if (resolved.projectId)
123
+ merged.projectId = resolved.projectId;
124
+ writeFileSync(neonContextPath, `${JSON.stringify(merged, null, 2)}\n`);
125
+ }
126
+ }
127
+ catch {
128
+ // Continue the flow regardless — missing .neon is not a blocker
129
+ }
130
+ }
131
+ // Phase 4: Neon Auth — only if features include "auth"
132
+ if (features.includes("auth")) {
133
+ const hasNeonAuth = checkNeonAuth(cwd);
134
+ if (!hasNeonAuth) {
135
+ return handleNeonAuthPhase({
136
+ agent: options.agent,
137
+ setup: true,
138
+ });
139
+ }
140
+ }
141
+ // Phase 5: Migrations
142
+ if (!options.skipMigrations) {
143
+ return handleMigrationsPhase({ agent: options.agent });
144
+ }
145
+ // All done — clean up ephemeral _init state from .neon
146
+ cleanupInitState(neonContextPath);
147
+ return {
148
+ phase: "setup",
149
+ status: "complete",
150
+ nextAction: {
151
+ type: "complete",
152
+ message: "Neon setup is complete. Your database is configured and your agent has the Neon MCP server and skills available.",
153
+ },
154
+ };
155
+ }
156
+ /** Remove the ephemeral _init key from .neon, preserving other fields. */
157
+ function cleanupInitState(neonContextPath) {
158
+ if (!existsSync(neonContextPath))
159
+ return;
160
+ try {
161
+ const context = JSON.parse(readFileSync(neonContextPath, "utf-8"));
162
+ if (context._init !== undefined) {
163
+ delete context._init;
164
+ writeFileSync(neonContextPath, `${JSON.stringify(context, null, 2)}\n`);
165
+ }
166
+ }
167
+ catch { }
168
+ }
169
+ function readNeonContext(neonContextPath) {
170
+ if (!existsSync(neonContextPath))
171
+ return {};
172
+ try {
173
+ return JSON.parse(readFileSync(neonContextPath, "utf-8"));
174
+ }
175
+ catch {
176
+ return {};
177
+ }
178
+ }
179
+ function checkNeonAuth(cwd) {
180
+ const envPath = resolve(cwd, ".env");
181
+ if (!existsSync(envPath))
182
+ return false;
183
+ try {
184
+ const content = readFileSync(envPath, "utf-8");
185
+ return /^NEON_AUTH_/m.test(content);
186
+ }
187
+ catch {
188
+ return false;
189
+ }
190
+ }
@@ -0,0 +1,209 @@
1
+ import { isAuthenticated } from "../auth.js";
2
+ import { neonctlCmd } from "../neonctl.js";
3
+ function getSignupUrl() {
4
+ return process.env.NEON_API_HOST
5
+ ? `${new URL(process.env.NEON_API_HOST).origin}/signup`
6
+ : "https://console.neon.tech/signup";
7
+ }
8
+ function getSignupCommands() {
9
+ const url = getSignupUrl();
10
+ return {
11
+ darwin: `open ${url}`,
12
+ linux: `xdg-open ${url}`,
13
+ win32: `start ${url}`,
14
+ };
15
+ }
16
+ export async function handleAuthPhase(options) {
17
+ const agentArgs = options.agent
18
+ ? ["--agent", options.agent, "--json"]
19
+ : ["--json"];
20
+ // --verify: just check if credentials exist
21
+ if (options.verify) {
22
+ const authed = await isAuthenticated();
23
+ if (authed) {
24
+ // Continue the flow immediately — don't use "complete" which
25
+ // causes agents to stop and get distracted by neonctl output.
26
+ return {
27
+ phase: "auth",
28
+ status: "verified",
29
+ nextAction: {
30
+ type: "run_neon_init",
31
+ args: agentArgs,
32
+ },
33
+ };
34
+ }
35
+ return {
36
+ phase: "auth",
37
+ status: "not_authenticated",
38
+ nextAction: {
39
+ type: "run_neon_init",
40
+ args: ["auth", "--json"],
41
+ },
42
+ };
43
+ }
44
+ // Check if already authenticated
45
+ const authed = await isAuthenticated();
46
+ if (authed) {
47
+ return {
48
+ phase: "auth",
49
+ status: "verified",
50
+ nextAction: {
51
+ type: "run_neon_init",
52
+ args: agentArgs,
53
+ },
54
+ };
55
+ }
56
+ // --method new: guide through signup
57
+ if (options.method === "new") {
58
+ const openCmd = getSignupCommands()[process.platform] ?? getSignupCommands().linux;
59
+ return {
60
+ phase: "auth",
61
+ status: "in_progress",
62
+ nextAction: {
63
+ type: "agent_action",
64
+ steps: [
65
+ {
66
+ id: "open_signup",
67
+ description: "Open the Neon sign-up page in the user's browser",
68
+ command: openCmd,
69
+ },
70
+ {
71
+ id: "wait_for_signup",
72
+ description: "Tell the user: 'I've opened the Neon sign-up page. Create your account and verify your email, then let me know when you're ready.'",
73
+ },
74
+ ],
75
+ onComplete: {
76
+ type: "run_neon_init",
77
+ args: ["auth", "--json", "--method", "existing"],
78
+ },
79
+ },
80
+ };
81
+ }
82
+ // --method existing: run OAuth flow
83
+ if (options.method === "existing") {
84
+ return {
85
+ phase: "auth",
86
+ status: "in_progress",
87
+ nextAction: {
88
+ type: "run_command",
89
+ command: `${neonctlCmd()} auth`,
90
+ description: "This will open your browser for Neon OAuth sign-in.",
91
+ timeout: 120000,
92
+ onSuccess: {
93
+ type: "run_neon_init",
94
+ args: ["auth", "--json", "--verify"],
95
+ },
96
+ onFailure: {
97
+ "2": {
98
+ type: "ask_user",
99
+ question: "The sign-in timed out. Did you complete the sign-in in your browser?",
100
+ options: ["yes_retry", "need_help"],
101
+ responseMapping: {
102
+ yes_retry: {
103
+ args: [
104
+ "auth",
105
+ "--json",
106
+ "--method",
107
+ "existing",
108
+ ],
109
+ },
110
+ need_help: {
111
+ args: ["auth", "--json", "--method", "new"],
112
+ },
113
+ },
114
+ },
115
+ other: {
116
+ type: "run_neon_init",
117
+ args: ["auth", "--json"],
118
+ },
119
+ },
120
+ },
121
+ };
122
+ }
123
+ // No method specified: ask the user, then launch OAuth directly for
124
+ // "existing account" without an intermediate CLI round-trip.
125
+ const openCmd = getSignupCommands()[process.platform] ?? getSignupCommands().linux;
126
+ return {
127
+ phase: "auth",
128
+ status: "required",
129
+ nextAction: {
130
+ type: "ask_user",
131
+ instructions: "IMPORTANT: You MUST present this question to the user and WAIT for their response before proceeding. Do NOT assume the answer or auto-select an option. The user's answer determines the next step.",
132
+ question: "Do you have an existing Neon account, or do you need to create one?",
133
+ options: [
134
+ {
135
+ value: "existing_account",
136
+ label: "I have an existing Neon account",
137
+ },
138
+ {
139
+ value: "new_account",
140
+ label: "I need to create a new account",
141
+ },
142
+ ],
143
+ context: "Neon is a complete set of cloud backend primitives built around Lakebase Postgres. A free account is required to continue.",
144
+ responseMapping: {
145
+ existing_account: {
146
+ action: {
147
+ type: "run_command",
148
+ command: `${neonctlCmd()} auth`,
149
+ description: "This will open your browser for Neon OAuth sign-in.",
150
+ timeout: 120000,
151
+ onSuccess: {
152
+ type: "run_neon_init",
153
+ args: ["auth", "--json", "--verify"],
154
+ },
155
+ onFailure: {
156
+ "2": {
157
+ type: "ask_user",
158
+ question: "The sign-in timed out. Did you complete the sign-in in your browser?",
159
+ options: ["yes_retry", "need_help"],
160
+ responseMapping: {
161
+ yes_retry: {
162
+ args: [
163
+ "auth",
164
+ "--json",
165
+ "--method",
166
+ "existing",
167
+ ],
168
+ },
169
+ need_help: {
170
+ args: [
171
+ "auth",
172
+ "--json",
173
+ "--method",
174
+ "new",
175
+ ],
176
+ },
177
+ },
178
+ },
179
+ other: {
180
+ type: "run_neon_init",
181
+ args: ["auth", "--json"],
182
+ },
183
+ },
184
+ },
185
+ },
186
+ new_account: {
187
+ action: {
188
+ type: "agent_action",
189
+ steps: [
190
+ {
191
+ id: "open_signup",
192
+ description: "Open the Neon sign-up page in the user's browser",
193
+ command: openCmd,
194
+ },
195
+ {
196
+ id: "wait_for_signup",
197
+ description: "Tell the user: 'I've opened the Neon sign-up page. Create your account and verify your email, then let me know when you're ready.'",
198
+ },
199
+ ],
200
+ onComplete: {
201
+ type: "run_neon_init",
202
+ args: ["auth", "--json", "--method", "existing"],
203
+ },
204
+ },
205
+ },
206
+ },
207
+ },
208
+ };
209
+ }
@@ -0,0 +1,27 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ /**
4
+ * Terminal phase: cleans up ephemeral _init state from .neon and
5
+ * returns a complete message. All feature chains should end here.
6
+ */
7
+ export function handleCleanup() {
8
+ const neonContextPath = resolve(process.cwd(), ".neon");
9
+ if (existsSync(neonContextPath)) {
10
+ try {
11
+ const context = JSON.parse(readFileSync(neonContextPath, "utf-8"));
12
+ if (context._init !== undefined) {
13
+ delete context._init;
14
+ writeFileSync(neonContextPath, `${JSON.stringify(context, null, 2)}\n`);
15
+ }
16
+ }
17
+ catch { }
18
+ }
19
+ return {
20
+ phase: "setup",
21
+ status: "complete",
22
+ nextAction: {
23
+ type: "complete",
24
+ message: "Neon setup is complete! Your database is connected and your agent has the Neon MCP server and skills available.",
25
+ },
26
+ };
27
+ }