DEV Community

UnAIMyText
UnAIMyText

Posted on AI-assisted

Humanize AI21 Jamba Output in C: A .desktop File Comment Linter + 5 Free Tools (2026)

Tested on 2026-11-20 with gcc 14.2 and curl 8.14 on Debian. Disclosure: I help build UnAIMyText, which sits at #3 in the tools list below by my own choice. The code is yours to copy and bend.

On Linux, every app in the menu comes from a .desktop file, and the Comment= line in that file is the tooltip you see when you hover. It's one short line, which makes it a strange place for model-written prose to show up, but it does. Here's a file I was asked to review for a small photo app:

[Desktop Entry]
Type=Application
Name=Shelfie
GenericName=Photo Organizer
Comment=This application provides a powerful and intuitive way to seamlessly organize your photos.
Exec=shelfie %U
Icon=shelfie
Categories=Graphics;Photography;
Comment=Organize photos
Enter fullscreen mode Exit fullscreen mode

Ninety characters, a full stop, "This application," three filler words, and a second Comment= added at the bottom instead of fixing the first. So I wrote a linter for that one line: a single C file needing only libc and the curl binary. With --draft it asks AI21's Jamba model for a Comment= line and checks that reply too, before it reaches a package.

What the spec actually asks for

The freedesktop Desktop Entry Specification describes Comment as the tooltip for the entry, gives "View sites on the Internet" as an example, and adds one rule: the value "should not be redundant with the values of Name and GenericName." Name is required; Comment is optional. Elsewhere it says localestring values are UTF-8, that \s, \n, \t, \r and \\ are the escapes allowed in string values, and that one group can't use the same key twice.

Everything else the linter checks is house style: start with a verb, stay under 60 characters, no full stop, no emoji.

The AI21 part

AI21's chat request reference shows a POST to https://api.ai21.com/studio/v1/chat/completions with a bearer key, a model, and a messages list using system, user and assistant roles. You can name a model without a version: jamba-large or jamba-mini. Their models page says jamba-mini currently points to jamba-mini-2-2026-01. The response puts the text in choices[0].message.content. The program defaults to jamba-mini and caps max_tokens at 100, because the answer is one line.

Sent a fake key, AI21's live endpoint returns 401 and {"detail":"Authentication required."}. With no Authorization header at all it's a 400 instead. The program prints the status and body to stderr and exits 2 either way.

Why C, and what it costs

C's standard library has no JSON or HTTP, so three pieces are hand-written:

  • Escaping the request. jesc() escapes quotes, backslashes, \n, \r, \t and writes other control bytes as \u00XX. Exec= lines are full of quotes and backslashes, so one test sends exactly that.
  • Reading one field of the reply. content_of() finds "message", then the next "content", and decodes that string, including \uXXXX and surrogate pairs. It isn't a JSON parser, and it returns NULL for "content": null.
  • Calling curl without a shell. The key is written to a mkstemp file created under umask 077, the body to a second one, and curl runs through fork/execvp with -H @file and --data-binary @file. Both files are deleted right after. No system(), and the key never appears in ps.

What it checks

  • Type=Application with no Comment, and a missing Name
  • A Comment whose words all come from Name or GenericName (plus "a", "the", "app" and similar glue words)
  • Over 60 characters, counted as UTF-8 code points, not bytes
  • A trailing full stop (a trailing ... is fine)
  • Openers like "This application", "This tool", "Allows you", "Helps you"
  • Filler words: seamlessly, comprehensive, leverage, robust, powerful, intuitive, user-friendly and a few more
  • Emoji
  • \n or \t escapes that would put a line break or tab in a tooltip
  • Duplicate keys in [Desktop Entry]

Only [Desktop Entry] is linted; action groups are ignored. The first Comment= is the one that counts. It exits 0 when clean, 1 on problems, and 2 for usage errors, a missing file or key, a curl failure or a non-200 reply.

The program

/* desklint.c - lint the Comment= tooltip in .desktop files, or ask AI21's
 * Jamba for a draft and lint that before you paste it.
 *
 * Build: cc -std=c11 -Wall -Wextra -O2 -o desklint desklint.c
 * Lint:  ./desklint app.desktop [more.desktop ...]
 * Draft: AI21_API_KEY=... ./desklint --draft app.desktop
 * Env:   AI21_MODEL (default jamba-mini), AI21_BASE_URL (default
 *        https://api.ai21.com/studio/v1)
 * Exit:  0 clean, 1 problems, 2 usage, I/O, curl or API error
 */
#define _POSIX_C_SOURCE 200809L
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

#define MAXCHARS 60
#define VAL 2048
#define MAXKEYS 128

typedef struct {
    char name[VAL], generic[VAL], comment[VAL], type[64];
    int comment_line, name_line;
    char raw[8192]; /* the [Desktop Entry] group as text, for the prompt */
} Entry;

static int problems, io_error, quiet;

static void report(const char *where, int line, const char *msg, const char *detail)
{
    if (quiet) return; /* draft mode reads the file without linting it */
    printf("%s:%d: %s%s%s\n", where, line, msg, detail ? ": " : "", detail ? detail : "");
    problems++;
}

/* \s \n \t \r \\ are the escapes the spec allows in string values */
static void unescape(char *s)
{
    char *o = s;
    for (; *s; s++) {
        if (*s == '\\' && s[1]) {
            s++;
            switch (*s) {
            case 's': *o++ = ' '; break;
            case 'n': *o++ = '\n'; break;
            case 't': *o++ = '\t'; break;
            case 'r': *o++ = '\r'; break;
            case '\\': *o++ = '\\'; break;
            default: *o++ = '\\'; *o++ = *s;
            }
        } else {
            *o++ = *s;
        }
    }
    *o = 0;
}

static char *trim(char *s)
{
    while (*s == ' ' || *s == '\t') s++;
    size_t n = strlen(s);
    while (n && (s[n - 1] == ' ' || s[n - 1] == '\t' || s[n - 1] == '\n' || s[n - 1] == '\r'))
        s[--n] = 0;
    return s;
}

/* next UTF-8 code point; bad bytes come back as U+FFFD */
static unsigned long next_cp(const unsigned char **p)
{
    const unsigned char *s = *p;
    unsigned long c = *s++;
    int extra = 0;
    if (c >= 0xF0 && c < 0xF8) { c &= 0x07; extra = 3; }
    else if (c >= 0xE0) { c &= 0x0F; extra = 2; }
    else if (c >= 0xC0) { c &= 0x1F; extra = 1; }
    else if (c >= 0x80) { *p = s; return 0xFFFD; }
    while (extra--) {
        if ((*s & 0xC0) != 0x80) { *p = s; return 0xFFFD; }
        c = (c << 6) | (*s++ & 0x3F);
    }
    *p = s;
    return c;
}

static size_t char_count(const char *s)
{
    const unsigned char *p = (const unsigned char *)s;
    size_t n = 0;
    while (*p) { next_cp(&p); n++; }
    return n;
}

static int has_emoji(const char *s)
{
    const unsigned char *p = (const unsigned char *)s;
    while (*p) {
        unsigned long c = next_cp(&p);
        if ((c >= 0x1F000 && c <= 0x1FAFF) || (c >= 0x2600 && c <= 0x27BF) || c == 0xFE0F)
            return 1;
    }
    return 0;
}

/* lowercase ASCII words of s, one per call; returns 0 at the end */
static int next_word(const char **s, char *w, size_t cap)
{
    const char *p = *s;
    while (*p && !isalnum((unsigned char)*p)) p++;
    if (!*p) return 0;
    size_t n = 0;
    while (*p && (isalnum((unsigned char)*p) || *p == '-' || *p == '\'')) {
        if (n + 1 < cap) w[n++] = (char)tolower((unsigned char)*p);
        p++;
    }
    w[n] = 0;
    *s = p;
    return 1;
}

static int word_in(const char *word, const char *text)
{
    char w[128];
    const char *p = text;
    while (next_word(&p, w, sizeof w))
        if (!strcmp(w, word)) return 1;
    return 0;
}

static const char *FILLER[] = {
    "seamless", "seamlessly", "comprehensive", "leverage", "robust", "streamline",
    "utilize", "powerful", "intuitive", "effortless", "effortlessly", "cutting-edge",
    "elevate", "unleash", "next-generation", "all-in-one", "user-friendly", NULL
};
static const char *OPENERS[] = {
    "this application", "this app ", "this program", "this tool", "an application",
    "a powerful", "allows you", "enables you", "helps you", NULL
};
static const char *GLUE[] = { "a", "an", "the", "and", "for", "of", "your", "app", "application", NULL };

static int in_list(const char *w, const char **list)
{
    for (; *list; list++)
        if (!strcmp(w, *list)) return 1;
    return 0;
}

static void lint_comment(const char *where, int line, const char *c, const char *name, const char *generic)
{
    char w[128], lower[VAL];
    size_t n = char_count(c), len = strlen(c), i;

    if (!*c) { report(where, line, "empty Comment", NULL); return; }
    if (n > MAXCHARS) {
        char d[64];
        snprintf(d, sizeof d, "%zu characters, limit is %d", n, MAXCHARS);
        report(where, line, "too long", d);
    }
    if (c[len - 1] == '.' && !(len >= 3 && !strcmp(c + len - 3, "...")))
        report(where, line, "ends with a full stop", NULL);
    if (strpbrk(c, "\n\t\r"))
        report(where, line, "contains a line break or tab", NULL);
    if (has_emoji(c))
        report(where, line, "contains emoji", NULL);

    for (i = 0; c[i] && i + 1 < sizeof lower; i++) lower[i] = (char)tolower((unsigned char)c[i]);
    lower[i] = 0;
    for (const char **o = OPENERS; *o; o++)
        if (!strncmp(lower, *o, strlen(*o))) {
            report(where, line, "describes the app instead of what it does", *o);
            break;
        }

    const char *p = c;
    int words = 0, repeated = 0;
    while (next_word(&p, w, sizeof w)) {
        words++;
        if (in_list(w, FILLER)) report(where, line, "filler word", w);
        if (in_list(w, GLUE) || word_in(w, name) || word_in(w, generic)) repeated++;
    }
    if (words && repeated == words)
        report(where, line, "only repeats Name/GenericName (the spec says it shouldn't)", NULL);
}

static int parse(const char *path, Entry *e)
{
    FILE *f = fopen(path, "r");
    if (!f) { perror(path); return -1; }
    memset(e, 0, sizeof *e);
    char *buf = NULL, seen[MAXKEYS][64];
    int seen_line[MAXKEYS], nseen = 0, lineno = 0, in_main = 0, saw_main = 0;
    size_t cap = 0;
    while (getline(&buf, &cap, f) != -1) {
        lineno++;
        char *s = trim(buf);
        if (!*s || *s == '#') continue;
        if (*s == '[') {
            in_main = !strcmp(s, "[Desktop Entry]");
            if (in_main) saw_main = 1;
            continue;
        }
        if (!in_main) continue;
        if (strlen(e->raw) + strlen(s) + 2 < sizeof e->raw) {
            strcat(e->raw, s);
            strcat(e->raw, "\n");
        }
        char *eq = strchr(s, '=');
        if (!eq) { report(path, lineno, "line without '='", s); continue; }
        *eq = 0;
        char *key = trim(s), *val = trim(eq + 1);
        for (int i = 0; i < nseen; i++)
            if (!strcmp(seen[i], key)) {
                char d[128];
                snprintf(d, sizeof d, "%s (first on line %d)", key, seen_line[i]);
                report(path, lineno, "duplicate key", d);
            }
        if (nseen < MAXKEYS) {
            snprintf(seen[nseen], sizeof seen[0], "%s", key);
            seen_line[nseen++] = lineno;
        }
        unescape(val);
        if (!strcmp(key, "Name")) { snprintf(e->name, VAL, "%s", val); e->name_line = lineno; }
        else if (!strcmp(key, "GenericName")) snprintf(e->generic, VAL, "%s", val);
        else if (!strcmp(key, "Type")) snprintf(e->type, sizeof e->type, "%s", val);
        else if (!strcmp(key, "Comment") && !e->comment_line) {
            snprintf(e->comment, VAL, "%s", val);
            e->comment_line = lineno;
        }
    }
    free(buf);
    fclose(f);
    if (!saw_main) { report(path, 1, "no [Desktop Entry] group", NULL); return 1; }
    return 0;
}

static void lint_file(const char *path)
{
    Entry e;
    int r = parse(path, &e);
    if (r < 0) io_error = 1;
    if (r != 0) return;
    if (!e.name_line) report(path, 1, "no Name (required by the spec)", NULL);
    if (!e.comment_line) {
        if (!strcmp(e.type, "Application")) report(path, 1, "no Comment", NULL);
        return;
    }
    lint_comment(path, e.comment_line, e.comment, e.name, e.generic);
}

/* ---------- draft mode: JSON by hand, curl does the HTTP ---------- */

static void jesc(FILE *o, const char *s)
{
    fputc('"', o);
    for (; *s; s++) {
        unsigned char c = (unsigned char)*s;
        if (c == '"' || c == '\\') { fputc('\\', o); fputc(c, o); }
        else if (c == '\n') fputs("\\n", o);
        else if (c == '\r') fputs("\\r", o);
        else if (c == '\t') fputs("\\t", o);
        else if (c < 0x20) fprintf(o, "\\u%04x", c);
        else fputc(c, o);
    }
    fputc('"', o);
}

static void put_utf8(char **o, unsigned long c)
{
    char *p = *o;
    if (c < 0x80) *p++ = (char)c;
    else if (c < 0x800) { *p++ = (char)(0xC0 | (c >> 6)); *p++ = (char)(0x80 | (c & 0x3F)); }
    else if (c < 0x10000) {
        *p++ = (char)(0xE0 | (c >> 12)); *p++ = (char)(0x80 | ((c >> 6) & 0x3F));
        *p++ = (char)(0x80 | (c & 0x3F));
    } else {
        *p++ = (char)(0xF0 | (c >> 18)); *p++ = (char)(0x80 | ((c >> 12) & 0x3F));
        *p++ = (char)(0x80 | ((c >> 6) & 0x3F)); *p++ = (char)(0x80 | (c & 0x3F));
    }
    *o = p;
}

static unsigned long hex4(const char *s)
{
    char h[5] = {0};
    for (int i = 0; i < 4; i++) {
        if (!isxdigit((unsigned char)s[i])) return 0xFFFD;
        h[i] = s[i];
    }
    return strtoul(h, NULL, 16);
}

/* choices[0].message.content: first "content" string after "message".
 * Not a JSON parser; it handles exactly this one field. */
static char *content_of(const char *json)
{
    const char *p = strstr(json, "\"message\"");
    if (!p || !(p = strstr(p, "\"content\""))) return NULL;
    p += 9;
    while (*p == ' ' || *p == ':' || *p == '\n' || *p == '\t' || *p == '\r') p++;
    if (*p != '"') return NULL; /* null or something else */
    p++;
    char *out = malloc(strlen(p) * 2 + 1), *o = out;
    if (!out) return NULL;
    while (*p && *p != '"') {
        if (*p != '\\') { *o++ = *p++; continue; }
        p++;
        switch (*p) {
        case 'n': *o++ = '\n'; p++; break;
        case 't': *o++ = '\t'; p++; break;
        case 'r': *o++ = '\r'; p++; break;
        case 'b': *o++ = '\b'; p++; break;
        case 'f': *o++ = '\f'; p++; break;
        case 'u': {
            unsigned long c = hex4(p + 1);
            p += 5;
            if (c >= 0xD800 && c <= 0xDBFF && p[0] == '\\' && p[1] == 'u') {
                unsigned long lo = hex4(p + 2);
                if (lo >= 0xDC00 && lo <= 0xDFFF) {
                    c = 0x10000 + ((c - 0xD800) << 10) + (lo - 0xDC00);
                    p += 6;
                } else c = 0xFFFD;
            } else if (c >= 0xD800 && c <= 0xDFFF) c = 0xFFFD;
            put_utf8(&o, c);
            break;
        }
        case 0: break;
        default: *o++ = *p++; /* \" \\ \/ */
        }
    }
    *o = 0;
    return out;
}

static char *slurp(const char *path)
{
    FILE *f = fopen(path, "rb");
    if (!f) return NULL;
    fseek(f, 0, SEEK_END);
    long n = ftell(f);
    rewind(f);
    char *b = malloc((size_t)n + 1);
    if (b && fread(b, 1, (size_t)n, f) != (size_t)n) { free(b); b = NULL; }
    if (b) b[n] = 0;
    fclose(f);
    return b;
}

static int make_temp(char *tmpl, size_t cap, const char *tag)
{
    const char *dir = getenv("TMPDIR");
    snprintf(tmpl, cap, "%s/desklint-%s-XXXXXX", dir && *dir ? dir : "/tmp", tag);
    return mkstemp(tmpl);
}

static int draft(const char *path)
{
    const char *key = getenv("AI21_API_KEY");
    const char *model = getenv("AI21_MODEL");
    const char *base = getenv("AI21_BASE_URL");
    if (!key || !*key) { fprintf(stderr, "desklint: AI21_API_KEY is not set\n"); return 2; }
    if (!model || !*model) model = "jamba-mini";
    if (!base || !*base) base = "https://api.ai21.com/studio/v1";

    Entry e;
    quiet = 1;
    int r = parse(path, &e);
    quiet = 0;
    if (r != 0) return 2;

    char user[sizeof e.raw + 512];
    snprintf(user, sizeof user,
             "Write the Comment= line for this .desktop file. Start with a verb, "
             "60 characters at most, no full stop, plain words, and don't repeat "
             "the Name or GenericName. Reply with exactly one line, "
             "Comment=<text>, and nothing else.\n\n%s", e.raw);

    char hdr[512], body[512], resp[512], url[1024];
    mode_t old = umask(077);
    int fh = make_temp(hdr, sizeof hdr, "hdr"), fb = make_temp(body, sizeof body, "body"),
        fr = make_temp(resp, sizeof resp, "resp");
    umask(old);
    if (fh < 0 || fb < 0 || fr < 0) { perror("mkstemp"); return 2; }
    close(fr);

    FILE *h = fdopen(fh, "w");
    fprintf(h, "Authorization: Bearer %s\n", key);
    fclose(h);
    FILE *b = fdopen(fb, "w");
    fputs("{\"model\":", b); jesc(b, model);
    fputs(",\"max_tokens\":100,\"messages\":[{\"role\":\"system\",\"content\":", b);
    jesc(b, "You write menu tooltips for Linux desktop entries.");
    fputs("},{\"role\":\"user\",\"content\":", b); jesc(b, user);
    fputs("}]}", b);
    fclose(b);

    snprintf(url, sizeof url, "%s/chat/completions", base);
    char hdrarg[600], bodyarg[600];
    snprintf(hdrarg, sizeof hdrarg, "@%s", hdr);
    snprintf(bodyarg, sizeof bodyarg, "@%s", body);
    char *argv[] = { "curl", "-sS", "--max-time", "60", "-o", resp, "-w", "%{http_code}",
                     "-H", hdrarg, "-H", "Content-Type: application/json",
                     "--data-binary", bodyarg, url, NULL };

    int pfd[2];
    char code[16] = "";
    if (pipe(pfd) != 0) { perror("pipe"); return 2; }
    pid_t pid = fork();
    if (pid == 0) {
        dup2(pfd[1], 1);
        close(pfd[0]);
        execvp("curl", argv);
        _exit(127);
    }
    close(pfd[1]);
    ssize_t got = read(pfd[0], code, sizeof code - 1);
    close(pfd[0]);
    code[got > 0 ? got : 0] = 0;
    int st = 0;
    waitpid(pid, &st, 0);
    unlink(hdr);
    unlink(body);
    char *json = slurp(resp);
    unlink(resp);

    if (!WIFEXITED(st) || WEXITSTATUS(st) != 0) {
        fprintf(stderr, "desklint: curl failed (exit %d)\n", WIFEXITED(st) ? WEXITSTATUS(st) : -1);
        free(json);
        return 2;
    }
    if (strcmp(code, "200") != 0) {
        fprintf(stderr, "desklint: HTTP %s from %s\n%s\n", code, url, json ? json : "");
        free(json);
        return 2;
    }
    char *text = json ? content_of(json) : NULL;
    free(json);
    if (!text) { fprintf(stderr, "desklint: no content in the reply\n"); return 2; }

    char *line = NULL, *copy = strdup(text);
    for (char *t = strtok(copy, "\n"); t; t = strtok(NULL, "\n")) {
        t = trim(t);
        if (!strncmp(t, "Comment=", 8)) { line = t; break; }
    }
    if (!line) {
        report("<draft>", 1, "reply has no Comment= line", NULL);
        printf("%s\n", text);
    } else {
        printf("%s\n", line);
        char val[VAL];
        snprintf(val, sizeof val, "%s", trim(line + 8));
        unescape(val);
        lint_comment("<draft>", 1, val, e.name, e.generic);
    }
    free(copy);
    free(text);
    return problems ? 1 : 0;
}

int main(int argc, char **argv)
{
    if (argc >= 2 && !strcmp(argv[1], "--draft")) {
        if (argc != 3) { fprintf(stderr, "usage: desklint --draft FILE.desktop\n"); return 2; }
        return draft(argv[2]);
    }
    if (argc < 2) { fprintf(stderr, "usage: desklint FILE.desktop...\n"); return 2; }
    for (int i = 1; i < argc; i++) lint_file(argv[i]);
    return io_error ? 2 : problems ? 1 : 0;
}
Enter fullscreen mode Exit fullscreen mode

Running it

cc -std=c11 -Wall -Wextra -O2 -o desklint desklint.c
./desklint ~/.local/share/applications/*.desktop
export AI21_API_KEY=...          # your AI21 key
./desklint --draft shelfie.desktop
Enter fullscreen mode Exit fullscreen mode

On the photo app file above:

samples/shelfie.desktop:9: duplicate key: Comment (first on line 5)
samples/shelfie.desktop:5: too long: 90 characters, limit is 60
samples/shelfie.desktop:5: ends with a full stop
samples/shelfie.desktop:5: describes the app instead of what it does: this application
samples/shelfie.desktop:5: filler word: powerful
samples/shelfie.desktop:5: filler word: intuitive
samples/shelfie.desktop:5: filler word: seamlessly
$ echo $?
1
Enter fullscreen mode Exit fullscreen mode

For comparison, desktop-file-validate from desktop-file-utils 0.28 reports only the duplicate key on this file, as an error. On another sample it warned that a Comment "looks the same as" GenericName, so the two overlap there. It said nothing about emoji, which is right: emoji are valid UTF-8, and that rule is mine, not the spec's.

Across the 24 .desktop files on the test box, it flagged LibreOffice's long tooltips with full stops, two apps with no Comment, and two that repeat themselves, like picom's Comment=An X compositor next to GenericName=X compositor.

Draft mode against a chatty reply

Models like a preamble, so the program takes the first line starting with Comment=. One mock reply was "Here you go:" plus a typical generated line:

Comment=This application seamlessly organizes your photos.
<draft>:1: ends with a full stop
<draft>:1: describes the app instead of what it does: this application
<draft>:1: filler word: seamlessly
Enter fullscreen mode Exit fullscreen mode

Another sent the emoji as a \ud83d\udcf8 surrogate pair, which has to decode back into one character before the emoji check can see it:

Comment=📸 Shelfie Photo Organizer
<draft>:1: contains emoji
<draft>:1: only repeats Name/GenericName (the spec says it shouldn't)
Enter fullscreen mode Exit fullscreen mode

The mock server

For tests, a short Python script pretends to be /studio/v1/chat/completions. It logs the path, bearer header (true/false), model, max_tokens and roles, and saves the user message for a byte-for-byte comparison. A control file sets each reply:

# mock.py - stand-in for POST /studio/v1/chat/completions, for tests only
import json, os, sys
from http.server import BaseHTTPRequestHandler, HTTPServer

LOG = os.environ.get("MOCK_LOG", "mock_log.jsonl")
CTL = os.environ.get("MOCK_CTL", "mock_ctl.json")  # {"status": 200, "content": "..."}

class H(BaseHTTPRequestHandler):
    def do_POST(self):
        req = json.loads(self.rfile.read(int(self.headers["Content-Length"])))
        auth = self.headers.get("Authorization", "")
        with open(LOG, "a") as f:
            f.write(json.dumps({
                "path": self.path,
                "bearer": auth.startswith("Bearer ") and len(auth) > 7,
                "model": req["model"],
                "max_tokens": req.get("max_tokens"),
                "roles": [m["role"] for m in req["messages"]],
            }) + "\n")
        with open(LOG + ".user.txt", "w") as f:
            f.write(req["messages"][-1]["content"])
        ctl = json.load(open(CTL))
        status = ctl.get("status", 200)
        if status != 200:
            body = {"detail": "Authentication required."}
        else:
            content = ctl.get("content")  # null is allowed
            body = {"id": "mock-1", "choices": [{"index": 0,
                    "message": {"role": "assistant", "content": content},
                    "finish_reason": "stop"}],
                    "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}}
        data = json.dumps(body).encode()  # ensure_ascii: emoji go out as \ud83d... pairs
        self.send_response(status)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(data)))
        self.end_headers()
        self.wfile.write(data)

    def log_message(self, *a):
        pass

HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
Enter fullscreen mode Exit fullscreen mode

tests.sh runs 52 checks; all 52 pass. They cover every lint rule and exit code, a clean file that desktop-file-validate also accepts, the missing-key path (nothing sent), request path, bearer, default and overridden model, the JSON round trip, preamble, no Comment= line, null content, a 401, a refused connection, \", \\, \u2014 and surrogate-pair decoding, an empty temp directory afterward, and a curl shim confirming the header file is mode 600 and that neither key nor body appears in curl's arguments. The 51 behavior checks also pass under -fsanitize=address,undefined.

One honest result: with the quote and backslash branch in jesc() disabled, only one check fails, the one sending quoted Exec= arguments. The other samples are too plain to notice, which is why that sample exists.

Five free tools to pair with it

  1. desktop-file-validate. The reference validator from desktop-file-utils. Run it in CI next to this linter; it covers the whole file, including keys, action groups and Exec quoting. Watch: it checks the spec, not whether the tooltip reads well.
  2. Vale. If your project has a style guide, Vale can enforce it on the README. Watch: it needs rules before it's useful.
  3. UnAIMyText. When the app description or README around your .desktop file reads like a launch announcement, try UnAIMyText on that paragraph. There's no charge or signup (500 words per run), and it turned "Shelfie is a powerful, intuitive solution that empowers users to seamlessly organize their photo collections" into "Shelfie sorts your photos into albums by date and place." Watch: a 40-character tooltip doesn't need it. Use it on paragraphs, then check names and features afterward.
  4. LanguageTool. Catches grammar slips and misspellings in the longer description, free. Watch: expect it to question package names.
  5. Hemingway Editor. Highlights long sentences in your README. Watch: it has no idea what a .desktop file is.

FAQ

Which free AI humanizer works on Linux app descriptions a model wrote?
For the tooltip, this linter and your own edit. For README and store descriptions, UnAIMyText, with desktop-file-validate keeping the file itself valid.

Why 60 characters?
House rule; the spec sets no limit. Change MAXCHARS.

Does draft mode send my whole file?
Only the [Desktop Entry] group, including Exec=. If your Exec line contains tokens or internal paths, strip them first.

Verdict

Overall, for model-written Linux app metadata, I pair this C linter with UnAIMyText as my free AI humanizer: the linter keeps Comment= short, specific and different from Name, and the tool fixes the inflated descriptions around it. Start every tooltip with a verb, keep it under 60 characters, run desktop-file-validate too, and lint drafts before they land in a package.

Top comments (0)