#ktistec 107 hashtags

The prologue to this post is here.

Investigating commit e2327eea might be a bust.

I dumped the symbols before and after this change. The new symbols were all specializations of the core library Hash class introduced by adding JSON parsing support for the "language" property.

So what does that mean and why is this commit a dead end?

You can think of Crystal classes and methods as being implicitly generics. If you have a method foo with one parameter bar and call it with an Array, Crystal creates a version of that method specialized to handle an Array type as an argument. If you call it with a Hash, Crystal creates another version of that method specialized to handle a Hash type as an argument. If the method has 20 lines of code, you effectively get two copies of those 20 lines of code. There is no runtime polymorphic dispatch, which is one of the reasons Crystal is so fast. You can make all of this explicit with Crystal type restrictions, method overloading, and generics, of course, but you don't have to.

This path is a dead end (for now) because any improvements that I can see that I can make (replacing hash construction with a more fluent sequence of attribute assignments) will need to be made to other classes where this is a problem, and there are only a few of those, so the net potential for improvement seems small.

#ktistec #crystallang

After I release a new version of ktistec, I build the server commit-by-commit to see which commits increase the server executable size and build time the most. I do this because I’ve learned that small implementation details (inlined code, small methods, using blocks) can have large impacts on these numbers.

Here's the output:

Commit         Size          Time
======== ========== ======= ===== =======
248850b1   36426264          10.3
47268073   36425688  -0.00%  10.5  +1.60%
344de272   36425688  +0.00%  10.8  +3.24%
ef561f52   36425944  +0.00%  10.8  -0.08%
8ae2cbd4   36429128  +0.01%  10.8  -0.01%
3e425f3b   36429128  +0.00%  10.8  +0.22%
1487d903   36427704  -0.00%  11.0  +1.42%
935c9ceb   36427016  -0.00%  11.0  +0.14%
de37dc6a   36427016  +0.00%  10.9  -0.97%
a660a326   36427016  +0.00%  10.8  -1.12%
ff3d990e   36427016  +0.00%  10.8  +0.54%
5724a58d   36523192  +0.26%  11.0  +1.78%
7b5057d4   36523640  +0.00%  11.0  -0.44%
30ca6a3f   36541352  +0.05%  11.6  +5.73%
e2327eea   36671592  +0.36%  11.0  -5.36%
ad0d76eb   36671592  +0.00%  10.9  -0.48%
d388e74f   36671592  +0.00%  11.4  +4.59%
dacea7ad   36671592  +0.00%  11.0  -3.76%
03d5dfd8   36671592  +0.00%  10.8  -1.63%
79d9d89f   36671576  -0.00%  11.0  +1.82%
b65d292f   36792376  +0.33%  11.1  +0.95%
0ef53365   36808904  +0.04%  11.6  +4.88%
b3766e7b   36808904  +0.00%  11.1  -4.50%
56ba79ce   36825416  +0.04%  11.1  -0.50%
4824df58   36825736  +0.00%  11.1  +0.31%
c4705143   36837544  +0.03%  11.1  -0.03%
e3d37ef7   36837768  +0.00%  11.5  +3.52%
4509fa0d   36837768  +0.00%  11.0  -3.83%
0ff9237b   36837768  +0.00%  11.0  -0.55%

Overall, the server executable size increased by about 1.1% and the build time increased by about 6.8%. Maybe that's not too bad for a major feature, but let's dig in.

It's nice to see that three commits account for almost all of the increase in server executable size:

  • 5724a58d Add `language` to `Object`.
    2 files +19  loc
  • e2327eea Render `contentMap` on ActivityPub objects.
    2 files +17 -1 loc
  • b65d292f Add translation actions to the objects controller.
    1 file +35 loc

But, compare 5724a58d to 8ae2cbd4 (Add `language` to `Account`). It added +22 loc but didn't increase the server executable size as much.

In any case, I'll look at e2327eea first. I'd like to understand why this relatively small change adds 130,240 bytes to the server executable size!

The follow ups are here, here, here, and here.

#ktistec #crystallang

Release v2.4.3 of Ktistec

Ktistec release v2.4.3 supports language translation.

animation demonstrating the translation of text from Japanese to English

Inspiration for this feature comes from Mastodon.

In order to enable translation, you need an API key for either DeepL or LibreTranslate. These are the only services Ktistec supports at this time.

Posts from properly configured accounts on supported servers, like Mastodon, include the content language. On posts like these, Ktistec will display a button to translate the content if the language differs from your language.

Unfortunately, not all Fediverse/ActivityPub servers explicitly support language (I mean, Ktistec didn't until just now). And not all users correctly set their posts' language, so ymmv... but it has been hugely useful for me.

I'm going to focus on site customization next (colors, etc.).

#ktistec #fediverse #activitypub #crystallang

Release v2.4.2 of Ktistec

Release v2.4.2 fixes a few more bugs. Only one is a regression—I found the others while testing. In this release:

Fixed

  • Fix metrics chart line labels.
  • Permit del, ins, and s elements in sanitized HTML.
  • Only store the redirect_after_auth_path on browser navigation.
  • Add "content" property to editor JSON error response.
  • Use FileUtils.mv to move uploaded files. (fixes #117)

Thanks to @jayvii for help with troubleshooting the last one!

#ktistec #fediverse #activitypub #crystallang

Release v2.4.1 of Ktistec

Eh, I didn't test enough and released v2.4.0 of Ktistec with a few annoying regressions. Release v2.4.1 fixes them! ☹️ 😠 😡 🤬

Fixed

  • Handle edge cases and race conditions in script runner.
  • Reconnect editor autocomplete support.
  • Fix permissions on uploaded files.

#ktistec #fediverse #activitypub #crystallang

Release v2.4.0 of Ktistec

I just released v2.4.0 of Ktistec. This release encompasses a few things that I've been working on for a while: improved support for operating without JavaScript available/enabled and support for running scripted automations.

Except for a few items, Ktistec now works without JavaScript. Obviously, things like WYSIWYG editing of HTML don't work—I plan to add support for Markdown to compensate. Running in Lynx is a stretch, but...

lynx on osx displaying the authenticated home page

Since the early days, most controller actions supported both text/html and application/json.  I cleaned up support for the latter and have officially documented the Ktistec API in the README.

In addition, I've added support for running bots/automations (prior announcement). The Ktistec server will periodically run any executable script in the etc/scripts directory. These scripts have access to the Ktistec API and can post, follow, share, like, etc. This is experimental and obviously introduces an attack surface, though that shouldn't be a problem on correctly configured hosts.

Here's the full changelog:

Added

  • Support running scripted automations.
  • "Fetch Once" button on hashtag and thread pages. (fixes #108)
  • Support navigation to a post's threaded view. (fixes #108)
  • Add support for post name and summary.

Fixed

  • Improve support for operating without JavaScript available/enabled.
  • Only enforce CSRF protection on "simple" requests.

Changed

  • Replace use of multi-action controller with formaction. (fixes #101)

Other

  • API usability improvements.


#ktistec #fediverse #activitypub #crystallang

I've been thinking about the demise of botsin.space. Running a site for bots is hard (and expensive) but writing and running an ActivityPub-based bot should be easy.

To prove this was the case I added experimental support for bots/automations to Ktistec in the form of scripts that the server periodically runs. These scripts can be in a programming language of your choice. The server provides credentials for its API in the process environment (if you can use curl you can publish posts), simple interaction happens via stdin/stdout/stderr, and the complexity of using ActivityPub is abstracted away.

The code is only available on the following branch for the moment:

    https://github.com/toddsundsted/ktistec/commits/run-scripts/

There are a couple example shell scripts here:

    https://github.com/toddsundsted/ktistec/commit/4982925a...

I have a few enhancements in mind, but it's already proven useful as a means to periodically log data from my server host, and I'll use it, when finished, to publish release notes.

#ktistec #activitypub #fediverse #bots

TIL scripting media queries... gone are the days of the no-js class on the body tag...

i'm working on improving the ktistec user experience when javascript is disabled.

ktistec uses trix as its rich text editor.  of course. trix doesn't work without javascript. behind the scenes, however, trix uses a hidden textarea to hold the body of the post being edited. using scripting media queries, ktistec can now show (or hide) either the editor or the textarea based on the availability of javascript (2030b26b). 

#ktistec #activitypub #fediverse

i'm working toward providing a decent experience in ktistec with javascript turned off.  the first step was emitting minified css instead of using the webpack style loader plugin to apply css via javascript (fd7a5369).

#ktistec #activitypub #fediverse

I just released v2.3.0 of Ktistec.  It fixes a few bugs introduced in the previous release. In particular, it handles a case I've observed a few times in production where the fetching of followed content hangs. The fix adds a monitor that periodically checks for "running" tasks without a backing fiber and sets socket timeouts to ensure requests eventually terminate (I believe the latter actually fixes the problem, but belts and suspenders...)

#ktistec #crystallanguage #crystallang #activitypub #fediverse