Skip to content

Commit 61f586b

Browse files
PeterDaveHelloCopilotqodo-merge-pro[bot]coderabbitai[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> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a2251fa commit 61f586b

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed

.github/copilot-instructions.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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+
- Analyze bundle: `npm run analyze` -- Inspects the size of webpack output files.
16+
- Format code: `npm run pretty` -- uses Prettier to format all JS/JSX/CSS files. Run this before linting.
17+
- Lint code: `npm run lint` -- uses ESLint.
18+
- Safari build: `npm run build:safari` (see Platform-Specific Instructions for details)
19+
20+
### Build Output Structure
21+
22+
Production build creates multiple variants in `build/` directory:
23+
24+
- `chromium/` - Chromium-based browsers (Chrome, Edge) with full features
25+
- `firefox/` - Firefox with manifest v2
26+
- `chromium-without-katex-and-tiktoken/` - Minimal build without math rendering and token encoding
27+
- `firefox-without-katex-and-tiktoken/` - Minimal Firefox build without math rendering and token encoding
28+
- Distribution artifacts:
29+
- Chromium: `build/chromium.zip`
30+
- Firefox: `build/firefox.zip`
31+
- Safari: `Fission - ChatBox.app` and `safari.dmg` (see Safari Build section for details)
32+
33+
## Architecture Overview
34+
35+
The project uses Preact (for React-like components), SCSS (for styling), and Webpack 5 (for bundling).
36+
37+
### Key Components
38+
39+
- **Content Script** (`src/content-script/index.jsx`) - Injected into all web pages, provides main chat functionality
40+
- **Background Script** (`src/background/index.mjs`) - Handles browser APIs and cross-page communication
41+
- **Popup** (`src/popup/`) - Extension popup interface accessible via browser toolbar
42+
- **Independent Panel** (`src/pages/IndependentPanel/`) - Standalone chat page and side panel
43+
- **Site Adapters** (`src/content-script/site-adapters/`) - Custom integrations for specific websites (Reddit, GitHub, YouTube, etc.)
44+
- **Selection Tools** (`src/content-script/selection-tools/`) - Text selection features (translate, summarize, explain, etc.)
45+
46+
### Manifests
47+
48+
- `src/manifest.json` - Manifest v3 for Chromium browsers (Chrome, Edge, Opera, etc.)
49+
- `src/manifest.v2.json` - Manifest v2 for Firefox (current status; future MV3 migration may change this)
50+
- Background runs as service worker (MV3) vs background page (MV2)
51+
- Different permission models between manifest versions
52+
53+
## Testing and Validation
54+
55+
### Manual Browser Extension Testing (CRITICAL)
56+
57+
This browser extension has no automated tests, so manual testing is essential:
58+
59+
1. **Load Extension in Browser:**
60+
- Chrome: Go to `chrome://extensions/`, enable Developer Mode, click "Load unpacked", then select the folder `build/chromium/` (the folder must contain `manifest.json`).
61+
- Firefox: Go to `about:debugging#/runtime/this-firefox`, click "Load Temporary Add-on", then select the `manifest.json` file inside `build/firefox/` (do not select the folder directly). Note: Temporary (unsigned) add-ons are removed on browser restart; reload them via the same "This Firefox" page after every restart, and some environments with enterprise policies may block loading from file.
62+
- **Important**: Extension files cannot be tested by serving them via HTTP server - they must be loaded as a proper browser extension.
63+
64+
2. **Core Functionality Tests:**
65+
- Press `Ctrl+B` (Windows/Linux) or `⌘+B` (macOS) to open the chat dialog on any webpage
66+
- Select text on a page, verify selection tools appear
67+
- Right-click and verify "Ask ChatGPT" context menu appears
68+
- Click extension icon to open popup
69+
- Press `Ctrl+Shift+H` (Windows/Linux) or `⌘+Shift+H` (macOS) to open the independent conversation page
70+
71+
3. **Site Integration Tests:**
72+
- Visit YouTube.com, verify video summary features work
73+
- Visit Reddit.com, verify ChatGPT integration appears in sidebar
74+
- Visit GitHub.com, verify code analysis features work
75+
- Visit Google.com search results, verify ChatGPT responses appear
76+
77+
4. **Configuration Tests:**
78+
- Open extension popup, navigate through tabs (General, Feature Pages, Modules > Selection Tools, Modules > Sites, Advanced)
79+
- Test API mode switching (Web API vs OpenAI API) under Modules > API Modes
80+
- 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
81+
- Verify language settings work
82+
83+
Debugging tips:
84+
- Inspect background Service Worker, page DevTools for content scripts, and use "Inspect popup" for the popup UI
85+
- After rebuilds, reload the extension and refresh the page to re‑inject content scripts
86+
87+
### Build Validation
88+
89+
Ensure these files exist in `build/chromium/` after successful build:
90+
91+
- `manifest.json` (contains proper extension metadata)
92+
- `background.js` (service worker bundle)
93+
- `content-script.js` (main functionality)
94+
- `content-script.css` (styling)
95+
- `popup.html` and `popup.js` (popup interface)
96+
- `IndependentPanel.html` and `IndependentPanel.js` (standalone chat page)
97+
- `shared.js` (shared vendor/runtime; size varies by environment and dependencies)
98+
- `logo.png` (extension icon)
99+
- `rules.json` (declarative net request rules)
100+
101+
Bundle sizes are approximate and not validation criteria.
102+
103+
### Verify Script Limitations
104+
105+
- `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.
106+
- **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.
107+
- **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.
108+
- 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.
109+
110+
Usage notes:
111+
- Default checks target: `https://www.bing.com/search?q=hello`, `https://search.yahoo.co.jp/search?p=hello`, `https://www.baidu.com/s?wd=hello`, `https://search.naver.com/search.naver?query=hello`
112+
- Optional engines (may be blocked by region or anti-bot measures): Google, DuckDuckGo, Brave, Searx.
113+
- Troubleshooting: If a site fails, try adjusting `Accept-Language`/`User-Agent` headers in the script, update the site's selector arrays with ordered fallbacks, or temporarily reduce the test to a single URL while iterating.
114+
115+
## Development Workflow
116+
117+
### Code Style, Quality, and File Organization
118+
119+
- ALWAYS run `npm run lint` before committing - CI will fail otherwise
120+
- ALWAYS run `npm run pretty` to format code consistently
121+
- ESLint configuration in `.eslintrc.json` enforces React/JSX standards
122+
- Prettier configuration in `.prettierrc` handles formatting
123+
124+
- Naming conventions: component directories use PascalCase; feature folders use kebab-case; entry files are typically `index.jsx` or `index.mjs`
125+
- Avoid heavy dependencies; if necessary, justify and keep bundle size under control
126+
127+
**Pre-commit hooks automatically:**
128+
129+
1. Run prettier formatting
130+
2. Stage formatted files
131+
3. Run lint checks
132+
133+
**Key file locations:**
134+
135+
- Configuration: `src/config/index.mjs`
136+
- API integrations: `src/services/apis/`
137+
- Localization: `src/_locales/`
138+
- UI components: `src/components/`
139+
- Utilities: `src/utils/`
140+
141+
### Commits & PRs
142+
143+
- Keep changes minimal and focused. Avoid unrelated refactors in the same PR.
144+
- Commit subject: imperative, capitalize first word; separate subject/body with a blank line; wrap at ~72 characters; explain what and why.
145+
- PRs: link related issues, summarize scope/behavior changes; include screenshots for UI changes.
146+
- Note i18n updates in PR description when `src/_locales/` changes.
147+
148+
### Directory Structure
149+
150+
```text
151+
src/
152+
├── background/ # Background script/service worker
153+
├── components/ # Reusable UI components
154+
├── config/ # Configuration management
155+
├── content-script/ # Main content script and features
156+
│ ├── site-adapters/ # Website-specific integrations
157+
│ ├── selection-tools/ # Text selection features
158+
│ └── menu-tools/ # Context menu features
159+
├── pages/IndependentPanel/ # Standalone chat page
160+
├── popup/ # Extension popup
161+
├── services/ # API clients and wrappers
162+
└── utils/ # Helper functions
163+
```
164+
165+
## Platform-Specific Instructions
166+
167+
### Safari Build (macOS Only)
168+
169+
- Run `npm run build:safari` (requires macOS with Xcode installed)
170+
- Creates `Fission - ChatBox.app` bundle and `safari.dmg` installer
171+
- Uses `safari/build.sh` script with platform-specific patches
172+
173+
### Cross-Browser Compatibility
174+
175+
- Uses `webextension-polyfill` for API compatibility
176+
177+
## Security & Privacy
178+
179+
- Do not commit secrets, API keys, or user data
180+
- Keep manifest permissions minimal and justify any additions
181+
- Centralize network/API logic under `src/services/apis/` and keep endpoints auditable
182+
183+
## Localization
184+
185+
- Source of truth: `src/_locales/en/main.json`; do not change keys
186+
- Add new strings to `en/main.json` first, then propagate to other locales
187+
- Register new locales in `src/_locales/resources.mjs`
188+
- Preserve placeholders and product names; keep punctuation/quotes intact
189+
- For Traditional Chinese (Taiwan), use `src/_locales/zh-hant/main.json` and avoid zh‑CN terms
190+
191+
## AI Model Support
192+
193+
The extension supports multiple AI providers:
194+
195+
- **Web (cookie-based)**: ChatGPT (Web), Claude (Web), Kimi.Moonshot (Web), Bing (Web), Bard (Web), Poe (Web)
196+
- **APIs (key-based)**: OpenAI (API), Azure OpenAI (API), Anthropic (Claude API), OpenRouter (API), AI/ML (API), DeepSeek (API), Ollama (local), ChatGLM (API), Waylaidwanderer (API), Kimi.Moonshot (API)
197+
- **Custom/self-hosted**: Alternative endpoints and self-hosted backends
198+
199+
## Troubleshooting
200+
201+
### Build Issues
202+
203+
- Build failures: Check Node.js version (requires Node 20+), clear caches and rebuild.
204+
- macOS/Linux: `rm -rf node_modules && npm ci && rm -rf node_modules/.cache build/ dist/`
205+
- 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`
206+
- "Module not found" errors: Usually indicate missing `npm ci`
207+
208+
### Runtime Issues
209+
210+
- Extension not loading: Check console for manifest errors
211+
- API not working: Verify browser has required permissions and cookies
212+
- Selection tools not appearing: Check if content script loaded correctly
213+
214+
### Common Development Tasks
215+
216+
- Adding new site adapter: Create new file in `src/content-script/site-adapters/`, register it in `src/content-script/site-adapters/index.mjs`, keep selectors minimal with feature detection, and verify on Chromium/Firefox
217+
- Adding new selection tool: Modify `src/content-script/selection-tools/`, keep UI and logic separate, and reuse helpers in `src/utils/`
218+
- Updating API integration: Modify files in `src/services/apis/`
219+
- Adding new UI component: Create in `src/components/`
220+
221+
## Time Expectations
222+
223+
- Do not interrupt builds or long-running commands unless they appear hung or unresponsive.
224+
- `npm ci`: ~30 seconds
225+
- `npm run build`: ~35 seconds (measured). Set timeout to 5-10 minutes for system variations.
226+
- `npm run dev`: ~15 seconds initial build, then watches for changes; use Ctrl+C to stop when switching branches or after config/dependency changes.
227+
- `npm run lint`: ~5 seconds
228+
- Manual extension testing: 5-10 minutes for thorough validation
229+
- Safari build: 2-5 minutes (macOS only)
230+
231+
## Critical Validation Steps
232+
233+
1. ALWAYS run `npm run build` after any code changes
234+
2. ALWAYS manually load and test the built extension in a browser (no automated testing available)
235+
3. ALWAYS verify the build creates expected file structure (non-empty bundles, no missing files)
236+
4. ALWAYS test core extension functionality (popup, content script injection, keyboard shortcuts)
237+
238+
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)