Skip to content

Commit 426f742

Browse files
committed
Merge branch 'feature/agent' into worktree-opfs-tools
2 parents 30c36b9 + 3b2cf33 commit 426f742

217 files changed

Lines changed: 32172 additions & 2358 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/ISSUE_TEMPLATE/bug_report_en.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ body:
1414
attributes:
1515
label: "Problem Description"
1616
description: "What problem occurred? What is the expected normal behavior?"
17-
placeholder: "e.g., When clicking the download button on YouTube page, the script throws a 404 error, expected to show a download window"
17+
placeholder:
18+
"e.g., When clicking the download button on YouTube page, the script throws a 404 error, expected to show a
19+
download window"
1820
validations:
1921
required: true
2022

@@ -37,7 +39,9 @@ body:
3739
id: scriptcat-version
3840
attributes:
3941
label: ScriptCat Version
40-
description: You can view it by clicking on the ScriptCat popup window. If possible, please use the latest version as your issue may have already been resolved
42+
description:
43+
You can view it by clicking on the ScriptCat popup window. If possible, please use the latest version as your
44+
issue may have already been resolved
4145
placeholder: e.g., v0.17.0
4246
validations:
4347
required: true

.github/ISSUE_TEMPLATE/feature_request_en.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Please clearly describe the feature you want:
1212

1313
### Use Case
1414

15-
In what situations is this feature needed? (e.g., when processing specific websites, improving operational efficiency, etc.)
15+
In what situations is this feature needed? (e.g., when processing specific websites, improving operational efficiency,
16+
etc.)
1617

1718
### Additional Information
1819

.github/copilot-instructions.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,77 @@ When performing a code review, respond in Chinese.
99
ScriptCat is a sophisticated browser extension that executes user scripts with a unique multi-process architecture:
1010

1111
### Core Components
12-
- **Service Worker** (`src/service_worker.ts`) - Main background process handling script management, installations, and chrome APIs
12+
13+
- **Service Worker** (`src/service_worker.ts`) - Main background process handling script management, installations, and
14+
chrome APIs
1315
- **Offscreen** (`src/offscreen.ts`) - Isolated background environment for running background/scheduled scripts
1416
- **Sandbox** (`src/sandbox.ts`) - Secure execution environment inside offscreen for script isolation
1517
- **Content Scripts** (`src/content.ts`) - Injected into web pages to execute user scripts
1618
- **Inject Scripts** (`src/inject.ts`) - Runs in page context with access to page globals
1719

1820
### Message Passing System
21+
1922
ScriptCat uses a sophisticated message passing architecture (`packages/message/`):
23+
2024
- **ExtensionMessage** - Chrome extension runtime messages between service worker/content/pages
2125
- **WindowMessage** - PostMessage-based communication between offscreen/sandbox
2226
- **CustomEventMessage** - CustomEvent-based communication between content/inject scripts
2327
- **MessageQueue** - Cross-environment event broadcasting system
2428

25-
Key pattern: All communication flows through Service Worker → Offscreen → Sandbox for background scripts, or Service Worker → Content → Inject for page scripts.
29+
Key pattern: All communication flows through Service Worker → Offscreen → Sandbox for background scripts, or Service
30+
Worker → Content → Inject for page scripts.
2631

2732
### Script Execution Flow
33+
2834
1. **Page Scripts**: Service Worker registers with `chrome.userScripts` → injected into pages
2935
2. **Background Scripts**: Service Worker → Offscreen → Sandbox execution
3036
3. **Scheduled Scripts**: Cron-based execution in Sandbox environment
3137

3238
## Key Development Patterns
3339

3440
### Path Aliases
41+
3542
```typescript
3643
"@App": "./src/"
3744
"@Packages": "./packages/"
3845
"@Tests": "./tests/"
3946
```
4047

4148
### Repository Pattern
49+
4250
All data access uses DAO classes extending `Repo<T>` base class:
51+
4352
```typescript
4453
// Example: ScriptDAO, ResourceDAO, SubscribeDAO
4554
export class ScriptDAO extends Repo<Script> {
46-
public save(val: Script) { return super._save(val.uuid, val); }
55+
public save(val: Script) {
56+
return super._save(val.uuid, val);
57+
}
4758
}
4859
```
4960

5061
### Service Layer Structure
62+
5163
Services follow a consistent pattern with dependency injection:
64+
5265
```typescript
5366
export class ExampleService {
5467
constructor(
55-
private group: Group, // Message handling group
56-
private messageQueue: IMessageQueue, // Event broadcasting (MessageQueue's interface)
57-
private dataDAO: DataDAO // Data access
68+
private group: Group, // Message handling group
69+
private messageQueue: IMessageQueue, // Event broadcasting (MessageQueue's interface)
70+
private dataDAO: DataDAO // Data access
5871
) {}
59-
72+
6073
init() {
6174
this.group.on("action", this.handleAction.bind(this));
6275
}
6376
}
6477
```
6578

6679
### Script Compilation & Sandboxing
80+
6781
User scripts are compiled with sandbox context isolation:
82+
6883
- `compileScriptCode()` - Wraps scripts with error handling and context binding
6984
- `compileInjectScript()` - Creates window-mounted functions for inject scripts
7085
- Sandbox uses `with(arguments[0])` for controlled variable access
@@ -77,10 +92,10 @@ User scripts are compiled with sandbox context isolation:
7792
- **Rspack** - Fast bundler (Webpack alternative) with SWC
7893
- **TypeScript** - Type-safe development
7994

80-
8195
## Development Workflows
8296

8397
### Build & Development
98+
8499
```bash
85100
pnpm run dev # Development with source maps
86101
pnpm run dev:noMap # Development without source maps (needed for incognito)
@@ -89,44 +104,51 @@ pnpm run pack # Create browser extension packages
89104
```
90105

91106
### Testing
107+
92108
```bash
93109
pnpm test # Run all tests with Vitest
94110
pnpm run coverage # Generate coverage reports
95111
```
96112

97113
**Testing Patterns:**
114+
98115
- Uses Vitest with jsdom environment
99116
- Chrome extension APIs mocked via `@Packages/chrome-extension-mock`
100117
- Message system testing with `MockMessage` classes
101118
- Sandbox testing validates script isolation
102119

103120
### Code Organization
121+
104122
- **Monorepo structure** with packages in `packages/` (message, filesystem, etc.)
105123
- **Feature-based organization** in `src/app/service/` by environment
106124
- **Shared utilities** in `src/pkg/` for cross-cutting concerns
107125
- **Type definitions** in `src/types/` with global declarations
108126

109127
### Browser Extension Specifics
128+
110129
- **Manifest V3** with service worker background
111130
- **User Scripts API** for script injection (Chrome/Edge)
112-
- **Offscreen API** for DOM access in background contexts
131+
- **Offscreen API** for DOM access in background contexts
113132
- **Declarative Net Request** for script installation interception
114133

115134
## Critical Integration Points
116135

117136
### Script Installation Flow
137+
118138
1. URL patterns trigger declarative net request rules
119139
2. Service Worker opens install page with cached script data
120140
3. Install page validates and processes script metadata
121141
4. Scripts registered with appropriate execution environment
122142

123143
### GM API Implementation
144+
124145
- Split between Service Worker (`GMApi`) and Offscreen (`OffscreenGMApi`)
125146
- Permission verification via `PermissionVerify` service
126147
- Value storage abstracted through `ValueService`
127148
- Cross-origin requests handled in service worker context
128149

129150
### Resource Management
151+
130152
- `ResourceService` handles script dependencies (@require, @resource)
131153
- Content Security Policy handling for external resources
132154
- Caching layer via `Cache` class with automatic expiration
@@ -139,33 +161,42 @@ pnpm run coverage # Generate coverage reports
139161
- Sandbox script execution isolated from page context - use `unsafeWindow` for page access
140162

141163
## File Structure Patterns
164+
142165
- Tests co-located with source files (`.test.ts` suffix)
143166
- Template files use `.tpl` extension for build-time processing
144167
- Configuration files use factory pattern for environment-specific setup
145168

146169
## Language
170+
147171
- The code is developed and maintained by developers based in Mainland China.
148172
- Comments should preferably be written in Simplified Chinese.
149173
- The user interface supports multiple languages, with English set as the default for global users.
150174

151175
## PR Review Policy
152176

153-
When performing Pull Request (PR) reviews, Copilot must always conduct a **comprehensive and independent review** of the entire PR content.
177+
When performing Pull Request (PR) reviews, Copilot must always conduct a **comprehensive and independent review** of the
178+
entire PR content.
154179

155180
- **Full Review Every Time**
156-
Always review **all modified files** in every PR, regardless of previous reviews or user comments. Even during re-reviews, treat the PR as new and **do not rely on prior review states**.
181+
Always review **all modified files** in every PR, regardless of previous reviews or user comments. Even during
182+
re-reviews, treat the PR as new and **do not rely on prior review states**.
157183

158184
- **No Skipping of Files**
159-
Do not skip or ignore any text-based file types (including `.md`, `.json`, `.yml`, `.toml`, `.ts`, `.js`, `.py`, `.html`, `.css`, `.tsx`, `.vue`, `.sh`, etc.). Every file that is changed must be fully examined.
185+
Do not skip or ignore any text-based file types (including `.md`, `.json`, `.yml`, `.toml`, `.ts`, `.js`, `.py`,
186+
`.html`, `.css`, `.tsx`, `.vue`, `.sh`, etc.). Every file that is changed must be fully examined.
160187

161188
- **Reference as Context Only**
162-
PR descriptions, commit messages, or user discussions serve only as **reference context**. The review must focus primarily on the **actual code and file changes**.
189+
PR descriptions, commit messages, or user discussions serve only as **reference context**. The review must focus
190+
primarily on the **actual code and file changes**.
163191

164192
- **Infer Intent from Code Changes**
165-
Always attempt to **infer the purpose and intent** of the changes directly from the modified content, rather than relying solely on user statements or PR titles.
193+
Always attempt to **infer the purpose and intent** of the changes directly from the modified content, rather than
194+
relying solely on user statements or PR titles.
166195

167196
- **Critical Thinking Requirement**
168-
For each change, Copilot should assess correctness, consistency, and maintainability — ensuring that logic, style, and architectural impact align with project standards.
197+
For each change, Copilot should assess correctness, consistency, and maintainability — ensuring that logic, style, and
198+
architectural impact align with project standards.
169199

170200
- **Independent Verification**
171-
Do not assume unchanged files or previously reviewed sections are safe; verify all code paths potentially affected by the modifications.
201+
Do not assume unchanged files or previously reviewed sections are safe; verify all code paths potentially affected by
202+
the modifications.

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
- release/*
8+
- feature/*
89
- dev
910
paths-ignore:
1011
- ".github/**"
@@ -25,7 +26,7 @@ jobs:
2526
uses: actions/setup-node@v4
2627
with:
2728
node-version: 22
28-
cache: 'pnpm'
29+
cache: "pnpm"
2930

3031
- name: Package with Node
3132
env:
@@ -51,4 +52,3 @@ jobs:
5152
name: scriptcat-chrome-extension
5253
path: |
5354
dist/ext/*
54-

.github/workflows/packageRelease.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/setup-node@v4
1919
with:
2020
node-version: 22
21-
cache: 'pnpm'
21+
cache: "pnpm"
2222

2323
- name: Package with Node
2424
env:

.github/workflows/test.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
- release/*
8+
- feature/*
89
- dev
910
- develop/*
1011
pull_request:
@@ -21,7 +22,7 @@ jobs:
2122
uses: actions/setup-node@v4
2223
with:
2324
node-version: 22
24-
cache: 'pnpm'
25+
cache: "pnpm"
2526

2627
- name: Setup pnpm
2728
run: corepack enable
@@ -61,7 +62,7 @@ jobs:
6162
uses: actions/setup-node@v4
6263
with:
6364
node-version: 22
64-
cache: 'pnpm'
65+
cache: "pnpm"
6566

6667
- name: Setup pnpm
6768
run: corepack enable

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ need_check=0
1313
while read local_ref local_sha remote_ref remote_sha; do
1414
branch=$(echo "$remote_ref" | sed 's|refs/heads/||')
1515

16-
if [ "$branch" = "main" ] || echo "$branch" | grep -q "^release"; then
16+
if [ "$branch" = "main" ] || echo "$branch" | grep -q "^release/"; then
1717
need_check=1
1818
echo "🔍 Detected push target: $branch"
1919
fi

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"trailingComma": "es5",
1717
"useTabs": false,
1818
"endOfLine": "auto"
19-
}
19+
}

CONTRIBUTING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ git commit -m "✨ add login feature"
4646
### 工作流概述
4747

4848
`main` 分支是 ScriptCat 的主分支。为了保持代码的完整性,请不要直接修改 `main`
49-
分支。你应该创建一个新的分支,并在这个分支上进行修改,然后发起一个目标分支为
50-
`main` 的 Pull Request。Pull Request
51-
的标题请尽量使用中文,以便于自动生成更新日志。
49+
分支。你应该创建一个新的分支,并在这个分支上进行修改,然后发起一个目标分支为 `main` 的 Pull Request。Pull
50+
Request 的标题请尽量使用中文,以便于自动生成更新日志。
5251

53-
如果你不是 ScriptCat 团队的成员,你可以先 fork 本仓库,然后向本仓库的 `main`
54-
分支发起 Pull Request。在创建 commit 时,请按照上述 commit message
55-
规范进行。我们将在 code review 完成后将你的贡献合并到主分支。
52+
如果你不是 ScriptCat 团队的成员,你可以先 fork 本仓库,然后向本仓库的 `main` 分支发起 Pull
53+
Request。在创建 commit 时,请按照上述 commit message 规范进行。我们将在 code review 完成后将你的贡献合并到主分支。
5654

5755
## 撰写文档
5856

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ smooth.
7171

7272
| Browser | Store Link | Status |
7373
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
74-
| Chrome | [Stable Version](https://chromewebstore.google.com/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf) [Beta Version](https://chromewebstore.google.com/detail/scriptcat-beta/jaehimmlecjmebpekkipmpmbpfhdacom) | ✅ Available |
74+
| Chrome | [Stable Version](https://chromewebstore.google.com/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf) [Beta Version](https://chromewebstore.google.com/detail/scriptcat-beta/jaehimmlecjmebpekkipmpmbpfhdacom) | ✅ Available |
7575
| Edge | [Stable Version](https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh) [Beta Version](https://microsoftedge.microsoft.com/addons/detail/scriptcat-beta/nimmbghgpcjmeniofmpdfkofcedcjpfi) | ✅ Available |
7676
| Firefox | [Stable Version](https://addons.mozilla.org/en/firefox/addon/scriptcat/) [Beta Version](https://addons.mozilla.org/en/firefox/addon/scriptcat-pre/) | ✅ MV2 |
7777

0 commit comments

Comments
 (0)