`include: merge` in frontmatter splices a bundle's includes before the parse, so
a page assembled from several files is one document: one footnote list at its
end, numbered straight through, and an abbreviation defined anywhere reaching
every part. Moving the rendered block afterwards would have meant editing
goldmark's own markup; handing the parser one source gets the right answer from
it instead. Without the flag nothing changes — each fragment stays its own
document with namespaced ids, so no existing content re-renders.
Heading ids are unique under either model. Merging gets that free, because one
parse means one id set, but embedding did not: three `## Description`s across a
page and its fragments produced three identical anchors, and every link to them
landed on the first. A nested parse now shares the parent's id set, so the
second becomes #description-1 — goldmark's own suffixing, reaching across files
because they finally share the set it counts in.
Auditing for other policies the author could not reach found two more.
A heading may declare its anchor: `## Title {#stable-anchor}`. This is the one
that mattered most and nobody had asked for it — a derived id changes when the
text does, so rewording a heading silently broke every link to that anchor,
which is indefensible in an engine whose first value is that published addresses
are permanent.
`::toc{depth=2}` shortens a contents list, because a theme cannot know per page
how deep is useful and the author can.
Deliberately not added: a typographer toggle, a per-picture "do not resample",
icon overrides. No second user for any of them.
The hand-copied wiring in example_test.go drifted for the third time this
session — Compose this time, after the dialect and notation — each caught by a
demo case rather than by the copy. The latent row is now marked due, with what
moving the list would require.
20 KiB
State
Currency is compared, not declared. verify.sh warns unless this file's last commit is at least as new
as the last commit touching .go, so it ships inside the change it describes — no sha to write, and no
trailing commit to write one (ADR-0057).
If this file disagrees with the code, the code is right and this file is a bug.
Inventory
Line counts are not here: docs/surface.md is generated from the code and carries per-file sizes
plus every declaration's location (ADR-0053). This column drifted on six files before it was removed,
which is what a number written in two places always does. What each file is for is the fact this
table owns.
| File | Purpose |
|---|---|
go.mod |
module khosra; goldmark, x/text, yaml.v3 direct |
internal/content/doc.go |
package comment |
internal/content/content.go |
bundles: os.Root open, walk, frontmatter split, key/lang derivation, NFC, tag slugs, partial files, permalink building |
internal/content/clock.go |
the one place the engine reads the wall clock, which verify.sh enforces by filename |
internal/content/extras.go |
a bundle's supporting files: enumeration, classification, and their URLs (ADR-0047) |
internal/content/settings.go |
site.yaml: the site's own declarations (base, title) and absolute-URL building (ADR-0039) |
internal/content/site.go |
the indexed site: lookup with language fallback, aliases, Query and Run, sections, Sequence, Everything, slug routes, publication visibility |
internal/render/render.go |
goldmark with the typographer, per-kind template sets with site override, the render methods. The parsed sets plus the stylesheet are one snapshot behind an atomic.Pointer; Refresh is the only thing that replaces it, so every page serves one theme (ADR-0055, ADR-0056). Heading ids are a parser option set here, declared or derived (ADR-0058, ADR-0066), and this is the one renderer that enables raw HTML (ADR-0060). Compose is the seam a merging bundle's splice arrives through |
internal/render/view.go |
the theme contract in Go: Page, List, Sequence, Extras, Item, Fragment (with Body and Headings, ADR-0064, ADR-0065), Heading, Picture, Origin |
internal/render/chrome.go |
the engine's own words: phrase table, month names, digits, and the t/num/day template funcs (ADR-0034) |
internal/render/templates/ |
reference theme, complete (six icon names map to Unicode, no assets — ADR-0063): base.html (shell, navigation, language links, feed and OpenGraph), page.html (bundle, sequence, tags, extras), list.html, extras.html, shortcodes.html (figure, gallery, icon, note/warn/tip, details, aside, toc), theme.css (ADR-0026, ADR-0049) |
internal/ext/shortcodes/ |
first feature: ::name{key=value} block parser and node renderer, rendering through a theme fragment (ADR-0036). figure, gallery, include, plus the derivative pass and remembered picture inspection (ADR-0042, ADR-0044). FootnotePrefix namespaces an included file's footnote ids (ADR-0058). Directive syntax since ADR-0059, plus icons.go: :name: inline, rendered by the theme's one icon fragment (ADR-0063), containers.go: :::name{…} … ::: wrapping a rendered body (ADR-0064), and toc.go: the document's headings for a ::toc call, to a depth the call may set (ADR-0065, ADR-0066). Merge splices includes before the parse for a bundle that asks for it, and an embedded fragment parses against the page's id set so repeated headings are suffixed rather than duplicated (ADR-0066) |
internal/ext/notation/ |
the inline marks CommonMark lacks: ~sub~, ^sup^, ==mark==, and ~~strike~~, which it owns so a single tilde can mean subscript (ADR-0061). abbr.go adds *[TERM]: definitions and the pass that expands them (ADR-0062) |
internal/ext/scaffold/ |
writes one draft directory bundle into a site root through os.Root: never an overwrite |
internal/ext/watch/ |
polls content/ and templates/ on an interval it is given, ignores editor droppings, and reports a settled change (ADR-0022, ADR-0048, ADR-0056). site.yaml is deliberately not fingerprinted (ADR-0055) |
internal/ext/check/ |
third feature: validates a site root — what the engine worked around, broken internal links, missing titles and alt text, mixed series ordering, and calls left in the retired shortcode form (ADR-0059) |
cmd/khosra/wire.go |
the only list of enabled features (extensions.md), and the Markdown dialect with it — tables, footnotes, definition lists, strikethrough (ADR-0058) |
internal/web/resolve.go |
URL → (key, lang, page, tag, feed, extras) or a canonical redirect |
internal/web/extras.go |
the extras route: listing, one entry selected, or ?raw bytes, all behind the bundle lookup |
internal/web/asset.go |
files inside a bundle's own directory, looked up through the owning bundle so visibility can only ever inherit (ADR-0024) |
internal/web/feed.go |
Atom for the site, a section or a tag, from dated bundles via one Query (ADR-0043) |
internal/web/discover.go |
/robots.txt and /sitemap.xml, absolute and only with a declared base (ADR-0039) |
internal/web/web.go |
handler: serve dispatches by kind, serveBundle answers the commonest one; listings, /static/, /derived/, degrade on failure |
cmd/khosra/main.go |
flags (including -poll, zero to stop watching), wiring, startup, the derivative pass, and the atomic swaps a change goes through — theme in the watcher's callback, index in rebuilder. main dispatches subcommands, runServe assembles the server, rebuilder is used at startup and on every change alike |
cmd/khosra/check.go |
the check subcommand: parse, print, exit code. What counts as a finding lives in the feature |
cmd/khosra/new.go |
the new subcommand: arguments in either order, then the feature does the writing |
*_test.go |
table-driven, one file per source file; symlink escape (content and static), canonical paths, language fallback, aliases, pagination, tags, sequences, chrome, typography, shortcode escaping, galleries, includes, partials, site settings, absolute URLs, robots, sitemap, slug routes, bundle assets, derivatives, feeds, 404, plus benchmarks for the render path and the checker, unpublished visibility, listing shapes, scaffolding, extras, change detection, what a page can reach, the root listing, and the example site end to end |
Serves a listing of everything at / (ADR-0050), a bundle at /{section}/{slug}/ — the slug derived, or declared in frontmatter without moving the
key (ADR-0035) — a paginated listing per section, tag listings global and
section-narrowed, sequence navigation and a series archive on any nested bundle, static/ verbatim, a directory bundle's own files under its
URL, generated derivatives under /derived/, Atom feeds per site,
section and tag, a bundle's extras as a browsable tree, plus /robots.txt and /sitemap.xml.
Markdown is CommonMark plus tables, footnotes, definition lists, heading ids and the inline marks
(~sub~, ^sup^, ==mark==, ~~strike~~, *[TERM]:), and nothing else (ADR-0058, ADR-0061, ADR-0062); HTML an author writes renders, because the site root is trusted (ADR-0060). Chrome text, dates and digits render in English or Bengali; authored text is untouched but for typographic
smoothing (ADR-0034); line breaking is left to CSS (ADR-0045). This repo holds engine source only — the site root is external and passed with
khosra check validates a site root and exits non-zero on anything that makes it wrong; khosra new
scaffolds a draft bundle into one. A running server notices changes under content/ and templates/ by
polling — -poll, zero to stop — and swaps both the index and the parsed theme atomically, so a content or
template edit appears without a restart and every page updates together (ADR-0022, ADR-0055, ADR-0056);
site.yaml applies at startup only. A draft or
future-dated bundle is not served at all — nor is any file inside it (ADR-0024) — until -dev on reveals it and
polls four times a second (ADR-0056).
-site (ADR-0011). site.yaml declares base and title; with a base, canonical, hreflang and OpenGraph
URLs go absolute (ADR-0039).
Frontmatter the parser lifts today: title, date, tags, aliases, order, slug. include: merge is read from Extra by the renderer (ADR-0066). Every other key in
content-model.md's table — including draft and type — lands in Extra unread, so that table
is the accepted format, not a list of what runs.
examples/demo-site/ is a complete site kept in the repository to be read and served — 30 bundles across six
sections, one case per feature in TestTheExampleSiteExercisesEveryFeature, and khosra check run over it by
verify.sh (ADR-0051). make demo serves it. Features are spread across the bundles where a real site would
put them rather than piled on one page: text marks and the margin note on writing/typography, icons and
panels on pages/colophon, the include, table, glossary and contents list on writing/notes-on-water.
A Dockerfile ships the binary alone: the site root is a mounted volume, never copied in (ADR-0010, ADR-0011).
Dependencies: four, all allowlisted — goldmark, golang.org/x/text, golang.org/x/image, gopkg.in/yaml.v3.
Counters — the earn-it authority
Never anticipate a threshold. Increment when the code lands, then check whether the extraction is due this change.
| Counter | Now | Extraction due at | What it buys |
|---|---|---|---|
| Render transforms — page-level only | 0 | 3 | Stage pipeline (ordered func(ctx,*Page) error). Parse-phase work does not count and must not: goldmark's extender list is already an ordered pipeline for it, so typography and shortcodes compose there (cmd/khosra/wire.go) and a second pipeline beside it would be pure duplication. This counts transforms over the assembled page, which nothing hosts yet — OpenGraph and JSON-LD (queue 15) are the first candidates |
| Routing cases | 11 | 2 — done | Resolver at internal/web/resolve.go: bundle, language prefix, pagination, tag, section-narrowed tag |
| Collection pages | 4 | 1 — done | Query primitive: content.Query{Section, Tag, Lang} + Site.Run. The fourth — a series archive — resolves through Site.Sequence instead: membership is structural and the sort ascends, so it shares the index but not the Query |
| Views — per-bundle selection only | 0 | 2 | The View layer architecture.md describes: view: in frontmatter choosing a presentation, resolved through the cascade. Nothing selects a view yet. Output formats are counted separately and are not it: HTML, sitemap XML and Atom are three functions with nothing to share — an interface over them would have one member and no leverage |
| Effects | 1 | 2 | Effect runner + trigger wiring (change / schedule / demand). The first and only is the derivative pass (ADR-0042), called straight from cmd inside rebuilder, so it already answers both triggers it will ever need — startup and a settled change (ADR-0048) — and one call needs no runner. Swapping the index or the theme is not an Effect: both re-read the site root into memory, writing no artifact and calling nothing outbound (ADR-0055) |
| Extensions | 4 | 3 — passed, and the answer is still no | Extension registry (extensions.md). It reached 3 once before and went back to 2 when the widows feature was deleted (ADR-0045) — a threshold reached by a feature that should not exist was never a threshold. It is 4 with notation, and the note below the table says why a registry still buys nothing |
| Interface implementations | — | 2 | The interface itself |
| Non-stdlib dependencies | 4 direct | budget in scripts/budgets.env |
— |
The Extensions counter is past its threshold, and a registry would still buy nothing. The four features
attach in three unrelated ways: shortcodes and notation are goldmark extenders listed in extenders(),
check and scaffold are functions cmd calls for a subcommand, and watch is a goroutine. A registry would
have to abstract over "extends Markdown", "validates content", "writes a file" and "polls a directory", which
share nothing but the word feature — one member and no leverage. Adding notation made this clearer rather
than more urgent: two goldmark extenders compose in goldmark's own extender list, which is already the registry
for that shape, and they need no order relative to each other because one is inline and the other block.
Build the registry when a feature wants a route (the seam ADR-0042 named) or when two features genuinely
need to agree on an order that no existing mechanism expresses.
Allowlist, all four imported: goldmark (markdown), golang.org/x/text (NFC, ADR-0015),
gopkg.in/yaml.v3 (frontmatter, ADR-0020), golang.org/x/image (resampling and WebP, ADR-0040).
Latent items — known, deliberately unfixed
Do not fix these mid-feature. They become features when the human says so. An arc does not close with an untriaged item: at each arc boundary every row is fixed, scheduled into an arc, or accepted with a stated reason. A list nothing drains is a graveyard of known defects.
| Item | Why it waits | Trigger to fix |
|---|---|---|
| No mechanical check that the counters are correct | Accepted at the Arc 1 boundary: the coupling gate makes forgetting them impossible, which is the real failure mode, and checking the values needs code to count | The first page-level transform (queue 15), now that the transform counter means something narrower |
| No mechanical gate on the untrusted boundary (ADR-0003) | Scheduled to Arc 3: nothing untrusted is read yet. Half of it is mechanical in a different way since ADR-0060 — verify.sh requires html.WithUnsafe() in exactly one file, so a second pipeline trusting its input cannot appear unnoticed — but there is still no check that a future untrusted source stays out of shortcode and template evaluation |
The comment path — a test that untrusted input reaches no shortcode or template evaluation |
date stays in Extra after being lifted onto Bundle.Date, unlike title, aliases, tags and order, which are deleted |
Spotted while adding order; the theme contract says Extra holds what the parser does not name, so one of the two is wrong. Harmless today — a template reading .Extra.date gets the raw YAML value |
Whatever next reads Extra generically: feeds (queue 14) or check (17) |
A gallery's images carry no alt |
width/height now come from the original (ADR-0042), so only alt text is missing, and a filename does not supply one. An empty alt is honest for a picture the page has already introduced |
Captions per gallery entry — a sidecar or a frontmatter list — if the reference theme ever needs them |
Sequence resolution rescans the index on every bundle request — two passes over every key, each doing a Lookup |
Measured at the same time as the pictures (ADR-0044): a whole page is ~63µs, so this is not what costs anything. Remembering it would be a cache with no measurement behind it | A page render exceeding a few milliseconds, which is also what would revive the parked cache model |
The root listing's <title> repeats itself — "A Khosra Demo · A Khosra Demo" |
Spotted 2026-08-01 by looking at the served page, not by any test: base.html joins page title and site title unconditionally, and at the root those are the same string. Cosmetic, and the fix is one if in a template — theme layer, not engine |
The first time the reference theme is worked on (Phase G4 touches it), or sooner if a feed or OpenGraph title inherits the same doubling |
The theme and the index are two separate atomic.Pointer stores, so a request landing between them sees a new theme with the previous index |
Accepted 2026-08-01 with ADR-0056: both halves are internally coherent and the gap is microseconds, so no page is ever internally inconsistent — it is simply not a snapshot of the disk. Closing it means one pointer holding both, which changes web.Handler's signature and 20 test construction sites |
Anything that makes the gap observable — a request rate high enough to land in it, or a feature where content and theme must agree exactly (an export, where every page is generated in one pass) |
internal/web/example_test.go rebuilds the extender list by hand, so it can drift from cmd/khosra/wire.go |
A package cannot import a main, and extensions.md puts the list in cmd on purpose — nothing below it may know which features exist. Bounded today: the dialect's own test lives in cmd/khosra/wire_test.go, beside the real list, and the demo test fails loudly when the copy lags |
Due. It has now drifted three times in one session — the dialect, notation, and Compose — each caught by a demo case rather than by the copy itself. The next change to the wiring should move it somewhere a test can import, which needs the list to leave cmd without a package below it knowing which features exist |
Under the default include model, a fragment's footnotes render where the include sits, so a long one puts an <hr> and a numbered list mid-article |
Spotted 2026-08-01 by looking at the served page, not by any test. It is ADR-0038's documented consequence, and the ids are correctly namespaced (ADR-0058); only the placement reads badly. An author who minds now says include: merge (ADR-0066), which makes the page one document and puts every note at its end, so this is a default rather than a limit |
The default itself proving wrong — a site where every composed page sets the flag, at which point the flag is the wrong way round |
| The picture memo is never evicted — one entry per picture on the site, for the life of the process | Correct for one author's site, and the alternative is an eviction policy nothing needs. It is keyed on size and modification time, so it cannot go stale, only grow | A site root large enough that memory matters, or a long-running process where pictures churn |
Open questions
Subagents for fan-out reads — policy, not judgment. Delegating read-heavy sweeps (/audit,
/refresh-docs, /invariants, rename sweeps) keeps thousands of lines of file dumps out of the main
window and returns only the verdict. Deferred 2026-08-01; the case for and against is written out in
ideas/token-conservation.md, including where it is clearly right (locating things) and clearly wrong
(deciding things). Nothing blocks on it.
Nothing else blocks Arc 1 or the first deploy.
Every feature has been audited against the layer test (ADR-0046). One was wrong and was deleted (widow prevention, ADR-0045); one quietly decided presentation and now offers both shapes (tag listing grouping). The verdict table is in the ADR, and remaining queue entries carry a layer note before they are built.
Every ADR in decisions.md is accepted; none is open or proposed.
Build queue
Working plan lives in .scratch/build-queue.md, which is deliberately not committed — git log is the
record of what actually landed. If that file is absent, read the log and rebuild the plan from it.
Arc retro log
One line per completed arc: what it cost, what it taught, what it made unnecessary.
- Arc 1 — the spine. 619 core lines, 3 dependencies, 4 queue entries. Taught:
os.Rootmakes the path guard a property of the type, so the latent item that shipped with the harness died instead of being implemented; and running the gates against real code found six defects in the gates — an allowlist parser that rejected its own documented format, two advisories that fired only on correct code, a coupling gate that demanded explanations for permission edits, an untidygo.modhiding a direct dependency, and a nesting check off by one level. Made unnecessary: a hand-rolled traversal cleaner, and a second routing branch — the resolver arrived by counter at exactly the right moment.