You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify env setup: use .env.local with Bun native loading
Refactor environment variable management to leverage Bun native .env loading:
- Replace .infisical-cache with .env.local as the secrets file
- Use .env.development.local for worktree port overrides (highest precedence)
- Simplify .bin/bun wrapper: sync Infisical to .env.local, let Bun load natively
- Add create_env_symlinks() for subdirectory .env.local access
- Simplify CONTRIBUTING.md: manual .env.local setup as default path
- Move Infisical to optional team setup in INFISICAL_SETUP_GUIDE.md
- Add "bun run setup" script for quick .env.local creation
- Update knowledge.md with correct env file hierarchy
- Fix Next.js dev server: use PORT env var instead of shell expansion
- Fix init-worktree.ts to set PORT to webPort for Next.js
@@ -99,7 +71,7 @@ Before you begin, you'll need to install a few tools:
99
71
100
72
**Note**: CLI requires both backend and web server running for authentication.
101
73
102
-
9.**Giving yourself credits**:
74
+
6.**Giving yourself credits**:
103
75
104
76
1. Log into Codebuff at [http://localhost:3000/login](http://localhost:3000/login)
105
77
@@ -115,7 +87,7 @@ Before you begin, you'll need to install a few tools:
115
87
116
88
Now, you should be able to run the CLI commands locally from within the `codebuff` directory.
117
89
118
-
10.**Running in other directories**:
90
+
7.**Running in other directories**:
119
91
120
92
In order to run the CLI from other directories, you need to first publish the agents to the database.
121
93
@@ -271,14 +243,12 @@ Level up the web interface in `web/` with better agent management, project templ
271
243
272
244
**Setup issues?**
273
245
274
-
-**direnv problems?** Make sure it's hooked into your shell, run `direnv allow`, and restart your terminal
275
246
-**Script errors?** Double-check you're using bun for all commands
276
-
-**Infisical issues?** See our [Infisical Setup Guide](./INFISICAL_SETUP_GUIDE.md) for step-by-step instructions
277
247
-**Database connection errors?** If you see `password authentication failed for user "postgres"` errors:
278
-
1. Ensure DATABASE_URL uses the correct credentials: `postgresql://manicode_user_local:secretpassword_local@localhost:5432/manicode_db_local`
279
-
2.Update both your local `.env` file and Infisical secret: `infisical secrets set DATABASE_URL=postgresql://manicode_user_local:secretpassword_local@localhost:5432/manicode_db_local`
280
-
3.Run the database migration: `infisical run -- bun run db:migrate`
281
-
4. Restart your development services
248
+
1. Ensure DATABASE_URL in `.env.local`uses the correct credentials: `postgresql://manicode_user_local:secretpassword_local@localhost:5432/manicode_db_local`
249
+
2.Run the database migration: `bun run db:migrate`
250
+
3.Restart your development services
251
+
-**Using Infisical?** See the [Infisical Setup Guide](./INFISICAL_SETUP_GUIDE.md) for team secrets management
282
252
-**Empty Agent Store in dev mode?** This is expected behavior - agents from `.agents/` directory need to be published to the database to appear in the marketplace
283
253
284
254
**Questions?** Jump into our [Discord community](https://codebuff.com/discord) - we're friendly and always happy to help!
Quick 5-step setup to get Codebuff running with Infisical secrets.
3
+
This guide is for **team/advanced secrets management** using [Infisical](https://infisical.com/).
4
+
5
+
> **Personal development?** Just copy `.env.example` to `.env.local` and fill in your values. See [CONTRIBUTING.md](./CONTRIBUTING.md) for the full setup guide.
6
+
7
+
## Why Infisical?
8
+
9
+
-**Team sync**: Share secrets securely across team members
10
+
-**Auto-refresh**: The `.bin/bun` wrapper automatically syncs secrets to `.env.local`
11
+
-**No manual copying**: Secrets stay up-to-date with a 15-minute cache
12
+
13
+
## Prerequisites
14
+
15
+
-**direnv**: Required for the bun wrapper to work
16
+
- macOS: `brew install direnv`
17
+
- Ubuntu/Debian: `sudo apt install direnv`
18
+
-[Hook it into your shell](https://direnv.net/docs/hook.html)
4
19
5
20
## Setup Steps
6
21
7
-
### 1. Install & Setup
22
+
### 1. Enable the bun wrapper
23
+
```bash
24
+
direnv allow
25
+
```
26
+
This adds `.bin/` to your PATH so the Infisical sync wrapper runs automatically.
27
+
28
+
### 2. Install & Login
8
29
```bash
9
30
npm install -g @infisical/cli
10
31
infisical init
11
32
infisical login
12
33
# Select "US" region when prompted
13
-
infisical secrets # Verify setup works
14
34
```
15
35
16
-
### 2. Browser Login
36
+
### 3. Browser Login
17
37
- Browser opens automatically to https://app.infisical.com
18
-
- Login with **any email** (Gmail, etc.)
19
-
-Fill in any **name** and **organization name** when asked
38
+
- Login with your email
39
+
-Select or create your organization and project
20
40
- Copy the token from browser and paste in terminal
21
41
22
-
### 3. Select Project
23
-
- Use arrow keys to choose your organization
24
-
- Select or create a Codebuff project
25
-
26
-
### 4. Load Environment Variables
42
+
### 4. Load Initial Secrets
27
43
```bash
28
-
# Load all variables at once
44
+
# Load all variables from .env.example as a starting point
29
45
infisical secrets set --file .env.example
30
46
31
-
#IMPORTANT: Fix the database password separately
47
+
# Fix the database password to match Docker
32
48
infisical secrets set DATABASE_URL=postgresql://manicode_user_local:secretpassword_local@localhost:5432/manicode_db_local
33
49
```
34
50
35
-
### 5. Done! Run Codebuff
51
+
### 5. Run Codebuff
36
52
```bash
37
-
bun run dev #Starts everything automatically
53
+
bun run dev #Secrets auto-sync to .env.local
38
54
```
39
55
40
-
## Common Issues & Quick Fixes
56
+
## How It Works
41
57
42
-
**Token won't paste?** → Right-click → paste
43
-
**Database error?** → Run the DATABASE_URL command above
44
-
**Can't navigate menus?** → Use arrow keys ↓ ↑
58
+
1. The `.bin/bun` wrapper checks if `.env.local` needs refreshing
59
+
2. If stale (>15 min) or missing, it syncs from Infisical
60
+
3. Bun then loads `.env.local` automatically
45
61
46
-
## That's It!
62
+
## Common Issues
47
63
48
-
The `.env.example` file contains all the dummy values needed for development. Only the database password needs to be fixed to match Docker's password.
64
+
| Problem | Solution |
65
+
|---------|----------|
66
+
| Token won't paste | Right-click → paste |
67
+
| Session expired | Run `infisical login` again |
68
+
| Can't navigate menus | Use arrow keys ↓ ↑ |
69
+
| Infisical not working | Fall back to manual `.env.local`|
49
70
50
-
You will need to populate all the secrets in the Infisical UI at https://app.infisical.com. You can provide dummy values for the secrets if you get an error about missing secrets, but you will need to update them with real values in order to use the associated feature.
Copy file name to clipboardExpand all lines: knowledge.md
+34-15Lines changed: 34 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -366,33 +366,52 @@ Important constants are centralized in `common/src/constants.ts`:
366
366
367
367
## Environment Variables
368
368
369
-
This project uses [Infisical](https://infisical.com/)for secret management. All secrets are injected at runtime.
369
+
This project uses standard `.env.*` files for environment configuration. Bun natively loads these files automatically.
370
370
371
-
### Release Process
371
+
### File Hierarchy
372
372
373
-
The release mechanism uses the `CODEBUFF_GITHUB_TOKEN` environment variable directly. The old complex GitHub App token generation system has been removed in favor of using a simple personal access token or the infisical-managed token.
373
+
Bun loads `.env` files in this order (highest precedence last):
374
374
375
-
Environment variables are defined and validated in `packages/internal/src/env.ts`. This module provides type-safe `env` objects for use throughout the monorepo.
375
+
1.`.env.local` - Main secrets file synced from Infisical (gitignored)
376
+
2.`.env.development.local` - Worktree-specific overrides like ports (gitignored, highest precedence)
377
+
378
+
**Note**: Bun also supports `.env` and `.env.development`, but this project only uses `.env.local` and `.env.development.local`.
379
+
380
+
### Infisical Integration
381
+
382
+
Infisical is used as a background sync mechanism to populate `.env.local`:
376
383
377
-
### Bun Wrapper Script
384
+
- The `.bin/bun` wrapper syncs secrets from Infisical to `.env.local`
385
+
- Caching: 15-minute TTL (configurable via `INFISICAL_CACHE_TTL`)
386
+
- Cache invalidates when `.infisical.json` is modified or TTL expires
387
+
- If Infisical is not set up, existing `.env.local` is used directly
378
388
379
-
The `.bin/bun` script automatically wraps bun commands with infisical when secrets are needed. It prevents nested infisical calls by checking for `NEXT_PUBLIC_INFISICAL_UP` environment variable, ensuring infisical runs only once at the top level while nested bun commands inherit the environment variables.
389
+
**Setup Options**:
390
+
1.**With Infisical**: Run `infisical login`, secrets auto-sync to `.env.local`
391
+
2.**Without Infisical**: Copy `.env.example` to `.env.local` and fill in values
380
392
381
-
**Worktree Support**: The wrapper automatically detects and loads `.env.worktree` files when present, allowing worktrees to override Infisical environment variables (like ports) for local development. This enables multiple worktrees to run simultaneously on different ports without conflicts.
393
+
### Worktree Support
382
394
383
-
The wrapper also loads environment variables in the correct precedence order:
395
+
For git worktrees running on different ports:
384
396
385
-
1. Infisical secrets are loaded first (if needed)
386
-
2.`.env.worktree` is loaded second to override any conflicting variables
387
-
3. This ensures worktree-specific overrides (like custom ports) always take precedence over cached Infisical defaults
397
+
- Create `.env.development.local` in the worktree with port overrides
398
+
- Bun loads `.env.development.local` with highest precedence, so it overrides ports from `.env.local`
399
+
- The `scripts/init-worktree.ts` script creates this file automatically
388
400
389
-
The wrapper looks for `.env.worktree` in the project root directory, making it work consistently regardless of the current working directory when bun commands are executed.
401
+
### Bun Wrapper Script (`.bin/bun`)
390
402
391
-
**Performance Optimizations**: The wrapper uses `--silent` flag with Infisical to reduce CLI output overhead and sets `INFISICAL_DISABLE_UPDATE_CHECK=true` to skip version checks for faster startup times.
403
+
The wrapper's role is simple: ensure `.env.local` is synced from Infisical before running bun.
392
404
393
-
**Infisical Caching**: The wrapper implements robust caching of environment variables in `.infisical-cache` with a 15-minute TTL (configurable via `INFISICAL_CACHE_TTL`). This reduces startup time from ~1.2s to ~0.16s (87% improvement). The cache uses `infisical export` which outputs secrets directly in `KEY='value'` format, ensuring ONLY Infisical-managed secrets are cached (no system environment variables). Multi-line secrets like RSA private keys are handled correctly using `source` command. Cache automatically invalidates when `.infisical.json` is modified or after TTL expires. Uses subshell execution to avoid changing the main shell's working directory.
405
+
- Checks `NEXT_PUBLIC_INFISICAL_UP` to prevent nested syncs
406
+
- Uses `INFISICAL_DISABLE_UPDATE_CHECK=true` for faster startup
407
+
- 10-second timeout on Infisical commands to prevent hangs
408
+
- Falls back gracefully if Infisical is not available
394
409
395
-
**Session Validation**: The wrapper detects expired Infisical sessions using `infisical export` with a robust 10-second timeout implementation that works cross-platform (macOS and Linux). Uses background processes with polling to prevent hanging on interactive prompts. Valid sessions output environment variables in `KEY='value'` format, while expired sessions either output interactive prompts or timeout. Provides clear error messages directing users to run `infisical login`.
410
+
### Release Process
411
+
412
+
The release mechanism uses the `CODEBUFF_GITHUB_TOKEN` environment variable directly.
413
+
414
+
Environment variables are defined and validated in `packages/internal/src/env.ts`. This module provides type-safe `env` objects for use throughout the monorepo.
0 commit comments