diff --git a/.dockerignore b/.dockerignore index abc62d2..38718a6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,7 +7,5 @@ extension/ website/ scripts/ *.md -*.bat -*.sh .env server/.env diff --git a/AI_INIT.md b/AI_INIT.md index 13923f3..c240907 100644 --- a/AI_INIT.md +++ b/AI_INIT.md @@ -25,7 +25,7 @@ KoalaSync is a specialized tool for **synchronized video playback** across multi > [!IMPORTANT] > **Single Source of Truth**: `shared/constants.js` and `shared/blacklist.js` are the master files. They must be synchronized to the `extension/shared/` directory using `node scripts/build-extension.js`. > - **Extension Modules** (`background.js`, `popup.js`) import directly from `./shared/constants.js`. -> - **Content Scripts** (`content.js`) use a **manual synchronous mirror** to prevent race conditions during page load. Always verify parity after sync. +> - **Content Scripts** (`content.js`) use a **marker-injected synchronous copy** of the constants. The build script automatically replaces the marked blocks — no manual mirroring needed. ## 3. Mandatory Reading Before touching any code, you MUST read the following documents in order: @@ -36,10 +36,20 @@ Before touching any code, you MUST read the following documents in order: ## 4. The "Vanilla JS Mirror" Pattern To avoid boot-time race conditions in Manifest V3 without a bundler, the following architectural trade-off is enforced: - **Synchronous Execution**: `content.js` MUST execute synchronously to catch early media events. -- **Manual Mirroring**: `content.js` maintains a manual mirror of the `EVENTS` constants from `shared/constants.js`. -- **Maintenance**: Developers must ensure that any changes to `shared/constants.js` are manually reflected in `content.js` after running the build script. +- **Automated Injection**: The build script (`node scripts/build-extension.js`) automatically injects `EVENTS` and `HEARTBEAT_INTERVAL` into `content.js` using marker-based replacement (see `scripts/README.md` for marker details). +- **Maintenance**: After modifying `shared/constants.js`, simply run the build script. No manual mirroring is required. -## 5. Design Guidelines +## 5. File Responsibility Map + +| File | Responsibility | +|:-----|:---------------| +| `background.js` | WebSocket client, state orchestrator, event router, session persistence | +| `content.js` | Video element detection, media control, event origin detection (loop prevention) | +| `popup.js` | UI rendering, user input handling, peer display, invitation link generation | +| `bridge.js` | Landing page ↔ extension communication for invitation join flow | +| `server/index.js` | Room management, message relay, rate limiting, authentication, peer lifecycle | + +## 6. Design Guidelines The popup UI follows a strict design system. Do not modify these variables or the layout structure without explicit approval. - **Font**: System font stack. **MANDATORY**: No external CDNs or Google Fonts to ensure 100% privacy. - **Popup Width**: Fixed at `320px`. @@ -53,7 +63,7 @@ The popup UI follows a strict design system. Do not modify these variables or th | `--success` | `#22c55e` | Success states / Online dot | | `--error` | `#ef4444` | Errors / Offline dot | -## 5. Non-Negotiables (Core Logic) +## 7. Non-Negotiables (Core Logic) The following features are critical and must not be removed or fundamentally altered: - **Two-Phase Force Sync**: The `Prepare` → `ACK` → `Execute` flow ensures all peers are buffered before playback resumes. - **Episode Auto-Sync**: Ensures series binges stay perfectly synced. A lobby initiates during title transitions, freezing peers until everyone is ready. @@ -67,21 +77,22 @@ The following features are critical and must not be removed or fundamentally alt - **SW Keep-alive**: Use of `chrome.alarms` to prevent the Manifest V3 Service Worker from suspending. - **Diagnostics**: The "Dev" tab provides real-time access to the underlying `