Skip to content

Commit 729bff2

Browse files
CopilotPeterDaveHelloqodo-code-review[bot]
committed
Add comprehensive GitHub Copilot instructions
Co-authored-by: PeterDaveHello <3691490+PeterDaveHello@users.noreply.github.com> Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent 1e5f07e commit 729bff2

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed

.github/copilot-instructions.md

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# ChatGPTBox - Browser Extension
2+
3+
ChatGPTBox is a cross-platform browser extension that deeply integrates ChatGPT and other AI models into web browsing. The extension provides chat dialogs, selection tools, site-specific adapters, and AI-powered features across the web.
4+
5+
Always reference these instructions first and fall back to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Bootstrap and Build
10+
11+
- Install dependencies: `npm ci` -- takes ~30 seconds. npm audit warnings may appear; for development-only dependencies they generally do not affect the shipped extension. Review and address runtime-impacting advisories separately.
12+
- Development build: `npm run dev` -- takes ~13 seconds initial build, runs webpack in watch mode. Do not kill mid-compilation, but stop gracefully when switching branches or after dependency/config changes, then restart to avoid stale watchers and inconsistent state.
13+
- Production build: `npm run build` -- takes ~33 seconds. If it exceeds 10 minutes, treat as hung: confirm Node 20+, clear caches (`rm -rf node_modules && npm ci`), clear build caches (e.g., `rm -rf node_modules/.cache build/ dist/`), and rerun. Avoid force-killing mid-bundle; stop, fix, then rebuild.
14+
- Format code: `npm run pretty` -- uses Prettier to format all JS/JSX/CSS files. Run this before linting.
15+
- Lint code: `npm run lint` -- takes ~3-5 seconds, uses ESLint.
16+
- Safari build: `npm run build:safari` -- only works on macOS with Xcode installed.
17+
18+
### Build Output Structure
19+
20+
Production build creates multiple variants in `build/` directory:
21+
22+
- `chromium/` - Chromium-based browsers (Chrome, Edge) with full features
23+
- `firefox/` - Firefox with manifest v2
24+
- `chromium-without-KaTeX-and-tiktoken/` - Minimal build without math rendering and token encoding
25+
- `firefox-without-KaTeX-and-tiktoken/` - Minimal Firefox build without math rendering and token encoding
26+
- Distribution artifacts: `.zip` for Chromium variants and `.xpi` for Firefox.
27+
28+
## Architecture Overview
29+
30+
### Key Components
31+
32+
- **Content Script** (`src/content-script/index.jsx`) - Injected into all web pages, provides main chat functionality
33+
- **Background Script** (`src/background/index.mjs`) - Handles browser APIs and cross-page communication
34+
- Chromium (Manifest v3): runs as a service worker
35+
- Firefox (Manifest v2): runs as a background page
36+
- **Popup** (`src/popup/`) - Extension popup interface accessible via browser toolbar
37+
- **Independent Panel** (`src/pages/IndependentPanel/`) - Standalone chat page and side panel
38+
- **Site Adapters** (`src/content-script/site-adapters/`) - Custom integrations for specific websites (Reddit, GitHub, YouTube, etc.)
39+
- **Selection Tools** (`src/content-script/selection-tools/`) - Text selection features (translate, summarize, explain, etc.)
40+
41+
### Manifests
42+
43+
- `src/manifest.json` - Manifest v3 for Chromium browsers
44+
- `src/manifest.v2.json` - Manifest v2 for Firefox
45+
- Note: background runs as service worker in MV3 and as background page in MV2.
46+
47+
## Testing and Validation
48+
49+
### Manual Browser Extension Testing (CRITICAL)
50+
51+
Since this is a browser extension with no automated tests, ALWAYS manually test functionality:
52+
53+
1. **Load Extension in Browser:**
54+
- Chrome: Go to `chrome://extensions/`, enable Developer Mode, click "Load unpacked", select `build/chromium/`
55+
- Firefox: Go to `about:debugging#/runtime/this-firefox`, click "Load Temporary Add-on", then choose the built add-on (select the `build/firefox/` folder or the generated `.xpi`, not `manifest.json`). Note: Temporary add-ons are removed on browser restart.
56+
- **Important**: Extension files cannot be tested by serving them via HTTP server - they must be loaded as a proper browser extension
57+
58+
2. **Core Functionality Tests:**
59+
- Press `Ctrl+B` (Windows/Linux) or `⌘+B` (macOS) to open the chat dialog on any webpage
60+
- Select text on a page, verify selection tools appear
61+
- Right-click and verify "Ask ChatGPT" context menu appears
62+
- Click extension icon to open popup
63+
- Press `Ctrl+Shift+H` (Windows/Linux) or `⌘+Shift+H` (macOS) to open the independent conversation page
64+
65+
3. **Site Integration Tests:**
66+
- Visit YouTube.com, verify video summary features work
67+
- Visit Reddit.com, verify ChatGPT integration appears in sidebar
68+
- Visit GitHub.com, verify code analysis features work
69+
- Visit Google.com search results, verify ChatGPT responses appear
70+
71+
4. **Configuration Tests:**
72+
- Open extension popup, navigate through tabs (General, Feature Pages, Modules > Selection Tools, Modules > Sites, Advanced)
73+
- Test API mode switching (Web API vs OpenAI API) under Modules > API Modes
74+
- If using Web APIs, ensure you are signed in to the provider in the same browser profile; if using API Keys, configure valid keys in settings
75+
- Verify language settings work
76+
77+
### Build Validation
78+
79+
Ensure these files exist in `build/chromium/` after successful build:
80+
81+
- `manifest.json` (~2.4KB, contains proper extension metadata)
82+
- `background.js` (~427KB, service worker)
83+
- `content-script.js` (~1MB, main functionality)
84+
- `content-script.css` (~650KB, styling)
85+
- `popup.html` and `popup.js` (popup interface)
86+
- `IndependentPanel.html` and `IndependentPanel.js` (standalone chat page)
87+
- `shared.js` (typically around ~2MB; size may vary slightly by environment and dependencies)
88+
- `logo.png` (~18KB, extension icon)
89+
- `rules.json` (~1.4KB, declarative net request rules)
90+
91+
### Verify Script Limitations
92+
93+
- `npm run verify` tests search engine configurations by attempting to fetch search results from external search engines (Bing, Yahoo, Baidu, Naver) to validate that the site adapters can parse and handle real responses.
94+
- **Successful validation**: For each search engine, the script expects to receive a valid HTTP response (status 200) and to successfully extract and parse search results using the corresponding site adapter. If the adapter can parse the expected data structure from the response, the test is considered a pass.
95+
- **Expected failure modes**: In sandboxed or CI environments, the script may fail due to network restrictions (e.g., DNS errors, timeouts, connection refused), HTTP errors (e.g., 403, 429, 503), or changes in the search engine's response format. These failures are expected and do **not** indicate build problems.
96+
- If you see network or HTTP errors during `npm run verify`, you can safely ignore them unless you are specifically testing or updating site adapter logic.
97+
98+
## Development Workflow
99+
100+
### Code Style and Quality
101+
102+
- ALWAYS run `npm run lint` before committing - CI will fail otherwise
103+
- ALWAYS run `npm run pretty` to format code consistently
104+
- ESLint configuration in `.eslintrc.json` enforces React/JSX standards
105+
- Prettier configuration in `.prettierrc` handles formatting
106+
107+
### Pre-commit Hooks
108+
109+
The repository uses pre-commit hooks that automatically:
110+
111+
1. Run prettier formatting
112+
2. Stage formatted files
113+
3. Run lint checks
114+
115+
### Common File Locations
116+
117+
- Configuration: `src/config/index.mjs`
118+
- API integrations: `src/services/apis/`
119+
- Localization: `src/_locales/`
120+
- UI components: `src/components/`
121+
- Utilities: `src/utils/`
122+
123+
### Key Directories
124+
125+
```text
126+
src/
127+
├── background/ # Background script/service worker
128+
├── components/ # Reusable UI components
129+
├── config/ # Configuration management
130+
├── content-script/ # Main content script and features
131+
│ ├── site-adapters/ # Website-specific integrations
132+
│ ├── selection-tools/ # Text selection features
133+
│ └── menu-tools/ # Context menu features
134+
├── pages/IndependentPanel/ # Standalone chat page
135+
├── popup/ # Extension popup
136+
├── services/ # API clients and wrappers
137+
└── utils/ # Helper functions
138+
```
139+
140+
## Platform-Specific Instructions
141+
142+
### Safari Build (macOS Only)
143+
144+
- Requires macOS with Xcode installed
145+
- Run `npm run build:safari`
146+
- Creates `Fission - ChatBox.app` bundle and `safari.dmg` installer
147+
- Uses `safari/build.sh` script with platform-specific patches
148+
149+
### Cross-Browser Compatibility
150+
151+
- Uses `webextension-polyfill` for API compatibility
152+
- Manifest v3 for Chromium browsers (Chrome, Edge, Opera, etc.)
153+
- Manifest v2 for Firefox
154+
- Different permission models between manifest versions
155+
156+
## AI Model Support
157+
158+
The extension supports multiple AI providers:
159+
160+
- **Web APIs** (free): ChatGPT, Claude, Kimi Moonshot (requires browser cookies)
161+
- **API Keys**: OpenAI GPT models, Claude API, OpenRouter, AI/ML, DeepSeek, Ollama
162+
- **Custom models**: Support for self-hosted and alternative API endpoints
163+
164+
## Troubleshooting
165+
166+
### Build Issues
167+
168+
- If webpack build fails, check Node.js version (requires Node 20+)
169+
- If Safari build fails, ensure you're on macOS with Xcode installed
170+
- "Module not found" errors usually indicate missing `npm ci`. If persisting, remove caches and lockfile: `rm -rf node_modules package-lock.json && npm ci`.
171+
172+
### Runtime Issues
173+
174+
- Extension not loading: Check console for manifest errors
175+
- API not working: Verify browser has required permissions and cookies
176+
- Selection tools not appearing: Check if content script loaded correctly
177+
178+
### Common Development Tasks
179+
180+
- Adding new site adapter: Create new file in `src/content-script/site-adapters/`
181+
- Adding new selection tool: Modify `src/content-script/selection-tools/`
182+
- Updating API integration: Modify files in `src/services/apis/`
183+
- Adding new UI component: Create in `src/components/`
184+
185+
## Time Expectations
186+
187+
- Do not interrupt builds or long-running commands unless they appear hung or unresponsive.
188+
- `npm ci`: ~30 seconds
189+
- `npm run build`: ~33 seconds (measured). Set timeout to 5–10 minutes to allow for slowdowns; if it exceeds this window and appears hung, confirm Node 20+, clear caches (`rm -rf node_modules && npm ci`) and build caches (`rm -rf node_modules/.cache build/ dist/`), then rerun.
190+
- `npm run dev`: ~13 seconds initial build, then watches for changes; use Ctrl+C to stop when switching branches or after config/dependency changes.
191+
- `npm run lint`: ~3–5 seconds
192+
- Manual extension testing: 5-10 minutes for thorough validation
193+
- Safari build: 2-5 minutes (macOS only)
194+
195+
## Critical Validation Steps
196+
197+
1. ALWAYS run `npm run build` after any code changes
198+
2. ALWAYS manually load and test the built extension in a browser - automated testing is not available
199+
3. ALWAYS verify the build creates the expected file structure with correct file sizes
200+
4. ALWAYS test core extension functionality (popup, content script injection, keyboard shortcuts)
201+
202+
Always build and manually test the extension in a browser before considering any change complete. Simply running the build is NOT sufficient - you must load the extension and test actual functionality.

0 commit comments

Comments
 (0)