Skip to content

Commit c12bd35

Browse files
PeterDaveHelloCopilotqodo-merge-pro[bot]
committed
Add comprehensive GitHub Copilot instructions
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
1 parent a2251fa commit c12bd35

File tree

1 file changed

+205
-0
lines changed

1 file changed

+205
-0
lines changed

.github/copilot-instructions.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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` -- 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` -- 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` -- Avoid force-killing mid-bundle; stop, fix, then rebuild.
14+
See "Time Expectations" and "Build Issues" for the hung-build policy and recovery steps.
15+
- Format code: `npm run pretty` -- uses Prettier to format all JS/JSX/CSS files. Run this before linting.
16+
- Lint code: `npm run lint` -- uses ESLint.
17+
- Safari build: `npm run build:safari` -- macOS with Xcode required.
18+
19+
### Build Output Structure
20+
21+
Production build creates multiple variants in `build/` directory:
22+
23+
- `chromium/` - Chromium-based browsers (Chrome, Edge) with full features
24+
- `firefox/` - Firefox with manifest v2
25+
- `chromium-without-katex-and-tiktoken/` - Minimal build without math rendering and token encoding
26+
- `firefox-without-katex-and-tiktoken/` - Minimal Firefox build without math rendering and token encoding
27+
- Distribution artifacts:
28+
- Chromium: `build/chromium-*.zip` (e.g., `build/chromium-<version>.zip`)
29+
- Firefox: `build/firefox-*.xpi` (e.g., `build/firefox-<version>.xpi`)
30+
- Safari: `Fission - ChatBox.app` and `safari.dmg` (see Safari Build section for details)
31+
32+
## Architecture Overview
33+
34+
### Key Components
35+
36+
- **Content Script** (`src/content-script/index.jsx`) - Injected into all web pages, provides main chat functionality
37+
- **Background Script** (`src/background/index.mjs`) - Handles browser APIs and cross-page communication
38+
- **Popup** (`src/popup/`) - Extension popup interface accessible via browser toolbar
39+
- **Independent Panel** (`src/pages/IndependentPanel/`) - Standalone chat page and side panel
40+
- **Site Adapters** (`src/content-script/site-adapters/`) - Custom integrations for specific websites (Reddit, GitHub, YouTube, etc.)
41+
- **Selection Tools** (`src/content-script/selection-tools/`) - Text selection features (translate, summarize, explain, etc.)
42+
43+
### Manifests
44+
45+
- `src/manifest.json` - Manifest v3 for Chromium browsers (Chrome, Edge, Opera, etc.)
46+
- `src/manifest.v2.json` - Manifest v2 for Firefox (current status; future MV3 migration may change this)
47+
- Background runs as service worker (MV3) vs background page (MV2)
48+
- Different permission models between manifest versions
49+
50+
## Testing and Validation
51+
52+
### Manual Browser Extension Testing (CRITICAL)
53+
54+
Since this is a browser extension with no automated tests, ALWAYS manually test functionality:
55+
56+
1. **Load Extension in Browser:**
57+
- Chrome: Go to `chrome://extensions/`, enable Developer Mode, click "Load unpacked", then select the folder `build/chromium/` (the folder must contain `manifest.json`).
58+
- Firefox: Go to `about:debugging#/runtime/this-firefox`, click "Load Temporary Add-on", then choose the generated `.xpi` file from `build/` (recommended). To load unpacked instead, select the `manifest.json` file inside `build/firefox/` (do not select the folder directly). Note: Temporary add-ons are removed on browser restart.
59+
- **Important**: Extension files cannot be tested by serving them via HTTP server - they must be loaded as a proper browser extension.
60+
61+
2. **Core Functionality Tests:**
62+
- Press `Ctrl+B` (Windows/Linux) or `⌘+B` (macOS) to open the chat dialog on any webpage
63+
- Select text on a page, verify selection tools appear
64+
- Right-click and verify "Ask ChatGPT" context menu appears
65+
- Click extension icon to open popup
66+
- Press `Ctrl+Shift+H` (Windows/Linux) or `⌘+Shift+H` (macOS) to open the independent conversation page
67+
68+
3. **Site Integration Tests:**
69+
- Visit YouTube.com, verify video summary features work
70+
- Visit Reddit.com, verify ChatGPT integration appears in sidebar
71+
- Visit github.com, verify code analysis features work
72+
- Visit Google.com search results, verify ChatGPT responses appear
73+
74+
4. **Configuration Tests:**
75+
- Open extension popup, navigate through tabs (General, Feature Pages, Modules > Selection Tools, Modules > Sites, Advanced)
76+
- Test API mode switching (Web API vs OpenAI API) under Modules > API Modes
77+
- 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
78+
- Verify language settings work
79+
80+
### Build Validation
81+
82+
Ensure these files exist in `build/chromium/` after successful build:
83+
84+
- `manifest.json` (contains proper extension metadata)
85+
- `background.js` (service worker bundle)
86+
- `content-script.js` (main functionality)
87+
- `content-script.css` (styling)
88+
- `popup.html` and `popup.js` (popup interface)
89+
- `IndependentPanel.html` and `IndependentPanel.js` (standalone chat page)
90+
- `shared.js` (shared vendor/runtime; size varies by environment and dependencies)
91+
- `logo.png` (extension icon)
92+
- `rules.json` (declarative net request rules)
93+
94+
Bundle sizes are approximate and not validation criteria.
95+
96+
### Verify Script Limitations
97+
98+
- `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.
99+
- **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.
100+
- **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.
101+
- 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.
102+
103+
## Development Workflow
104+
105+
### Code Style and Quality
106+
107+
- ALWAYS run `npm run lint` before committing - CI will fail otherwise
108+
- ALWAYS run `npm run pretty` to format code consistently
109+
- ESLint configuration in `.eslintrc.json` enforces React/JSX standards
110+
- Prettier configuration in `.prettierrc` handles formatting
111+
112+
### Pre-commit Hooks
113+
114+
The repository uses pre-commit hooks that automatically:
115+
116+
1. Run prettier formatting
117+
2. Stage formatted files
118+
3. Run lint checks
119+
120+
### Common File Locations
121+
122+
- Configuration: `src/config/index.mjs`
123+
- API integrations: `src/services/apis/`
124+
- Localization: `src/_locales/`
125+
- UI components: `src/components/`
126+
- Utilities: `src/utils/`
127+
128+
### Key Directories
129+
130+
```text
131+
src/
132+
├── background/ # Background script/service worker
133+
├── components/ # Reusable UI components
134+
├── config/ # Configuration management
135+
├── content-script/ # Main content script and features
136+
│ ├── site-adapters/ # Website-specific integrations
137+
│ ├── selection-tools/ # Text selection features
138+
│ └── menu-tools/ # Context menu features
139+
├── pages/IndependentPanel/ # Standalone chat page
140+
├── popup/ # Extension popup
141+
├── services/ # API clients and wrappers
142+
└── utils/ # Helper functions
143+
```
144+
145+
## Platform-Specific Instructions
146+
147+
### Safari Build (macOS Only)
148+
149+
- Run `npm run build:safari`
150+
- Creates `Fission - ChatBox.app` bundle and `safari.dmg` installer
151+
- Uses `safari/build.sh` script with platform-specific patches
152+
153+
### Cross-Browser Compatibility
154+
155+
- Uses `webextension-polyfill` for API compatibility
156+
157+
## AI Model Support
158+
159+
The extension supports multiple AI providers:
160+
161+
- **Web (cookie-based)**: ChatGPT (Web), Claude.ai (Web), Kimi.Moonshot (Web), Bing (Web), Gemini (Web)
162+
- **APIs (key-based)**: OpenAI (API), Azure OpenAI (API), Claude.ai (API), OpenRouter (API), AI/ML (API), DeepSeek (API), Ollama (local), ChatGLM (API), Waylaidwanderer (API), Kimi.Moonshot (API)
163+
- **Custom/self-hosted**: Alternative endpoints and self-hosted backends
164+
165+
## Troubleshooting
166+
167+
### Build Issues
168+
169+
- Build failures: Check Node.js version (requires Node 20+), clear caches and rebuild.
170+
- macOS/Linux: `rm -rf node_modules && npm ci && rm -rf node_modules/.cache build/ dist/`
171+
- Windows (PowerShell): `Remove-Item -Recurse -Force node_modules, build, dist; if (Test-Path node_modules\.cache) { Remove-Item -Recurse -Force node_modules\.cache }; npm ci`
172+
- Safari build fails: Ensure macOS with Xcode installed
173+
- "Module not found" errors: Usually indicate missing `npm ci`
174+
175+
### Runtime Issues
176+
177+
- Extension not loading: Check console for manifest errors
178+
- API not working: Verify browser has required permissions and cookies
179+
- Selection tools not appearing: Check if content script loaded correctly
180+
181+
### Common Development Tasks
182+
183+
- Adding new site adapter: Create new file in `src/content-script/site-adapters/`
184+
- Adding new selection tool: Modify `src/content-script/selection-tools/`
185+
- Updating API integration: Modify files in `src/services/apis/`
186+
- Adding new UI component: Create in `src/components/`
187+
188+
## Time Expectations
189+
190+
- Do not interrupt builds or long-running commands unless they appear hung or unresponsive.
191+
- `npm ci`: ~30 seconds
192+
- `npm run build`: ~35 seconds (measured). Set timeout to 5-10 minutes; if it exceeds this and appears hung, see "Build Issues" for recovery steps.
193+
- `npm run dev`: ~15 seconds initial build, then watches for changes; use Ctrl+C to stop when switching branches or after config/dependency changes.
194+
- `npm run lint`: ~5 seconds
195+
- Manual extension testing: 5-10 minutes for thorough validation
196+
- Safari build: 2-5 minutes (macOS only)
197+
198+
## Critical Validation Steps
199+
200+
1. ALWAYS run `npm run build` after any code changes
201+
2. ALWAYS manually load and test the built extension in a browser - automated testing is not available
202+
3. ALWAYS verify the build creates the expected file structure with correct file sizes
203+
4. ALWAYS test core extension functionality (popup, content script injection, keyboard shortcuts)
204+
205+
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)