Commit be2e1c7
committed
feat: v0.2 — port XActions scraper patterns, ship real commands
v0.1 was scaffolding + transport. v0.2 makes the commands real by
porting the production-grade subset of XActions' HTTP scraper
(`reference/XActions/src/scrapers/twitter/http/*`) into a typed Go
domain layer with the same stable rules:
api/extract.go
Shared map-walking helpers (getMap, getString, getInt with string→int
for X's view counts, getBool, getSlice, walkPath, walkPathSlice,
walkPathMap, copyMap). Single source of truth for the parser layer.
api/tweets.go — ParseTweet projection
- Recognizes Tweet | TweetWithVisibilityResults (unwrap one level) |
TweetTombstone (typename → non-nil marker).
- Recursive quote and retweet projection with a hard maxQuoteDepth=5
cap so a malicious or pathological response cannot drive the parser
into stack exhaustion.
- Picks the highest-bitrate video/mp4 variant for video URLs.
- parseTimelineInstructions dispatches on TimelineAddEntries /
TimelineAddToModule / TimelinePinEntry, with cursor-bottom-/
cursor-top-/tweet-/user- entry-ID prefix typing.
- GetThread reconstructs a conversation from TweetDetail, filters to
the focal tweet's author by default (self-thread), sorts
chronologically.
- resolveUserID is cached per Client via sync.Map so paginated reads
and the monitor poll loop only pay the UserByScreenName roundtrip
once per session.
api/relationships.go — Followers / Following / Likers / Retweeters
- ParseUserSummary projects user_results.result, drops UserUnavailable,
bumps avatar from _normal to _400x400.
- Generic scrapeUserList paginator with username-keyed Map dedup,
progress callback, multi-page cursor advance.
- Endpoint-specific instructions paths:
Followers/Following → data.user.result.timeline.timeline.instructions
Retweeters → data.retweeters_timeline.timeline.instructions
Favoriters → data.favoriters_timeline.timeline.instructions
api/search.go — SearchPosts / SearchUsers
- Wraps SearchTimeline with the product flag (Latest|Top|People|
Photos|Videos).
- BuildAdvancedQuery composes from:, to:, since:, until:, min_faves:,
min_retweets:, min_replies:, lang:, filter:, -filter: into the raw
query string.
- Dedicated parseSearchUserInstructions for product=People shape.
api/actions.go — Follow / Unfollow + classifyMutationErrors
- REST form POST to friendshipsCreate / friendshipsDestroy with
user_id + include_profile_interstitial_type=1 + skip_status=true,
matching what real browsers send.
- classifyMutationErrors inspects the response `errors[]` envelope
and treats idempotent failures ("already followed", etc.) as
success, so a re-run after a partial batch does not log false
failures. Maps "rate limit" / "spam protection" to RateLimitError,
"cannot find specified user" to NotFoundError, suspended to
APIError.
api/media.go — DownloadTweetMedia
- Streams every media asset on a tweet to disk via the same
http.Client (so any future TLS impersonation round-tripper applies).
- Atomic write via temp + rename so a crash mid-download cannot
corrupt a previously valid file.
- applyImageQuality appends the X CDN size hint (?name=large by
default; small|medium|large|orig).
cmd/* — real commands replacing v0.1 stubs (cmd/stubs.go deleted)
cmd/tweets.go tweets list <user> [-n --replies], tweets get <id>
cmd/relationships.go followers, following (shared paginated runner)
cmd/search.go search posts (--product --since --until --from
--to --lang --filter --exclude --min-likes
--min-retweets), search users
cmd/thread.go thread unroll [--all-authors]
cmd/media.go media download <id|url> [-o --quality]
cmd/monitor.go monitor account [-i --once] poll loop with new-
tweet streaming and follower delta; interval is
clamped to a minimum of 15s
cmd/grow.go grow follow-engagers <tweet>, grow
follow-by-keyword <query>; dry-run by default,
--apply required to mutate; refuses to mutate
from a cloud ASN unless --i-know-its-a-cloud-ip
is also passed (now wired to cmd/doctor.go's
EgressIsCloud — was a stub in the first draft);
--max --min-followers; mergeUserCandidates dedups,
sorts into log-buckets by follower count, then
shuffles within each bucket so the action pattern
is not deterministically biased toward the same
whales every run.
cmd/doctor.go
Exports EgressIsCloud(ctx) for grow's mutation gate.
internal/cmdutil/render.go
PrintJSON, TabPrinter, HumanCount (1.2k / 3.4M), RelTime, TruncateRunes
(rune-safe so multi-byte text doesn't get corrupted), SingleLine.
Tests
api/tweets_test.go rich UserTweets fixture covering Pinned +
wrapped + tombstone + quote + video bitrate;
full UserTweets pipeline against a fake
server with two pages; ParseTweet depth-cap
regression.
api/relationships_test.go full Followers pipeline with cross-page
dedup + UserUnavailable filter.
api/search_test.go BuildAdvancedQuery cases,
parseSearchUserInstructions.
api/actions_test.go FollowUser form body shape,
classifyMutationErrors dispatch
(idempotent / rate-limit / not-found /
unknown).
api/media_test.go image+video download against a fake server,
applyImageQuality, extFromURL.
api/profile_test.go getInt now accepts string-encoded ints.
Coverage: api/ 70.8%, internal/store/ 62.8%. Race-clean under
go test -race -count=1 ./...
Reviewed by an internal Linus-style pass; the four mandatory fixes
(asnIsCloud wired to real doctor egress check, ParseTweet recursion
depth cap, dead sentinel + joinArgs reimpl removed, resolveUserID
cached per Client) are all in this commit.
Docs
skills/x-cli/SKILL.md updated to match real flag names
docs/comparison-xactions.md §6 marked features Implemented with file
references; new bullet for media chunked
uploader = Drop (out of scope for v0.1).1 parent efada90 commit be2e1c7
27 files changed
Lines changed: 3811 additions & 114 deletions
File tree
- api
- cmd
- docs
- internal/cmdutil
- skills/x-cli
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
0 commit comments