Skip to content

[docs] kyo-doctest + readmes for all modules - #1645

Merged
fwbrasil merged 8 commits into
mainfrom
kyo-doctest
May 29, 2026
Merged

fwbrasil merged 8 commits into
mainfrom
kyo-doctest

Conversation

@fwbrasil

Copy link
Copy Markdown
Collaborator

Problem

Module-level documentation in the repo was uneven. The root README was the only validated doc, checked by sbt-mdoc against a handful of fenced blocks. A few module READMEs (kyo-config, kyo-flow, kyo-http, kyo-pod, kyo-schema) existed and had drifted against the API they were meant to describe. The other 29 modules had no README at all.

Closing that gap meant validating hundreds of fenced Scala blocks across 30+ modules on every commit. mdoc was already a bottleneck at the much smaller scale we were running it at. There was also no shared mechanism for writing the next README or for catching when an API change broke an existing one, so any module added later would land into the same drift the existing ones had.

Solution

  • kyo-doctest. A new kyo-agnostic sbt plugin and JVM-side library that compiles (but does not run) every fenced Scala block in a Markdown file against its module's classpath, and validates every internal link inside the file. A block-level DSL in HTML-comment modifiers controls scope, expectation, target platforms, and setup-prelude injection. A content-hash cache keeps the per-block cost near zero. The aggregate sbt doctest task runs the whole repo's READMEs in 14 seconds on a warm cache, and CI runs it on every PR. mdoc is replaced.

  • The /readme skill. A multi-stage agent pipeline at .claude/skills/readme that produced these READMEs and is what maintainers run to add or rewrite one. It walks a module's source, picks a use-case-first or type-first spine, drafts (or cleans up) the README, runs a whole-document critique pass that catches catalog-style writing where the README enumerates APIs instead of teaching them, and verifies coverage against the source inventory. Conventions (running-domain example, cluster headings, opener style) live inside the sub-skills rather than as prose to follow. AGENTS.md and CONTRIBUTING.md trim their "writing module READMEs" sections to a one-line pointer at the skill. CLAUDE.md is added as a symlink so Claude and other agents converge on the same instructions.

  • 29 new module READMEs. One per module that previously had none, plus a refreshed root index with an "Introduction to Kyo" section covering the import kyo.* convention, the pending type, composition, the shape of an effect (init / get / run lifecycle), effect ordering, and the idiomatic monadic style. Every fenced block compiles under sbt <module>/doctest.

Notes

  • The plugin auto-enables on every JVM project via trigger = allRequirements, so a new module gets doctest for free and opts out with .disablePlugins(KyoDoctestPlugin). Non-JVM crosses are filtered out of the aggregate automatically.
  • The link validator covers same-document anchors, relative paths to other files in the repo, and anchors into those files. External URLs (http, https, mailto, etc.) are skipped because network reachability is out of scope. Inline-code spans inside prose are masked before extracting links so Scala signatures like Abort.run[E](v) are not mistaken for Markdown links.
  • The default predef is just import kyo.*. READMEs that need other imports keep them in their code blocks where the reader can see them. Actor.Subject, Browser.Image, caliban.RootResolver, kyo.zioSchema and friends are spelled out the same way a user copying the example would have to spell them. The three READMEs that genuinely need an AllowUnsafe witness (root, kyo-stats-registry, kyo-stats-otlp) import it explicitly in their code blocks and call out the risk.
  • kyo-kernel sets doctestFreshDriver := true. Reusing the dotty driver across blocks trips a "denotation invalid in run N" assertion on macro-heavy code (kyo-kernel is the only current case, but the same toggle is what a dotty-cps-async user would need).
  • OTLPConfig.loadIfEnabled widened from private[otlp] to public. The README documents it as the user-facing entry point and it was unreachable from user code.

fwbrasil added 5 commits May 27, 2026 08:15
…locks

mdoc is too slow to validate every fenced Scala block across the kyo
modules on every commit. kyo-doctest forks a dotty driver per task and
caches per-block by content hash, so warm aggregate runs across all
module READMEs complete in seconds. The sbt plugin (sbt-kyo-doctest)
auto-enables on every JVM cross via allRequirements + JvmPlugin and
exposes doctest, doctestFresh, doctestClean tasks plus an aggregate
command that schedules every enabled project through sbt's task engine.

Per-fork JVM options (default -Xmx8G -Xss10M) and Tags.limit(DoctestTag, 2)
bound concurrent forks so the aggregate run stays predictable. The plugin
filters out non-JVM crosses; scala-native and scala.js compiled classes
on the JVM classpath wedged forks in UndefinedBehaviorError loops.

In-tree wiring (project/build.sbt picks up sbt-kyo-doctest's source under
the meta-build's unmanagedSourceDirectories, same pattern as kyo-compat)
keeps the plugin and library on the same version without an ivy round trip.
… READMEs

A README that doctest validates is worth little if writing it is still
manual. The /readme skill orchestrates a Stage 0 source-analysis agent,
a Stage 1 writer or cleanup-editor, a Stage 1.5 gestalt critique, and a
Stage 2 verify-against-source-coverage gate. Each sub-skill carries the
conventions (use-case-first vs type-first spine, cluster grouping,
running-domain example, no marketing copy, no em-dashes) so the
supervisor only assembles outputs; it never writes prose itself.

AGENTS.md and CONTRIBUTING.md trim the previous "writing module READMEs"
sections to a one-line pointer at the skill, so the conventions live in
one place. .gitignore exempts .claude/skills/ from the existing .claude
ignore (the rest of .claude remains local-only).
29 new module READMEs plus a refreshed root README that indexes them.
The skill from the previous commit produced this set; doctest from the
commit before that validates every fenced Scala block.

A handful of source files (kyo-stats-registry's UnsafeCounter/UnsafeGauge,
kyo-stats-otlp's OTLPConfig, plus three test files) pick up small tweaks
that pair with the worked examples in their READMEs.
Adds an internal-link validator to the doctest pipeline: same-document
anchors, relative paths to other files in the repo, and anchors
into other files in the repo are all resolved (external URLs are
skipped). Inline-code spans are masked before extracting links to
avoid false positives on Scala signatures like `Abort.run[E](v)`.

The aggregate `doctest` command now runs in two phases: phase 1 is
`all <projects>/Test/compile` at sbt's normal task parallelism so
the compile cascade is its own bounded burst; phase 2 is
`all <projects>/doctest` which respects `Tags.limit(DoctestTag, 2)`.
The tag is exposed via `autoImport.DoctestTag` because the kyo
build replaces `Global / concurrentRestrictions` wholesale with
`:=` and would otherwise drop the plugin's `+=`. Each fork also
caps dotty's internal worker pools via
`doctestForkJavaOptions := Seq("-Xmx8G", "-Xss10M", "-XX:ActiveProcessorCount=2")`,
keeping per-fork CPU around 2 cores.

The root README grows an "Introduction to Kyo" section that covers
the `import kyo.*` convention, the pending type, composition,
the shape of an effect (init / get / run lifecycle), effect
ordering, and the idiomatic monadic style. Per-block hidden
`AllowUnsafe.embrace.danger` setup is gone; the three READMEs
that genuinely need it (root, kyo-stats-registry, kyo-stats-otlp)
import it explicitly in their code blocks and call out the risk.
Five stale relative links in kyo-case-app and the root README are
fixed (a moved `internal/KyoAppRunner.scala` and a couple of
modules without their own README).

The fork log now reports the README's repo-relative path
(`doctest: validating kyo-core/README.md`) instead of the bare
filename.
@fwbrasil fwbrasil changed the title [docs] kyo-doctests + readmes for all modules [docs] kyo-doctest + readmes for all modules May 27, 2026
Comment thread README.md Outdated

Note that `Render` does not convert to string but to `Text`--an enriched `String` alternative provided and used internally by Kyo. Kyo methods for displaying strings all accept `Text` values (see `Console` and `Log`, below). Converting values using `Render` directly can be cumbersome, however, so Kyo also provides a string interpolator to construct properly formatted `Text`s automatically. To use this interpolator, prefix your interpolated strings with `t` instead of `s`.
## Idiomatic style: monadic by default

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoy-jon @hearnadam this is a departure from our recommendations so far. I think kyo-direct isn't mature enough and suggesting it can end up actually hurting adoption. We should explore a compiler plugin for direct syntax instead

fwbrasil added 3 commits May 27, 2026 13:16
scalafmt was rewriting the sbt plugin's Scala 2.12 sources as Scala 3
(end markers, brace removal, `import x as y`) because the default
`runner.dialect = scala3` had no override for `sbt-kyo-doctest/**`.
Adds a fileOverride matching how the other in-repo sbt plugin source
(`kyo-compat/plugin/src/main/**`) is configured, and reformats
`Runner.scala` and `KyoDoctestPlugin.scala` to plain Scala 2.12.

The `readme` job was failing with a coursier bootstrap cycle. The
plugin was adding `libraryDependencies += "io.getkyo" %% "kyo-doctest"`
to every enabled project. Coursier resolves the whole build's dep
graph eagerly, so any project that has the plugin enabled blocks
`kyo-doctest/publishLocal` because kyo-doctest itself is not in ivy
yet. Replaces the lib dep with a project-graph reference resolved
by sbt's task engine: `kyo-settings` does
`Test / unmanagedJars ++= (LocalProject("kyo-doctest") / Compile / fullClasspath).value`,
which wires kyo-doctest's full Compile classpath (the jar plus all
transitive deps: kyo-core, kyo-schema, kyo-parse, dotty,
scala-library, ...) onto every doctest-enabled project's Test
classpath without involving coursier. The CI workflow drops the
no-longer-needed `publishLocal;` step.

Local verification: `sbt 'scalafmtCheckAll' 'sbt-kyo-doctest/compile'`
green; `sbt 'doctest'` aggregate runs all 33 modules with 0 failures
in 5:29 (3:26 phase-1 compile cascade plus 1:51 phase-2 doctest forks
at Tag=2).
Test/unmanagedJars carries kyo-doctest only when scalaVersion is the
current 3.x, so LTS fallback modules (3.3.7) no longer get a 3.8.3
scala3-library on Test compile. Their doctest forks receive kyo-doctest
through the plugin's new doctestExtraClasspath, with reconcileClasspath
stripping the mismatched scala3-library at fork time.
…pile

Aggregate sbt doctest first compiles every plugin-enabled module's Test
scope in parallel. With kyo's inline-heavy macros, 2G is too small and
dotty OOMs on kyo-data/kyo-compat-kyo. Match build.yml's heap (8G heap,
2G metaspace, 256M code cache).
@fwbrasil
fwbrasil merged commit 2be34a0 into main May 29, 2026
23 of 27 checks passed
@fwbrasil
fwbrasil deleted the kyo-doctest branch May 29, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant