From 8525a8eeb9c87ce571a6ce5eb82e0e733a1aa1d7 Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sun, 19 Jul 2026 22:50:03 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=F0=9F=93=84=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=9E=B6=E6=9E=84/=E6=B5=8B=E8=AF=95/i18n=20?= =?UTF-8?q?=E4=BA=8B=E5=AE=9E=E5=B9=B6=E8=A7=A3=E5=86=B3=E8=B7=A8=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=94=BF=E7=AD=96=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AGENTS.md/copilot-instructions.md/architecture*.md: 用 Repo/DAO/OPFSRepo 后端分类 替换"新实体一律 Repo"的过期普遍规则;架构速览补充 agent/、extension/、queue.ts; 新增 docs/references/architecture-agent.md 覆盖 Agent 子系统(工具注册表、LLM 工具循环、 后台会话/子代理/定时任务生命周期、存储后端、跨 context 委派边界) - architecture-build.md: rspack entry 补上 common、json.worker - architecture-gm-api.md: 明确 sendMessage vs connect 的选择依据与 DOM/linter 落点路径 - develop.md: 记录 toast.ts 对 no-restricted-imports 的完整豁免(同时覆盖 Sonner 与 Radix) - verification.md: 补充"何时可跳过本指南"、按比例的前置检查、TDD 例外与 bug 复现的同步、 可见的 report.md 创建步骤、双主题验证注意事项 - verification-debugging.md: 补充 Firefox 无独立 Offscreen 页面的调试提示 - design-patterns.md: 移除过期的固定 locale 数与未经测量的百分比断言 - translation.md/src/locales/README.md: 记录 i18n-usage.test.ts 的真实扫描范围与盲区; 修正 i8next 拼写;翻译工作流去重指向 translation.md - DOC-MAINTENANCE.md: 扩大到全部 tracked agent/contributor Markdown,新增 baseline/working-diff/final-tree 区分、政策一致性检查、隐私扫描、批量编辑建议 - packages/{message,filesystem,cloudscript}/README.md: 修正过期/模糊的实现描述 - 删除未被引用且已过期的 src/pages/options/routes/Setting/Setting/i18nKeys.md 迁移快照 Co-Authored-By: Claude Sonnet 5 --- .github/copilot-instructions.md | 21 ++- AGENTS.md | 19 +- docs/DOC-MAINTENANCE.md | 97 ++++++++++- docs/README.md | 6 +- docs/architecture.md | 28 ++- docs/design.md | 2 +- docs/develop.md | 6 + docs/pull-request.md | 17 +- docs/references/architecture-agent.md | 125 ++++++++++++++ docs/references/architecture-build.md | 10 +- docs/references/architecture-data.md | 71 ++++++-- docs/references/architecture-gm-api.md | 27 ++- docs/references/architecture-services.md | 53 +++++- docs/references/design-components.md | 3 +- docs/references/design-patterns.md | 9 +- docs/references/design-tokens.md | 2 +- docs/references/develop-testing.md | 8 +- docs/references/verification-debugging.md | 7 + .../verification-report-template.md | 4 + docs/translation.md | 9 + docs/verification.md | 72 ++++++-- packages/cloudscript/README.md | 12 +- packages/filesystem/README.md | 17 +- packages/message/README.md | 23 ++- src/locales/README.md | 9 +- src/pages/options/routes/Setting/i18nKeys.md | 163 ------------------ 26 files changed, 558 insertions(+), 262 deletions(-) create mode 100644 docs/references/architecture-agent.md delete mode 100644 src/pages/options/routes/Setting/i18nKeys.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 661d44371..c36abade4 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -10,10 +10,10 @@ ScriptCat is a sophisticated browser extension that executes user scripts with a ### 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 +- **Offscreen** (`src/offscreen.ts`) - Isolated background environment for running background/scheduled scripts on Chrome. Firefox MV3 has no separate Offscreen document; `EventPageOffscreenManager` (`src/app/service/offscreen/event_page_manager.ts`) runs the same logic inside the DOM-capable background event page instead. +- **Sandbox** (`src/sandbox.ts`) - Secure execution environment for background/scheduled scripts only (no page context); isolated via `with(arguments[0])` - **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 +- **Inject Scripts** (`src/inject.ts`) - Runs in page context with access to page globals, including `unsafeWindow` ### Message Passing System ScriptCat uses a sophisticated message passing architecture (`packages/message/`): @@ -22,7 +22,7 @@ ScriptCat uses a sophisticated message passing architecture (`packages/message/` - **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. +Key pattern: background scripts flow Service Worker → Offscreen → Sandbox; page scripts flow Service Worker → Content → Inject. Other paths exist alongside this: UI pages talk to the Service Worker directly, `MessageQueue` broadcasts across contexts outside the request/reply chain, and Agent storage (OPFS/Dexie) is read/written without going through this message flow. ### Script Execution Flow 1. **Page Scripts**: Service Worker registers with `chrome.userScripts` → injected into pages @@ -33,15 +33,14 @@ Key pattern: All communication flows through Service Worker → Offscreen → Sa ### Path Aliases ```typescript -"@App": "./src/" -"@Packages": "./packages/" -"@Tests": "./tests/" +import x from "@App/service_worker"; // -> src/service_worker +import y from "@Packages/message"; // -> packages/message +import z from "@Tests/utils"; // -> tests/utils ``` ### Repository Pattern -All data access uses DAO classes extending `Repo` base class: +Persistence is a small backend taxonomy, not one base class: `Repo` (`chrome.storage.local`, e.g. `ScriptDAO`, `ResourceDAO`, `SubscribeDAO`), `DAO` (Dexie/IndexedDB, e.g. `LoggerDAO`), `OPFSRepo` (OPFS-backed data, e.g. `AgentChatRepo`, `SkillRepo`), and a few custom repositories (e.g. `TrashScriptDAO`) where none of those fit. See [`docs/references/architecture-data.md`](../docs/references/architecture-data.md) for the full inventory and entity-decision recipe. ```typescript -// Example: ScriptDAO, ResourceDAO, SubscribeDAO export class ScriptDAO extends Repo