« Documentation

WIP. Last update: 0.6.6

Solutions

Made in Switzerland  in personal time, at private expense.
Donate (external site, opens in a new tab) to help cover development costs, or support a charity (external site, opens in a new tab).

Some parts of Sleevesight solve their problems in ways a reader would not guess from the product page. This page describes them: for each, the problem, what was done, why, and whether it is new here or a known technique written again on purpose. Most are rules written for this app’s problems rather than inventions; where a library could have done the job, the page says why none was used.

Each section links the design section that holds the detail, and the issue where the work was done. The architecture page shows how the parts fit together, and the dependencies page lists the libraries the app does use.

Insights that cite their sources, checked in code

The problem. A language model asked about a song writes fluent text whether or not it knows anything. A wrong year or a misattributed cover reads as well as a true one.

What was done. The model is not asked what it knows. The app retrieves evidence first, from MusicBrainz, Wikipedia and Wikidata, Last.fm and, if switched on, web search, and gives each line an id (W1, L3). The prompt holds only those lines, fenced and labelled as data, and asks for every factual sentence to end with the ids of the lines that support it. The reply shows as it arrives; once it is complete, the grounding check (GroundingCheck) splits it into sentences and classifies each: it cites only lines that exist; it cites the model’s own knowledge, [AI], which is allowed only with AI service knowledge switched on and is shown as unverified; it states a gap in the evidence; it cites nothing; or it cites a line that does not exist. A sentence that cites lines that exist is then compared with them, narrowly (Support): a year it states must be in a cited line (as the year, its last two digits or its decade), and a name of two or more capitalised words must have at least one of its words there. The track’s, the artist’s and the album’s own names count as backed, and a sentence citing a line in another language is not compared. A sentence that fails is marked as not backed by its source. Uncited sentences, citations to missing lines and sentences their lines do not back are marked in the insight, not hidden. Each citation becomes a chip the app builds from its own ids, so the model’s text never becomes a link.

Its limit. The check sees whether a sentence cites real lines, and compares only its years and its longer names with them, not whether those lines say what the sentence says. In doubt it finds a sentence backed, since a false mark dims a true sentence, so a plausible false sentence with a valid citation can pass. It narrows what the model can invent; it does not prove the text true.

New or known. Asking a model to cite retrieved sources is a common technique. The check itself is this project’s own code, first written for its browser prototype and ported to Kotlin, with the prototype’s sentence splitting corrected where the test tracks showed it wrong (abbreviations such as U.S. and feat., a citation after a closing quotation mark) or where a reply in Markdown hid an uncited sentence (a list item, or a sentence opening with an italic title). No library was used: what counts as a sentence, a citation and a stated gap is defined by this app’s prompts.

Design: Synthesis in the design, Synthesis and grounding in the architecture. Issues: #42, #423, #574, #1036.

The right song, the right article, the right artist

The problem. Players report a title and an artist as text. Many songs share a title, many artists share a name, and the sources are searched by name: a search for a small act’s song can land on a famous song of the same name, or on another artist’s Wikipedia article.

What was done. Every source is asked by name at once, and MusicBrainz resolves the track alongside them: the recording, chosen from up to 100 candidates by title, credited artists and length, the earliest released of those that fit (a pair the player names as one artist, such as “Derya Yıldırım & Grup Şimşek”, is also tried as the two artists MusicBrainz credits separately); its artists’ MusicBrainz ids; whether it is a cover, and of what. The answers of MusicBrainz, Wikipedia, Wikidata and Last.fm are then checked against those ids before any of their lines may be cited. Web search results have no id to check: a text filter keeps only pages that name the song and a distinctive credited artist, and their lines may be cited without that verification. A Wikipedia article is accepted only if its Wikidata item says it is a song, single or musical work performed by one of the credited artists, matched by MusicBrainz id where there is one; an artist’s article only through the artist’s MusicBrainz id. Of the sources checked against the ids, a match that cannot be checked is shown but never cited, and one that fails is shown as rejected, with the reason.

New or known. Matching records across databases through shared identifiers is a known technique (entity resolution, or record linkage). The rules are this project’s own, tuned on its test tracks: bands credited under their leader’s name (Dick Dale and His Del-Tones for Dick Dale), names with honorifics, covers whose earlier recordings are undated, a songwriter’s own song later made famous by others. The rules are specific to MusicBrainz’s and Wikidata’s data and decide what may be cited, so they are written and tested here, with the test tracks’ known cases as tests.

Design: Entity resolution in the architecture. Issues: #36, #37.

Last.fm pages that belong to more than one artist

The problem. Last.fm keeps one page per artist name, so every artist of that name shares it, and it corrects names it does not know to ones it does. A small act can land on an unrelated band’s page; a page’s listener counts, tags and similar artists may mix several artists; its biography may be about someone else.

What was done. Each credited artist’s Last.fm page is judged against the resolved artist. A page whose MusicBrainz id differs is rejected, and so is a name Last.fm corrected, unless its MusicBrainz id is the resolved artist’s. A biography that says the name is shared (“There are several artists …”, or a numbered list) gives no sentence to cite. Otherwise one MusicBrainz artist search for the name decides: if the search shows the resolved artist is the only one of that name, the whole page is verified; if another artist of the name exists, or the search cannot rule one out, only the biography’s sentences may be cited, and the counts and tags are shown but not cited. A search that fails leaves the page unverified and is not cached, so a later lookup can verify it.

New or known. Not taken from a library or from Last.fm’s documentation: it is a rule written for this problem, using MusicBrainz’s identifiers to decide how much of a Last.fm page to trust. The biography check is deliberately too eager, since taking a shared page for one artist’s is the unsafe mistake.

Design: Last.fm verification in the architecture. Issues: #39, #75.

Telling a skip from a song that ended

The problem. Reactive can write only when you skip (On track skip (auto)), so the app has to tell a skip from a song that ended on its own. Android’s media session does not say: none of the players measured reported a skip state, and a skip in the player, from earphones or from the notification looks the same as a natural end. A player’s crossfade makes a natural end come seconds before the track’s end, where a skip may also fall. Players also re-send the same track with a new length or new art, which must not count as a change at all.

What was done. Both rules come from measurements of real players on a phone. The session layer settles a player’s reports into plays: a report continues the play, compared with everything known of it so far, or starts a new one. Two players are two tracks; a media id on both reports decides; otherwise the title must match, and known artists that differ mean a new track. A new album in the first second of a play fills it in, since YouTube Music sends a placeholder album first; after that, a new album means a new track, such as a live take after a studio one. A new length or new art is an update, not a change. The queue item decides nothing: it only times a change, when it moves just before a new title. At each change the app reads the time the previous track had left and the playback states the player reported just before. A change with little time left is a natural end. For Spotify, a cluster of playing states in the second and a half before the change marks a natural end even inside a crossfade, since Spotify publishes one before every natural end and none before a skip. Under Crossfade, Autodetect learns the player’s crossfade on the phone from natural ends that two in a row agree on, and never from its own guesses; a fixed value can be set instead. When in doubt the rules choose a natural end: a missed skip costs a tap on Write insight, while a false one costs a paid call nobody asked for.

New or known. Worked out here, from measurements on a phone, and written as the app’s own code; it rests on what the measured players were seen to report. The Spotify cluster is undocumented behaviour, so it is used with the timing, never alone, and other players are judged by timing only until they are measured. The identity rules were settled against a capture of YouTube Music on a phone, the player that sends no track id; a false change would cost a duplicate row in the history and a false skip, while a repeat counted as one play costs nothing.

Design: Track changes in the design, Session layer and Learning skip detection in the architecture. Issues: #48, #53, #297.

Artist facts told once, and kept per artist

The problem. What Last.fm, Wikipedia and Wikidata say about an artist is the same on every track by that artist. Played through an album, every insight’s prompt carried the same artist lines, and where the songs were thinly documented the model filled each insight with them: the same facts, track after track, paid for each time. Each track also looked the artist up again.

What was done. Two separate changes. First, the prompt leaves artist lines out where the track does not need them (PromptEvidence): a track with enough evidence of its own gets none, and a track with less gets only the artist lines no other insight in the listening session has cited. When leaving them out would leave nothing to write from, the prompt gets them all. A fact is matched by its source and its text, so it is told once a session. A setting, Don’t repeat artist facts, on by default, turns this off for those who want every insight to introduce the artist (#407). Either way, the prompt leaves out the player’s own album line when MusicBrainz says the song first came out on that album (#424), so a thinly documented track’s insight is not padded with a sentence saying the song is on the album it is playing from. Measured on three albums and a playlist when it was built (#239), the repeated facts disappeared and the prompts got shorter. Second, with Keep what sources said about each artist on, what the sources said about an artist is kept on the phone per artist, not per track, so a new track by a known artist asks only what is about the track. The artist’s and the album’s insights under Key insights are kept the same way, per artist and per album rather than per track: each is written from evidence gathered for the artist or the album alone, numbered on its own, so it is the same on every track of theirs, and is written once for all of them, again only when that evidence, the prompt or the model changes (#240). The cache of what the sources said is off by default, since what it keeps amounts to a list of the artists you have heard; with it off, each track’s artists are looked up again, so their names go to the sources with every track.

New or known. Caching by part of a request rather than the whole is a known technique, written here over the app’s own database because each part has to expire with the shortest lifetime of the sources behind it. Leaving out facts a session has already told is this project’s own rule; no library was involved.

Design: Synthesis (The insight stays on the track) in the design, Cache and history in the architecture. Issues: #238, #239, #240, #407, #420, #522.

API keys by QR code

The problem. Sleevesight uses your own API keys: an AI service’s, and optionally Last.fm’s and Exa’s. They are long random strings, and typing them on a phone is slow and error-prone. Online QR generators would receive the keys.

What was done. A key’s dialog has Scan QR code, which fills the field from a code holding that one key, once the key has its service’s form (an Anthropic key starts sk-ant-, a Last.fm key is 32 hexadecimal digits, and so on). Load keys, under Secrets in the settings, reads a setup code holding several, a first line sleevesight-keys:v1 and one name=value line per key, and lists what it found, each key by its last four characters, before anything is saved; then it asks which of the keys’ services to switch on, one AI service at a time. The setup code travels sealed: Load keys first shows five words, drawn at random from the EFF’s short wordlist 2, which are typed on the computer; the code then holds the keys encrypted with a key derived from those words (PBKDF2-HMAC-SHA256, 600,000 rounds, then AES-256-GCM; sleevesight-keys:v2:), which opens only with those words; the phone takes one code, within 5 minutes of showing them. A photo, a screenshot or a screen recording of the code alone is useless without the words: searching for them offline takes some 2^71 HMAC-SHA256 calls, thousands of GPU-years. Anyone who has both can open it, so a code and its words leaked together call for new keys. The setup code is drawn on a computer in one of two ways:

The phone decodes the camera’s frames itself; no frame is kept or sent, the camera is asked for only when you scan, and the key dialogs and the scan cannot be captured in a screenshot.

New or known. QR codes are a standard. Decoding on the phone and drawing in the terminal use the ZXing library. Google’s code scanner was not used because its ML Kit reports usage to Google. The page loads no code from elsewhere, ZXing included, and draws the code with its own encoder (next section). The setup code’s format is this project’s own; the page’s copy of the key checks, and its sealing, are tested against the app’s, from vectors the page’s code makes. Several words from a fixed list are the Diceware idea; a short code such as Magic Wormhole’s would need a PAKE, with every guess an online exchange, which no server rules out here, so the words carry their full strength (about 52 bits), stretched by the rounds.

Design: Privacy and security in the design. Issues: #268, #436, #589, #590.

Typing on a computer, over Bluetooth, with no server

The problem. Some fields are easier to fill from a computer, where the key often is already. Sending text from a computer to a phone usually goes through a server, a cloud clipboard, or a page the phone serves over Wi-Fi, which would be plain HTTP on a shared network.

What was done. sleevesight.app/keyboard.html makes a session for that visit: a random 8-byte id and a random 128-bit AES key. It shows both as a QR code. In a key’s dialog, Type on a computer scans it. The phone then offers a Bluetooth Low Energy service whose UUID is made from the session id, so the browser’s device chooser lists only that phone, as Unknown or Unsupported Device, since it advertises no name (unless Share phone’s name with Type on a computer is on, when the phone’s Bluetooth name goes in the scan response); Connect on the page links to it through Web Bluetooth (Chrome and Edge). At each change the page sends the whole text, at most 480 bytes, sealed with AES-GCM under the session key:

The phone sends nothing back but Bluetooth’s acknowledgements, and the page is allowed no network request: the text goes over Bluetooth alone.

sequenceDiagram
  participant B as Browser (keyboard.html)
  participant P as Phone (Sleevesight)
  B->>B: new session: random id and AES key
  B-->>P: QR code (id and key), scanned with the camera
  P->>P: refuse a code run before; advertise the service named for the id
  B->>P: Connect, over Web Bluetooth
  loop each change of the text
    B->>P: counter, and the text sealed with AES-GCM
    P->>P: open it; take it only if the counter is above the last
  end
  P->>P: dialog closed: the key wiped

New or known. Each part is standard: AES-GCM, from the browser’s Web Crypto and Java’s standard cryptography on the phone; Bluetooth Low Energy; QR codes. Putting them together as a keyboard with no server is this project’s own design. It was chosen over a page served by the phone on Wi-Fi, which a page served over HTTPS may not reach, and over sending the text as QR codes, which is not live. The page’s QR encoder is its own, written from the QR standard (ISO/IEC 18004) as Project Nayuki’s open-source encoder implements it, rather than loaded, so the page fetches nothing from elsewhere; the app’s tests read codes it drew with ZXing, and check messages the page sealed against the app’s side of the protocol.

Design: Privacy and security in the design; the protocol is in assets/keyboard/protocol.js and KeyboardSession.kt. Issue: #394.

Logs that hold no key

The problem. Logs of network requests are what a developer needs to find a fault, and what most often leaks a key: in a header, in a URL’s query, in a redirect’s address.

What was done. A key is a Secret, a type whose text form is redacted, and it is revealed only into the request’s own field for credentials. The network log holds no header name or value, and no query value; a URL’s path and query names are logged only when the request is known to be public, so a request whose URL may hold a key (marked so, or with a query parameter named like a key), and any hop after a redirect, whose address the server chose, shows its host but neither its path nor its query names. Tests log requests with a key in each of those places and compare the whole lines.

New or known. Redacting secrets in logs is a known practice. The rule here is stricter than matching values: rather than finding keys in the log and hiding them, the log is built only from what is known to be public. It is this project’s own code, part of its one network module.

Design: Networking in the architecture.

Promises the build enforces

The problem. A privacy promise such as “no analytics” or “nothing goes on the network except through the sources” is easy to break without noticing: a library can bring an analytics SDK or a permission with it, and a call to a network API can be added in any module.

What was done. The build fails when one is broken, on every pull request:

New or known. Allowlists and dependency rules are known practice, and tools such as Detekt, which the project also runs, cover part of it. These checks are small Gradle tasks written here, because they encode this app’s own rules (which modules may reach the network, which permissions may be asked for) and read the build’s real outputs, the merged manifest and the compiled classes, rather than the sources.

Design: Structural constraints in the architecture. Issues: #10, #113, #251.

« Documentation