Files
Ydisks-Xianyu-Helper/AGENTS.md
T
Christ 9a5b20d189 文档:冻结滑块认证逻辑并完善项目目录说明
新增仓库级 AGENTS.md,将滑块认证设为最高级别生产冻结区域,明确受保护文件、禁止的直接与间接变更,以及仅限用户当次明确授权的例外流程。

新增滑块认证冻结规范,完整记录标准 NC DOM 选择器、300px 减 42px 等于 258px 的精确距离、Playwright 主引擎轨迹与严格 x5sec 成功条件、失败重试和页面重载恢复、直接 Chromium/CDP 备用引擎、持久化 profile、诊断日志及必须保留的回归测试。

扩展 README 项目目录树,补充命令行工具、后端模块、前端、文档、脚本与本地数据目录职责,并增加冻结规范入口。

提交范围仅包含文档;README 中其他既有工作区改动未暂存。格式验证:git diff --cached --check 通过。
2026-07-14 21:03:32 +08:00

134 lines
5.8 KiB
Markdown

# AGENTS.md
## Repository shape
The active application contains:
- `cmd/server/` — server entrypoint, administrator bootstrap (`-init-admin`), and HTTP server.
- `cmd/init-admin/` — interactive administrator initialization CLI.
- `cmd/dbverify/` — migration + core CRUD verification tool across SQLite/MySQL/Postgres.
- `internal/server/` — chi HTTP API and SPA serving.
- `internal/adapter/` — wiring layer that implements `engine.Handler` and `automation.OrderDetailFetcher` (system events → automation center, order-detail fetch / password-login refresh → browser, account alerts → notifier).
- `internal/account/` — enabled-account supervisor.
- `internal/engine/` — per-account runtime, replies, and delivery behavior.
- `internal/automation/` — unified automation center (paid delivery, review gifts, review requests) + scheduler.
- `internal/xianyu/` — MTOP, WebSocket, QR login, and protocol code.
- `internal/browser/` — in-process Chromium automation through playwright-go.
- `internal/db/` — multi-database access (SQLite/MySQL/Postgres) with embedded Goose migrations per dialect.
- `frontend/` — active React/Vite source.
- `internal/webui/static/` — embedded frontend build output.
## Common commands
```bash
cd /Users/christ/Workspace/git/xianyu/xianyu-go
make build # go build ./cmd/server
make test # go test ./...
make vet # go vet ./...
make lint # golangci-lint run ./... (0 issues baseline)
make check # vet + lint + test
make frontend # build frontend into internal/webui/static
```
Run the server (SQLite by default; MySQL/Postgres via `-db-url` or `DATABASE_URL`):
```bash
go run ./cmd/server -db data/xianyu_data.db -addr :8080
DATABASE_URL="mysql://user:pass@tcp(host:3306)/db" go run ./cmd/server -addr :8080
```
Disable browser automation when Chromium is unavailable:
```bash
go run ./cmd/server -db data/xianyu_data.db -addr :8080 -no-browser
```
Initialize or reset the administrator:
```bash
go run ./cmd/server -init-admin -db data/xianyu_data.db -admin-password '...'
```
Verify a database (migration + CRUD across dialects):
```bash
go run ./cmd/dbverify "mysql://user:pass@tcp(host:3306)/db"
```
Run a focused test:
```bash
go test ./internal/server -run TestName -v
go test ./internal/db -run TestMigrate -v
```
Cross-database regression (requires Docker containers or external DBs):
```bash
TEST_MYSQL_URL="mysql://root:pass@tcp(host:3306)/db" \
TEST_POSTGRES_URL="postgres://user:pass@host:5432/db" \
go test ./internal/db -run TestMultiDB -v
```
Build the frontend:
```bash
cd /Users/christ/Workspace/git/xianyu/xianyu-go/frontend
npm install
npm run build
```
Run the frontend development server:
```bash
npm run dev
```
Vite proxies backend routes to `localhost:8080`. Production builds are written to `internal/webui/static/` and embedded by the Go server.
## Architecture
`cmd/server/main.go` opens the database (SQLite/MySQL/Postgres by URL scheme), constructs the adapter + account manager + automation center + notifier, starts enabled account runtimes, initializes the optional in-process browser manager, and starts the HTTP server. Business logic does not live in `main.go` — it delegates to `internal/adapter` (Handler/OrderDetailFetcher wiring), `internal/engine`, `internal/account`, `internal/automation`, and domain-specific server handlers.
`internal/xianyu` owns lower-level platform integration:
- `mtop` for signed HTTP calls (interface `mtop.Client` allows test mocking).
- `ws` for WebSocket transport.
- `qrlogin` for QR login.
- `protocol` for cookies, signing, decoding, and message IDs.
Browser-backed verification, password login refresh, and order-detail fallbacks live in `internal/browser`. Keep the browser contract and its server/engine callers aligned.
## Frozen slider CAPTCHA logic — DO NOT MODIFY
The current slider CAPTCHA implementation is production-frozen. Its authoritative behavior is documented in `docs/slider-captcha-frozen-spec.md`.
Unless the user explicitly requests a slider CAPTCHA behavior change in the current task, agents MUST NOT:
- edit, refactor, optimize, rename, move, delete, or reformat the protected slider implementation or its tests;
- change selectors or selector priority, same-frame visibility checks, the exact `300px - 42px = 258px` standard NC distance, trajectories, point counts, timing, mouse-event order, or main-engine no-overshoot behavior;
- change fresh-`x5sec` success criteria, punish/captcha URL checks, retry selectors, retry text checks, origin checks, reload recovery, retry counts, or timeouts;
- change Playwright-first / direct-Chromium-CDP-fallback ordering, persistent-profile reuse and locking, verification-URL refresh timing, Cookie merge behavior, browser flags, environment defaults, or engine result labels;
- weaken, skip, delete, or rewrite slider tests to permit different behavior;
- modify a caller or shared helper in another file when that would indirectly change any frozen behavior above.
Directly protected files are:
- `internal/browser/slider.go`
- `internal/browser/slider_test.go`
- `internal/browser/token_captcha.go`
- `internal/browser/token_captcha_test.go`
- `internal/browser/token_captcha_fallback.go`
- `internal/browser/token_captcha_fallback_integration_test.go`
- `internal/browser/token_captcha_orchestrator_test.go`
Only an explicit user instruction in the current task can authorize a change. When authorized, update the implementation, tests, and frozen specification together, and run every verification required by the specification. Do not treat one authorization as permission for later tasks.
## Editing notes
- Preserve unrelated working-tree changes.
- Update `frontend/vite.config.ts` if API route prefixes change.
- Rebuild the frontend after source changes so embedded assets stay current.
- Keep protocol and database behavior covered by focused tests.