Disclosure first: I work at the company behind UnAIMyText, and it's ranked third of the five tools at the bottom. The program below is plain Nim with no dependency on our product.
Run nimble init and the wizard asks a handful of questions. According to Nimble's own guide to creating packages, one of them is the package description, and if you just press Enter you get the default: A new awesome nimble package. Your answers land in the .nimble file, which Nimble interprets as NimScript.
I review a lot of small Nim packages, and the description field has two failure modes. Either it's still that placeholder, or someone asked an assistant for "a better description" and got something like this:
version = "0.3.0"
author = "Sam Okafor"
description = "elfshift is a blazing-fast, robust and seamless Nim library that empowers teams to effortlessly schedule holiday shifts!"
license = "MIT"
srcDir = "src"
requires "nim >= 2.0.0"
So I wrote nimdesc: it reads the package's metadata, flags the patterns I keep running into, and can optionally ask a GLM model on Z.ai for a plainer one-liner. It's 81 lines of Nim using only the standard library.
Reading the description without parsing NimScript
Because a .nimble file is NimScript, a regex over description = "..." breaks the first time someone uses a triple-quoted string or computes a value. The same Nimble guide documents nimble dump, which prints the package's information in an ini-compatible format, or as JSON with --json, and says it's meant for tools that want the metadata without running the NimScript evaluator themselves. So nimdesc shells out to nimble dump --json and reads two keys, name and desc. You can also pipe the JSON in with -, which is handy in CI where you've already dumped it once.
What it flags
-
default: still
A new awesome nimble package. If this fires, nothing else is reported, since there's nothing else to fix yet. - multi-line: a triple-quoted description with a line break. Legal NimScript; I just prefer one line.
-
long: over 100 characters. My number, not Nimble's; change
Max. - restates name: begins with the package name.
- filler opener: "A Nim library for...", "This package...".
- buzzwords: a dozen words I'm tired of; a plural or third-person "s" still matches, so "empowers" is caught by "empower." Words are split on anything that isn't a letter, digit or hyphen, so "blazing-fast" stays one word.
-
exclamation: any
!.
Exit codes: 0 for a clean description, 1 when something was flagged, and 2 when nimdesc itself couldn't finish (no metadata, no key, an HTTP error). Keeping 1 and 2 apart lets CI tell "fix your description" from "fix your pipeline."
The program
# nimdesc: lint the description in a Nimble package (via `nimble dump --json`),
# optionally ask a GLM model on Z.ai for a plainer one-line rewrite.
import std/[httpclient, json, os, osproc, strutils]
const
Buzz = ["seamless", "seamlessly", "robust", "blazing-fast", "powerful", "effortless",
"effortlessly", "empower", "leverage", "cutting-edge", "next-gen", "supercharge"]
Default = "A new awesome nimble package" # what `nimble init` offers
Max = 100 # my own limit, not a Nimble rule
proc words(s: string): seq[string] =
for w in s.toLowerAscii.split(AllChars - Letters - Digits - {'-'}):
if w.len > 0: result.add w
proc lint(name, desc: string): seq[string] =
if desc.strip.len == 0: return @["missing: no description"]
if desc.strip == Default: return @["default: still the `nimble init` placeholder"]
if '\n' in desc: result.add "multi-line: keep it to one line"
if desc.len > Max: result.add "long: " & $desc.len & " chars (limit " & $Max & ")"
if name.len > 0 and desc.toLowerAscii.startsWith(name.toLowerAscii):
result.add "restates name: starts with '" & name & "'"
var ws = words(desc)
if ws.len > 2 and ws[0] in ["a", "an", "this"]:
let noun = if ws[1] == "nim": ws[2] else: ws[1]
if noun in ["library", "package", "module", "tool"]:
result.add "filler opener: '" & desc.splitWhitespace[0..1].join(" ") & " ...'"
var hits: seq[string]
for b in Buzz:
if b in ws or (b & "s") in ws: hits.add b
if hits.len > 0: result.add "buzzwords: " & hits.join(", ")
if '!' in desc: result.add "exclamation: it's a package index, not a billboard"
proc rewrite(name, desc: string): string =
let key = getEnv("ZAI_API_KEY")
if key.len == 0:
stderr.writeLine "nimdesc: set ZAI_API_KEY to use --rewrite"; quit 2
let base = getEnv("ZAI_BASE_URL", "https://api.z.ai/api/paas/v4")
let body = %*{
"model": getEnv("ZAI_MODEL", "glm-5.2"),
"max_tokens": 200,
"temperature": 0.2,
"thinking": {"type": "disabled"},
"messages": [
{"role": "system", "content": "Rewrite this Nimble package description. One line, " &
"under 100 characters, plain words, no buzzwords, no exclamation marks, " &
"do not start with the package name. Reply with the line only."},
{"role": "user", "content": "Package: " & name & "\nDescription: " & desc}]}
let client = newHttpClient(timeout = 30_000, headers = newHttpHeaders({
"Authorization": "Bearer " & key, "Content-Type": "application/json"}))
defer: client.close()
let resp = client.request(base.strip(chars = {'/'}, leading = false) & "/chat/completions",
httpMethod = HttpPost, body = $body)
let data = try: parseJson(resp.body) except JsonParsingError: newJObject()
if not resp.code.is2xx:
let msg = data{"error", "message"}.getStr("no JSON body")
echo "nimdesc: HTTP ", resp.code.int, " from Z.ai (", msg, ")"; quit 2
data["choices"][0]["message"]["content"].getStr.strip
var target = "."
var wantRewrite = false
for a in commandLineParams():
if a == "--rewrite": wantRewrite = true else: target = a
var raw: string
if target == "-": raw = stdin.readAll
else:
let (output, code) = execCmdEx("nimble dump --json", workingDir = target)
if code != 0: # dump can fail silently, e.g. when description is missing
echo "nimdesc: nimble dump exited ", code, " in ", target, "; run `nimble check` there"; quit 2
raw = output[output.find('{') .. ^1] # skip any warnings printed before the JSON
let dump = parseJson(raw)
let (name, desc) = (dump{"name"}.getStr, dump{"desc"}.getStr)
let issues = lint(name, desc)
if issues.len == 0: echo "ok: ", desc; quit 0
for i in issues: echo name, ": ", i
if wantRewrite and desc.strip.len > 0:
let line = rewrite(name, desc)
echo "suggested: ", line
for i in lint(name, line): echo " still: ", i
quit 1
No regular expressions on purpose: std/re needs the PCRE shared library at runtime, and my first build died on a clean box with could not load: libpcre.so(.3|.1|). Splitting into words with strutils did the job with nothing extra to install.
Build it with SSL enabled, since the default Z.ai endpoint is HTTPS:
nim c -d:release -d:ssl -o:nimdesc nimdesc.nim
./nimdesc path/to/elfshift
./nimdesc path/to/elfshift --rewrite # needs ZAI_API_KEY
nimble dump --json | ./nimdesc -
Output
On the package above (exit code 1):
elfshift: long: 120 chars (limit 100)
elfshift: restates name: starts with 'elfshift'
elfshift: buzzwords: seamless, robust, blazing-fast, effortlessly, empower
elfshift: exclamation: it's a package index, not a billboard
On a fresh nimble init package where someone hit Enter:
ornament: default: still the `nimble init` placeholder
On description = "A Nim library for routing snowplows by street priority":
snowplow: filler opener: 'A Nim ...'
One surprise: on a .nimble file with no description at all, nimble dump --json exited with status 1 and printed nothing, so nimdesc can only point you elsewhere:
nimdesc: nimble dump exited 1 in samples/nodesc; run `nimble check` there
nimble check is the command that explains it (path shortened):
Error: Incorrect .nimble file: ./nodesc.nimble does not contain a description field.
Failure: Validation failed.
The Z.ai call
Z.ai's chat completion reference documents POST https://api.z.ai/api/paas/v4/chat/completions with a bearer token and the familiar model and messages body. The model list on that page is glm-5.3, glm-5.2, glm-5.1, glm-5, glm-4.7 and glm-4.6, with glm-5.3 as the documented default.
The part worth reading closely is the thinking parameter. It takes enabled or disabled; the page says GLM-5.3 can only run with it enabled, GLM-4.7 always thinks, and GLM-5.2, GLM-5.1, GLM-5 and GLM-4.6 decide for themselves when it's enabled. For a one-line rewrite I wanted a model where I could switch it off, so nimdesc defaults to glm-5.2 and sends "thinking": {"type": "disabled"}. ZAI_MODEL overrides the model and ZAI_BASE_URL overrides the endpoint (useful for a mock or a proxy). The reference allows max_tokens from 1 up to 131072; I send 200.
Errors come back as JSON with an error object, and the program prints its message instead of a stack trace. With a made-up key, the real endpoint answered HTTP 401:
nimdesc: HTTP 401 from Z.ai (token expired or incorrect)
What was tested, and against what
I have no paid Z.ai key, so to be precise about what was tested: everything that touches the API ran against a small Python mock of /chat/completions, plus real requests to Z.ai with a fake key. Eighteen checks in a bash script, all passing with Nim 2.4.2 and nimble 0.26.2 on Linux:
- every rule triggers on a dedicated sample package, the placeholder is reported alone, a clean description prints
ok:with exit 0, no argument uses the current folder, and pipednimble dump --jsonworks with-; - a missing description makes
nimble dumpfail andnimdescexits 2; -
--rewritewithoutZAI_API_KEYprints one line to stderr and exits 2; - requests arrive at the mock on
/api/paas/v4/chat/completions(a trailing slash inZAI_BASE_URLis tolerated) with the bearer header, a JSON content type,glm-5.2, thinking disabled,max_tokens200 and a system plus user message whose user part starts withPackage: elfshift;ZAI_MODELoverrides the model; - the canned reply is trimmed, printed and linted again; a mock 401 and a non-JSON 502 both exit 2 with a readable message.
With the mock, --rewrite adds:
suggested: Plans holiday shift rotations for small teams from one CSV of names
That's the mock's fixed answer, not something GLM wrote.
Five free tools for what the linter can't judge
A linter can count characters and spot "seamless." It can't tell whether the README sounds like it was written by someone who uses the package. For the prose around the code:
-
nimble check - not a prose tool, but run it in the same job; it validates the
.nimblefile and package layout, and it's what explained the silent dump failure above. - Vale - rule-based style checks you configure once and run on every docs change; it reports, it doesn't rewrite.
- UnAIMyText - free with no sign-up, up to 500 words per run in Standard mode. Drop in README prose that came out of a generator, and the "powerful, robust, seamless" layer comes off. Afterwards, check that proc names, flags and version numbers survived unchanged.
-
Hemingway Editor - flags long sentences in the README; ignore what it thinks of
execCmdEx. - LanguageTool - free grammar checks that mostly leave identifiers alone.
FAQ
Which free AI humanizer suits Nim package docs?
For the one-line description, the linter and a quick edit by you will do. When the README's opening paragraphs sound machine-written, I'd paste them into UnAIMyText as a free AI humanizer first, then run Vale or LanguageTool.
Why not parse the .nimble file directly?
It's NimScript, so it can contain anything Nim can express. nimble dump --json asks Nimble itself, which is the only parser guaranteed to agree with Nimble.
Does it work with other OpenAI-style endpoints?
Probably, if they accept the same body and return choices[0].message.content, but I only tested the Z.ai shape, and the thinking field is Z.ai-specific.
Verdict
Lint the description mechanically, ask GLM for a draft line when you're stuck, and make the final edit to the .nimble file by hand. For the longer README prose, UnAIMyText is the free AI humanizer I reach for, since it strips the generated gloss and leaves your facts where they were, provided you read the result before you push.
Top comments (0)