Treehole - 北大树洞 CLI
A CLI client for PKU's anonymous discussion platform (PKU Helper Treehole).
Architecture
- Crate location:
crates/treehole/ - Auth flow: IAAA SSO (
app_id="PKU Helper") → JWT callback at/chapi/cas_iaaa_login→ optional SMS verify - API: JSON REST at
/chapi/api/v3/*(modern) and/chapi/api/*(legacy) - API docs:
docs/treehole-api.md
Key Source Files
src/main.rs— Clap CLI definition with all subcommandssrc/commands.rs— Command implementations (login, post, search, etc.)src/api.rs— HTTP API client, request builders, response typessrc/display.rs— Terminal output formatting withcoloredcratesrc/client.rs— reqwest client builders (buildfor auth,build_simplefor IAAA)
CLI Commands
| Command | Alias | Function |
|---|---|---|
login | IAAA password/QR login → JWT | |
logout / status | Session management | |
list | ls | Browse posts/feed |
show | View single post with replies | |
search | Full-text search | |
post | Create post (text, tags, images, rewards/树叶) | |
reply | Reply to a post | |
like / tread | Vote on posts | |
star / unstar / stars | Bookmark management | |
follow / unfollow | Follow posts | |
msg / read | Notifications | |
me | Profile + own posts | |
score | Grade query (with color rendering) | |
course | Weekly course schedule (canonical source — includes 主修 + 辅修 + 双学位) | |
schedule | This week's day-by-day schedule | |
academic-cal / activity-cal | Academic / activity calendar | |
otp | TOTP 2FA management (bind/set/show/clear) |
Auto-Login for AI Agents
# Check session status
info-auth check
# Auto-login (reads credentials from OS keyring, no password needed)
treehole login -p
# If SMS verification is needed (first login or periodic):
PKU_SMS_CODE=123456 treehole login -p
Treehole may require SMS verification on first login or periodically (~30 days). When PKU_SMS_CODE env var is set, it auto-confirms sending and submits the code without interactive prompts.
Development Conventions
- All user-facing strings are in Chinese (prompts, errors, output)
- Error handling:
anyhow::Resultwith.context("中文描述") - HTTP client uses
redirect(Policy::none())for manual redirect handling - Session persisted to
~/.config/info/treehole/viainfo_common::session::Store - Credentials resolved via
info_common::credential(keyring → env → interactive) - Shared auth from
info-commoncrate (see info-common skill for details)