feat: anti-detection hardening, transaction cache, article parsing, structured write output

Anti-detection:
- Add 6 sec-ch-ua-* Client Hints headers (arch, bitness, full-version, etc.)
- POST requests now send Referer: x.com/compose/post + Priority: u=1, i
- follow/unfollow REST adds include_profile_interstitial_type param

Performance:
- Transaction ID cache with 1h TTL (~/.twitter-cli/transaction_cache.json)
- resolve_user_id: auto-detect screen_name vs numeric user_id

Features:
- Twitter Article parsing: extract long-form content as Markdown
- Write operations emit structured JSON/YAML when piped or OUTPUT env set
  ActionResult: {success, action, id, url, ...}

84 tests passing
This commit is contained in:
jackwener
2026-03-10 20:48:42 +08:00
parent 97708889c9
commit 32d074dc9f
10 changed files with 533 additions and 145 deletions

View File

@@ -48,6 +48,18 @@ def get_sec_ch_ua():
)
def get_sec_ch_ua_full_version():
# type: () -> str
return '"%s.0.0.0"' % _chrome_version
def get_sec_ch_ua_full_version_list():
# type: () -> str
return '"Google Chrome";v="%s.0.0.0", "Chromium";v="%s.0.0.0", "Not.A/Brand";v="99.0.0.0"' % (
_chrome_version, _chrome_version,
)
def _get_locale_tag():
# type: () -> str
raw = (
@@ -86,6 +98,10 @@ def get_sec_ch_ua_platform():
# Static Client Hints
SEC_CH_UA_MOBILE = "?0"
SEC_CH_UA_PLATFORM = get_sec_ch_ua_platform()
SEC_CH_UA_ARCH = '"arm"' if sys.platform == "darwin" else '"x86"'
SEC_CH_UA_BITNESS = '"64"'
SEC_CH_UA_MODEL = '""'
SEC_CH_UA_PLATFORM_VERSION = '"15.0.0"' if sys.platform == "darwin" else '"10.0.0"'
# Legacy aliases — modules that import these get the default value.
# _build_headers() should use get_user_agent() / get_sec_ch_ua() instead.