mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
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:
1 parent
358abbf20e
commit
da6cad8b3a
51 files changed
+4276
-353
No files matched your search
@@ -0,0 +1,214 @@
|
||||
# Contributing
|
||||
|
||||
Guide for contributing to OpenCode Manager.
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Fork the repository
|
||||
2. Clone your fork
|
||||
3. Set up local development (see [Local Setup](setup.md))
|
||||
4. Create a feature branch
|
||||
5. Make changes
|
||||
6. Submit a pull request
|
||||
|
||||
## Code Style
|
||||
|
||||
### General Guidelines
|
||||
|
||||
- **No comments** - Code should be self-documenting
|
||||
- **No console.log** - Use proper logging
|
||||
- **Strict TypeScript** - Proper typing everywhere
|
||||
- **Named imports** - No default imports
|
||||
- **DRY principles** - Don't repeat yourself
|
||||
- **SOLID design** - Follow SOLID principles
|
||||
|
||||
### Backend (Bun + Hono)
|
||||
|
||||
```typescript
|
||||
// Route handler
|
||||
app.get('/api/repos', async (c) => {
|
||||
const repos = await repoService.listAll()
|
||||
return c.json(repos)
|
||||
})
|
||||
|
||||
// Service
|
||||
export const repoService = {
|
||||
async listAll(): Promise<Repository[]> {
|
||||
return db.query.repositories.findMany()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Guidelines:
|
||||
|
||||
- Use Zod for validation
|
||||
- Async/await (no .then() chains)
|
||||
- Structured error handling
|
||||
- Follow existing patterns
|
||||
|
||||
### Frontend (React + Vite)
|
||||
|
||||
```typescript
|
||||
import { useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useRepositories } from '@/hooks/useRepositories'
|
||||
|
||||
export function RepoList() {
|
||||
const { data: repos } = useRepositories()
|
||||
|
||||
return (
|
||||
<div>
|
||||
{repos?.map(repo => (
|
||||
<RepoCard key={repo.id} repo={repo} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Guidelines:
|
||||
|
||||
- Use `@/` alias for imports
|
||||
- React Query for server state
|
||||
- React Hook Form + Zod for forms
|
||||
- Radix UI + Tailwind for components
|
||||
|
||||
## Pull Request Process
|
||||
|
||||
### Before Submitting
|
||||
|
||||
1. **Run linting**: `pnpm lint`
|
||||
2. **Run tests**: `pnpm test`
|
||||
3. **Check types**: `pnpm typecheck`
|
||||
4. **Test manually**: Verify your changes work
|
||||
|
||||
### PR Guidelines
|
||||
|
||||
- Keep PRs focused on a single feature/fix
|
||||
- Write clear commit messages
|
||||
- Include tests for new functionality
|
||||
- Update documentation if needed
|
||||
- Reference related issues
|
||||
|
||||
### Commit Messages
|
||||
|
||||
Format: `type: brief description`
|
||||
|
||||
Types:
|
||||
- `feat` - New feature
|
||||
- `fix` - Bug fix
|
||||
- `docs` - Documentation
|
||||
- `refactor` - Code refactoring
|
||||
- `test` - Adding tests
|
||||
- `chore` - Maintenance
|
||||
|
||||
Examples:
|
||||
```
|
||||
feat: add file upload progress indicator
|
||||
fix: resolve session expiry on mobile
|
||||
docs: update installation guide
|
||||
refactor: extract git service from routes
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
### Writing Tests
|
||||
|
||||
```typescript
|
||||
import { expect, test, describe, beforeEach } from 'bun:test'
|
||||
|
||||
describe('featureName', () => {
|
||||
beforeEach(() => {
|
||||
// Setup
|
||||
})
|
||||
|
||||
test('should do something', async () => {
|
||||
const result = await doSomething()
|
||||
expect(result).toBe(expected)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### Coverage Requirements
|
||||
|
||||
- Minimum 80% coverage
|
||||
- Cover edge cases
|
||||
- Test error conditions
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
# All tests
|
||||
pnpm test
|
||||
|
||||
# With coverage
|
||||
cd backend && bun test --coverage
|
||||
|
||||
# Single file
|
||||
cd backend && bun test path/to/test.ts
|
||||
```
|
||||
|
||||
## Architecture Decisions
|
||||
|
||||
### Why Bun?
|
||||
|
||||
- Fast startup and execution
|
||||
- Built-in TypeScript support
|
||||
- SQLite driver included
|
||||
- Modern JavaScript runtime
|
||||
|
||||
### Why Hono?
|
||||
|
||||
- Lightweight and fast
|
||||
- TypeScript-first
|
||||
- Works with Bun natively
|
||||
- Simple, Express-like API
|
||||
|
||||
### Why React Query?
|
||||
|
||||
- Automatic caching and refetching
|
||||
- Server state management
|
||||
- Optimistic updates
|
||||
- SSE support for streaming
|
||||
|
||||
### Why Radix UI?
|
||||
|
||||
- Accessible by default
|
||||
- Unstyled (pairs with Tailwind)
|
||||
- Headless components
|
||||
- Production-ready
|
||||
|
||||
## Adding Features
|
||||
|
||||
### New API Endpoint
|
||||
|
||||
1. Create route in `backend/src/routes/`
|
||||
2. Add service logic in `backend/src/services/`
|
||||
3. Define types in `shared/`
|
||||
4. Add tests
|
||||
5. Update API client in frontend
|
||||
|
||||
### New UI Component
|
||||
|
||||
1. Create component in `frontend/src/components/`
|
||||
2. Use Radix UI primitives if applicable
|
||||
3. Style with Tailwind
|
||||
4. Add to relevant page
|
||||
5. Test responsiveness
|
||||
|
||||
### New Feature Flag
|
||||
|
||||
1. Add to settings schema
|
||||
2. Create migration if needed
|
||||
3. Add UI toggle in settings
|
||||
4. Check flag in relevant code
|
||||
|
||||
## Getting Help
|
||||
|
||||
- **Questions**: Open a GitHub Discussion
|
||||
- **Bugs**: Open a GitHub Issue
|
||||
- **Features**: Open a GitHub Issue with `feature` label
|
||||
|
||||
## License
|
||||
|
||||
By contributing, you agree that your contributions will be licensed under the MIT License.
|
||||
@@ -0,0 +1,232 @@
|
||||
# Local Development Setup
|
||||
|
||||
Guide for setting up a local development environment.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- [pnpm](https://pnpm.io/installation) - Package manager (required for workspaces)
|
||||
- [Bun](https://bun.sh) - Backend runtime
|
||||
- [OpenCode TUI](https://opencode.ai) - `npm install -g @opencode/tui`
|
||||
- Node.js 18+
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/chriswritescode-dev/opencode-manager.git
|
||||
cd opencode-manager
|
||||
|
||||
# Install dependencies
|
||||
pnpm install
|
||||
|
||||
# Copy environment configuration
|
||||
cp .env.example .env
|
||||
|
||||
# Start development servers
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
This starts:
|
||||
|
||||
- **Backend** on http://localhost:5003
|
||||
- **Frontend** on http://localhost:5173 (with HMR)
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
opencode-manager/
|
||||
├── backend/ # Bun + Hono API server
|
||||
│ ├── src/
|
||||
│ │ ├── routes/ # API route handlers
|
||||
│ │ ├── services/ # Business logic
|
||||
│ │ ├── db/ # Database schema and queries
|
||||
│ │ └── index.ts # Entry point
|
||||
│ └── tests/ # Backend tests
|
||||
├── frontend/ # React + Vite SPA
|
||||
│ ├── src/
|
||||
│ │ ├── components/ # UI components
|
||||
│ │ ├── pages/ # Page components
|
||||
│ │ ├── hooks/ # Custom React hooks
|
||||
│ │ ├── api/ # API client
|
||||
│ │ └── lib/ # Utilities
|
||||
│ └── public/ # Static assets
|
||||
├── shared/ # Shared types and utilities
|
||||
└── docker/ # Docker configuration
|
||||
```
|
||||
|
||||
## Available Scripts
|
||||
|
||||
### Root Level
|
||||
|
||||
```bash
|
||||
pnpm dev # Start both backend and frontend
|
||||
pnpm build # Build both packages
|
||||
pnpm lint # Lint both packages
|
||||
pnpm test # Run all tests
|
||||
```
|
||||
|
||||
### Backend
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
bun run dev # Start with hot reload
|
||||
bun test # Run tests
|
||||
bun test <file> # Run single test file
|
||||
bun run lint # ESLint
|
||||
bun run typecheck # TypeScript check
|
||||
```
|
||||
|
||||
### Frontend
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
pnpm dev # Start Vite dev server
|
||||
pnpm build # Production build
|
||||
pnpm lint # ESLint
|
||||
pnpm typecheck # TypeScript check
|
||||
```
|
||||
|
||||
## Database
|
||||
|
||||
Using Better SQLite3 with Drizzle ORM.
|
||||
|
||||
### Location
|
||||
|
||||
- **Development**: `./backend/data/opencode.db`
|
||||
- **Docker**: `/app/data/opencode.db`
|
||||
|
||||
### Schema Changes
|
||||
|
||||
1. Edit schema in `backend/src/db/schema.ts`
|
||||
2. Generate migration: `cd backend && bun run db:generate`
|
||||
3. Apply migration: `cd backend && bun run db:migrate`
|
||||
|
||||
### Inspection
|
||||
|
||||
```bash
|
||||
sqlite3 ./backend/data/opencode.db
|
||||
|
||||
# Useful commands
|
||||
.tables # List tables
|
||||
.schema users # Show table schema
|
||||
SELECT * FROM users; # View data
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
# All tests
|
||||
cd backend && bun test
|
||||
|
||||
# Single file
|
||||
cd backend && bun test src/services/repo.test.ts
|
||||
|
||||
# With coverage
|
||||
cd backend && bun test --coverage
|
||||
```
|
||||
|
||||
### Writing Tests
|
||||
|
||||
```typescript
|
||||
import { expect, test, describe } from 'bun:test'
|
||||
import { repoService } from '../src/services/repo'
|
||||
|
||||
describe('repoService', () => {
|
||||
test('listAll returns repositories', async () => {
|
||||
const repos = await repoService.listAll()
|
||||
expect(Array.isArray(repos)).toBe(true)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### Coverage Requirements
|
||||
|
||||
Minimum 80% coverage is enforced.
|
||||
|
||||
## Debugging
|
||||
|
||||
### Backend
|
||||
|
||||
Logs output to terminal when running `pnpm dev`.
|
||||
|
||||
For more detailed debugging:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
DEBUG=* bun run dev
|
||||
```
|
||||
|
||||
### Frontend
|
||||
|
||||
1. Open browser DevTools (F12)
|
||||
2. Check Console for errors
|
||||
3. Check Network tab for API calls
|
||||
4. Use React DevTools extension
|
||||
|
||||
### VS Code
|
||||
|
||||
Launch configurations are provided in `.vscode/launch.json`:
|
||||
|
||||
- **Debug Backend** - Attach debugger to backend
|
||||
- **Debug Frontend** - Launch Chrome with debugging
|
||||
|
||||
## Building
|
||||
|
||||
### Development Build
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### Production Build
|
||||
|
||||
```bash
|
||||
NODE_ENV=production pnpm build
|
||||
```
|
||||
|
||||
### Docker Build
|
||||
|
||||
```bash
|
||||
docker build -t opencode-manager .
|
||||
```
|
||||
|
||||
## Common Issues
|
||||
|
||||
### Port Already in Use
|
||||
|
||||
```bash
|
||||
# Find process using port
|
||||
lsof -i :5003
|
||||
|
||||
# Kill process
|
||||
kill -9 <PID>
|
||||
```
|
||||
|
||||
### Module Not Found
|
||||
|
||||
```bash
|
||||
# Clear node_modules and reinstall
|
||||
rm -rf node_modules
|
||||
rm -rf */node_modules
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### TypeScript Errors
|
||||
|
||||
```bash
|
||||
# Check types
|
||||
pnpm typecheck
|
||||
|
||||
# Clear TypeScript cache
|
||||
rm -rf */tsconfig.tsbuildinfo
|
||||
```
|
||||
|
||||
### Database Issues
|
||||
|
||||
```bash
|
||||
# Reset database
|
||||
rm -f backend/data/opencode.db
|
||||
pnpm dev # Database is recreated
|
||||
```
|
||||
Reference in new issue
Block a user