Some Bits: Nelson's log

6 posts about mastodon

Vibe coding a Mastodon thread unroller

Just had my first experience using an AI (Claude Code) to write a whole program start to finish. See the result here.

The AI coding was amazing. With about 60 minutes of “work” and $5.50 I had my result. (I then spent another 30 minutes and $3 tinkering without much improvement.) It would have taken me 4+ tedious hours to do this myself and while my resulting code would probably be better, the AI code was more than adequate for my one-off needs.

A key part of this project’s success is how simple it was. It was a Python program to download some data from a Mastodon server and format it as HTML. I could just look at the HTML output and decide if it was working. I didn’t even bother reading the Python code the AI generated. If I cared more about what the system itself was doing, how the Python script worked, it would still have been useful but taken a lot more work on my part to review everything.

I’ve been using LLMs for awhile now in chat interfaces and am impressed with them, but they are clearly just stochastic parrots, text prediction machines. Claude Code felt different. It’s still mostly an LLM but it has enough of a reasoning engine in it that I could give it high level instructions and it’d figure things out on its own. That’s really impressive to me.

I don’t think AIs are going to replace human programmers entirely anytime soon. Part of why this project went so well is I have some expertise in this kind of thing, so I knew how to tell it to (say) cache all the data from Mastodon once up front and then generate HTML locally. Or to rewrite images to make them smaller. That’s hard-won knowledge from years of building systems. But the actual scutwork of looking up Mastodon APIs and remembering how to resize images in Python? Claude did that just fine.

Anyway I’m sold on vibe coding, at least for a certain kind of workaday code where you can easily inspect the output and decide it’s good enough. And you don’t care how good the code is. I’m certain there’s still plenty of need for human expertise for more important or complicated systems but this AI experience was very impressive.

The application

I took a trip to SE Asia recently and used Mastodon to share a bunch of postcards as a Mastodon thread. Now that I’m home I wanted a nice static copy of all that easy to view and share forever. There’s a bunch of Mastodon thread unrollers but I didn’t like the output of any of them.

Here’s the HTML output Claude and I produced. I’m pretty happy with it!

That’s the final output, the customer deliverable. It looks good! Even better the HTML it generated is quality. Reasonable semantic HTML, simple structure, nothing too stupid in it. That’s better than any other automated tool I’ve ever used.

There’s also the intermediate product, the Python and shell scripts it generated. Those are also pretty good. I didn’t really read them, I’m running on vibes here, but on a quick glance it looks like reasonably OK Python code that I could understand and maintain. I would not trust Claude to do more complicated things but for this straightforward task it is good.

Claude Code even thoughtfully generates and updates a README explaining what it does. You can also get it to export a conversation of your chat log, which in some sense is the “real” programming I did.

Getting the AI to write the application

I never wrote or edited any code. I did all of this within the Claude Code shell. It wrote the code. I mostly didn’t run any code either, the agent does that for you.

High level development was in two pieces: write a Mastodon downloader to a local database, then write an HTML formatter from that local data. Then a lot of iteration, particularly on the HTML portion. I’d tell it things like “change the layout so images are only one column” or “change this text to a different font and color”.

Here’s the important choices I made:

  1. I broke the project into two parts: download the Mastodon data from the API to local disk, then generate HTML on local disk. That’s an important pattern for projects like this, it lets you iterate on the HTML presentation much faster without spamming the API.
  2. I told Claude to write simple static HTML. These tools have an alarming habit of bringing in React and other Javascript garbage.
  3. I tried out a couple of strategies to make the pages smaller, finally settling on using downsampled JPGs. I’m not sure if Claude would have thought to suggest that, I wish I’d asked!
  4. About a quarter of the way into the project I thought to ask Claude to use git. It happily did so, checking in code as appropriate.

I’ve got the conversation stored away (well most of it, it got “compacted”). Here’s some key prompts I gave it:

I want to write a Python script that downloads a bunch of posts from my Mastodon account. I want it to download a single thread: my original post and all of my replies, about 100 of them. Every post contains photos or videos that should also be downloaded. I want you to keep the original JSON data from the Mastodon API and also extract everything into a simple sqlite database with columns for post timestamp, post text, and references somehow to the images in the post. the images are important!

you’ve made two errors already converting datatypes. did you make any others? think hard about the code you wrote and try to fix anything else before I run it again

now I want you to make a nice HTML view of all the posts and pictures from the mastodon thread that I downloaded. I want the output HTML to be a simple static HTML file without any javascript dependencies, no frameworks, definitely no react. it should have minimal CSS styling but something that looks nice and modern. The images are most important, I want to be sure they look good. the images have alt tags on them in the mastodon posts, those shoudl be displayed as captions. And I want you to generate all this HTML from the downloaded files, do not make any requests on the Internet like to the Mastodon API. can you do that? tell me how you will proceed before doing it so I can review.

I ran it. It only downloaded two posts: the original and one reply. but not the others. the third post is a reply to the reply, did you remember to recurse and load the thread?

can you write code to generate smaller images to save bandwidth? ie, resize the original JPGs to new JPGs which aren’t bigger than 800 pixels. I also want it so if the user clicks on one of the JPGs in the HTML view, it links to the full size image. it can just link directly to the JPG, don’t need an HTML page for each full size image. write code to generate the smaller files, alter the HTML generator to use those files, and alter the deploy script to deploy both the smaller JPGs and the originals to my server.

Some observations

Some interesting things Claude did:

  1. It made a couple of errors converting types from JSON output (numbers to strings, datetimes). I fixed those one at a time and got annoyed so I scolded it and told it to look at its own code and fix any other errors. It made some more changes I didn’t review, and the resulting code worked first time.
  2. I asked it to download a font from Google Fonts and use it locally. It tried to download it with curl and was blocked (a security policy in the Claude agent?) So then it just wrote a Python script to download the fonts instead and ran it. It’s hacking its own sandbox!
  3. Its first attempt to download fonts failed, wrong URLs. It detected the errors and did something itself to find the correct URLs and ran the download a second time. That also had one error for one font variant and it realized it didn’t need it so just ignored that error.
  4. It got confused with HTML templates and Javascript, some sort of problem with { quoting. It sort of hacked its way into fixing it just like a junior programmer would. It got there in the end!
  5. It did OK with an open ended “can you think of anything to improve”. It suggested adding some good generic HTML things like ARIA tags, print CSS, lightbox view, social media sharing. It also suggested adding map integration or location tags to the posts, a very thoughtful suggestion for my travel app!

I don’t love the Claude Code UI. It’s some terminal UI thing and very chat-oriented. I think the VS.Code integrated tools like Cursor are probably better for more careful coding. OTOH this worked well for my one-off task. I like how Claude Code has a very agent-centric design, it’s actively doing things on your behalf. It’s much more like giving instructions to a junior programmer rather than having someone pair programming with you making suggestions.

Taking over Feditrends

About a week ago I took over the service Feditrends, a link aggregator that shows trending stories on the Fediverse and Bluesky. The project creator (Jackson Palmer) had gotten tired of running it and shut it down a couple of times. I visit it every day so I took it over.

I have no immediate plans to change anything, I want to get some familiarity with what it’s doing and how it’s used first. Personally I use it partly to find interesting links and partly to keep tabs on what the Fediverse is talking about. The current dataset tends towards US news stories. I mostly avoid the mainstream news cycle but I like seeing what folks are talking about.

Taking it over

Taking it over was quite simple. Jackson did a great job releasing the code as open source. I got it running in about 15 minutes of work. It’s very simple, just a few hundred lines of Python code to fetch feeds and generate static HTML. It stores some stuff in a sqlite database. I haven’t looked closely.

Once I had it running locally and pushing to a web server of my own, Jackson just transferred the Namecheap domain name to me. I changed the DNS record and that was that. He also transferred the GitHub organization and the Mastodon account.

Observations

It all seems to run fine on its own. It does not have a lot of users. Feedly reports 22 subscribers, but of course that’s only a small fraction. The whole server is getting only a few thousand requests a day. About 30% of that is for the RSS feed for the main site, another 22% accessing the main HTML page. Maybe 1% of the requests are for the second experimental Bluesky product. I may remove that since I don’t use it and it’s completely separate code.

Feditrends now is pretty much entirely news links. That’s because its data source is Mastodon’s trending links (for example) on about 10 of the biggest English language Mastodon services. Mastodon.social is quite clear these are “News”. I’m not certain but I’ve been told these links are hand-curated, that a moderator has to approve a link to be valid for showing up there. Update: a friend says that the publishers have to be approved but not the links themselves. Also points to the Mastodon code for links.

Earlier versions of Feditrends used to have three tabs: News, Posts, and Hashtags. I’m not quite sure why Jackson narrowed down to just News but I can think of several reasons the other views could be harder to make work well. The code for posts is on GitHub.

Plans

The site could use an About page. With a last updated slug in it.

I never used the RSS feed before. It’s quite noisy, Feedly says it’s like 500 articles per week. I’ve gotten a suggestion to have a feed with fewer links, the Top 10 instead of all trending or something.

I really miss belong.io, Andy Baio’s old trending links service. That worked by watching Twitter accounts of a carefully selected list of 1000+ people for trending links. It’s possible a similar idea would work for the Fediverse but there’s various cultural forces at work that make me wonder if it really would. I should look at the “Trending Posts” data at Mastodon instances again to see if it’s interesting. Or consider my own curated set of accounts to track.

There’s some tinkering I could do to make the production a bit better. All my Proxmox work has paid off though, I got it up and running in an Ubuntu container on my server with simple backups, etc. I’m not sure what’s in the sqlite database and if it’s growing without bound. The static site publisher logs need some attention.

I should consolidate GitHub, right now I’m working in a fork.

I’d like to move the web serving off my own datacenter server and into some hosted solution. It’s so little traffic it’d be cheap or free on Github Pages or Netlify or just some sort of S3-like host or Cloudflare or something. Static sites are so easy to work with! The hard part is I’d like some basic access log info; I don’t want to add tracking Javascript just to get a rough count of visitors. I’m using GoAccess on the Apache logs for now.

Every Mastodon client is broken

I have a simple goal with Mastodon. When I wake up in the morning I want to see every single post in my Following timeline. In reverse time order, oldest first. I do not want to see boosts ever but I want to see every original post. In Twitter I could do this easily, just by scrolling down (with algorithmic timeline disabled).

Not a single Mastodon client I’ve tried can do it.

Fedilab, tooot, and Megaladon all will just miss posts. I’ll see a post that’s 7 hours old, then a post that’s 1 hour old, and everything from 7–1 in between is missing.

Moshidon looks like it might be able to show all the posts inbetween. I like the UI above: it shows the 11 hour gap and has buttons to fill it on either side. A little more manual than I’d like, but workable. Only it has a fatal bug; when I tap “load newer posts” it does load them but for some stupid reason ignores my client-wide setting to ignore Boosts. So I see a stream of lots of boosts, not just the actual posts I want. It doesn’t have this bug when loading posts in other contexts, only pressing this button. Also if I quit Moshidon and relaunch it now that UI is missing; any posts I didn’t tap to load last time are now forever inaccessible.

Writing this now I realize I haven’t tried the official Mastodon Android client. In the past I didn’t like that one much, but I suppose I should try it now. Nevermind: it doesn’t have the ability to hide boosts.

The problem is so commonplace I wonder if it’s a problem with my server, or with the Mastodon API. But it’s not exactly consistent: each Android client seems to have a slightly different gap it refuses to show, it’s not like the same set of 23 posts are missing. And the Mastodon web client (or rather the Glitch soc fork) I use on tech.lgbt also shows this bug in the web view. But only sometimes. It doesn’t today, whereas all 4 Android clients I tried do.

One thing I’ve noticed trying all these clients is they all suck in various ways. 3 of the 4 lack the “tap at top of screen to scroll to beginning” UI that every Android app should have. Tooot doesn’t even have a humane inertial scrolling, so I have to swipe up one screen at a time over and over again to get to the most recent posts.

Another big probem is these apps all love giving user preferences. Fedilab must have 200+ settings. Some I understand; a single button to show or hide boosts, for instance. Others are baffling. Why are there buttons for “show indicator for image alt text” and also “show indicator for missing alt text”? Just pick an alt text presentation style (the right one) and do it, don’t make the user create their own custom client experience. Lots of choices for configuring correct behavior too, like “load missing content from servers”. Um? Yes? Why is this a toggle? It’s classic open source product design: the folks building the product just love all those choices so they figure their users must want choices too. Too many choices.

Sorry, feeling a bit ranty today. The inability to simply load old posts is pretty maddening.

Update: an iOS using friend says Ivory has no trouble with showing all old posts. Unfortunately I don’t have any iOS devices to try it on.

Update 2: I like this speculation it could be related to paginating incorrectly while filtering boosts. That the client loses count because it’s skipping some posts. Plausible? Hard for me to test short of spamming myself with boosts and seeing if it works.

Update 3: another line of inquiry is that I am informed that the Mastodon server keeps a queue of 800 posts for you in the timeline. That’s it and that includes all things, including stuff I’m filtering out in the client like boosts. That number is hardcoded in feed_manager.rb. I don’t really understand the code but it’s more complicated than that, with some calculations happening with just 200 or 400 items. I don’t think the posts I’m missing are 800 down a time ordered queue, I’d guess more like 100-300. But it’s worth a closer look.

Mastodon Chrome extensions

I like Mastodon. But the mess which is cross-server following UI is really terrible. One bandaid for it is a browser extension. There’s a bunch of them. But the extensions have to have permission to modify data on all Internet sites, a potentially scary thing. Extension authors have definitely abused that power in the past. So my rule for this kind of thing now is it has to be open source.

There’s three open source Chrome extensions I found that make following cross-server easier.

  • Tootski (GitHub). This is the one I use. It works by adding a button to the awful “following users on Mastodon is a terrible experience” popup. It’s been a little flaky but does seem to work. Also ads a “share any page on Mastodon” button which I don’t need.
  • Mastodon Link. Obtrusive UI, so I skipped it.
  • Mastodon Profile Redirect. Two-step explicit process involving navigating to a web page at your instance.

ActivityPub servers

I want an ActivityPub server so I can do Fediverse experiments and see them in Mastodon. What I really want is something like CGI; I don’t care about the protocol server, I just want to write little scripts that easily federate. I don’t want a consumer product with a web UI, I want a little platform for which I can create experimental scripted accounts for people to subscribe to. I’m not sure that exists.

I asked on Mastodon about servers and got some suggestions. Here they are. Lines of code are rough estimated calculated with scc.

takahe. 9,000 lines of Python. Active, seems very new (2 months old), not yet at a 1.0 release. Seems web UI centric.

gotosocial. 58,000 lines of Go. Active, six months old, labelled “alpha”. Also focussed on a web UI and consumer product.

epicyon. 103,000 lines of Python. Active, 3.5 years old. Also web based but an emphasis on being simple. OTOH runs as a proxy server and needs nginx in front.

honk. 10,000 lines of Go, 3.5 years old. Not entirely active, but has had some recent updates. Seems.. idiosyncratic. But also nicely minimalist. Someone mentioned it has lots of forks.

minipub. 7200 lines of Typescript+Javascript. A year old, but no edits in 6 months, maybe one developer. “for posting federated podcast comments”.

minimal-activitypub, 650 lines of Python, 4 months old, one author. Found this one myself and as the name says, it’s minimal. May be a suitable start for the platform I want? I note from the docs that it’s all client to server stuff, not server to server, and I don’t even understand enough about ActivityPub to know exactly what that might mean. There’s a couple of the author’s projects built on top of it.

express-activitypub. 440 lines of Javascript, 4 years old, one author and seems largely moribund. OTOH it’s by the great Darius Kazemi, ActivityPubber extraordinaire, so it’s worth a look. Darius says his projects are live, just stable.

rss-to-activitypub. 700 lines of Javascript, 4 years old, also Darius and mostly moribund? But this specific RSS product is very close to what I want to tinker with, also worth revisiting.

snac2, 6000 lines of C. Two months old, active but maybe just one developer. Has a simple web interface. Mostly runs like an old school Unix daemon, this post talks about setup. The earlier snac was a prototype in 3800 lines of Python written in six weeks.

microblog.pub. 13,000 lines of Python. 5 months old (v2), active. Simple web UI. Single user, minimalist, blog-oriented. This looks promising as a starting point for me.

notes. Ruby, new, experimental.

6 static files. 0 lines of code, just some static JSON. Not a real server but a nice demonstration of a very very simple ActivityPub participant. The writeup notes that you have to accept POST requests to handle people following you, so that takes a little code.

Playing with ActivityPub, tmcw’s article about writing his own very simple ActivityPub instance. Describes the complexity required.

How to implement a basic ActivityPub server: notes from 2018.

Adding ActivityPub to your static site.

None of these are an obvious thing for me to Just Use.

Mastodon account migration (Apr 2022)

My old Mastodon instance stopped working. I want to migrate to nelson@tech.lgbt. Unfortunately migration is pretty limited in Mastodon. There is no simple way to move your actual content, your toots. You can move your list of who you follow though, and in some circumstances get your followers to follow your new account. There’s three ways to migrate:

  • Just redirect the old account. This doesn’t actually move any data or set up the new account at all, but it does tell any new visitors you’ve moved.
  • Use the “account migration” tool. This basically does a redirect, but then also “irreversibly force everyone to unfollow your current account and follow your new account”.
  • Migrate manually with data exports and imports.

The first two methods require the server you’re moving from be online and federated. My old server is dead. But I do have a data export archive so I can use that to set up the new account.

What’s in a Mastodon export? It’s a bit messy, there are several files.

  • Who you follow, block, mute. Also lists and bookmarks. These are in separate CSV files you have to download individually. These are the stuff you can usefully import elsewhere.
  • All your toots in an archive, along with a bunch of images. The toots are in a big JSON blob. There’s also some other data like your avatar image. These cannot be imported.

Bottom line, the only thing I can really import usefully is who I follow. And doing that won’t get them to follow me. Mastodon’s blog post says “moving instances is painless and straightforward with Mastodon” but that’s really not true. Not surprised, doing this in a federated system with user security as a top priority is hard.

The import seemed to go smoothly. It’s not instance, the import page says “we’ll get to it eventually”. It seemed to take a few minutes.

The import was not complete, but maybe it takes awhile. My export had 275 accounts I was following. First time I looked after 15 minutes I had about 114 people I was following (according to the new server’s export tool). The second time after 45 minutes it was 177. I don’t expect all 275 of the accounts will ever import, some are from servers that are gone.

I’m starting to get followers again, I suspect because they saw the “nelson followed you” notification. It will be impossible to get most of them over without the old server coming back up.

The nicest thing about my new instance is the skin is now some clean, single column layout of toots. I really hated that old darkmode multicolumn thing!