Add comprehensive documentation and download feature (#83)

* fix: markdown files now default to rendered view and render properly

- Add .md and .mdx MIME type support in backend (files.ts, defaults.ts)
- Add key props to FilePreview components to force proper remounting when switching files
- Fix markdown file detection with case-insensitive extension check
- Reset markdownPreview state when file changes to ensure correct default view
- Add onContentLoaded callback to VirtualizedTextView for reactive content updates
- Add fullContent state to properly handle large markdown file rendering
- Add error handling for async content loading to prevent blank screens
- Reduce loading timeout from 50ms to 0ms for more responsive loading

Fixes issues where:
- Markdown files opened in raw view instead of rendered view
- Large markdown files (12k+ lines) showed blank after loading completed
- State persisted incorrectly when switching between different file types

* Add directory download feature with ZIP archive support

* Improve voice recording UX with loading states and better transcript handling

* Fix auth config for prod/dev ports and add documentation

Update AUTH_TRUSTED_ORIGINS and PASSKEY_ORIGIN to use backend port 5003 (frontend uses 5173 in dev). Add comprehensive auth documentation covering secrets, trusted origins, admin reset, and passkeys. Update README and add mkdocs config.

* Remove roadmap section from README
This commit is contained in:
Chris Scott authored and GitHub committed 2026-01-26 23:09:27 -05:00
1 parent 358abbf20e
commit da6cad8b3a
51 files changed
+4276 -353

No files matched your search

+190
View File
@@ -0,0 +1,190 @@
# Authentication
OpenCode Manager uses single-user authentication designed for personal deployments.
## Overview
The authentication system supports:
- Email/password login
- Passkey/WebAuthn authentication
- OAuth social login (optional)
- Session-based auth with secure cookies
## First-Run Setup
On first launch with no admin account:
1. You're redirected to the Setup page
2. Create your admin account
3. Optionally configure providers
4. Start using the application
## Pre-Configured Admin
Skip interactive setup for automated deployments:
```bash
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=your-secure-password
```
When set:
- Admin user is created automatically
- Setup wizard is skipped
- Registration is disabled
## Password Reset
If you forget your password:
1. Set environment variables:
```bash
ADMIN_EMAIL=your@email.com
ADMIN_PASSWORD=new-password
ADMIN_PASSWORD_RESET=true
```
2. Restart the application:
```bash
docker-compose restart
```
3. Log in with new password
4. Remove `ADMIN_PASSWORD_RESET=true` from environment
!!! warning
Remove the reset flag after successful reset to prevent accidental password changes.
## Session Security
### AUTH_SECRET
Required for production. Encrypts session data.
Generate:
```bash
openssl rand -base64 32
```
Configure:
```bash
AUTH_SECRET=your-generated-secret
```
### Session Duration
Sessions last until:
- User logs out
- Browser is closed (unless "Remember me")
- Session expires (configurable)
### Secure Cookies
By default, cookies require HTTPS in production:
```bash
# For HTTP on trusted networks only
AUTH_SECURE_COOKIES=false
```
## Remote Access
### Local Network (HTTP)
For accessing via IP on a local network:
```bash
# Include all access URLs (both frontend and backend)
AUTH_TRUSTED_ORIGINS=http://localhost:5173,http://localhost:5003,http://192.168.1.244:5003
# Disable secure cookies for HTTP
AUTH_SECURE_COOKIES=false
```
### Production (HTTPS)
For production with HTTPS:
```bash
AUTH_TRUSTED_ORIGINS=https://yourdomain.com
# AUTH_SECURE_COOKIES defaults to true
```
## Passkeys
Passwordless authentication using WebAuthn.
### Setup
Configure your domain:
```bash
# Local development (use backend port)
PASSKEY_RP_ID=localhost
PASSKEY_RP_NAME=OpenCode Manager
PASSKEY_ORIGIN=http://localhost:5003
# Production
PASSKEY_RP_ID=yourdomain.com
PASSKEY_RP_NAME=OpenCode Manager
PASSKEY_ORIGIN=https://yourdomain.com
# Local network access
PASSKEY_RP_ID=localhost
PASSKEY_RP_NAME=OpenCode Manager
PASSKEY_ORIGIN=http://192.168.1.244:5003
```
!!! note "Port Selection"
- Use the **backend** port (5003) for PASSKEY_ORIGIN
- Not the frontend port (5173)
- The origin must match where the auth API is served
### Adding a Passkey
1. Log in with password
2. Go to **Settings > Security**
3. Click **Add Passkey**
4. Follow browser/device prompts
5. Name your passkey
### Supported Authenticators
- Touch ID / Face ID (macOS, iOS)
- Windows Hello
- Hardware security keys (YubiKey, etc.)
- Android fingerprint/face
### Passkey Requirements
- RP ID must match the domain
- Origin must match exactly (including port)
- HTTPS recommended (required for some browsers)
## Troubleshooting
### Can't Log In
1. Clear browser cookies
2. Check credentials are correct
3. Verify AUTH_SECRET hasn't changed
4. Check AUTH_TRUSTED_ORIGINS includes your URL
### Session Keeps Expiring
1. Check AUTH_SECRET is persistent across restarts
2. Verify cookies aren't being blocked
3. Check AUTH_SECURE_COOKIES setting
### Passkey Not Working
1. Verify PASSKEY_RP_ID matches domain
2. Check PASSKEY_ORIGIN is exact
3. Try a different browser
4. Ensure WebAuthn is supported
+347
View File
@@ -0,0 +1,347 @@
# Docker Configuration
Advanced Docker setup and configuration options.
## Basic Setup
```bash
git clone https://github.com/chriswritescode-dev/opencode-manager.git
cd opencode-manager
docker-compose up -d
```
## docker-compose.yml
Default configuration:
```yaml
version: '3.8'
services:
opencode-manager:
build: .
container_name: opencode-manager
ports:
- "5003:5003" # OpenCode Manager
- "5100:5100" # Dev server 1
- "5101:5101" # Dev server 2
- "5102:5102" # Dev server 3
- "5103:5103" # Dev server 4
volumes:
- ./workspace:/workspace
- ./data:/app/data
- opencode-cache:/root/.opencode
environment:
- NODE_ENV=production
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5003/health"]
interval: 30s
timeout: 10s
retries: 3
volumes:
opencode-cache:
```
## Port Configuration
### Main Application
The application runs on port 5003 by default:
```yaml
ports:
- "5003:5003"
```
Change the host port if needed:
```yaml
ports:
- "8080:5003" # Access at localhost:8080
```
### Dev Server Ports
Ports 5100-5103 are exposed for running dev servers inside repositories:
```yaml
ports:
- "5100:5100"
- "5101:5101"
- "5102:5102"
- "5103:5103"
```
Configure your dev server to use one of these ports:
=== "Vite"
```typescript
// vite.config.ts
export default {
server: {
port: 5100,
host: '0.0.0.0'
}
}
```
=== "Next.js"
```bash
next dev -p 5100 -H 0.0.0.0
```
=== "Express"
```javascript
app.listen(5100, '0.0.0.0')
```
## Volume Mounts
### Workspace
Repository storage:
```yaml
volumes:
- ./workspace:/workspace
```
All cloned repositories are stored here. The directory is created automatically.
### Data
Database and configuration:
```yaml
volumes:
- ./data:/app/data
```
Contains:
- SQLite database
- User settings
- Session data
### OpenCode Cache
OpenCode runtime cache:
```yaml
volumes:
- opencode-cache:/root/.opencode
```
Using a named volume for better performance.
## Environment Variables
### Using .env File
Create `.env` in project root:
```bash
AUTH_SECRET=your-secret-here
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=secure-password
```
Reference in docker-compose.yml:
```yaml
env_file:
- .env
```
### Inline Environment
Set directly in docker-compose.yml:
```yaml
environment:
- NODE_ENV=production
- AUTH_SECRET=your-secret-here
- ADMIN_EMAIL=admin@example.com
```
## Health Checks
The container includes health checks:
```yaml
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5003/health"]
interval: 30s
timeout: 10s
retries: 3
```
Check health status:
```bash
docker inspect --format='{{.State.Health.Status}}' opencode-manager
```
## Resource Limits
Limit container resources:
```yaml
services:
opencode-manager:
# ... other config
deploy:
resources:
limits:
cpus: '2'
memory: 4G
reservations:
cpus: '0.5'
memory: 1G
```
## Networking
### Custom Network
Create an isolated network:
```yaml
services:
opencode-manager:
networks:
- opencode-net
networks:
opencode-net:
driver: bridge
```
### Host Network
Use host networking (Linux only):
```yaml
services:
opencode-manager:
network_mode: host
```
## Commands
### Basic Operations
```bash
# Start
docker-compose up -d
# Stop
docker-compose down
# Restart
docker-compose restart
# View logs
docker-compose logs -f
# View logs (last 100 lines)
docker-compose logs --tail 100
```
### Maintenance
```bash
# Rebuild image
docker-compose build
# Rebuild without cache
docker-compose build --no-cache
# Pull latest base images
docker-compose pull
# Update and restart
docker-compose pull && docker-compose up -d --build
```
### Debugging
```bash
# Access shell
docker exec -it opencode-manager sh
# View running processes
docker exec opencode-manager ps aux
# Check disk usage
docker exec opencode-manager df -h
# View environment
docker exec opencode-manager env
```
## Global Agent Instructions
The container creates a default `AGENTS.md` file at `/workspace/.config/opencode/AGENTS.md`.
### Default Content
Instructions for AI agents working in the container:
- Reserved ports information
- Available dev server ports
- Docker-specific guidelines
### Editing
**Via UI:** Settings > OpenCode > Global Agent Instructions
**Via File:**
```bash
docker exec -it opencode-manager vi /workspace/.config/opencode/AGENTS.md
```
### Precedence
Global instructions merge with repository-specific `AGENTS.md` files. Repository instructions take precedence.
## Troubleshooting
### Container Won't Start
```bash
# Check logs
docker-compose logs
# Check if port is in use
lsof -i :5003
# Try running in foreground
docker-compose up
```
### Permission Issues
```bash
# Fix workspace permissions
sudo chown -R $(id -u):$(id -g) ./workspace ./data
# Or run with specific user
docker-compose run --user $(id -u):$(id -g) opencode-manager
```
### Out of Disk Space
```bash
# Check Docker disk usage
docker system df
# Clean up unused resources
docker system prune -a
# Remove unused volumes
docker volume prune
```
+111
View File
@@ -0,0 +1,111 @@
# Environment Variables
Complete reference for all configuration options.
## Authentication
| Variable | Description | Default |
|----------|-------------|---------|
| `AUTH_SECRET` | Session encryption secret (required for production) | Auto-generated in dev |
| `ADMIN_EMAIL` | Pre-configured admin email | - |
| `ADMIN_PASSWORD` | Pre-configured admin password | - |
| `ADMIN_PASSWORD_RESET` | Set to `true` to reset admin password | `false` |
| `AUTH_TRUSTED_ORIGINS` | Comma-separated list of trusted origins (frontend + backend) | `http://localhost:5173,http://localhost:5003` |
| `AUTH_SECURE_COOKIES` | Use secure cookies (HTTPS only) | `true` in prod |
| `AUTH_SECURE_COOKIES` | Use secure cookies (HTTPS only) | `true` in prod |
## OAuth Providers
| Variable | Description |
|----------|-------------|
| `GITHUB_CLIENT_ID` | GitHub OAuth client ID |
| `GITHUB_CLIENT_SECRET` | GitHub OAuth client secret |
| `GOOGLE_CLIENT_ID` | Google OAuth client ID |
| `GOOGLE_CLIENT_SECRET` | Google OAuth client secret |
| `DISCORD_CLIENT_ID` | Discord OAuth client ID |
| `DISCORD_CLIENT_SECRET` | Discord OAuth client secret |
## Passkeys (WebAuthn)
| Variable | Description | Default |
|----------|-------------|---------|
| `PASSKEY_RP_ID` | Relying party ID (your domain) | `localhost` |
| `PASSKEY_RP_NAME` | Display name for passkey prompts | `OpenCode Manager` |
| `PASSKEY_ORIGIN` | Origin URL for WebAuthn (backend port) | `http://localhost:5003` |
!!! tip "IMPORTANT"
- `PASSKEY_ORIGIN` must use the **backend** port (5003), not the frontend port (5173)
- The origin must exactly match where the auth API is served
## Server
| Variable | Description | Default |
|----------|-------------|---------|
| `PORT` | Server port | `5003` |
| `NODE_ENV` | Environment (`development` or `production`) | `development` |
| `WORKSPACE_PATH` | Path to workspace directory | `/workspace` |
## Example .env File
```bash
# Required for production
AUTH_SECRET=generate-with-openssl-rand-base64-32
# Pre-configured admin (optional)
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=your-secure-password
# Remote access (optional - include both frontend and backend ports)
AUTH_TRUSTED_ORIGINS=http://localhost:5173,http://localhost:5003,http://192.168.1.244:5003
AUTH_SECURE_COOKIES=false
# OAuth providers (optional)
GITHUB_CLIENT_ID=your-client-id
GITHUB_CLIENT_SECRET=your-client-secret
# Passkeys (optional - use BACKEND port)
PASSKEY_RP_ID=localhost
PASSKEY_RP_NAME=OpenCode Manager
PASSKEY_ORIGIN=http://localhost:5003
```
## Generating Secrets
### AUTH_SECRET
Generate a secure random secret:
```bash
openssl rand -base64 32
```
Output example:
```
K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=
```
!!! warning "Security"
- Never commit AUTH_SECRET to version control
- Use different secrets for development and production
- Rotate secrets periodically
## Environment Precedence
Variables are loaded in this order (later overrides earlier):
1. System environment variables
2. `.env` file in project root
3. Docker Compose `environment` section
4. Docker Compose `env_file` reference
## Validating Configuration
Check your configuration:
```bash
# View current environment (inside container)
docker exec opencode-manager env | grep -E '^(AUTH|ADMIN|PASSKEY)'
# Check if secrets are set (without revealing values)
docker exec opencode-manager sh -c 'if [ -n "$AUTH_SECRET" ]; then echo "AUTH_SECRET: set"; else echo "AUTH_SECRET: NOT SET"; fi'
```
+172
View File
@@ -0,0 +1,172 @@
# OAuth Providers
Configure social login with OAuth providers.
## Supported Providers
| Provider | Purpose |
|----------|---------|
| GitHub | Social login |
| Google | Social login |
| Discord | Social login |
## GitHub OAuth
### Create OAuth App
1. Go to [GitHub Developer Settings](https://github.com/settings/developers)
2. Click **OAuth Apps** > **New OAuth App**
3. Fill in:
- **Application name**: `OpenCode Manager`
- **Homepage URL**: `http://localhost:5003`
- **Authorization callback URL**: `http://localhost:5003/api/auth/callback/github`
4. Click **Register application**
5. Copy **Client ID**
6. Generate and copy **Client Secret**
### Configure
```bash
GITHUB_CLIENT_ID=your-client-id
GITHUB_CLIENT_SECRET=your-client-secret
```
### Callback URL
Adjust the callback URL for your environment:
| Environment | Callback URL |
|-------------|--------------|
| Local | `http://localhost:5003/api/auth/callback/github` |
| Production | `https://yourdomain.com/api/auth/callback/github` |
## Google OAuth
### Create OAuth Client
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project or select existing
3. Go to **APIs & Services** > **Credentials**
4. Click **Create Credentials** > **OAuth client ID**
5. Select **Web application**
6. Configure:
- **Name**: `OpenCode Manager`
- **Authorized redirect URIs**: `http://localhost:5003/api/auth/callback/google`
7. Click **Create**
8. Copy **Client ID** and **Client Secret**
### Configure
```bash
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
```
### Consent Screen
You may need to configure the OAuth consent screen:
1. Go to **APIs & Services** > **OAuth consent screen**
2. Select **External** (or Internal for Workspace)
3. Fill in required fields
4. Add scopes: `email`, `profile`
5. Save
## Discord OAuth
### Create Application
1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
2. Click **New Application**
3. Name it `OpenCode Manager`
4. Go to **OAuth2** section
5. Add redirect: `http://localhost:5003/api/auth/callback/discord`
6. Copy **Client ID** and **Client Secret**
### Configure
```bash
DISCORD_CLIENT_ID=your-client-id
DISCORD_CLIENT_SECRET=your-client-secret
```
## Using OAuth Login
Once configured:
1. Go to the login page
2. Click the provider button (GitHub, Google, Discord)
3. Authorize in the popup
4. You're logged in
### First OAuth Login
On first OAuth login:
- Account is created automatically
- Email from provider is used
- No password is set (OAuth-only)
### Linking Accounts
If you have an existing password account:
1. Log in with password
2. Go to **Settings > Connected Accounts**
3. Click **Connect** for a provider
4. Authorize the connection
## Production Considerations
### Update Callback URLs
Before deploying, update OAuth apps with production URLs:
```
https://yourdomain.com/api/auth/callback/github
https://yourdomain.com/api/auth/callback/google
https://yourdomain.com/api/auth/callback/discord
```
### Verify Domains
Some providers require domain verification:
- Google requires verification for production
- Discord may require verification for many users
### Secrets Management
- Never commit OAuth secrets to version control
- Use environment variables or secrets management
- Rotate secrets periodically
## Troubleshooting
### Redirect URI Mismatch
Error: "redirect_uri_mismatch" or similar
**Solution:**
1. Check callback URL in provider settings
2. Ensure exact match (including trailing slash)
3. Verify protocol (http vs https)
4. Check port number
### Invalid Client
Error: "invalid_client" or "unauthorized_client"
**Solution:**
1. Verify Client ID is correct
2. Check Client Secret hasn't changed
3. Ensure OAuth app is not suspended
### Access Denied
Error: "access_denied" or user cancels
**Solution:**
1. User may have denied permission
2. Check required scopes are configured
3. Verify consent screen is configured properly