Skip to content

Commit b422c81

Browse files
committed
chore(dev): 添加格式化配置、Agent指南和代码检查 CI
1 parent 426f9f9 commit b422c81

67 files changed

Lines changed: 1897 additions & 1785 deletions

Some content is hidden

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

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[*.json]
18+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
lint-and-format:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
cache: npm
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Run ESLint
27+
run: npm run lint
28+
29+
- name: Check formatting
30+
run: npm run format:check

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
package-lock.json
4+
.qoder

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "semi": false, "singleQuote": true, "tabWidth": 4, "trailingComma": "all", "printWidth": 100 }

AGENTS.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# AGENTS.md
2+
3+
## Project Overview
4+
5+
Brainllo is a Chrome extension that monitors user browsing behavior (tab switches, mouse movements, keyboard input, scrolling, etc.) and calculates cognitive load and physical fatigue levels in real time. Built with React + TypeScript + Vite + CRXJS.
6+
7+
## Tech Stack
8+
9+
- **Language**: TypeScript (strict mode)
10+
- **Framework**: React 19
11+
- **Build**: Vite 8 + @crxjs/vite-plugin
12+
- **Linting**: ESLint 10 (flat config) with typescript-eslint
13+
- **Formatting**: Prettier
14+
- **Package Manager**: npm
15+
16+
## Commands
17+
18+
| Command | Description |
19+
| ---------------------- | ------------------------------------ |
20+
| `npm run dev` | Start dev server with HMR |
21+
| `npm run build` | Type-check then build for production |
22+
| `npm run lint` | Run ESLint |
23+
| `npm run format` | Format all files with Prettier |
24+
| `npm run format:check` | Check formatting without writing |
25+
26+
## Code Style
27+
28+
- No semicolons
29+
- Single quotes
30+
- 4 spaces indentation
31+
- Trailing commas
32+
- Print width: 100 characters
33+
- LF line endings
34+
35+
## Architecture
36+
37+
- `src/background/` — Service worker, event listeners, cognitive load engine
38+
- `src/background/engine/` — Core calculation engine (cognitive load, fatigue, calibration)
39+
- `src/background/helper/` — Analyzers (keyboard, mouse, tab switch, event frequency)
40+
- `src/content/` — Content scripts injected into web pages
41+
- `src/models/` — Data models and event type definitions
42+
- `src/services/` — Service layer (AI, storage, options)
43+
- `src/popup/` — Extension popup UI (React)
44+
45+
## Guidelines for AI Agents
46+
47+
1. Always run `npm run lint` and `npm run format:check` before considering a task complete.
48+
2. Follow the existing code style — no semicolons, single quotes, 4-space indent.
49+
3. Use TypeScript strict typing; avoid `any` unless absolutely necessary.
50+
4. New event types should extend the base `Event` class in `src/models/events/`.
51+
5. Background scripts run in a service worker context — no DOM access.
52+
6. Content scripts have DOM access but run in an isolated world.
53+
7. Do not modify `dist/` — it is generated by the build process.

README.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,30 @@ If you are developing a production application, we recommend updating the config
2020

2121
```js
2222
export default defineConfig([
23-
globalIgnores(['dist']),
24-
{
25-
files: ['**/*.{ts,tsx}'],
26-
extends: [
27-
// Other configs...
23+
globalIgnores(['dist']),
24+
{
25+
files: ['**/*.{ts,tsx}'],
26+
extends: [
27+
// Other configs...
2828

29-
// Remove tseslint.configs.recommended and replace with this
30-
tseslint.configs.recommendedTypeChecked,
31-
// Alternatively, use this for stricter rules
32-
tseslint.configs.strictTypeChecked,
33-
// Optionally, add this for stylistic rules
34-
tseslint.configs.stylisticTypeChecked,
29+
// Remove tseslint.configs.recommended and replace with this
30+
tseslint.configs.recommendedTypeChecked,
31+
// Alternatively, use this for stricter rules
32+
tseslint.configs.strictTypeChecked,
33+
// Optionally, add this for stylistic rules
34+
tseslint.configs.stylisticTypeChecked,
3535

36-
// Other configs...
37-
],
38-
languageOptions: {
39-
parserOptions: {
40-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
41-
tsconfigRootDir: import.meta.dirname,
42-
},
43-
// other options...
36+
// Other configs...
37+
],
38+
languageOptions: {
39+
parserOptions: {
40+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
41+
tsconfigRootDir: import.meta.dirname,
42+
},
43+
// other options...
44+
},
4445
},
45-
},
4646
])
47-
4847
```
4948

5049
You can also
@@ -58,24 +57,23 @@ import reactX from 'eslint-plugin-react-x'
5857
import reactDom from 'eslint-plugin-react-dom'
5958

6059
export default defineConfig([
61-
globalIgnores(['dist']),
62-
{
63-
files: ['**/*.{ts,tsx}'],
64-
extends: [
65-
// Other configs...
66-
// Enable lint rules for React
67-
reactX.configs['recommended-typescript'],
68-
// Enable lint rules for React DOM
69-
reactDom.configs.recommended,
70-
],
71-
languageOptions: {
72-
parserOptions: {
73-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
74-
tsconfigRootDir: import.meta.dirname,
75-
},
76-
// other options...
60+
globalIgnores(['dist']),
61+
{
62+
files: ['**/*.{ts,tsx}'],
63+
extends: [
64+
// Other configs...
65+
// Enable lint rules for React
66+
reactX.configs['recommended-typescript'],
67+
// Enable lint rules for React DOM
68+
reactDom.configs.recommended,
69+
],
70+
languageOptions: {
71+
parserOptions: {
72+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
73+
tsconfigRootDir: import.meta.dirname,
74+
},
75+
// other options...
76+
},
7777
},
78-
},
7978
])
80-
8179
```

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import globals from 'globals'
33
import reactHooks from 'eslint-plugin-react-hooks'
44
import reactRefresh from 'eslint-plugin-react-refresh'
55
import tseslint from 'typescript-eslint'
6-
import {defineConfig, globalIgnores} from 'eslint/config'
6+
import { defineConfig, globalIgnores } from 'eslint/config'
77

88
export default defineConfig([
99
globalIgnores(['dist']),

index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8"/>
5-
<link href="/favicon.svg" rel="icon" type="image/svg+xml"/>
6-
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
7-
<title>brainllo</title>
8-
</head>
9-
<body>
10-
<div id="root"></div>
11-
<script src="/src/popup/main.tsx" type="module"></script>
12-
</body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link href="/favicon.svg" rel="icon" type="image/svg+xml" />
6+
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
7+
<title>brainllo</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script src="/src/popup/main.tsx" type="module"></script>
12+
</body>
1313
</html>

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
{
2-
"name": "brainrest",
3-
"private": true,
4-
"version": "0.0.0",
5-
"type": "module",
6-
"scripts": {
7-
"dev": "vite",
8-
"build": "tsc -b && vite build",
9-
"debug": "tsc -b && vite build --sourcemap",
10-
"lint": "eslint .",
11-
"preview": "vite preview"
12-
},
13-
"dependencies": {
14-
"idb": "^8.0.3",
15-
"markitdown-html": "^0.1.0",
16-
"openai": "^6.48.0",
17-
"react": "^19.2.7",
18-
"react-dom": "^19.2.7"
19-
},
20-
"devDependencies": {
21-
"@crxjs/vite-plugin": "^2.7.1",
22-
"@eslint/js": "^10.0.1",
23-
"@types/chrome": "^0.2.2",
24-
"@types/node": "^24.13.2",
25-
"@types/react": "^19.2.17",
26-
"@types/react-dom": "^19.2.3",
27-
"@vitejs/plugin-react": "^6.0.3",
28-
"eslint": "^10.6.0",
29-
"eslint-plugin-react-hooks": "^7.1.1",
30-
"eslint-plugin-react-refresh": "^0.5.3",
31-
"globals": "^17.7.0",
32-
"typescript": "~6.0.2",
33-
"typescript-eslint": "^8.62.0",
34-
"vite": "^8.1.1"
35-
}
2+
"name": "brainrest",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc -b && vite build",
9+
"debug": "tsc -b && vite build --sourcemap",
10+
"lint": "eslint .",
11+
"format": "prettier --write .",
12+
"format:check": "prettier --check .",
13+
"preview": "vite preview"
14+
},
15+
"dependencies": {
16+
"idb": "^8.0.3",
17+
"markitdown-html": "^0.1.0",
18+
"openai": "^6.48.0",
19+
"react": "^19.2.7",
20+
"react-dom": "^19.2.7"
21+
},
22+
"devDependencies": {
23+
"@crxjs/vite-plugin": "^2.7.1",
24+
"@eslint/js": "^10.0.1",
25+
"@types/chrome": "^0.2.2",
26+
"@types/node": "^24.13.2",
27+
"@types/react": "^19.2.17",
28+
"@types/react-dom": "^19.2.3",
29+
"@vitejs/plugin-react": "^6.0.3",
30+
"eslint": "^10.6.0",
31+
"eslint-plugin-react-hooks": "^7.1.1",
32+
"eslint-plugin-react-refresh": "^0.5.3",
33+
"globals": "^17.7.0",
34+
"prettier": "^3.9.6",
35+
"typescript": "~6.0.2",
36+
"typescript-eslint": "^8.62.0",
37+
"vite": "^8.1.1"
38+
}
3639
}

0 commit comments

Comments
 (0)