Agent Guidelines for Sparkles
Instructions for AI agents working on the sparkles codebase. This file is the single source of truth: the root AGENTS.md is a symlink to it, and CLAUDE.md includes it. Keep it accurate — a stale fact here propagates into every agent's work.
Project Overview
sparkles is a D monorepo of CLI/library utilities. The authoritative package list is the subPackage entries in the root dub.sdl. Before working in an unfamiliar package, read its entry in the Package Catalog — the detailed descriptions and the module map live there.
| Package | One line |
|---|---|
ci, dub-forward | repo CI helper: tests, markdown examples, link/sidebar audits; the dev shells' forwarding dub |
hue | syntax-highlighting viewer (ANSI/HTML/--gui), diff/PR viewer, APK |
release | tag scanning, bump suggestion, notes, publishing |
fsx | copy, list and compare the files a fileset selects, every copy verified (fscp, fsls, fsdiff) |
shader-compile | D shaders → SPIR-V → GLSL, built by sparkles:ui's gpu-effects build |
terminal, terminal-benchmark | terminal emulator on libghostty-vt; its render-CPU benchmark |
ui-gallery, diagram, text-lab, fileset-explorer | sparkles:ui-app apps: the toolkit catalog; a diagram board; the Vulkan text lab; a live fileset query explorer |
nix-eval, twoslash-extract | sparkles:nix demo; batch D twoslash extractor |
base, text-buffer | Buffer, @nogc text, lifetime, logging, caps; persistent editable text and undo |
appearance | the desktop's scheme, accent, contrast, title-bar controls and fonts (the settings portal) |
core-cli | argument parsing, help, prompts, process utilities |
ui, ui-app, ui-tui, ui-raylib, ui-sdl3, ui-vulkan, input, tui | the one UI stack: toolkit, host, backends, input vocabulary, cell grid |
syntax, tree-sitter, source-view, doc-view, diff, dsv | highlighting, markdown model, code/markdown views, the document viewer, diff and DSV engines |
twoslash, twoslash-d, twoslash-protocol, dmd-lsp, dmd-fmt, d-source, unittest-layout | type overlays, the DMD-frontend semantic core, the D formatter, source scans on DMD's lexer, the unittest layout lint |
event-horizon, http, dbus, iroh-send | completion-first event loop with effects; HTTP/1.1 and D-Bus over it; sending files over iroh |
recovery | crash recovery: leased private archives, immutable generations, a durable background writer |
wsi, vulkan, vulkan-wsi, raylib-text, ghostty, terminal-view, shaders, profiling (+ profiling-counters) | windowing, GPU, fonts, VT engine, embeddable terminal, shader vocabulary, frame profiling |
font, font-oracle | font files parsed in D; its HarfBuzz differential tests |
wired, reflection, metadata, dql, fuzzy | serialization, reflection kernel, UDA vocabulary, query engine, fuzzy search |
build-primitives, build-graph, dub-manifest, fileset-tools, ci-provider, code-instrumentation, docs, nix, versions, math, image | gitignore/walk/runGit + task DAG, the build graph, the dub.sdl schema, fileset copy and ids (fsx), CI log conventions, coverage, SSG, Nix C API, versioning, vectors, PNG |
test-runner (+ test-harness, test-attributes, test-runner-core, test-runner-impl), test-utils | the unittest runner (shim, in-binary harness, core, runner executable); test helpers |
Libraries are documented under docs/libs/<name>/ as a Diátaxis tree (tutorial/, how-to/, reference/, explanation/); designs live in docs/specs/<name>/. When you add or substantially extend a library, add or extend its docs there.
Detailed Guidelines
Cross-cutting guides live in docs/guidelines/:
- Code Style — module layout, imports, contracts, named arguments, literals
- D Style — broader D style reference
- Functional & Declarative Programming — range pipelines, UFCS, purity, laziness
- Design by Introspection — Intro & Guidelines — capability traits, optional primitives, shell-with-hooks
- Interpolated Expression Sequences — IES syntax, metadata, context-aware encoding
- DDoc — documentation comments, sections, macros
- Writing Research Docs — research catalogs, house style, VitePress gotchas
- Writing Specification Docs — falsifiable contracts, test oracles, delivery gates
- Writing Specification Prose — front matter, abstract, introduction, timeless prose, the cold read
- Cutting a Release — monorepo versioning, changelog tags, code.dlang.org
- Integrating C Libraries (ImportC) — ImportC + pkg-config + Nix + dub (
sourceLibrarygotcha) - Benchmarking & Profiling — the measure→profile→fix loop for the terminal renderer
- Build Settings — read before changing compiler/linker flags; measurements, test/benchmark policies, and manifest regeneration
- Modern D Language Features — which 2.060–2.112 features new code should reach for
- Composable Memory Allocators —
std.experimental.allocatorbuilding blocks and composition - Idioms — Expected Error Handling, Forcing Named Arguments
Environment, Build & Test
nix develop (or direnv) puts dub, ldc, dmd, delta, and ci on PATH. The shell's dub forwards: dub build|test|run of this repository's packages run as ci build|test|run, planned on the build graph against the shared store, so a repeat with nothing changed compiles nothing:
dub test :base # test a sub-package
dub test :base -- -i "Buffer" # filter by test name (-v runs on dub: per-test lines)
dub --root /path/to/worktree test :ui # another worktree, no cd
dub build :twoslash-extract -b checked # build the way the flake does
./libs/base/examples/build-mode-probe.d # a shebang file, as dub run --singleAnything else reaches the pinned dub unchanged: dub describe, dub fetch, a registry package, and a request asking for what ci does not model (--force, -a, the runner's -t or -l), the last after a one-line notice (ci CIC30). The pinned dub is $SPARKLES_REAL_DUB. SPARKLES_DUB_PASSTHROUGH=1 dub test :base runs a request on dub, with every dub it starts; ci sets that variable for itself and everything it starts. Forwarded, dub test leaves out the @slow tests and dub run keeps standard output for the program, as ci does.
ci takes what dub takes (:pkg or a path, -c, -b, --compiler, arguments after --) and refuses what the graph cannot model instead of calling dub:
ci test :base -- -i "Buffer" # dub test :base -- -i "Buffer"
ci test :base -c unittest-portable # dub test :base -c unittest-portable
ci build :twoslash-extract -b checked # artifact where dub puts it
ci run :hue -- --help # exit status is the program's
ci run apps/ci/tools/plan-graph.d -- --check # a single-file program (inline recipe)nix develop -c <cmd> is slower and can rebuild ci; reserve it for reproducing CI exactly.
IMPORTANT
git addnew files before any flake build. The flake sees tracked files (and edits to them), never untracked ones — a newdub.sdlor module "doesn't exist" until staged.- After editing
apps/ci, rundub run :ci -- …ornix run .#ci -- …. The barecionPATHis a Nix-store build and lags behind.
Dev shells: default, full, ci
All three come from mkSparklesShell in nix/shells/default.nix. default is quiet (no banner) — the one agents and scripts get via nix develop -c; full adds the figlet greeting for interactive use; ci is the CI floor (no browser, profilers, corpora, oracle libraries, or pre-commit tooling). direnv picks ${DEV_SHELL:-default}, settable in a git-ignored .env.
Adding a tool means choosing a tier: ciPackages is built on every CI run, so put a tool there only if a CI job runs it; everything else goes in devPackages.
Offline dub
The shells seed DUB's writable source cache from packages.dub-sources on entry, preserving existing versions. After building .#ci without entering a shell, run nix run --offline .#ci -- cache seed-dub before using plain dub offline. The destination is $DUB_HOME or ~/.dub (custom settings.json dubHome users must set DUB_HOME explicitly). Only sources are imported, not compiled caches, settings or local overrides. ci retains the Nix source bundle in its runtime closure. The Markdown and standalone examples build on the graph from the locked sources and start no dub, so they verify offline, and so do the shell's dub build|test|run, which run as ci. What still reaches the pinned dub ($SPARKLES_REAL_DUB: another subcommand, a fallback) reads the seeded cache.
nix/dub-lock.json covers application dependencies; nix/ci-dub-lock.json adds example-only packages, including the pinned Eve Git revision. New dependencies must join the relevant lock to work offline. sparkles.cachix.org substitutes these Nix store objects; it does not implement DUB's registry/Git protocols.
Flake-input store paths
The dev shell exports every flake input (except self) as a store path: $SPARKLES_FLAKE_INPUT_<NAME> (input name uppercased, - → _, pointing at the checkout root), and $SPARKLES_ALL_FLAKE_INPUTS, a JSON object keyed by the original input names. Read pinned third-party checkouts through these — never by scraping flake.lock, dub.selections.json, or $DUB_HOME — and have the test assert the var is set and the path exists.
Derived-package vars ($SPARKLES_DMD_IMPORT_PATH, $SPARKLES_LDC_IMPORT_PATH, $SPARKLES_TS_GRAMMAR_PATH, $JSON_TEST_SUITE) point at linkFarm/applyPatches outputs instead; their tests skip when unset.
Locating C Headers & System Dependencies
Ask pkg-config (pkg-config --cflags raylib, pkg-config --libs vulkan). Searching /nix/store directly is slow and finds stale or unrelated packages.
GUI apps: the native arm by default, raylib by name
Every windowed application (hue, terminal, ui-gallery, diagram, text-lab) builds the native arm by default — sparkles:wsi windows drawn by sparkles:ui-vulkan, on Wayland, X11, AppKit (through MoltenVK) and Win32 — and links no raylib. The raylib window, until it is retired, is the raylib configuration (dub build :hue -c raylib; the terminal's tests: -c unittest-raylib), and the Nix packages follow: .#hue is the native arm, .#hue-raylib the raylib one. Screenshots of a native-arm app come from --debug shot=PATH (with frames=N to end a scripted run; HUE_GUI_CRT=1 turns hue's CRT on). With the screen locked nothing is presented and a scripted run stalls: capture headless under xvfb-run with lavapipe (VK_ICD_FILENAMES naming lvp_icd) instead.
On Android the native arm is .#hue-apk and .#terminal-apk (raylib: .#hue-raylib-apk, .#terminal-raylib-apk). Run them on the emulator from nix develop .#android: hue-emulator -no-window -gpu swiftshader_indirect (Vulkan through SwiftShader), then adb install, adb shell input … to drive it and adb exec-out screencap -p > shot.png to see it.
Build types: debug to test, checked to ship, never release
Every in-repo dub.sdl and every single-file example's inline recipe declares:
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}| Build type | assert | debug { } | Use for |
|---|---|---|---|
debug | live | on | dub test, local iteration |
release | gone | off | nothing |
checked | live | off | every nix artifact: apps, examples, the ci helper |
-releasedeletes an assert's whole expression, so a call inside one stops happening:assert(!client.connect(addr).hasError)never connected, and the example hung until CI's 20-minute cap.libs/base/examples/build-mode-probe.dshows what each mode really does.-debugcompiles indebug { }blocks — checks too expensive to ship, and exactly what tests want.checkedmeasured ~3% overrelease(twoslash-extract) and half ofdebug.- For a hot path where assertions really cost, apply
-checkaction=haltto that package, with a measurement in hand.
dub resolves --build=<name> against the root recipe only, which is why each example repeats the declaration; apps/ci/tools/add-checked-buildtype.d re-applies it idempotently to new packages and examples.
Scripts are D
Write any script with real logic — parsing, decisions, more than ~5–10 lines — as D: repo tooling in apps/ci (or a small apps/ sub-package, invoked from Nix via lib.getExe), throwaway work (a table transform, a bulk edit, a repro, a PTY probe) as a single-file dub run --single foo.d. A D script can import the sparkles libraries and graduate into apps/ci, a test, or an example. Shell or inline Nix is for a handful of lines of glue; python/node for a genuinely trivial one-liner.
Test runner (sparkles:test-runner)
The project's own runner (silly's successor, same core CLI; dub test :x -- --help lists every flag, docs). Beyond -i/-e/-v/ -t/-l, it runs special modes selected by marker UDAs from sparkles.test_runner.attributes — @ctfe, @betterC (--better-c), @wasm (--wasm), @benchmark/@benchCases/@workload (--bench), @slow (--skip-slow/--only-slow). A benchmark whose body is the measured unit is @benchmark; one that registers benchCase rows (a matrix, or one case that keeps setup out of the timing) is @benchCases, and registering none is an error unless it skipTests. Mark a test that takes minutes @slow, with a @("name"): ci test skips it and CI runs it as a job of its own. Mark a test that must run alone @serial (process-wide state): it runs after the parallel tests, whatever -t says; @serial(threadAffinity: ThreadAffinity.mainThread) also pins it to the main thread (a thread-confined library, such as Nix's evaluator). Import the attributes unconditionally, never under version (unittest) (reference). @ctfe tests are evaluated by a separate -o- -unittest probe after filtering, so a failing one cannot break the build, --help, or --list.
The runner runs out of process (process model). A test binary holds its tests and the measurement layer (sparkles:test-harness, which depends on no other repository package) and hands its run to the runner executable, sparkles-test-runner, which the dev shell exports as $SPARKLES_TEST_RUNNER. That executable, a main, pool and reporter over the I/O-free sparkles:test-runner-core that ci will drive too, is built from the revision in nix/test-runner-pin.json, not from the working tree, so a change to libs/test-runner-impl reaches only its own package's tests until the pin moves. Without a runner (--no-runner, or no variable) a binary runs its tests itself, one at a time — the way to put a test under a debugger. Every sub-package integrates it the same way:
dependency "sparkles:test-runner" path="../.."insideconfiguration "unittest"; copy the block fromlibs/versions.- A library whose modules carry the marker attributes depends on
sparkles:test-attributes(most get it throughbase). Never namesparkles:test-runner-impl, and never reach into a runner package's directory throughsourcePaths/importPaths. - A test that re-runs its own binary as a child passes
--no-runner, so the child's exit status is its own.
WARNING
Tests in package.d are never discovered — dub's generated test root omits it, so such a module runs zero tests and "passes". Keep tests in feature modules and package.d for public imports.
Run the full CI check locally
nix run .#ci -- pipeline # every CI job this host runs, then a report
nix run .#ci -- test --fail-fast # every sub-package's tests, on the build graph
nix run .#ci -- test --from base --dependents --dry-run # what a focused run would plan
DC=ldc2 nix run .#ci -- test --sanitize address --fail-fast # Linux: AddressSanitizer
nix run .#ci -- test --special-modes all # --better-c/--wasm where used
nix run .#ci -- test --slow # the @slow tests `ci test` skips
nix run .#ci -- examples verify --include-files README.md # markdown examples
nix run .#ci -- check vcs-urls # unpinned GitHub URLs
nix run .#ci -- check sidebar # sidebar ↔ pages
nix run .#ci -- check spec-evidence # spec evidence cites what exists
nix run .#ci -- check blob-paths # local only, see belowci test plans every selected package's test root as one build graph and runs it against the shared store beneath $XDG_CACHE_HOME/sparkles: a second run, or another worktree, compiles only what changed (ci cache explain <task> says why an action missed). Each test binary runs through the runner core, and DC=dmd plans DMD's variants. ci pipeline adds the extracted modes, the checks, the examples, the sanitized and slow tests and the determinism check, and names each CI job it skips.
ci check blob-paths checks that a SHA-pinned citation names a path that exists at that SHA (git cat-file -e against the upstream clones under $REPOS) — the 404 ci check vcs-urls cannot see. Uncloned repositories report as unchecked, so it is neither a hook nor a CI job: run it before publishing a research catalog.
What the default branch reports
main does not re-run CI. .github/workflows/main-checks.yml compares the landed (rebased) tree with the tree the pull request built: equal trees get the PR's checks mirrored onto the commit; different ones call ci.yml as a reusable workflow. Rehearse it with nix run .#ci-minimal -- github mirror-checks --repo PetarKirov/sparkles --sha "$(git rev-parse origin/main)" --no-write (ci stats --merges measures the split). Before touching the workflows:
- Jobs that only talk to an API use
.#ci-minimal— the same binary without the compiler toolchain in its runtime closure (83 MiB vs 1.4 GiB on x86_64-linux).ci test(every form) andci examples standaloneneed.#ci. - Every
ci.ymljob runs on every trigger; select work through the trigger list. A called workflow sees the caller's event (pushon the rebuild path), and the merge-queue run is the only one that sees the batched result — anif:guard on either silently builds nothing and reports green. - The networked link sweep is
link-check.yml, nightly, reconciling one issue viaci github link-rot-issue. PRs runlychee-offlineon the tree and the networked check on their own diff.
Code Style & Idioms
Follow Code Style (module layout, imports, DIP1009 contracts, DIP1030 named arguments) and prefer UFCS range pipelines per the functional guidelines.
Shortened function syntax & imports
Write single-expression functions in the => form:
bool active() const @safe pure nothrow @nogc => _active;A local import forces a braced body, so hoist it to a module-level selective import (import std.conv : text;). Keep local imports for already-braced bodies that scope a heavy dependency. Examples (libs/*/examples/*.d) use module-level selective imports throughout.
Safety attributes — annotate non-templates, infer on templates
- Non-templates: annotate explicitly (
@safe pure nothrow @nogc; a module-level@safe pure nothrow:block is fine). - Templates — and anything generic over a caller-supplied
Writer/Hook— let attributes infer, so non-@safewriters stay accepted. Annotate a template only when the attribute is intrinsic (recycledErrorInstanceis deliberately@system). @trustedwraps only the unavoidable operation, in a lambda or block — never a whole function, never a template. Often it can be sidestepped:char[1] a = c; put(w, a[]);keeps a writer call@safe.
Preview flags
Each sub-package's dub.sdl sets dflags "-preview=in" "-preview=dip1000" (unittest builds add -checkaction=context -allinst); the root dub.sdl has none. Some Phobos functions reject scope (std.regex.replaceAll, reached via unstyle): on "scope parameter may not be returned", relax that one parameter to const(char)[] or pass by value.
Build-setting policy
apps/ci/tools/standardize-build-settings.d owns the managed build types in every tracked dub.sdl. Regenerate with dub run --single apps/ci/tools/standardize-build-settings.d; add -- --check to audit without editing. Preserve package-specific compiler workarounds outside the managed block. After adding a dub.sdl, stage it before running the generator's tracked-file audit. Default dub test uses unittest (debug mode, assertions live; LDC line tables); -b unittest-debug retains full debugger information. Shipping stays checked. Linux defaults to lld. Nix environments must use pkgs.lld-sparkles (the fork LLVM's lld, nix/d-toolchain.nix): a raw ld.lld omits runtime search paths for external store libraries. Re-enter the development shell after linker-tool changes; do not mask missing paths with LD_LIBRARY_PATH. Benchmarks use assertion-preserving -b bench. Use bench-unchecked/bench-static for peak throughput only after validating setup and correctness with assertions enabled; the DMD frontend and assertion-dependent setup must retain bench. Benchmark builds are measurement artifacts, not shipping or correctness-test builds. See the build-settings report before selecting static Phobos, changing linkers, or publishing new baselines.
Error handling — Expected in @nogc nothrow code
@safe pure nothrow @nogc code reports errors with sparkles.base.expected (tchaloupka/expected, vendored): ok(v) / err!T(e), hasValue/hasError, chained with map, mapError, andThen, orElse. An Expected is a range, so joiner flattens results and drops errors. A path that must still throw in @nogc uses recycledErrorInstance!T("msg") (sparkles.base.lifetime). Full guide: Expected Error Handling.
@nogc primitives (and what breaks @nogc/nothrow)
Use a sparkles.base.buffer buffer where appender would allocate, and let the alias state what it may do (spec):
| Alias | Reach for it when |
|---|---|
UniqueBuffer!(T, N) | The default. One owner; move-only, so growth carries no refcount. |
SharedBuffer!(T, N) | Copies genuinely happen (copy-on-write) — naming it claims that something copies. |
InlineBuffer!(T, N) | The bound is hard and overflow is reported; not an output range — write with tryWrite. |
HeapBuffer!T | An inline array would be dead weight; size it with reserve. |
Other combinations spell the policy out: Buffer!(T, N, storage).
Format and parse numbers with sparkles.base.text.writers/.readers; .text, std.conv, and std.format allocate. splitter(' ') and std.utf can throw UTFException, so nothrow @nogc paths use the text package too. Manual allocation uses pureMalloc/pureFree; known sizes use static arrays.
Locks and waits come from sparkles.base.sync (Mutex, Condition, Guarded!T, RwLock, Semaphore, …), not core.sync or pthread_mutex_t: each is @nogc nothrow and its .init is ready, with no constructor or new (how-to).
Strings, and the C boundary
A D API takes string or in char[]; NUL-termination happens at the C seam — InitWindow(…, title.ptr) shipped a macOS crash because a D slice has no terminator. sparkles.base.text.cstring has one tool per lifetime:
| Need | Use |
|---|---|
| Hand a C string to a call, nothing more | toTempStringz |
| The buffer outlives the call (a field) | stringz on it |
| Input has a known bound | CString!N via toCString / tryToCString |
| Name a literal as a C string | cstr!"…" |
| A pointer arriving from C | CStr.fromStringz |
| Append a terminator into a writer | writeStringz |
SetWindowTitle(title.toTempStringz.ptr); // temporary lives past the callWARNING
Name the buffer (auto z = s.toTempStringz;), never its pointer: auto p = s.toTempStringz.ptr; dangles once the statement ends, and dip1000 does not catch it. std.string.toStringz fits a GC-owned string that must outlive the call.
Render plain interpolated text with writeText (no markup parsing); reserve writeStyled for {red …} style templates — it eats braces in, say, a filename. Outside @nogc, std.conv.text(i"…") does the same job. See Write @nogc text.
Output ranges
Rendering functions take any output range (ref Writer writer) rather than returning a string, so callers choose appender, a Buffer, or a stream.
Testing
- Follow every public function with a DDoc'd (
///) unittest. - Name tests with a string UDA,
@("Module.function.case"). - Give every unittest an explicit
@safeor@system(never@trusted), pluspure,nothrow,@nogcwherever they hold — and check that an accidental allocation has not quietly relaxed them. - Environment-dependent tests (perf counters, root-only interfaces, missing toolchains) call
skipTest(reason)fromsparkles.test_runner.skip; an earlyreturncounts a degraded environment as a pass. - Assert rendered text with the helpers, which diff on mismatch and stay
@safe pure nothrow @nogc:checkWriter!((ref b) => …)("expected")andcheckToString(value, "expected")fromsparkles.base.buffer;checkRoundTrip/checkRejects/checkAscendingfromsparkles.versions.testingfor version schemes. (How-to.)
@("MyType.toString.basic")
@safe pure nothrow @nogc
unittest
{
import sparkles.base.buffer : checkToString;
checkToString(MyType(42), "MyType(42)");
}Examples & Documentation
Where docs live
Cross-cutting guides in docs/guidelines/; per-library Diátaxis docs in docs/libs/<name>/; research catalogs in docs/research/<topic>/ (follow Writing Research Docs); specs in docs/specs/ (follow Writing Specification Docs).
The docs sidebar is data
docs/.vitepress/sidebar.json (the sidebar tree) and docs/.vitepress/docs-config.json (srcExclude) are the single source of truth, read by config.mts as JSON imports, by ci check sidebar, and by ci docs fences-audit. Edit the JSON — config.mts only passes it through.
To add a page, add { "text": "…", "link": "/route" } to the right group (a group is { "text", "collapsed": true, "items": [ … ] }); the link is the route — leading /, no .md, /dir/ for dir/index.md. Then run ci check sidebar.
The glossary is data too: docs/.vitepress/glossary.json (schema: sparkles.docs.glossary) renders the /glossary page and every <GlossaryList owner="…" />, and ci check glossary validates it together with every docs link into it. Link a term to …/glossary.md#<id>; never redefine it in prose. See Writing Specification Prose.
Runnable README examples
A new feature gets a runnable README example: a d fence holding a dub single-file program, followed by an ```ansi fence with its verbatim output (escape sequences included — colour survives on VitePress and GitHub):
```d
#!/usr/bin/env dub
/+ dub.sdl:
name "readme_my_feature"
dependency "sparkles:core-cli" version="*"
+/
import sparkles.core_cli.my_module;
void main() { /* … */ }
```
```ansi
Expected output here
```--verify treats only an output-labelled fence as expected output. The legacy ```[Output] label still verifies but strips colour; convert any you touch to ansi by regenerating it.
nix run .#ci -- examples verify --include-files README.md # check
nix run .#ci -- examples update --include-files README.md # regenerate the ansi blocks
nix run .#ci -- examples run --include-files README.md # just runREADME examples use version="*" (readers copy them), so dub add-local <repo> first to verify against the working tree.
Dynamic output with <!-- md-example-expected -->
For timestamps, paths, or durations, place a <!-- md-example-expected --> comment between the code and the ansi block. --verify matches its pattern against the ANSI-stripped output, with {{_}} matching any non-empty text, while readers see the literal block:
<!-- md-example-expected
[ {{_}} | info | {{_}} ]: Server started
-->
```ansi
[ 14:32:01 | info | app.d:12 ]: Server started
```In-repo dub dependency paths
Everything inside the repo — dub.sdl files, single-file examples, guideline snippets — depends on siblings through a relative path= to the repo root: libs/base/dub.sdl and docs/guidelines/*.d use path="../.."; libs/<lib>/examples/*.d uses path="../../..". Only README.md keeps version="*".
Conventions
Commit messages
Conventional commits, <type>(<scope>): <description>. Types: feat, fix, refactor, docs, build, ci, test, style, chore, config; ! after the scope marks a breaking change. Wrap the body at 80 columns after a blank line.
Use the most specific scope that is still short and obvious:
| Form | Example |
|---|---|
{lib}.module | fix(base.buffer): saturate grownCapacity on overflow |
{pkg}/subdir | feat(core-cli/examples): add animated streaming table demo |
docs(research/{topic}) | docs(research/window-system-integration): add NDK example |
| whole package, when cohesive | feat(terminal): implement text selection |
| tool or config area | config(lychee): …, ci(gh-actions): … |
A bare top-level scope (base, docs, nix, …) fits genuinely cross-cutting work; nix covers both sparkles:nix and the flake.
Backtick @-tokens in commit messages, PR/issue text, and comments (`@safe`, `@nogc nothrow`, `@property`): GitHub renders a bare @name as a mention of a real account. Backtick `#123` and SHAs you do not want cross-linked too. Committed source and Markdown files are unaffected.
Git hygiene & atomic commits
- Confirm the branch before any commit, amend, or rebase; branch off the default branch first.
- Commit at each significant step, without waiting to be asked. Pushing needs an explicit ask — except documentation work, which, once committed, validated, and rebased, you push and open as a PR.
- Each commit is atomic and green (build + test + lint on its own); tweaks to an earlier commit go in as
git commit --fixup=<sha>. CI builds only a PR's tip, so check the rest before pushing a series:nix run .#ci -- commits build-eachbuilds every commit since the merge-base withorigin/mainin a scratch worktree (--base <ref>,--packages <name>…; by defaulthue,ui-galleryanddiagram, whose GUI configurationsdub testnever compiles). - Before opening a PR, rebase onto a fresh
origin/mainwithgit rebase --update-refs(passed explicitly — it keeps a stacked series intact), rerun the affected validation, and update a pushed branch with--force-with-lease. - Back up a branch you are about to rewrite with a tag (
git tag backup/<effort>-pre-rebase):--update-refsmoves backup branches along with the rewrite. - At the end of a session, propose tidying the branch (autosquash fixups, every commit green, related commits adjacent, preparation commits — config, dependencies, scaffolding — first) and rewrite only once the user agrees.
Pre-commit hooks (prek)
Hooks run on commit and may modify or block it; each bypasses with SKIP=<hook> git commit …. Implement new hook logic in D (see Scripts are D).
- editorconfig-checker — 4-space-multiple indentation, DDoc bodies included.
- prettier — reformats markdown; re-check tables of literal data afterwards (it once turned
5.004_05into5.004*05). - verify-md-examples — runs the example verifier; OOM-prone on large runs.
- detailed-scope (
commit-msg) — flags useless scopes (wip,misc) and suggests a narrower one when the diff is localized. - check-vcs-urls — staged
.mdfiles must pingithub.com/raw.githubusercontent.comURLs to a 40-character SHA ($/%placeholders are skipped). - check-docs-sidebar — whole-tree sidebar ↔ pages check whenever
docs/is staged. - check-spec-evidence — resolves every symbol, file and sub-package a spec's evidence column cites, whenever a spec, a D source or a
dub.sdlis staged. Citations stale when it became a gate are listed indocs/specs/evidence-backlog.txt, which may only shrink: a new unresolved citation fails, and so does a listed one that now resolves (delete its line). Only rows that claim delivery are checked: a row whose status isnot started,researched,deferred,planned,proposedoropennames code it will be, not code that exists. So fix a backlog row by citing what satisfies it, or, if it was never delivered, by giving it that status. - check-opaque-recipes — whenever a
dub.sdlis staged, reports every recipe entry no input set can hold: apreBuildCommands-style command (other thanshader-compilerun through$DUB run), a flag carrying a path, or a path through a variable or outside the repository. Each makes every request that builds it selected by any change, so the check says what to write instead. One not inapps/ci/opaque-recipe-allowlist.txtwith a reason fails.
Pitfalls Checklist
- [ ] New files are
git added before a flake build. - [ ] After editing
apps/ci, run it viadub run :ci/nix run .#ci. - [ ] Tests live in feature modules, never
package.d. - [ ] Templates infer attributes;
@trustedwraps one operation. - [ ]
nothrow @nogcpaths use thetextpackage, notsplitter/std.utf/std.conv. - [ ] D APIs take
string/in char[]; atoTempStringzbuffer is named, its.ptris not. - [ ] Example output blocks are
```ansi. - [ ] Cross-module-but-internal symbols use
packagevisibility. - [ ] Symbols used only as UDAs are camelCase.
- [ ] C headers come from
pkg-config. - [ ] Large value types in a unittest (
MatcherWorkspace,DqlEnginescratch, …) are heap-owned (Unique/HeapBuffer): test workers have 512 KiB stacks and a 384 KiB watermark fails the test. - [ ] A git call naming its repository (
-C <dir>, aworkDir, a path) goes throughrunGit(sparkles.build_primitives.git_env). Git exportsGIT_DIRto every child it spawns (rebase exec, hooks,bisect run), and an inheritinggit initfixture has twice setcore.bare = truein this repository. Tools that mean the ambient repository (ciunder a hook,release) keep inheriting. - [ ] Dependency version changes update both
dub.selections.jsonandnix/dub-lock.json. - [ ] Nothing generated from
sparkles.ui.effect_shadersorlibs/ui/shaders/effects.dis committed: thegpu-effectsbuild (anything onui-raylib) re-derives the GLSL when its inputs change, and needsldc2-vulkan(the dev and CI shells have it).@computemodules hold no string literals (a test name is one), so their tests live in a host-only module.
Dependencies
D dependencies are pinned in dub.selections.json and nix/dub-lock.json. Expected is not one of them: it is vendored into sparkles:base as sparkles.base.expected (from tchaloupka/expected; its header names the revision). System tools, delta included, come from the flake.