Skip to content

feat: neon-init v2 agent-driven state machine#151

Open
jeff-at-neon wants to merge 2 commits into
mainfrom
neon-init-v2-plan
Open

feat: neon-init v2 agent-driven state machine#151
jeff-at-neon wants to merge 2 commits into
mainfrom
neon-init-v2-plan

Conversation

@jeff-at-neon
Copy link
Copy Markdown

Summary

Redesigns neon-init as a stateless state machine where each CLI invocation returns a typed JSON response with a nextAction that tells the agent exactly what to do next.

  • Orchestrator inspects filesystem (MCP config, skills, Neon connection string) to skip phases that are already satisfied
  • Phase handlers for auth, setup, getting-started, db, neon-auth, migrations, mcp, skills, and status as composable subcommands
  • Agent detection via TTY: IDE env vars + non-TTY stdin = agent invocation → JSON mode; TTY stdin = human → interactive mode
  • Interactive mode with clack prompts, Neon green branding, independent detection of MCP/skills/extension, org/project selection, .neon context file
  • responseMapping supports inline { action: NextAction } to eliminate CLI round-trips (e.g. auth OAuth launches directly after user confirms)
  • ensureSkillsUpToDate() with 12-hour freshness window — verifies actual SKILL.md exists on disk, not just lock file
  • .neon context resolution — when a Neon connection string exists but .neon is missing, the CLI resolves the org/project by searching via neonctl
  • Extension install fallback chain: marketplace → VSIX download (corporate proxy or Open VSX) → manual instructions
  • Input validation (assertSafeId) for org/project IDs in shell commands
  • Neon-specific connection detection — distinguishes Neon DATABASE_URL from local postgres
  • picocolors patch for Neon green branding in clack prompts (replaces stdout monkeypatch)
  • 95 tests across 11 test files

Key design decisions

  • Auth verified responses use run_neon_init (not complete) to prevent agents from getting distracted
  • Neon-auth skip goes directly to complete action (no CLI round-trip needed)
  • Getting-started chains back to orchestrator so flow continues to neon-auth
  • Skills installation always runs ensureSkillsUpToDate regardless of agent-reported state — CLI verifies independently
  • Setup phase consent question comes first, inspection after — agent checks happen between consent and mode selection

Test plan

  • Run neon-init in Cursor terminal (human) — should show interactive mode
  • Have Cursor agent run neon-init — should get JSON mode
  • Run neon-init with MCP+skills already installed — should skip to getting-started
  • Delete .neon file with existing connection string, run neon-init — should resolve and recreate
  • Skip Neon Auth — should complete without additional CLI calls
  • Run neon-init from Claude Code — should detect via CLAUDECODE env var

This pull request and its description were written by Isaac.

Adds a --json flag that outputs structured JSON and suppresses interactive UI, making it suitable for agent consumption. Refactors init to return result objects and adds tests.

Co-authored-by: Isaac
Redesigns neon-init as a stateless state machine where each CLI invocation
returns a typed JSON response with a `nextAction` that tells the agent
exactly what to do next. Key changes:

- Orchestrator inspects filesystem (MCP config, skills, DATABASE_URL) to
  skip phases that are already satisfied — no unnecessary round-trips
- Phase handlers for auth, setup, getting-started, db, neon-auth,
  migrations, mcp, skills, and status as composable subcommands
- `responseMapping` supports inline `{ action: NextAction }` to eliminate
  CLI round-trips (e.g. auth OAuth launches directly after user confirms)
- Auth verified responses use `run_neon_init` instead of `complete` to
  prevent agents from getting distracted by neonctl output
- `ensureSkillsUpToDate()` with 12-hour freshness window — called from
  phase handlers, skips if skills-lock.json or global skills dir is recent
- Agent detection via TTY: IDE env vars + non-TTY stdin = agent invocation,
  IDE env vars + TTY stdin = human in terminal → interactive mode
- Interactive mode with clack prompts, Neon green branding via picocolors
  patch, org/project selection, .neon context file
- Extension install fallback chain: marketplace → VSIX download (corporate
  proxy or Open VSX) → manual instructions
- Input validation (assertSafeId) for org/project IDs in shell commands
- Filesystem inspection module (inspect.ts) shared by orchestrator, setup,
  and status phases
- 95 tests across 11 test files

Co-authored-by: Isaac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant