Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

Commit 5f78365

Browse files
authored
Merge pull request #107 from ahundt/feature/new-session-wizard-ux-improvements-merged
Feature/new session wizard ux improvements merged
2 parents 640507e + 29412d4 commit 5f78365

68 files changed

Lines changed: 8392 additions & 1197 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.envrc.example

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Happy CLI Development Environment
2+
#
3+
# This file is for direnv users who want automatic environment switching
4+
# when entering this directory.
5+
#
6+
# Setup:
7+
# 1. Install direnv: https://direnv.net/
8+
# 2. Copy this file: cp .envrc.example .envrc
9+
# 3. Run: direnv allow
10+
#
11+
# The .envrc file is gitignored, so each developer can customize it.
12+
13+
export HAPPY_HOME_DIR="$HOME/.happy-dev"
14+
export HAPPY_VARIANT="dev"
15+
export HAPPY_SERVER_URL="${HAPPY_SERVER_URL:-https://api.cluster-fluster.com}"
16+
17+
echo "🔧 DEV environment activated (data: $HAPPY_HOME_DIR)"

.gitignore

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@ pnpm-lock.yaml
1717
# Environment variables
1818
.env
1919
.env*.local
20+
.envrc
2021

2122
# Claude code session level settings
2223
.claude/settings.local.json
2324

24-
# Local installation
25+
# Local installation and data directories
2526
.happy/
27+
.happy-dev/
2628

2729
**/*.log
2830
.release-notes-temp.md
2931

32+
# Git worktrees for isolated branch work
33+
.worktrees/
34+
bun.lock
35+
claude-docs/
36+
note/
37+
happy-coder-*.tgz
38+
3039
# npm auth token (never commit)
31-
.npmrc
40+
.npmrc

CONTRIBUTING.md

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
# Contributing to Happy CLI
2+
3+
## Prerequisites
4+
5+
- Node.js >= 20.0.0
6+
- Yarn (`npm install -g yarn`)
7+
- Git
8+
- Claude CLI installed and logged in (`claude` command available in PATH)
9+
10+
## Getting Started
11+
12+
```bash
13+
git clone https://github.com/slopus/happy-cli.git
14+
cd happy-cli
15+
yarn install
16+
yarn build
17+
```
18+
19+
## Development Commands
20+
21+
### Global `happy-dev` Command
22+
23+
Create a global `happy-dev` command that runs your local development build:
24+
25+
```bash
26+
yarn link:dev # Create happy-dev symlink
27+
yarn unlink:dev # Remove happy-dev symlink
28+
```
29+
30+
This creates a `happy-dev` command in your PATH pointing to your local build, while leaving any npm-installed `happy` command untouched.
31+
32+
| Command | Runs |
33+
|---------|------|
34+
| `happy` | Stable npm version (from `npm install -g happy-coder`) |
35+
| `happy-dev` | Local development version (from this repo) |
36+
37+
**Note:** Run `yarn build` before `yarn link:dev` to ensure the binary exists.
38+
39+
### Build Commands
40+
41+
```bash
42+
yarn build # Build the project
43+
yarn typecheck # TypeScript type checking
44+
yarn test # Run tests
45+
yarn dev # Run without building (uses tsx)
46+
```
47+
48+
## Stable vs Dev Data Isolation
49+
50+
The CLI supports running stable and development versions side-by-side with completely isolated data.
51+
52+
### Initial Setup (Once)
53+
54+
```bash
55+
npm run setup:dev
56+
```
57+
58+
This creates:
59+
- `~/.happy/` - Stable version data (production-ready)
60+
- `~/.happy-dev/` - Development version data (for testing changes)
61+
62+
### Daily Usage
63+
64+
**Stable (production-ready):**
65+
```bash
66+
npm run stable:daemon:start
67+
```
68+
69+
**Development (testing changes):**
70+
```bash
71+
npm run dev:daemon:start
72+
```
73+
74+
## Visual Indicators
75+
76+
You'll always see which version you're using:
77+
- `✅ STABLE MODE - Data: ~/.happy`
78+
- `🔧 DEV MODE - Data: ~/.happy-dev`
79+
80+
## Common Tasks
81+
82+
### Authentication
83+
84+
```bash
85+
# Authenticate stable version
86+
npm run stable auth login
87+
88+
# Authenticate dev version (can use same or different account)
89+
npm run dev auth login
90+
91+
# Logout
92+
npm run stable auth logout
93+
npm run dev auth logout
94+
```
95+
96+
### Daemon Management
97+
98+
```bash
99+
# Check status of both
100+
npm run stable:daemon:status
101+
npm run dev:daemon:status
102+
103+
# Stop both
104+
npm run stable:daemon:stop
105+
npm run dev:daemon:stop
106+
107+
# Start both simultaneously
108+
npm run stable:daemon:start && npm run dev:daemon:start
109+
```
110+
111+
### Running Any Command
112+
113+
```bash
114+
# Stable version
115+
npm run stable <command> [args...]
116+
npm run stable notify "Test message"
117+
npm run stable doctor
118+
119+
# Dev version
120+
npm run dev:variant <command> [args...]
121+
npm run dev:variant notify "Test message"
122+
npm run dev:variant doctor
123+
```
124+
125+
## Data Isolation
126+
127+
Both versions maintain complete separation:
128+
129+
| Aspect | Stable | Development |
130+
|--------|--------|-------------|
131+
| Data Directory | `~/.happy/` | `~/.happy-dev/` |
132+
| Settings | `~/.happy/settings.json` | `~/.happy-dev/settings.json` |
133+
| Auth Keys | `~/.happy/access.key` | `~/.happy-dev/access.key` |
134+
| Daemon State | `~/.happy/daemon.state.json` | `~/.happy-dev/daemon.state.json` |
135+
| Logs | `~/.happy/logs/` | `~/.happy-dev/logs/` |
136+
137+
**No conflicts!** Both can run simultaneously with separate:
138+
- Authentication sessions
139+
- Server connections
140+
- Daemon processes
141+
- Session histories
142+
- Configuration settings
143+
144+
## Advanced: direnv Auto-Switching
145+
146+
For automatic environment switching when entering directories:
147+
148+
1. Install [direnv](https://direnv.net/):
149+
```bash
150+
# macOS
151+
brew install direnv
152+
153+
# Add to your shell (bash/zsh)
154+
eval "$(direnv hook bash)" # or zsh
155+
```
156+
157+
2. Setup direnv for this project:
158+
```bash
159+
cp .envrc.example .envrc
160+
direnv allow
161+
```
162+
163+
3. Now `cd` into the directory automatically sets `HAPPY_VARIANT=dev`!
164+
165+
## Troubleshooting
166+
167+
### Commands not working?
168+
```bash
169+
npm install
170+
```
171+
172+
### Permission denied on scripts?
173+
```bash
174+
chmod +x scripts/*.cjs
175+
```
176+
177+
### Data directories not created?
178+
```bash
179+
npm run setup:dev
180+
```
181+
182+
### Both daemons won't start?
183+
Check port conflicts - each daemon needs its own port. The dev daemon will automatically use a different port from stable.
184+
185+
### How do I check which version is running?
186+
Look for the visual indicator:
187+
- `✅ STABLE MODE` = stable version
188+
- `🔧 DEV MODE` = development version
189+
190+
Or check the daemon status:
191+
```bash
192+
npm run stable:daemon:status # Shows ~/.happy/ data location
193+
npm run dev:daemon:status # Shows ~/.happy-dev/ data location
194+
```
195+
196+
### `yarn link:dev` fails with permission denied?
197+
```bash
198+
sudo yarn link:dev
199+
```
200+
201+
### `happy-dev` command not found after linking?
202+
- Ensure your global npm bin is in PATH: `npm bin -g`
203+
- Try opening a new terminal window
204+
- Check the symlink was created: `ls -la $(npm bin -g)/happy-dev`
205+
206+
## Tips
207+
208+
1. **Use stable for production work** - Your tested, reliable version
209+
2. **Use dev for testing changes** - Test new features without breaking your workflow
210+
3. **Run both simultaneously** - Compare behavior side-by-side
211+
4. **Different accounts** - Use different Happy accounts for dev/stable if needed
212+
5. **Check logs** - Logs are separated: `~/.happy/logs/` vs `~/.happy-dev/logs/`
213+
214+
## Example Workflow
215+
216+
```bash
217+
# Initial setup (once)
218+
yarn install
219+
yarn build
220+
yarn link:dev
221+
npm run setup:dev
222+
223+
# Authenticate both
224+
npm run stable auth login
225+
npm run dev:variant auth login
226+
227+
# Start both daemons
228+
npm run stable:daemon:start
229+
npm run dev:daemon:start
230+
231+
# Do your development work...
232+
# Edit code, build, test with dev version
233+
234+
# When ready, update stable version
235+
npm run stable:daemon:stop
236+
git pull # or your deployment process
237+
npm run stable:daemon:start
238+
239+
# Dev continues running unaffected!
240+
```
241+
242+
## How It Works
243+
244+
The system uses the built-in `HAPPY_HOME_DIR` environment variable to separate data:
245+
246+
- **Stable scripts** set: `HAPPY_HOME_DIR=~/.happy`
247+
- **Dev scripts** set: `HAPPY_HOME_DIR=~/.happy-dev`
248+
249+
Everything else (auth, sessions, logs, daemon) automatically follows the `HAPPY_HOME_DIR` setting.
250+
251+
Cross-platform via Node.js - works identically on Windows, macOS, and Linux!
252+
253+
## Testing Profile Sync Between GUI and CLI
254+
255+
Profile synchronization ensures AI backend configurations created in the Happy mobile/web GUI work seamlessly with the CLI daemon.
256+
257+
### Profile Schema Validation
258+
259+
The profile schema is defined in both repositories:
260+
- **GUI:** `sources/sync/settings.ts` (AIBackendProfileSchema)
261+
- **CLI:** `src/persistence.ts` (AIBackendProfileSchema)
262+
263+
**Critical:** These schemas MUST stay in sync to prevent sync failures.
264+
265+
### Testing Profile Sync
266+
267+
1. **Create profile in GUI:**
268+
```
269+
- Open Happy mobile/web app
270+
- Settings → AI Backend Profiles
271+
- Create new profile with custom environment variables
272+
- Note the profile ID
273+
```
274+
275+
2. **Verify CLI receives profile:**
276+
```bash
277+
# Start daemon with dev variant
278+
npm run dev:daemon:start
279+
280+
# Check daemon logs
281+
tail -f ~/.happy-dev/logs/*.log | grep -i profile
282+
```
283+
284+
3. **Test profile-based session spawning:**
285+
```bash
286+
# From GUI: Start new session with custom profile
287+
# Check CLI daemon logs for:
288+
# - "Loaded X environment variables from profile"
289+
# - "Using GUI-provided profile environment variables"
290+
```
291+
292+
4. **Verify environment variable expansion:**
293+
```bash
294+
# If profile uses ${VAR} references:
295+
# - Set reference var in daemon environment: export Z_AI_AUTH_TOKEN="sk-..."
296+
# - Start session from GUI
297+
# - Verify daemon logs show expansion: "${Z_AI_AUTH_TOKEN}" → "sk-..."
298+
```
299+
300+
### Testing Schema Compatibility
301+
302+
When modifying profile schemas:
303+
304+
1. **Update both repositories** - Never update one without the other
305+
2. **Test migration** - Existing profiles should migrate gracefully
306+
3. **Version bump** - Update `CURRENT_PROFILE_VERSION` if schema changes
307+
4. **Test validation** - Invalid profiles should be caught with clear errors
308+
309+
### Common Issues
310+
311+
**"Invalid profile" warnings in logs:**
312+
- Check profile has valid UUID (not timestamp)
313+
- Verify environment variable names match regex: `^[A-Z_][A-Z0-9_]*$`
314+
- Ensure compatibility.claude or compatibility.codex is true
315+
316+
**Environment variables not expanding:**
317+
- Reference variable must be set in daemon's process.env
318+
- Check daemon logs for expansion warnings
319+
- Verify no typos in ${VAR} references
320+
321+
## Publishing to npm
322+
323+
Maintainers can publish new versions:
324+
325+
```bash
326+
yarn release # Interactive version bump, changelog, publish
327+
```
328+
329+
This runs tests, builds, and publishes to npm. The published package includes:
330+
- `happy` - Main CLI command
331+
- `happy-mcp` - MCP bridge command
332+
333+
**Note:** `happy-dev` is intentionally excluded from the npm package - it's for local development only.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ This will:
4747
- `HAPPY_DISABLE_CAFFEINATE` - Disable macOS sleep prevention (set to `true`, `1`, or `yes`)
4848
- `HAPPY_EXPERIMENTAL` - Enable experimental features (set to `true`, `1`, or `yes`)
4949

50+
## Contributing
51+
52+
Interested in contributing? See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
53+
5054
## Requirements
5155

5256
- Node.js >= 20.0.0

0 commit comments

Comments
 (0)