monopam #
Monorepo manager for OCaml.
Working across forty OCaml libraries usually means forty clones, forty pins and
a build that only sees one of them at a time. (An opam pin tells the package
manager to build a package from a local directory or a git URL instead of its
released version, so every library under development needs one pin in every
project that uses it.) monopam keeps them all in one directory instead. Each
subdirectory is a git subtree that mirrors an external repository: the
other repository's files are copied into the subdirectory and its history is
merged into this one. A submodule, by contrast, records only a pointer to a
commit elsewhere, so a clone needs a second fetch; a clone of a monorepo of
subtrees already holds every file. Dune builds the whole tree as a single
project. The subtrees are synchronised with their repositories only when you
ask, with monopam pull and monopam push.
Each subtree has a source, where pull reads from, and an origin, where
push writes to. The source can be any git repository and defaults to your own
monorepo remote; the origin is always your own remote. Since push only writes
to repositories you own, it cannot push to someone else's project by accident,
and a per-subtree source is how you track an upstream you do not own.
Installation #
Install with opam:
$ opam install monopam
If opam cannot find the package, it has probably not reached the public
opam-repository yet. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install monopam
Quick start #
$ # Initialize a workspace
$ monopam init --handle yourname.bsky.social
$ # Add packages (pulls from upstream, pushes to your monorepo)
$ monopam add https://github.com/mirage/eio.git
$ monopam add crowbar # resolve from opam
$ # Pull upstream changes
$ monopam pull
$ # Make changes, build, test, commit
$ dune build && dune test
$ git add lib/foo.ml && git commit -m "Add feature"
$ # Push to your monorepo remote
$ monopam push
The handle given to init is your AT Protocol identity (the naming system
behind Bluesky and Tangled), and it names you to other developers; see
Collaboration.
monopam clone URL does the same for a workspace someone else has already set
up. Pull and push are the only two commands that synchronise, and there is no
sync command combining them, since running both at once hides which state
the tree is in. The usual order is to pull, build and test, and push last.
monopam diff shows what a push would send, and monopam diff --incoming what
a pull would bring in.
Commands #
| Command | Description |
|---|---|
monopam init |
Initialise or refresh a workspace |
monopam clone <url> |
Clone an existing workspace and bootstrap its subtrees |
monopam add <source> [name] |
Add a subtree |
monopam remove <name> |
Remove a subtree |
monopam pull [names...] |
Fetch and merge changes from each source |
monopam push [names...] |
Push changes to your monorepo remote |
monopam fetch [name] |
Fetch changes without merging |
monopam status |
Show which subtrees are out of sync |
monopam diff [names...] |
Show outgoing (or, with --incoming, incoming) changes |
monopam inbox |
List the issues and pull requests others open on the packages' repositories |
monopam publish [names...] |
Publish opam files to an opam repository overlay |
monopam build-export [names...] |
Build each package as opam installs it from its exported repository |
monopam clean |
Remove empty commits from the monorepo and checkout histories |
monopam test [names...] |
Run the tests of each subtree |
monopam lint [names...] |
Check the root files, each subtree's source and UPSTREAM.md, its pins and the overlay |
monopam root <file> |
Print a root file (README.md, llms.txt, dune-project, CLAUDE.md) as the monorepo derives it |
monopam quality [name] |
Check packages against the quality policy |
monopam verse ... |
Work with the monorepos of other developers |
monopam <cmd> --help documents each command's flags.
The <source> argument to add is a URL
(https://github.com/mirage/eio.git), a URL pinned to a ref
(...eio.git#v0.15), or an opam package name (crowbar, resolved through its
dev-repo field). Without a ref, add follows the remote's default branch.
The sources registry #
sources.toml at the root of the monorepo holds origin, your monorepo's git
remote, and it is the only place push writes to. The file also marks the
directory as a monopam monorepo. Each subtree entry is a file of its own
under sources/, named after the subtree directory plus .toml, and its keys
override where pull reads from. A subtree with no entry pulls from origin,
so your own projects need no entry at all. Two changes that each add a subtree
write two different files.
# sources.toml: your monorepo remote, where push always goes
origin = "git@github.com:me/mono.git"
# sources/eio.toml: a subtree that pulls from upstream
source = "https://github.com/mirage/eio.git"
# sources/cohttp.toml
source = "https://github.com/mirage/cohttp.git"
branch = "main"
Overlay packages #
monopam publish writes the opam overlay from the monorepo: each subtree's
package as packages/<name>/<name>.dev/opam, and each pin of a root opam file
at its commit. A full publish removes every entry it did not write.
A package the tree does not build, such as a C library built from its release
tarball, is held in the monorepo at the path it takes in the overlay,
overlay/packages/<name>/<name>.<version>/opam, and publish copies it byte for
byte. It names a released version, never dev, and each url and
extra-source section it has carries a checksum, so the overlay serves the
archive the file names and nothing else:
extra-source "zstd-1.5.7.tar.gz" {
src: "https://github.com/facebook/zstd/releases/download/v1.5.7/zstd-1.5.7.tar.gz"
checksum: "sha256=eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3"
}
An entry without them stops the publish before anything is written, with the
file and what it lacks.
The root README #
monopam lint --fix writes the monorepo's README.md and llms.txt, and
monopam lint reports either one that is out of date. monopam root FILE
prints what one of them derives to and writes nothing, so a build rule or a
merge queue's generator can produce them in any copy of the tree and two
changes that each add a package regenerate the lists rather than merge them.
Three inputs shape them.
README.md.templateis the part a person writes: the title, what the
monorepo is, how to build it and how to contribute. The README is this file
followed by the package index.llms.txttakes its title from the
template's title and its summary from the first paragraph under it. Without
a template both files open on a generic title.- Each package's opam file gives its row: the
synopsis, and intagsan
area:IDand adomain:IDwhen the monorepo has anareas.json. That
file lists each node with itsid, itsaxis(capabilityforarea:,
domainfordomain:), itslabeland thepathof ids from its top
concept. The index then has one section per top concept, its rows ordered
by area, and a list of the packages of each domain. Without an
areas.jsonthe index is one table. - The sources registry gives each repository's link, and a table of
upstreams for the subtrees whose entry names one.
Nested monorepos #
A monorepo is itself a git repository, so it can be a subtree of another
monorepo. monopam recognises such a subtree by the sources.toml at its root,
and push and pull recurse into it, processing its own sources registry
first. The commands and the file format are the same at every level; only the working
directory changes.
Changes move one layer at a time. A pull brings upstream eio into an open
monorepo and the open monorepo into a product; a push goes the other way, from
the product to the open monorepo and on to your fork of eio, from which you
open a pull request upstream. One monopam push from the outermost directory
carries a change all the way out.
This is how open-source and closed-source code stay apart while building
together: each layer is a separate git repository with its own access control,
and dune still sees every directory. Each layer can carry its own opam overlay,
generated by monopam publish, so the closed layer's private overlay can use
the open layer's public one as its base.
How push, pull and lint behave #
- The per-subtree checkouts under
src/are a derived cache and the
monorepo is authoritative.pullandpushreconcile a checkout that has
diverged by resetting it (reset --hard, then removing untracked files),
so a checkout never holds work and deleting one only means it is cloned
again. - A split keeps only the commits that change the subtree. Split commits
depend on author and timestamp, so two monorepos produce different splits
of the same work; the upstream accepts either as a fast-forward, and
conflicts are resolved in the monorepo, by pulling, before pushing. - A package's published branch has one writer,
push. A merge queue that
also landed into that branch would race the nextpush, which would then
be refused as not a fast-forward, or with--forcewould leave the
queue's commit on no branch. A contributor to one package runs their queue
(mq, say) on their own clone and offers the branch it landed; the monorepo
takes it withpull, lands the change through the monorepo's own queue,
then publishes it withpush. The order is pull, land, push. pushforce-updates a checkout's branch only when the checkout's tip tree
appears in the split chain, so the split is a superset of it, and refuses
when the checkout holds content the split does not.--forceapplies to
the push to the remote, never to the checkout.push --localexports to the checkouts and pushes to no remote, so those
subtrees stay ahead of their remotes and are exported again on every run.- While
pushandpullrun, each repository a step moves has a row of
its own under the step's row, with its latest lines: the remote and its
URL, the ref it updates and how, the objects it counts, the lines the
remote writes and the pre-push hook it runs, and on the row the bytes it
sends or receives with their rate. A repository that succeeds leaves
nothing behind; one that fails keeps its row, with its lines under it. lintchecks what monopam owns: the generated root files, each
subtree's(source ...)against its entry undersources/and its
UPSTREAM.md,
pins, and with--overlaythe published entries. Whether an opam file
declares what its package's dune stanzas use, runtime and{with-test},
in both directions, is merlint's (E941, E943, E961, E962), as are dead
library dependencies (E956) and the%{dune-warnings}flag (E940).
lintbuilds nothing: the subtrees and the opam anddune-project
files it reads are the ones git's index lists, so a file git does not
track is not linted. It prints one finding per line,
SUBTREE: KIND DETAIL.- A package records a
pin-depends:entry only for its direct runtime
dependencies that the switch pins, never for transitive ones.lint
reports each missing entry asmissing-pin.lint --fixregenerates
the root files only, never a package's pins. build-exportbuilds a package asopam installdoes from the
repositorypushexports: the subtree alone as the dune root, with
dune build -p PACKAGE, and only its runtime and{build}
dependencies installed. The source packages it depends on build in the
monorepo anddune installinto_build/export/PACKAGE/prefix, which
the package's build finds onOCAMLPATH; a package from outside the
monorepo comes from the switch, which also holds the test libraries, so
a missing external dependency is merlint's E941 to find. It catches a
dependency on another subtree the opam file omits, a file outside the
subtree, and a rule dune loads at install that needs a test library.
--changed-since REVadds each package whose subtree differs from REV.
Collaboration #
A collaborator's monorepo is one more source to pull from. A registry is a git
repository whose opamverse.toml file lists the members of a community: each
member's handle, the git URL of their monorepo and the URL of their opam
overlay. monopam clones the registry into its data directory
(~/.local/share/monopam/opamverse-registry by default), and the verse
commands read that list to clone each member's monorepo under verse/<handle>/
and compare its subtrees with yours:
$ monopam verse diff # see what collaborators have
$ monopam verse pull alice.bsky.social # pull their changes
$ monopam verse cherry-pick <sha> # take one commit
$ monopam verse members # list members
Others also open issues and pull requests on the repository each package is
published to. For a repository on tangled.org, monopam inbox reads the open
ones from tangled's appview (api.tangled.org, which answers without a
session) and lists those opened by anyone but the repository's owner; it
writes nothing to tangled. With --file, each one not yet in the monorepo's
tracker is filed with tk operator finding, keyed by its AT-URI and labelled
triage:required. The tracker files a key once, so a second run files nothing
again, whether the row the first run filed is open or closed:
$ monopam inbox --file
inbox: 334 repositories on tangled, 334 read, 2 open from others
ocaml-wal pull Fix off-by-one in WAL block boundary check
https://tangled.org/gazagnaire.org/ocaml-wal/pulls/12
...
tracker: 1 already filed, 1 to file
Licence #
ISC