-
Notifications
You must be signed in to change notification settings - Fork 40
feat: local-first DX with zero-ceremony setup and model selector overhaul #2528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vibegui
wants to merge
15
commits into
main
Choose a base branch
from
feat/local-first-dx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f2d1ea3
feat: local-first developer experience with zero-ceremony setup
vibegui 2f79521
fix(cli): prompt for data directory on first run and fix dev mode
vibegui 8f38df9
fix(cli): auto-build frontend and prompt for data directory
vibegui 2bc6a9e
fix: resolve client dist directory when running from source
vibegui 086dd3e
fix(cli): always set DATABASE_URL to MESH_HOME/mesh.db
vibegui 4208fc0
fix(local-mode): use valid email format for local admin user
vibegui 36bae38
fix(local-mode): use longer password for local admin
vibegui 6221c09
fix(local-mode): use DB for admin role and auto-redirect to first org
vibegui 9e4757b
fix(local-mode): seed after server starts to avoid connection errors
vibegui d88d92d
feat(local-mode): use OS username for admin user and org name
vibegui f1d6fcf
fix(org-seed): use API key token when fetching tools from connections
vibegui 5c0bc3b
feat(model-selector): overhaul with tier categories, shortlist manage…
vibegui bacda67
feat(local-mode): auto-auth connection flow and dev script
vibegui d96d249
fix(model-selector): remove non-working providers from default shortlist
vibegui a2747b8
fix: address review violations and CI failures
vibegui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #!/usr/bin/env bun | ||
| /** | ||
| * Development environment setup script. | ||
| * | ||
| * Mirrors the CLI (src/cli.ts) behaviour so that `bun dev` and | ||
| * `bunx @decocms/mesh` share the same ~/deco data directory, secrets, | ||
| * and local-mode defaults. | ||
| * | ||
| * After setting up the environment it spawns the regular dev pipeline: | ||
| * bun run migrate && concurrently "bun run dev:client" "bun run dev:server" | ||
| */ | ||
|
|
||
| import { existsSync } from "fs"; | ||
| import { mkdir } from "fs/promises"; | ||
| import { createInterface } from "readline"; | ||
| import { homedir } from "os"; | ||
| import { join } from "path"; | ||
| import { randomBytes } from "crypto"; | ||
| import { spawn } from "child_process"; | ||
|
|
||
| // ============================================================================ | ||
| // Resolve MESH_HOME | ||
| // ============================================================================ | ||
|
|
||
| // When MESH_HOME is explicitly set, respect it (CI, tests, custom setups). | ||
| // Otherwise default to ~/deco for interactive dev. | ||
| const meshAppDir = import.meta.dir.replace("/scripts", ""); | ||
| const explicitHome = process.env.MESH_HOME; | ||
| const userHome = join(homedir(), "deco"); | ||
| // In CI / non-TTY without explicit MESH_HOME, use a repo-local directory | ||
| // so tests never touch the developer's real ~/deco data. | ||
| const ciHome = join(meshAppDir, ".mesh-dev"); | ||
|
|
||
| const dim = "\x1b[2m"; | ||
| const reset = "\x1b[0m"; | ||
| const bold = "\x1b[1m"; | ||
| const cyan = "\x1b[36m"; | ||
| const yellow = "\x1b[33m"; | ||
| const green = "\x1b[32m"; | ||
|
|
||
| function prompt(question: string): Promise<string> { | ||
| const rl = createInterface({ input: process.stdin, output: process.stdout }); | ||
| return new Promise((resolve) => { | ||
| rl.question(question, (answer) => { | ||
| rl.close(); | ||
| resolve(answer.trim()); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| let meshHome: string; | ||
|
|
||
| if (explicitHome) { | ||
| // Explicit MESH_HOME takes priority (CI, tests, custom setups) | ||
| meshHome = explicitHome; | ||
| } else if (!process.stdin.isTTY) { | ||
| // Non-interactive (CI) — use repo-local directory to avoid touching ~/deco | ||
| meshHome = ciHome; | ||
| } else if (existsSync(userHome)) { | ||
| // Interactive with existing ~/deco — use it | ||
| meshHome = userHome; | ||
| } else { | ||
| // Interactive, first run — prompt for location | ||
| const displayDefault = userHome.replace(homedir(), "~"); | ||
| console.log(""); | ||
| console.log(`${bold}${cyan}MCP Mesh${reset} ${dim}(dev)${reset}`); | ||
| console.log(""); | ||
| const answer = await prompt( | ||
| ` Where should Mesh store its data? ${dim}(${displayDefault})${reset} `, | ||
| ); | ||
| if (answer === "") { | ||
| meshHome = userHome; | ||
| } else { | ||
| meshHome = answer.startsWith("~") | ||
| ? join(homedir(), answer.slice(1)) | ||
cubic-dev-ai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| : answer; | ||
| } | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Secrets management (same logic as src/cli.ts) | ||
| // ============================================================================ | ||
|
|
||
| await mkdir(meshHome, { recursive: true, mode: 0o700 }); | ||
|
|
||
| const secretsFilePath = join(meshHome, "secrets.json"); | ||
|
|
||
| interface SecretsFile { | ||
| BETTER_AUTH_SECRET?: string; | ||
| ENCRYPTION_KEY?: string; | ||
| } | ||
|
|
||
| let savedSecrets: SecretsFile = {}; | ||
| try { | ||
| const file = Bun.file(secretsFilePath); | ||
| if (await file.exists()) { | ||
| savedSecrets = await file.json(); | ||
| } | ||
| } catch { | ||
| // File doesn't exist or is invalid — will create new secrets | ||
| } | ||
|
|
||
| let secretsModified = false; | ||
|
|
||
| if (!process.env.BETTER_AUTH_SECRET) { | ||
| if (savedSecrets.BETTER_AUTH_SECRET) { | ||
| process.env.BETTER_AUTH_SECRET = savedSecrets.BETTER_AUTH_SECRET; | ||
| } else { | ||
| savedSecrets.BETTER_AUTH_SECRET = randomBytes(32).toString("base64"); | ||
| process.env.BETTER_AUTH_SECRET = savedSecrets.BETTER_AUTH_SECRET; | ||
| secretsModified = true; | ||
| } | ||
| } | ||
|
|
||
| if (!process.env.ENCRYPTION_KEY) { | ||
| if (savedSecrets.ENCRYPTION_KEY) { | ||
| process.env.ENCRYPTION_KEY = savedSecrets.ENCRYPTION_KEY; | ||
| } else { | ||
| savedSecrets.ENCRYPTION_KEY = ""; | ||
| process.env.ENCRYPTION_KEY = savedSecrets.ENCRYPTION_KEY; | ||
| secretsModified = true; | ||
| } | ||
| } | ||
|
|
||
| if (secretsModified) { | ||
| try { | ||
| await Bun.write(secretsFilePath, JSON.stringify(savedSecrets, null, 2)); | ||
| } catch (error) { | ||
| console.warn( | ||
| `${yellow}Warning: Could not save secrets file: ${error}${reset}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Set environment variables | ||
| // ============================================================================ | ||
|
|
||
| process.env.MESH_HOME = meshHome; | ||
| process.env.DATABASE_URL = `file:${join(meshHome, "mesh.db")}`; | ||
| process.env.MESH_LOCAL_MODE = "true"; | ||
|
|
||
| // ============================================================================ | ||
| // Banner | ||
| // ============================================================================ | ||
|
|
||
| const displayHome = meshHome.replace(homedir(), "~"); | ||
|
|
||
| console.log(""); | ||
| console.log(`${bold}${cyan}MCP Mesh${reset} ${dim}(dev)${reset}`); | ||
| console.log(""); | ||
| console.log( | ||
| `${bold} Mode: ${green}Local${reset}${bold} (auto-login enabled)${reset}`, | ||
| ); | ||
| console.log(`${bold} Home: ${dim}${displayHome}/${reset}`); | ||
| console.log(`${bold} Database: ${dim}${displayHome}/mesh.db${reset}`); | ||
| console.log(""); | ||
|
|
||
| // ============================================================================ | ||
| // Spawn the dev pipeline | ||
| // ============================================================================ | ||
|
|
||
| const child = spawn( | ||
| "bun", | ||
| [ | ||
| "run", | ||
| "migrate", | ||
| "&&", | ||
| "concurrently", | ||
| '"bun run dev:client"', | ||
| '"bun run dev:server"', | ||
| ], | ||
| { | ||
| stdio: "inherit", | ||
| shell: true, | ||
| env: process.env, | ||
| cwd: meshAppDir, | ||
| }, | ||
| ); | ||
|
|
||
| child.on("exit", (code) => { | ||
| process.exit(code ?? 0); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
~/expansion is incorrect:answer.slice(1)starts with/, sojoin(homedir(), ...)resolves to the filesystem root (e.g./deco) instead of the user’s home directory. Strip the leading~/before joining to avoid writing data in the wrong location.Prompt for AI agents