- Single Rust 2021 binary crate named
thu-learn;src/main.rsis the only binary entrypoint and release output istarget/release/thu-learn. - The CLI talks to Tsinghua Learn at
learn.tsinghua.edu.cn; project-owned docs, comments, help text, and runtime output should be English. Preserve Chinese only for Learn protocol literals and realistic fixtures, and document those cases when they appear.
src/cli.rs: clap command surface, aliases, human vs--jsonoutput, login flow, cache clearing, and command orchestration.src/client.rs: reqwest client, cookie store,_csrfextraction, authenticated GET/POST/download helpers, and cookie persistence.src/api.rs: Learn API endpoints plus JSON/HTML parsing for courses, homework, announcements, files, and submit.src/browser_login.rs: Chrome WebDriver login;thirtyfour::WebDriver::manageddownloads/starts chromedriver, but local Google Chrome is still required.src/cache.rsandsrc/paths.rs: current-semester/course cache andcookies.jsonlocation;src/models.rsowns serialized output models and short ids.
- Run from the repo root:
cargo test,cargo fmt --check,cargo clippy --all-targets -- -D warnings, thencargo build --release. - Focused examples:
cargo test api::tests::parse_deadline_invalid,cargo test client::tests::csrf_extracted,cargo test cli::tests::prev_semester_invalid. - There is no CI, task runner, rustfmt config, or clippy config in this repo; trust Cargo commands and source tests over assumptions.
- Session cookies are stored at
~/.config/thu-learn-cli/cookies.json; this file contains session credentials and must never be printed, copied into the repo, committed, shared, or exposed. - The cache is under
~/.cache/thu-learn-cli/;thu-learn loginclears it after importing cookies. - The old
./cookies.jsonfile and old macOS app support cache are not migrated automatically, so users may need to log in again. - Do not make automated tests require live
learn.tsinghua.edu.cn, a real Tsinghua account, Chrome, chromedriver, or an existingcookies.json.
- Network Learning JSON fields are pinyin abbreviations and can vary; keep the
serde_json::Valueplus candidate-key parsing style insrc/api.rs. - Explain pinyin API fields near parsing/model code with both Chinese and English names, for example
xszyid: 学生作业 ID / student homework ID. - Session cookies are nonpersistent.
src/client.rsintentionally saves withsave_incl_expired_and_nonpersistent_jsonand loads withload_json_all; replacing these with ordinary cookie-store save/load breaks login reuse. - Authenticated GET, POST, and download requests need
_csrffrom the course page before calling Learn endpoints. - Course and announcement/file fetching is intentionally concurrent in several paths; avoid serializing it unless debugging or fixing a measured issue.
- Existing tests are inline unit tests in
src/api.rs,src/client.rs, andsrc/cli.rs; add pure parser/helper tests near the code being changed. - Use
--jsonfor scriptable CLI checks when supported; human output uses colors only when stdout supports them. - Hidden command
thu-learn debugprints raw JSON for field checks, but it requires a valid login session.