Files
Ydisks-Xianyu-Helper/AGENTS.md
T
Christ 6032dfed0f feat: 支持通过管理页面完成首次初始化
初始化流程:

- 新增一次性 POST /initialize 接口,仅在系统尚未存在管理员时允许创建账号。

- 校验管理员密码不少于 8 个字符,初始化成功后自动建立会话并登录。

- 增加初始化并发保护,避免首次打开多个页面时互相覆盖密码。

前端与资源:

- 将初始化页面改为密码和确认密码表单,移除普通用户需要执行的 CLI 命令和数据库路径提示。

- 初始化成功后直接进入管理后台,并重新构建嵌入式前端资源。

- 增加未初始化接口回归测试和自动登录验证。

文档同步:

- 更新 README、文档站、GitHub Wiki、前端说明和 AGENTS.md。

- 明确 Docker 使用 XIANYU_ADMIN_PASSWORD 非交互初始化。

- 明确独立二进制和 Linux 安装包通过 Web 页面初始化,CLI 仅作为无浏览器或运维备用方式。

- 同步桌面端 Chromium runtime 内置、Linux 安装流程和 Windows/macOS 签名包说明。
2026-08-12 03:04:28 +08:00

6.1 KiB

AGENTS.md

Repository shape

The active application contains:

  • cmd/server/ — server entrypoint, administrator bootstrap (/initialize and -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

cd /Users/christ/Workspace/git/xianyu/Ydisks-Xianyu-Helper

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):

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

On a new database, open the management page after starting the server. The first-run page accepts and confirms an administrator password, creates the admin user, and signs the user in automatically. The CLI bootstrap remains available for headless or operational environments.

Disable browser automation when Chromium is unavailable:

go run ./cmd/server -db data/xianyu_data.db -addr :8080 -no-browser

Initialize or reset the administrator:

go run ./cmd/server -init-admin -db data/xianyu_data.db -admin-password '...'

Verify a database (migration + CRUD across dialects):

go run ./cmd/dbverify "mysql://user:pass@tcp(host:3306)/db"

Run a focused test:

go test ./internal/server -run TestName -v
go test ./internal/db -run TestMigrate -v

Cross-database regression (requires Docker containers or external DBs):

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:

cd /Users/christ/Workspace/git/xianyu/Ydisks-Xianyu-Helper/frontend
npm install
npm run build

Run the frontend development server:

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.