Spaces:
Running
Running
File size: 7,399 Bytes
0646b18 |
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 |
# CUGA Frontend Workspaces
Monorepo for the CUGA browser extension and frontend tooling, managed with **pnpm workspaces**.
## π¦ Workspace Packages
- **`extension`**: Browser extension (Chrome/Edge/Firefox) that serves as the entry point to CUGA
- **`runtime`**: DOM/content-script runtime used by the extension and libraries
- **`shared`** (`@uiagent/shared`): Shared TypeScript utilities and types consumed by other packages
- **`agentic_chat`**: React-based frontend for the extension's side panel
- **`frontend`**: Alternative frontend implementation
## π§ Prerequisites
- **Node.js 18+**
- **pnpm 8+** (Package manager - install with `npm install -g pnpm`)
- **Chromium-based browser** (Chrome or Edge). Firefox supported via dedicated scripts.
## π Quick Start
### 1. Install Dependencies
From the workspace root (`frontend-workspaces/`):
```bash
pnpm install
```
This installs all workspace dependencies and runs post-install steps (e.g., `wxt prepare` in the extension).
### 2. Start the Backend Server
- Add `use_extension = true` to your `settings.toml` file under `advanced_features`
- Run the debug VS Code configuration or start the server through the main entrypoint
### 3. Run the Extension
Copy the environment file and start development:
```bash
cd extension
cp .env-example .env # Edit as needed
cd ..
pnpm --filter extension run dev
```
WXT will automatically open Chrome with the extension loaded.
## π pnpm Commands Reference
### Core Commands
| Task | Command |
|------|---------|
| **Install all dependencies** | `pnpm install` |
| **Build all workspaces** | `pnpm -r build` |
| **Clean all node_modules** | `pnpm -r clean` |
### Extension Commands
| Task | Command |
|------|---------|
| **Development (Chrome)** | `pnpm --filter extension run dev` |
| **Development (Firefox)** | `pnpm --filter extension run dev:firefox` |
| **Build for production** | `pnpm --filter extension run build` |
| **Build for Firefox** | `pnpm --filter extension run build:firefox` |
| **Release build (copy to releases/)** | `pnpm --filter extension run release` |
| **Release build for Firefox** | `pnpm --filter extension run release:firefox` |
| **Create distribution zip** | `pnpm --filter extension run zip` |
| **Run E2E tests** | `pnpm --filter extension run e2etest` |
| **Type checking** | `pnpm --filter extension run compile` |
### Frontend Commands
| Task | Command |
|------|---------|
| **Development server** | `pnpm --filter frontend run dev` |
| **Build for production** | `pnpm --filter frontend run build` |
| **Start production server** | `pnpm --filter frontend run start` |
### Agentic Chat Commands
| Task | Command |
|------|---------|
| **Development server** | `pnpm --filter agentic_chat run dev` |
| **Build for production** | `pnpm --filter agentic_chat run build` |
| **Run tests** | `pnpm --filter agentic_chat run test` |
| **Type checking** | `pnpm --filter agentic_chat run compile` |
### Shared Library Commands
| Task | Command |
|------|---------|
| **Build shared library** | `pnpm --filter @uiagent/shared run build` |
| **Watch mode** | `pnpm --filter @uiagent/shared run watch` |
| **Clean build** | `pnpm --filter @uiagent/shared run clean` |
### Runtime Commands
| Task | Command |
|------|---------|
| **Run tests** | `pnpm --filter runtime run test` |
## ποΈ Build Process
### Extension Build
1. **Prepare environment**:
```bash
cd extension
cp .env-example .env # Edit values as needed
```
2. **Build the extension**:
```bash
pnpm --filter extension run build
```
3. **Load in browser**:
- Open Chrome/Edge β Manage Extensions
- Enable Developer mode
- Load Unpacked β select `extension/.output/chrome-mv3/`
### Release Build
Build and copy to releases folder for distribution:
```bash
# Chrome/Edge release
pnpm --filter extension run release
# Firefox release
pnpm --filter extension run release:firefox
```
This builds the extension, cleans the releases folder, and copies the fresh output to:
- `extension/releases/chrome-mv3/` (Chrome/Edge)
- `extension/releases/firefox-mv2/` (Firefox)
### Distribution Build
Create a distributable zip file:
```bash
pnpm --filter extension run zip
```
Output will be in `extension/.output/`
## π Development Tips
### Working with Multiple Packages
```bash
# Run command in specific workspace
pnpm --filter extension run [command]
# Run command in all workspaces
pnpm -r run [command]
# Run command in workspaces matching pattern
pnpm --filter "*chat*" run build
```
### Dependency Management
```bash
# Add dependency to specific workspace
pnpm --filter extension add [package]
# Add dev dependency
pnpm --filter extension add -D [package]
# Add workspace dependency
pnpm --filter extension add agentic_chat@workspace:*
```
### Debugging
```bash
# Watch mode for shared library
pnpm --filter @uiagent/shared run watch
# Development with hot reload
pnpm --filter extension run dev -- --watch --mode development
```
## π Browser Support
### Chrome/Edge
- Full support with Manifest V3
- Hot reload during development
- Production builds ready for store submission
### Firefox
- Beta support with Manifest V2
- Requires manual `:has` pseudo-selector enablement
- Use `*:firefox` script variants
## π Troubleshooting
### Common Issues
**Extension not appearing after build:**
- Check terminal output for build directory
- Verify you're loading the correct `.output/` folder
**Type errors in shared library:**
```bash
pnpm --filter @uiagent/shared run build
# Then restart dev servers
```
**Dependency resolution issues:**
```bash
# Clean and reinstall
rm -rf node_modules pnpm-lock.yaml
find . -name "node_modules" -type d -exec rm -rf {} +
pnpm install
```
**Build failures:**
- Ensure all workspace dependencies use `workspace:*` protocol
- Check that shared library is built before extension
- Verify environment files are properly configured
### Firefox Specific
- Enable `:has` pseudo-selector: `about:config` β `layout.css.has-selector.enabled` β `true`
- Full support coming in Firefox 121+
## π Project Structure
```
frontend-workspaces/
βββ pnpm-workspace.yaml # pnpm workspace configuration
βββ package.json # Root package.json
βββ extension/ # Browser extension
β βββ src/
β βββ wxt.config.ts # WXT configuration
β βββ .output/ # Build output
βββ agentic_chat/ # React frontend
β βββ src/
β βββ dist/
βββ frontend/ # Alternative frontend
βββ shared/ # Shared utilities
β βββ src/
β βββ dist/
βββ runtime/ # Runtime utilities
```
## π Workflow Examples
### Full Development Setup
```bash
# 1. Install everything
pnpm install
# 2. Build shared library first
pnpm --filter @uiagent/shared run build
# 3. Start extension development
pnpm --filter extension run dev
```
### Production Build
```bash
# Build all packages
pnpm -r build
# Or build specific packages in order
pnpm --filter @uiagent/shared run build
pnpm --filter agentic_chat run build
pnpm --filter extension run build
```
### Testing
```bash
# Run all tests
pnpm -r test
# Test specific package
pnpm --filter extension run e2etest
``` |