File size: 8,758 Bytes
6a7089a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | # Contributing
This is the canonical contributor and development guide for PinchTab.
## System Requirements
### Minimum Requirements
| Requirement | Version | Purpose |
|------------|---------|---------|
| Go | 1.25+ | Build language |
| golangci-lint | Latest | Linting (required for pre-commit hooks) |
| Chrome/Chromium | Latest | Browser automation |
| macOS, Linux, or WSL2 | Current | OS support |
For dashboard work, use Bun 1.2+.
Older Bun releases fail on the checked-in `dashboard/bun.lock` during clean installs with `--frozen-lockfile`.
### Recommended Setup
- **macOS**: Homebrew for package management
- **Linux**: apt (Debian/Ubuntu) or yum (RHEL/CentOS)
- **WSL2**: Full Linux environment (not WSL1)
---
## Quick Start
**Fastest way to get started:**
```bash
# 1. Clone
git clone https://github.com/pinchtab/pinchtab.git
cd pinchtab
# 2. Run doctor (verifies environment, prompts before installing anything)
./dev doctor
# 3. Build and run
go build ./cmd/pinchtab
./pinchtab
```
**Example output:**
```
π¦ Pinchtab Doctor
Verifying and setting up development environment...
Go Backend
β Go 1.26.0
β golangci-lint
Required for pre-commit hooks and CI.
Install golangci-lint via brew? [y/N] y
β golangci-lint installed
β Git hooks
β Go dependencies
Dashboard (React/TypeScript)
β Node.js 22.15.1
Β· Bun not found
Optional β used for fast dashboard builds.
Install Bun? [y/N] n
curl -fsSL https://bun.sh/install | bash
Summary
Β· 1 warning(s)
```
The doctor asks for confirmation before installing anything.
If you decline, it shows the manual install command instead.
---
## Part 1: Prerequisites
### Install Go
**macOS (Homebrew):**
```bash
brew install go
go version # Verify: go version go1.25.0
```
**Linux (Ubuntu/Debian):**
```bash
sudo apt update
sudo apt install -y golang-go git build-essential
go version
```
**Linux (RHEL/CentOS):**
```bash
sudo yum install -y golang git
go version
```
**Or download from:** https://go.dev/dl/
### Install golangci-lint (Required)
Required for pre-commit hooks:
**macOS/Linux:**
```bash
brew install golangci-lint
```
**Or via Go:**
```bash
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
```
Verify:
```bash
golangci-lint --version
```
### Install Chrome/Chromium
**macOS (Homebrew):**
```bash
brew install chromium
```
**Linux (Ubuntu/Debian):**
```bash
sudo apt install -y chromium-browser
```
**Linux (RHEL/CentOS):**
```bash
sudo yum install -y chromium
```
### Automated Setup
After cloning, run doctor to verify and set up your environment:
```bash
git clone https://github.com/pinchtab/pinchtab.git
cd pinchtab
./dev doctor
```
Doctor checks your environment and **asks before installing** anything:
- Go 1.25+ and golangci-lint (offers `brew install` or `go install`)
- Git hooks (copies pre-commit hook)
- Go dependencies (`go mod download`)
- Node.js, Bun, and dashboard deps (optional, for dashboard development)
Run `./dev doctor` anytime to verify or fix your environment.
---
## Part 2: Build the Project
### Simple Build
```bash
go build -o pinchtab ./cmd/pinchtab
```
**What it does:**
- Compiles Go source code
- Produces binary: `./pinchtab`
- Takes ~30-60 seconds
> **Note:** This builds the Go server only. The dashboard will show a
> "not built" placeholder. To include the full React dashboard, use
> `./dev build` instead β it builds the dashboard, compiles Go, and
> runs the server in one step. Or run `./scripts/build-dashboard.sh`
> before `go build`.
**Verify:**
```bash
ls -la pinchtab
./pinchtab --version
```
---
## Part 3: Run the Server
### Start (Headless)
```bash
./pinchtab
```
**Expected output:**
```
π¦ PINCH! PINCH! port=9867
auth disabled (set PINCHTAB_TOKEN to enable)
```
### Start (Headed Mode)
```bash
BRIDGE_HEADLESS=false ./pinchtab
```
Opens Chrome in the foreground.
### Background
```bash
nohup ./pinchtab > pinchtab.log 2>&1 &
tail -f pinchtab.log # Watch logs
```
---
## Part 4: Quick Test
### Health Check
```bash
curl http://localhost:9867/health
```
### Try CLI
```bash
./pinchtab quick https://pinchtab.com
./pinchtab nav https://pinchtab.com
./pinchtab snap
```
---
## Development
### Run Tests
```bash
go test ./... # Unit tests only
go test ./... -v # Verbose
go test ./... -v -coverprofile=coverage.out
go tool cover -html=coverage.out # View coverage
./dev e2e # Run E2E tests (curl + CLI)
```
### Developer Toolkit (`dev`)
All dev scripts are accessible through `./dev`:
```bash
./dev # Interactive picker (uses gum if installed, numbered fallback)
./dev check # Run a command directly
./dev test unit # Subcommands supported
./dev --help # List all commands
```

**Available commands:**
| Command | Description |
|---------|-------------|
| `check` | All checks (Go + Dashboard) |
| `check go` | Go checks only |
| `check dashboard` | Dashboard checks only |
| `check security` | Gosec security scan |
| `check docs` | Validate docs JSON |
| `format dashboard` | Run Prettier on dashboard sources |
| `test` | Unit + E2E tests |
| `test unit` | Unit tests only |
| `e2e` | E2E tests (curl + CLI) |
| `e2e curl` | E2E curl tests only |
| `e2e cli` | E2E CLI tests only |
| `build` | Build & run (default) |
| `run` | Run the application |
| `doctor` | Setup dev environment |
For the fancy interactive picker, install [gum](https://github.com/charmbracelet/gum): `brew install gum`
**Tip:** Add this to `~/.zshrc` to use `dev` without `./`:
```bash
dev() { if [ -x "./dev" ]; then ./dev "$@"; else echo "dev not found in current directory"; return 1; fi }
```
### Code Quality
```bash
./dev check # Full non-test checks (recommended)
./dev format dashboard # Fix dashboard formatting
gofmt -w . # Format code
golangci-lint run # Lint
./dev doctor # Verify environment
```
### Git Hooks
Git hooks are installed by `./dev doctor` (or `./scripts/install-hooks.sh`). They run on every commit:
- `gofmt` β Format check
- `golangci-lint` β Linting
- `prettier` β Dashboard formatting
To manually reinstall hooks:
```bash
./scripts/install-hooks.sh
```
### Development Workflow
```bash
# 1. Setup (first time)
./dev doctor
# 2. Create feature branch
git checkout -b feat/my-feature
# 3. Make changes
# ... edit files ...
# 4. Run checks before pushing
./dev check
# 5. Commit (hooks run automatically)
git commit -m "feat: description"
# 6. Push
git push origin feat/my-feature
```
**Note:** Git hooks will automatically format and lint your code on commit. If checks fail, the commit is blocked.
---
## Continuous Integration
GitHub Actions automatically runs on push:
- Format checks (gofmt)
- Vet checks (go vet)
- Build verification
- Full test suite with coverage
- Linting (golangci-lint)
See `.github/workflows/` for details.
---
## Installation as CLI
### From Source
```bash
go build -o ~/go/bin/pinchtab ./cmd/pinchtab
```
Then use anywhere:
```bash
pinchtab help
pinchtab --version
```
### Via npm (released builds)
```bash
npm install -g pinchtab
pinchtab --version
```
---
## Resources
- **GitHub Repository:** https://github.com/pinchtab/pinchtab
- **Go Documentation:** https://golang.org/doc/
- **Chrome DevTools Protocol:** https://chromedevtools.github.io/devtools-protocol/
- **Chromedp Library:** https://github.com/chromedp/chromedp
---
## Troubleshooting
### Environment Issues
**First step:** Run doctor to verify your setup:
```bash
./dev doctor
```
This will tell you exactly what's missing or misconfigured.
### Common Issues
**"Go version too old"**
- Install Go 1.25+ from https://go.dev/dl/
- Verify: `go version`
**"golangci-lint: command not found"**
- Install: `brew install golangci-lint`
- Or: `go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest`
**"Git hooks not running on commit"**
- Run: `./scripts/install-hooks.sh`
- Or: `./dev doctor` (prompts to install)
**"Chrome not found"**
- Install Chromium: `brew install chromium` (macOS)
- Or: `sudo apt install chromium-browser` (Linux)
**"Port 9867 already in use"**
- Check: `lsof -i :9867`
- Stop other instance or use different port: `BRIDGE_PORT=9868 ./pinchtab`
**Build fails**
1. Verify dependencies: `go mod download`
2. Clean cache: `go clean -cache`
3. Rebuild: `go build ./cmd/pinchtab`
---
## Support
Issues? Check:
1. Run `./dev doctor` first
2. All dependencies installed and correct versions?
3. Port 9867 available?
4. Check logs: `tail -f pinchtab.log`
See `docs/` for guides and examples.
|