Artifact 45f591b7387010685894bdd1678ed96b60865c086811022d6c011beaaf47886f:
- File
docs/site/content/docs/extension-points.md
— part of check-in
[e2a2f28861]
at
2026-04-26 07:52:11
on branch trunk
— docs site + landing + Cloudflare auto-deploy (#6)
* design: docs site + landing page + Cloudflare auto-deploy
Mirror dagnats's docs/landing infrastructure for libfossil: a single-page landing at site/index.html (forked CSS/HTML, content rewritten), a Hugo + Hextra docs site at docs/site/, gomarkdoc-generated SDK reference under docs/site/content/docs/reference/sdk/, llms.txt artifacts, and a wrangler.jsonc that lets Cloudflare's git integration auto-deploy on push to main. Existing docs/*.md files move under docs/site/content/docs/.
* design: correct landing-page path to Hugo layout override
dagnats's working landing page lives at docs/site/layouts/index.html (a Hugo home-page layout override), not at site/index.html. The top-level site/index.html in dagnats is an older draft that the build pipeline ignores. Match the working setup.
* design: align visual system + section list with live dagnats landing
The earlier description came from dagnats's stale top-level site/index.html (JetBrains Mono + Instrument Serif italic + ember/teal accents, 8 sections). The live Hugo layout that actually serves at / uses Geist Mono only, prefers-color-scheme dual-mode (warm cream / warm dark), a single ember accent, and 7 sections (Install, What it is, Why you might want it, How it fits together, Compared to neighbors, What it is not, Get going). Update the spec to match what we are actually mirroring.
* design: drop SDK regen from CF build to match dagnats exactly
Earlier draft had CF install Go + gomarkdoc and re-run docs-gen-sdk on every deploy. dagnats does not do that; it relies on the pre-commit hook to keep committed SDK pages in sync, and ships only Hugo + llms-gen + hugo --minify in the CF build. Match that: smaller, faster CF build, no Go-runtime assumption about Workers Builds, and a true 1:1 mirror.
* plan: docs site + landing + CF auto-deploy implementation steps
11 tasks covering Hugo+Hextra bootstrap, content moves, gomarkdoc SDK generation with pre-commit drift check, llms.txt artifacts, Makefile targets, landing page fork from dagnats's live Hugo home layout, wrangler.jsonc for CF Workers Static Assets, README update, and PR creation.
* docs(site): bootstrap Hugo + Hextra skeleton
* docs(site): move existing docs into Hugo content tree
* docs(site): fix links + H1s broken by docs-tree move
- Drop .md extensions on Hugo cross-doc links - Switch source-code references to absolute github.com/danmestas/libfossil URLs (relative ../ paths broke when files moved 3 dirs deeper) - Align H1 of architecture.md and migration-from-fossil.md with their frontmatter titles
* docs(site): add quickstart, examples, and SDK section stubs
* docs(site): tighten quickstart snippets + reference index
- Make the Sync example self-contained (open + sync, full main, real signatures) - Bridge from Clone to Open with a one-line prose link - Add a sentence to reference/_index.md so it does not render blank - Use the project's canonical "pure-Go, CGo-free" phrasing
* docs(site): add docs-gen-sdk Makefile target + commit generated SDK pages
* docs(site): pin gomarkdoc version + replace empty driver stubs with prose
- Add GOMARKDOC_VERSION Makefile variable so contributors don't drift on output format when a new gomarkdoc ships - Drop the two driver packages (modernc, ncruces) from gomarkdoc and hand-write _index.md pages explaining the register-on-import contract; the stubs were byte-stable but rendered as visibly broken documentation
* docs(site): add gen-llms-txt.sh + docs-gen-llms target
* docs(site): switch llms-full frontmatter strip from sed to awk
The sed range-negation pattern '/^---$/,/^---$/!p' silently re-opens a suppression range on any bare '---' in body content, eating Markdown horizontal rules and embedded YAML in fenced code blocks. The awk pattern strips the frontmatter only when it begins on line 1, leaving body content intact regardless of how many '---' lines it contains.
* hooks: pre-commit fails when SDK pages drift from code
* hooks: pre-commit re-installs gomarkdoc if it's the wrong version
The drift check's existing gate just looks for gomarkdoc on PATH. A contributor with an older gomarkdoc installed locally would have the gate pass and then run regeneration with their stale binary, producing either a silent false-negative or a confusing OUT-OF-DATE error with no version hint. Compare the installed version against GOMARKDOC_VERSION from Makefile and re-install on mismatch. Best-effort; offline contributors can still commit.
* docs(site): add docs-serve, docs-build, docs aggregate targets
* docs(site): make docs aggregate parallel-safe via explicit deps
The docs aggregate previously listed gen-sdk, gen-llms, and build as side-by-side prereqs. Make doesn't guarantee left-to-right ordering under -j, and gen-llms reads what gen-sdk writes, while build reads both. Encode the chain explicitly so 'make -j docs' is correct. Side benefit: 'make docs-build' standalone now produces a complete deployable site, matching contributor expectation.
* site(landing): fork dagnats home layout; rebrand chrome
* site(landing): rewrite §01–§07 content for libfossil
* site(landing): use .ascii class for diagram + fix §03 phrasing
* deploy: add wrangler.jsonc for CF Workers Static Assets
* docs: point README at the new docs site (user: [email protected], size: 8514) [annotate] [blame] [check-ins using]
title: Extension Points
weight: 40
Extension Points
libfossil exposes three surfaces for consumers that want to instrument, extend, or replace pieces of the stack:
- Observer interfaces for sync and checkout lifecycle events (
SyncObserver,CheckoutObserver). - SQLite driver registration (
db.Register) — pick the SQLite backend at link time. - The
db.DBabstraction — an opaque wrapper arounddatabase/sqlwith Fossil-specific helpers. Treat it as internal; it is less stable than the observer and driver surfaces.
Observer interfaces
Observers are the supported way to attach telemetry, logging, or metrics to a Repo without forking or wrapping the public API. Both interfaces are defined in the root github.com/danmestas/libfossil package and are context-free by design so that they can be reused across synchronous and asynchronous callers.
SyncObserver
Source: observer.go.
type SyncObserver interface {
Started(info SessionStart)
RoundStarted(round int)
RoundCompleted(round int, stats RoundStats)
Completed(info SessionEnd)
Error(err error)
HandleStarted(info HandleStart)
HandleCompleted(info HandleEnd)
TableSyncStarted(info TableSyncStart)
TableSyncCompleted(info TableSyncEnd)
}
| Method | Fires when |
|---|---|
Started |
A client-side sync or clone session begins, before any rounds run. |
RoundStarted |
A new sync round starts (there are typically multiple rounds per session). |
RoundCompleted |
A sync round finishes — RoundStats carries per-round totals. |
Completed |
The sync/clone session ends successfully. |
Error |
The sync machinery reports a per-error event (protocol or transport). |
HandleStarted |
Server-side: an inbound sync/clone HTTP request is accepted. |
HandleCompleted |
Server-side: an inbound sync/clone request finishes. |
TableSyncStarted |
An extension table sync (for example peer_registry) is about to run. |
TableSyncCompleted |
An extension table sync finishes. |
Libfossil ships NopSyncObserver() and StdoutSyncObserver() as drop-in implementations.
CheckoutObserver
Source: observer.go.
type CheckoutObserver interface {
ExtractStarted(info ExtractStart)
ExtractFileCompleted(name string, change UpdateChange)
ExtractCompleted(info ExtractEnd)
ScanStarted(dir string)
ScanCompleted(info ScanEnd)
CommitStarted(info CommitStart)
CommitCompleted(info CommitEnd)
Error(err error)
}
| Method | Fires when |
|---|---|
ExtractStarted |
An extract or update begins writing files from a checkin into the working tree. |
ExtractFileCompleted |
One file has been written — change is ChangeAdded, ChangeModified, or ChangeDeleted. |
ExtractCompleted |
The extract/update finishes. |
ScanStarted |
A working-tree scan (status/change detection) begins for dir. |
ScanCompleted |
The working-tree scan finishes. |
CommitStarted |
A checkin commit begins after staging. |
CommitCompleted |
The commit lands — info.UUID and info.RID identify the new checkin. |
Error |
A per-error event fires from the checkout pipeline. |
Minimal logging observer
package main
import (
"log"
libfossil "github.com/danmestas/libfossil"
)
type logSync struct{ libfossil.SyncObserver } // embed nop for defaults
func (logSync) Started(info libfossil.SessionStart) {
log.Printf("sync start project=%s push=%v pull=%v", info.ProjectCode, info.Push, info.Pull)
}
func (logSync) RoundCompleted(round int, s libfossil.RoundStats) {
log.Printf("round %d sent=%d recv=%d", round, s.FilesSent, s.FilesRecvd)
}
func newLogSyncObserver() libfossil.SyncObserver {
return logSync{SyncObserver: libfossil.NopSyncObserver()}
}
The embedded NopSyncObserver() provides no-op implementations of the methods you do not override, so you only need to define the events you care about. The same pattern applies to CheckoutObserver via NopCheckoutObserver().
For a full real-world observer that emits spans and counters, see observer/otel/otel.go. It implements both interfaces and is the reference you should copy from when wiring up your own telemetry backend.
Adding an OpenTelemetry (or other) observer
observer/otel lives in its own Go module (separate go.mod) so that the OpenTelemetry SDK dependency does not leak into consumers that do not want it. To use it, import the subpackage explicitly and hand the observer to each Repo operation that accepts one (SyncOpts.Observer, CloneOpts.Observer, HandleOpts.Observer, CheckoutCreateOpts.Observer, CheckoutOpenOpts.Observer).
import (
libfossil "github.com/danmestas/libfossil"
"github.com/danmestas/libfossil/observer/otel"
)
obs := otel.NewSyncObserver() // implements libfossil.SyncObserver
_, err := repo.Sync(ctx, transport, libfossil.SyncOpts{
Pull: true,
Observer: obs,
})
otel.NewCheckoutObserver() returns the matching CheckoutObserver. Any third-party telemetry library (Prometheus, Datadog, zap, etc.) should be vendored the same way: a sibling module that imports libfossil and implements the observer interfaces.
SQLite driver interface
Source: db/register.go, db/db.go, db/doc.go.
libfossil never imports a SQLite driver directly. Instead, the db package exposes a single registration hook that a driver package calls from its init():
// db/register.go
type DriverConfig struct {
Name string
BuildDSN func(path string, pragmas map[string]string) string
}
func Register(cfg DriverConfig)
Each db.Open(path) / db.OpenWith(path, cfg) call routes through the currently registered driver. Exactly one driver may be registered per process — Register panics if called twice, if Name is empty, or if BuildDSN is nil. Likewise, calling Open with no driver registered panics with a message pointing at the driver import paths.
The driver contract is intentionally small:
Name: the name passed tosql.Open. The driver package is responsible for registering this name withdatabase/sql(typically via a blank import of the underlying SQLite library).BuildDSN(path, pragmas): return a DSN string that openspathand applies the given pragmas. libfossil callsdb.DefaultPragmas()and merges any caller overrides before handing them toBuildDSN.
Built-in drivers
| Driver | Import | When to use |
|---|---|---|
modernc |
_ "github.com/danmestas/libfossil/db/driver/modernc" |
Default. Pure Go, no cgo, works on every GOOS/GOARCH libfossil supports. |
ncruces |
_ "github.com/danmestas/libfossil/db/driver/ncruces" |
Uses github.com/ncruces/go-sqlite3 (WASM-based SQLite). Pick this for WASM builds or environments where you need the ncruces feature set. |
Registering a custom driver
Use this pattern when you want to wrap an instrumented SQLite build, redirect to a network-attached SQLite, or inject additional pragmas. Model the package after db/driver/modernc/modernc.go:
package mydriver
import (
"fmt"
"strings"
"github.com/danmestas/libfossil/db"
_ "example.com/my/sqlite" // registers "mysqlite" with database/sql
)
func init() {
db.Register(db.DriverConfig{
Name: "mysqlite",
BuildDSN: buildDSN,
})
}
func buildDSN(path string, pragmas map[string]string) string {
var parts []string
for k, v := range pragmas {
parts = append(parts, fmt.Sprintf("_pragma=%s(%s)", k, v))
}
if len(parts) == 0 {
return path
}
return fmt.Sprintf("file:%s?%s", path, strings.Join(parts, "&"))
}
Consumers then blank-import your package (_ "example.com/mydriver") exactly like they would for modernc or ncruces.
The DB abstraction
github.com/danmestas/libfossil/db wraps *sql.DB with Fossil-aware helpers: DSN construction, default-pragma setup, WAL/nolock handling for WASM, transaction scoping via DB.WithTx, and the Querier interface (satisfied by both DB and Tx) so repository code can be written transaction-agnostic. The exported surface is stable for reading — SqlDB(), Path(), Driver(), Exec/Query* — but the struct itself is treated as internal: the public Repo API is the intended extension point. Prefer writing a custom driver (above) over implementing DB yourself. See db/db.go, db/config.go, and db/scan.go for the source of truth.