diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 661d44371..49fe962a8 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,171 +1,30 @@ -# ScriptCat Development Guide +# ScriptCat — Copilot Instructions -## Code Review - -When performing a code review, respond in Chinese. - -## Architecture Overview - -ScriptCat is a sophisticated browser extension that executes user scripts with a unique multi-process architecture: - -### Core Components -- **Service Worker** (`src/service_worker.ts`) - Main background process handling script management, installations, and chrome APIs -- **Offscreen** (`src/offscreen.ts`) - Isolated background environment for running background/scheduled scripts -- **Sandbox** (`src/sandbox.ts`) - Secure execution environment inside offscreen for script isolation -- **Content Scripts** (`src/content.ts`) - Injected into web pages to execute user scripts -- **Inject Scripts** (`src/inject.ts`) - Runs in page context with access to page globals - -### Message Passing System -ScriptCat uses a sophisticated message passing architecture (`packages/message/`): -- **ExtensionMessage** - Chrome extension runtime messages between service worker/content/pages -- **WindowMessage** - PostMessage-based communication between offscreen/sandbox -- **CustomEventMessage** - CustomEvent-based communication between content/inject scripts -- **MessageQueue** - Cross-environment event broadcasting system - -Key pattern: All communication flows through Service Worker → Offscreen → Sandbox for background scripts, or Service Worker → Content → Inject for page scripts. - -### Script Execution Flow -1. **Page Scripts**: Service Worker registers with `chrome.userScripts` → injected into pages -2. **Background Scripts**: Service Worker → Offscreen → Sandbox execution -3. **Scheduled Scripts**: Cron-based execution in Sandbox environment - -## Key Development Patterns - -### Path Aliases -```typescript -"@App": "./src/" -"@Packages": "./packages/" -"@Tests": "./tests/" -``` - -### Repository Pattern -All data access uses DAO classes extending `Repo` base class: -```typescript -// Example: ScriptDAO, ResourceDAO, SubscribeDAO -export class ScriptDAO extends Repo