sourcerer
AGENTS.md19 starsChanged 4 months agoApache-2.0View on GitHub
- sourcerer setup [--config <file>] [--include-experimental] [CATEGORIES...] (reads the config's hosts: to generate per-host citation skills; without --config, uses only the built-in host defaults). Valid categories: all (default), agents, skills, tools, templates, dashboards, workflows. Experimental resources live under elastic/*/experimental/ and are excluded by default; pass --include-experimental to include them. - sourcerer index <org>/<repo> [-b <branch>] [-t <tag>] [-c <commit>] (single-repo path defaults to git.host = github) - sourcerer index --config <file> [--prune] [--dry-run] [--no-backfill] - sourcerer prune [--config <file>] [--dry-run]…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 35
All commands that communicate with Elasticsearch or Kibana accept --insecure (flag, default off).
- Distinctive: line 183
All values are inclusive.
- Very specific: line 289
In-progress guard: if a ref in scope has status: indexing with indexing_started_at newer than 6 hours ago, the whole source is skipped.
- Very specific: line 292
Two-phase marker: before content ingest, a ref doc is written with status: indexing and indexing_started_at.
- Very specific: line 298
--dry-run: when schedules are configured, --dry-run prints a schedule gate report (which sources are due / not-due / in-progress and why) … - Distinctive: line 318
Garbage collection: after each fetch, a best-effort git gc expires reflogs and prunes objects that are no longer reachable - chiefly blobs …
- Very specific: line 324
Every git invocation goes through _run_git in src/sourcerer/commands/index/git.py, which runs git under GIT_TERMINAL_PROMPT=0, an empty …
- Distinctive: line 373
Stderr only: all diagnostics (errors, startup messages) go to stderr.
- Very specific: line 454
Every Agent Builder content tool (sourcerer.code.*, sourcerer.files.*) uses the same shape that handles both modes without fan-out:
- Very specific: line 516
Every sourcerer-v3-refs document — snapshot ref-name markers and incremental join docs alike — carries a status field drawn from a …
- Very specific: line 554
Always pin dependencies to an exact version (pkg==X.Y.Z) in pyproject.toml — for both runtime and dev dependencies.
- Very specific: line 558
When bumping a dependency, set the pin to the version uv lock resolves and re-run the tests.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Sourcerer
CLI
Commands:
sourcerer setup [--config <file>] [--include-experimental] [CATEGORIES...](reads the config'shosts:to generate per-host citation skills; without--config, uses only the built-in host defaults). Valid categories:all(default),agents,skills,tools,templates,dashboards,workflows. Experimental resources live underelastic/*/experimental/and are excluded by default; pass--include-experimentalto include them.sourcerer index <org>/<repo> [-b <branch>] [-t <tag>] [-c <commit>](single-repo path defaults togit.host=github)sourcerer index --config <file> [--prune] [--dry-run] [--no-backfill]sourcerer prune [--config <file>] [--dry-run] [--wait] [--host <h> [--org <o> [--repo <r>]]](config-driven retention prune is skipped without--config; the orphan sweep always runs.--host/--org/--reponarrow the orphan sweep to one host/org/repo instead of the whole cluster ----orgrequires--host,--reporequires--org.--waitblocks until every submitted async content deletion actually completes instead of just reporting what was submitted; see "Prune completion semantics" below.)sourcerer mcp-proxy [-e <env>](run a stdio MCP proxy that forwards to the Kibana Agent Builder MCP endpoint; intended to be launched by Claude Desktop viamcpServers)sourcerer help
sourcerer --version (a top-level flag, not a subcommand) prints the installed version.
sourcerer index accepts --git-timeout <duration> (default 30m, also settable via
SOURCERER_GIT_TIMEOUT): the maximum wall-clock time for a single git command (clone, fetch,
ls-remote, checkout, ...) before it is killed and the repo reported as a failure. 0 disables it.
ls-remote is additionally capped at 2 minutes, since ref listing is never legitimately slower
than that and it runs during planning, ahead of every repo's indexing. See "Non-interactive git"
under the clone cache below for the related access-denied behaviour.
All commands that communicate with Elasticsearch or Kibana accept --insecure (flag, default
off). When set, TLS certificate verification is disabled — useful for locally-hosted clusters
with self-signed certificates that are trusted in your environment. Also configurable via the
ALLOW_INSECURE_TLS environment variable (set to 1 or true); the env var is read by all
commands including mcp-proxy when launched by Claude Desktop via its env block.
The --config file is sourcerer.yml (see specs/sourcerer-yml.md and sourcerer.example.yml
for the authoritative schema). Two optional top-level sections: hosts: (override/extend the
built-in git-host defaults) and sources: (what to index).
Multi-host support (git.host)
Content is namespaced by git host as well as org/repo. Each sources[i].git block names a single
concrete host, org, repo, and ref_type (no wildcards or arrays). Known hosts have built-in
clone + citation URL templates in src/sourcerer/hosts.py; hosts: in the config overrides or
adds hosts. For providers whose deployments are instance-scoped (AWS CodeCommit, Azure DevOps, GCP
Secure Source Manager), define one hosts: entry per deployment with the region/project/instance
baked into the URL templates; git.org then holds only the plain org or project name.
Indexing multiple repos with a config
sourcerer index --config sourcerer.yml indexes many repos, branches, and tags in one run. The
config's sources: is a YAML list, one entry per (host, org, repo, ref_type). See
sourcerer.example.yml.
Source fields (per sources[i] entry)
| Field | Required | Description |
git.host | yes | Host id (a git.host value); a built-in or a hosts:-defined id |
git.org | yes | Org name (may include a +extra segment for some providers) |
git.repo | yes | Repo name |
git.ref_type | yes | branch, tag, or commit |
match | yes | For branch/tag: pattern string or list of patterns matched against ref names (version DSL + glob), a ref matches if any pattern hits. For commit: a commit SHA/prefix string or list of them (see below). |
since | no | Index-side inclusion floor: the earliest commit to start indexing from. See below. Not valid for git.ref_type: commit. |
retain | no | Retention policy (see below). Omit to keep forever. For git.ref_type: commit, only age is valid. |
mode | no | snapshot (default) or delta (branch or tag). See below. |
mode (snapshot vs. delta)
snapshot (default): content is commit-addressed. A HEAD advance on a branch
indexes a whole new snapshot under the new commit.
delta (branch or tag; rejects since/retain -- there is no per-commit history for either
to apply to): content is ref-addressed instead. A HEAD advance runs git diff
--name-status between the previously-completed commit and the new tip and only deletes/
reindexes the paths git reports changed -- add/modify/delete -- instead of
reindexing the whole tree. Rename and copy detection are disabled (--no-renames): they score
candidates by content, which on a blobless clone stalls the diff on a promisor fetch of every
candidate blob, and they change nothing about the resulting plan (a rename is equivalent to the
delete + add it degrades to). A missing diff base (force-push, GC'd, or the first index) rebuilds
the whole ref namespace. The refs join doc publishes status: indexing before any content
change and status: complete (with the new commit) only after the deletes/indexes/refresh all
succeed, so a crash mid-update leaves the prior commit and content in place.
Delta mode is especially useful for fast-moving tags that are force-updated many times a day
(e.g. deploy@8-style Serverless promotion tags): snapshot mode would mint a fresh full snapshot
per force-update; delta mode diffs only what changed, keeping indexing cost proportional to the
diff size regardless of tag-move frequency.
- git:
host: github
org: elastic
repo: serverless-gitops
ref_type: branch
match: main
mode: deltagit.ref_type: commit (pinning an explicit commit)
Pins one or more commits directly, rather than matching named refs. match entries are
7-40 hex chars - a full 40-char SHA, or a shorter prefix (git's own "short hash" convention;
a git.commit lookup uses a prefix match against the resolved full SHA). There's nothing to
index "from" for a single pinned point, so since is rejected; likewise retain.count,
retain.version, and retain.prerelease have no meaning for one commit and are rejected --
only retain.age (or omitting retain to keep forever) is allowed. A pinned commit must be
reachable from some fetched branch or tag (the clone only contains commits reachable that
way) -- one that's been force-pushed away or only exists on an unfetched ref will fail to
check out, reported as a per-unit error.
- git:
host: github
org: elastic
repo: elasticsearch
ref_type: commit
match:
- cfefb3b # short prefix (>= 7 hex chars) or a full 40-char SHA
retain:
age: 2y # only 'age' is valid for commit sources (or omit = keep forever)since (inclusion floor)
Sets where indexing starts. Provide exactly one of:
| Field | Description |
age | Commit within this age of now (e.g. 1y). Starting point is the oldest matching commit. |
date | Commit on/after this YYYY-MM-DD date. |
commit | Start from this commit hash. |
ref | Start from the commit this tag/branch points to (accepts the full ref name or a bare version). |
Behavior by ref_type:
ref_type: tag—sinceis a filter on which tags are selected: only tags whose commit date is on or after the floor are indexed. Each matching tag is still one indexed snapshot.ref_type: branch—sincecauses the branch's commit history to be walked back to the floor. Every commit on the first-parent mainline from the branch tip back to (and including) the oldest commit whose committer date is >= the floor is indexed as its own snapshot (one set of content docs + one refs marker per commit). This turns a single branch into N indexed commits.Important: pair a branch
sincewithretain.countorretain.ageto bound how many historical commits are actually indexed. Without a date/countretain, every commit the floor selects is indexed. The retention pre-filter trims retention-doomed commits before ingest — soretain.count: 5withsince.age: 1yindexes only the 5 newest commits on the branch, not all commits in the past year.The history walk uses
--first-parentsemantics: only the branch's own mainline commits are enumerated; merged feature-branch commits appear only as the merge commit on the mainline, not as individual snapshots. This matches the intuitive "history of main."
Pattern syntax
Patterns combine a version DSL with glob syntax:
- Version placeholders:
{major},{minor},{patch},{build}(numeric) plus{prerelease}- each numeric placeholder matches one numeric segment, enabling the version-awaresincefloor and theretain.versionpolicy. Example:"v{major}.{minor}.{patch}"matchesv8.14.3; add"v{major}.{minor}.{patch}-{prerelease}"to also matchv9.0.0-rc1. - Glob outside placeholders:
*(any chars),?(any one char),[seq](character class). Example:"v[89].*"matches v8.x and v9.x refs without version-aware semantics. - Multiple patterns: pass a list of strings; a ref matches if any pattern matches.
Example:
match: [ "my-dev-tag", "v{major}.{minor}.{patch}" ]
A retain.version policy requires versioned patterns (containing numeric {…} placeholders),
and all versioned patterns in one selector must agree on their level set. Plain glob patterns
("*", "v[89].*") carry no version levels and cannot drive version-based retention.
Retention (retain block)
Omitting retain keeps every matched ref forever. A retain block trims the matched set:
a marker survives only if it satisfies every criterion present (intersection). Across
multiple selectors for the same repo, keeps are unioned - a marker is kept if any selector
keeps it (so a bare "keep forever" selector acts as an allowlist alongside a trimming rule).
All values are inclusive.
| Field | Applies to | Description |
age | any | Keep commits within this age; prune older. Duration <n><unit> (see below). |
count | any | Keep the newest N commits by commit date (per branch name for branches; pooled across the family for tags). |
version | versioned tags | Value-relative per-level retention (see below). |
prerelease | versioned tags | keep (default) or superseded (drop a prerelease once its final release ships). Sibling of version. |
version (value-relative)
Each field keeps the newest N values at that level within its parent group - a threshold
of latest − (N − 1), not a count of existing refs. Omit a field (or set null) for no
constraint at that level.
| Field | Description | |
majors | Newest N major values. majors: 2 keeps the latest major and the one behind it (n-1 EOL). | |
minors | Newest N minor values per (major). | |
patches | Newest N patch values per (major, minor). patches: 1 = newest patch per minor. | |
builds | Newest N build values per (major, minor, patch). | |
prereleases | Newest N prerelease tags per final-version group (by commit date). E.g. prereleases: 2 keeps the 2 most-recently committed prereleases for each (major,minor,patch[,build]) tuple. Finals are never dropped. Unlike the numeric levels, ordering is by commit date (not by value), so it is date-dependent and applied post-clone (not in the index-time pre-filter). Requires {prerelease} in at least one match pattern. Independent of `retain.prerelease: keep | superseded` — both may be set and intersect as normal. |
Because it is value- not count-based, with majors {2, 9} indexed, majors: 2 keeps {9}
(threshold 8), not {9, 2}.
Duration format (for age/since.age): <n><unit> where unit is s (seconds), m (minutes),
h (hours), d (days), w (weeks), M (30-day month), y (365-day year).
Example
sources:
- git:
host: github
org: elastic
repo: docs-content
ref_type: branch
match: main
retain:
count: 1 # head-only: keep the newest indexed commit
- git:
host: github
org: elastic
repo: elasticsearch
ref_type: tag
match:
- v{major}.{minor}.{patch}
- v{major}.{minor}.{patch}-{prerelease}
since:
ref: v8.17.0 # start indexing from this release
retain:
version:
majors: 2 # keep the latest major + one behind (n-1)
patches: 1 # newest patch per (major, minor)
prerelease: superseded # drop -rc once its final ships
- git:
host: github
org: elastic
repo: elasticsearch
ref_type: branch
match: main
retain:
count: 5 # newest 5 indexed commits of main
- git:
host: github
org: elastic
repo: elasticsearch
ref_type: tag
match: my-dev-tag # no retain -> kept forever (allowlist)
- git:
host: github
org: elastic
repo: elasticsearch
ref_type: commit
match: cfefb3b # pin an ad-hoc commit not on any tracked branch/tag tip
retain:
age: 2y # only 'age' is valid for commit sourcesIndexing is idempotent - re-running only indexes refs that are new or have moved.
Scheduling (schedules: / sources[i].schedule)
One sourcerer.yml can declare per-source schedules, replacing the old pattern of multiple
config files each driven by their own cron job. Run sourcerer index --config on a frequent
cron (e.g. every 5 minutes) and let the schedule config control the actual indexing cadence.
How the gate works: on each invocation of index --config, before any ls-remote or clone
work, the command queries sourcerer-v3-refs to see when each source was last fully indexed
(status: complete) and whether any ref in its scope is actively being indexed (status:
indexing). Only sources whose schedule has fired since their last indexed run proceed to the
expensive pipeline. Sources where another run is actively indexing are skipped.
- Schedule syntax: a 5-field cron expression (e.g.
"0 */3 * * *"= every 3 hours) or a duration ("3h","1d"— same syntax asretain.age). - Precedence:
sources[i].schedule> most-specificschedules[i]rule > default (always due). Schedule rule scope fields (host,org,repo,ref_type,ref) support fnmatch glob wildcards;ref_typeaccepts exact values or bare*only. Specificity weights: exact = 2, glob = 1, omitted = 0, summed across all five fields — so an exact field always beats a glob field at the same level.refis matched against the source's configuredmatchpattern string(s) (not live ref names — the gate runs pre-network). - In-progress guard: if a ref in scope has
status: indexingwithindexing_started_atnewer than 6 hours ago, the whole source is skipped. After 6 hours (stuck-retry interval), the source is treated as due regardless. - Two-phase marker: before content ingest, a ref doc is written with
status: indexingandindexing_started_at. On successful completion, it is overwritten withstatus: completeandindexed_at. A killed/crashed run leaves behind anindexingmarker that the gate detects; after 6 hours it retries automatically. - No-schedule fallback: a config with no
schedulessection and nosources[i].schedulefields behaves identically to before (all sources always due — the gate is transparent). --dry-run: when schedules are configured,--dry-runprints a schedule gate report (which sources are due / not-due / in-progress and why) before the normal ref-level preview.
Clone cache
index keeps each repo cloned under a persistent cache directory and refreshes it with
git fetch on later runs, rather than re-cloning every time. A frequently-scheduled run (e.g.
every 5 minutes via the scheduling feature above) then transfers only the new commits since the
last run instead of a full clone of a large repo's history. Combined with the cheap pre-clone
skip (a repo with no moved refs isn't even fetched) and immutable-tag dedup, repeated runs stay fast.
- Blobless clone: clones use
git clone --filter=blob:none- every commit, tree, and ref is present (so any branch/tag/pinned commit stays reachable and checkoutable), but file contents are not downloaded up front. A blob is faulted in fromoriginthe first time a commit that needs it is checked out, so disk usage tracks the working set actually indexed, not the repo's full history. - Location (precedence):
--cache-dirflag →SOURCERER_CACHE_DIRenv →$XDG_CACHE_HOME/sourcerer→~/.cache/sourcerer. Clones live at<cache>/repos/<host>/<org>/<repo>. - Safe to delete: the cache is a pure derived artifact (all index state lives in Elasticsearch). Removing it just forces a fresh (blobless) clone on the next run - this is also how a cache directory populated by an older, full-clone version of sourcerer gets converted to blobless: delete it once and let the next run re-create it.
--ephemeral: skip the cache and clone into a throwaway temp dir (good for one-off or CI runs).- Concurrency: a per-repo advisory lock prevents two overlapping runs from corrupting the same clone; if a repo is already locked by another run, it is skipped for that run.
- Garbage collection: after each fetch, a best-effort
git gcexpires reflogs and prunes objects that are no longer reachable - chiefly blobs faulted in for commits that fell out of a branch's retained window since the last run. A gc failure never fails the index run.
Non-interactive git
Every git invocation goes through _run_git in src/sourcerer/commands/index/git.py, which runs
git under GIT_TERMINAL_PROMPT=0, an empty GIT_ASKPASS (which also neutralizes core.askpass
and SSH_ASKPASS), and a batch-mode GIT_SSH_COMMAND default. Credentials must therefore come
from a non-interactive source - a credential helper (osxkeychain, gh, credential-store), an ssh
key, or the clone URL - because git is never allowed to prompt. Left promptable, git would block
forever on an inherited stdin nobody answers (with the prompt itself invisible, since stdout and
stderr are captured), which is what used to make one inaccessible repo hang an entire index run
while holding that repo's cache lock.
A remote that refuses access (401/403, GitHub's 404-for-private, a rejected credential, or a
suppressed prompt) raises GitAccessDenied. That is treated as permanent: the repo is skipped
immediately with git's own message, the ls-remote retry backoff is bypassed, a denied fetch
does not trigger the wipe-and-reclone recovery (which exists for a corrupt object store), and the
run exits non-zero rather than silently omitting the repo from the plan. A command killed at
--git-timeout raises GitTimeout. Both subclass subprocess.CalledProcessError, so existing
handlers keep catching them, and their str() carries git's stderr into the per-ref error report.
Prune completion semantics
Content deletions (the retention pass's per-commit delete_by_query, and the orphan sweep's
Class B/D/D-I content and Class C marker delete_by_query calls) are submitted with
wait_for_completion=False -- they return an Elasticsearch task id, not a finished result. The
whole-index DELETEs (Class A orphaned indices, Class E empty indices) and the marker-doc bulk
delete/single delete calls (retention pass, stale-marker reclaim) are synchronous and really
are done by the time the command exits.
The completion summary reflects this: it reports "Deleted N marker(s)/index(es)" for the
synchronous work and, separately, "Submitted async deletion of N commit(s)/marker commit(s)
(K task(s))" for everything still in flight, printing the task IDs so an operator can check them
via GET _tasks/<id>. Re-running prune immediately afterward may still show the same orphans
if their deletions haven't finished yet -- this is expected, not a bug.
Pass --wait to block until every submitted task reports completed: true (polled via
es.tasks.get, progress shown through the same reporter as planning) before printing a summary
of confirmed outcomes (deleted / version_conflicts from each task's status) instead of
submission targets.
Local stdio MCP proxy (sourcerer mcp-proxy)
Runs a local stdio↔streamable-HTTP MCP proxy so Claude Desktop can reach the Agent Builder MCP
endpoint ({KIBANA_URL}/api/agent_builder/mcp) without Node or npx. Claude Desktop launches
sourcerer mcp-proxy as a subprocess and communicates over stdio; the command forwards
every request to the remote endpoint with the Authorization header injected from the
environment.
- Auth: accepts
ELASTICSEARCH_API_KEY(Authorization: ApiKey <key>) or bothELASTICSEARCH_USERNAME+ELASTICSEARCH_PASSWORD(Authorization: Basic <base64>). - Env loading:
-e/--env <file>loads a.envbefore options resolve, same as other commands. In Desktop's config, set env vars directly in theenvblock ofmcpServers. - Stderr only: all diagnostics (errors, startup messages) go to stderr; stdout carries the JSON-RPC stream. Desktop never shows stderr to the user, so errors appear in its logs.
- No TLS: stdio transport needs no TLS on the proxy side; the upstream connection is plain
HTTPS to
KIBANA_URL(system CA bundle). - Implementation: uses
fastmcp.FastMCP.as_proxy(ProxyClient(StreamableHttpTransport(...))), which handles SSE responses,Mcp-Session-Idsession management, and server→client notifications automatically.
Typical claude_desktop_config.json entry:
{
"mcpServers": {
"sourcerer": {
"command": "sourcerer",
"args": ["mcp-proxy"],
"env": {
"KIBANA_URL": "<your-kibana-url>",
"ELASTICSEARCH_API_KEY": "<your-api-key>"
}
}
}
}Requires sourcerer installed and on PATH (e.g. uv tool install sourcerer).
Index fields
Content is addressed by host + commit, not by ref name. A file's bytes are fully determined
by (git.host, git.org, git.repo, git.commit, file.path), so the same file reached via any ref
collapses to a single doc (no per-ref duplication), while the same org/repo on two different git
hosts stays distinct. git.host is a lowercase keyword, placed before git.org in every index
template's mappings and index sort. Backing indices are sourcerer-v3-refs,
sourcerer-v3-files~{git.host}~{git.org}~{git.repo}, and
sourcerer-v3-lines~{git.host}~{git.org}~{git.repo} (read via the unchanged sourcerer-refs /
sourcerer-files / sourcerer-lines aliases).
Index routing (sources[i].index.level / index.suffix). A source can override the content
index name: level (host/org/repo (default)/commit) chooses the granularity
(sourcerer-v3-*~{host} … ~{host}~{org}~{repo}~{commit}), and suffix appends ^{suffix}
(e.g. ~{host}~{org}~{repo}^deploy). Routing is per-source, so two sources of the same
(host, org, repo) may target different indices; the read aliases match sourcerer-v3-files* /
sourcerer-v3-lines*, so every leveled/suffixed index auto-joins them and agents are unaffected.
The name is built by files_index/lines_index in src/sourcerer/indices.py; each ref marker in
sourcerer-v3-refs records the source's index_level/index_suffix (semantic, not the resolved
name — so a future prefix bump stays correct). Changing a source's routing between runs triggers a
migration (sourcerer index re-ingests at the new index, flips the marker, then deletes the old
copy; sourcerer prune sweeps any crash-leftover as orphan:stale-location, and deletes any
sourcerer content index drained to zero docs as orphan:empty-index). Commit-level indexing
creates one index/shard per commit — see specs/sourcerer-yml.md for the caveat.
suffix may embed the match pattern's version variables (index.suffix: "{major}.{minor}.x"),
letting one source route each ref to a per-version sibling index instead of needing one source
per version window. Selector.resolve_index_suffix renders the template from the matched ref's
own version at unit selection (selection.py), so index_suffix is always stored and compared
as a concrete value (9.5.x) — a template and the equivalent literal suffixes are
interchangeable and swapping them migrates nothing. Variables require mode: snapshot, a
non-commit ref_type, and every match pattern to capture every variable used; violations are
config-parse errors.
- Tags are not stored on content docs. Each tag is one tiny doc in
sourcerer-refsmapping the tag to its commit. To search a tagged release, resolve it to a commit via the refs index (thesourcerer.refs.listtool), then filter content bygit.host+git.commit. - Branches are not stored on content docs (a branch moves; keeping it there would
force expensive rewrites of the lines index on every move). Each branch is one tiny doc
in
sourcerer-refsmapping the branch to its current commit. To search a branch, resolve it to a commit via the refs index (thesourcerer.refs.listtool), then filter content bygit.host+git.commit.
Universal join query
Content docs come in two disjoint shapes depending on how they were indexed:
- Snapshot (
mode: snapshot): content docs carrygit.commitand nogit.ref. The ref-name marker insourcerer-v3-refs(keyed bybuild_ref_id, one per snapshot source) carries the commit and status.git.commiton the content row is already the answer; no join is needed to resolve it. - Delta (
mode: delta): content docs carrygit.refand nogit.commit. A dedicated refs join doc at_id = build_ref_key(host,org,repo,ref)(one per branch) holds the live HEAD commit and is advanced two-phase. The join resolvesgit.commitfrom this doc.
Every Agent Builder content tool (sourcerer.code.*, sourcerer.files.*) uses
the same shape that handles both modes without fan-out:
FROM sourcerer-lines
| WHERE git.host LIKE ?git_host AND ...
AND (
// Resolve git_commit, git_ref, and git_ref_type against the small sourcerer-refs
// index first (content docs carry no git.ref_type); the two membership sets handle
// both content-doc shapes in one pass.
(git.commit IS NOT NULL AND git.commit IN (
FROM sourcerer-refs
| WHERE git.host LIKE ?git_host AND ...
AND git.commit LIKE ?git_commit
AND git.ref LIKE ?git_ref
AND git.ref_type LIKE ?git_ref_type
| KEEP git.commit
))
OR
(git.ref IS NOT NULL AND git.commit IS NULL AND git.ref IN (
FROM sourcerer-refs
| WHERE git.host LIKE ?git_host AND ...
AND git.commit LIKE ?git_commit
AND git.ref LIKE ?git_ref
AND git.ref_type LIKE ?git_ref_type
| KEEP git.ref
))
)
// Branch by content-doc shape to resolve git.commit for incremental refs:
// Snapshot rows already carry git.commit (no join needed).
// Incremental rows carry only git.ref; the join resolves git.commit from the refs join doc.
// Safety of the incremental join (one doc per (host,org,repo,ref)) is enforced by
// the "one mode owns a ref name" invariant at index time.
| FORK
( WHERE git.commit IS NOT NULL )
( WHERE git.ref IS NOT NULL AND git.commit IS NULL
| LOOKUP JOIN sourcerer-refs ON git.host, git.org, git.repo, git.ref )Snapshot rows carry git.commit directly; they are matched by the first IN subquery and pass
through the FORK unchanged. Critically, the snapshot arm never touches sourcerer-refs at query
time, so two complete markers sharing the same commit (branch + same-named tag) do NOT fan out —
the commit set is resolved once and deduplicated naturally.
Incremental rows carry git.ref but no git.commit; they are matched by the second IN
subquery and then joined in the FORK incremental arm. The LOOKUP JOIN resolves git.commit from the
refs join doc so incremental rows carry a citable commit SHA in the output. The join is safe
(no fan-out) because there is always exactly one incremental join doc per (host,org,repo,ref):
_id = build_ref_key(...) (overwrite-in-place) and the runtime mode-conflict guard in
selection.py prevent multiple concurrent join docs for the same ref.
Scoping params (git_commit, git_ref, git_ref_type) are all optional (default "*") and
support */? wildcards (filters use LIKE). For a normal content question, resolve a ref first
(see src/sourcerer/skills/ref-resolution/SKILL.md), then pass the result through the appropriate
param: a commit SHA goes to git_commit; a branch or tag name goes to git_ref (optionally narrow
further with git_ref_type: branch or git_ref_type: tag). Leaving all three at "*" matches
content across all refs at once; because every content tool carries git.commit through to output
(and aggregations group BY git.commit), unpinned results stay attributable per commit rather than
being blended — but a version-specific answer should still pin a ref.
status field values
Every sourcerer-v3-refs document — snapshot ref-name markers and incremental join docs alike
— carries a status field drawn from a three-value vocabulary:
| Value | Meaning |
indexing | A run is mid-flight. indexing_started_at is set; indexed_at is absent/null. Present on snapshot ref-name markers (written by write_indexing_marker just before ingest) and incremental join docs (written by write_incremental_indexing). A stale indexing doc whose indexing_started_at is older than the retry window (default 6 h) marks a crashed run and is treated as due for re-indexing. |
complete | Fully indexed and ready to query. indexed_at is set; indexing_started_at is absent/null (the terminal write drops it). Written by write_ref_marker (snapshot markers) and write_incremental_ready (incremental join docs). The scheduler's "last indexed" aggregation and sourcerer.refs.list's default ?status == "complete" filter both use this value. |
stale | A snapshot marker superseded by a mode switch to delta. Written by mark_snapshot_markers_stale (called BEFORE the incremental join doc is published as complete). The prune command reclaims their content and deletes the marker via execute_stale_marker_deletions. |
Uniqueness gate
_run_uniqueness_gate (commands/index/command.py) runs after each index pass and calls
check_join_uniqueness (queries.py) to verify:
- Snapshot (git.commit IS NOT NULL in content): each distinct commit must have ≥1 complete refs doc (presence check — multi-ref-per-commit is legal).
- Delta (git.ref IS NOT NULL in content): each distinct ref must have exactly one
incremental join doc with
mode == "delta"(anti-fan-out guard for the surviving join).
The gate is non-fatal (logs a warning, does not block): with the flip-status switchover in place, violations should only occur if a stale-flip was skipped or crashed mid-way; the next prune run reclaims the stale marker and resolves the violation automatically.
Releases
pyproject.toml is the source of truth for the project version. Release version changes
must be made with ./scripts/release.sh prepare vMAJOR.MINOR.PATCH, which bumps
pyproject.toml, uv.lock, .claude-plugin/marketplace.json, and README.md together
and commits the result. Review and merge that commit to main before publishing.
Publish releases only by running ./scripts/release.sh publish vMAJOR.MINOR.PATCH from an
up-to-date main. Do not create or push release tags manually, modify an existing release
tag, or bypass the script's lockfile, test, build, branch, version, or remote-tag checks.
Pushing a valid tag triggers .github/workflows/release.yml, which repeats the quality
checks and creates the GitHub release.
Dependencies
Always pin dependencies to an exact version (pkg==X.Y.Z) in pyproject.toml — for both
runtime and dev dependencies. Do not use range constraints (>=, ~=, ^). Exact pins make
builds reproducible and let Dependabot recognize a fixed version directly from pyproject.toml
(a >= lower bound leaves the alert open even after the lockfile resolves to a safe version).
When bumping a dependency, set the pin to the version uv lock resolves and re-run the tests.
Upgrading from v1 to v2
v2.0.0 adds a git.host dimension so the same org/repo can be indexed and cited across
different git hosting providers. This is a breaking change:
- Config:
repos.ymlbecomessourcerer.ymlwith a new schema. The old flat list of{org, repo, refs: [{type, ...}]}entries becomes asources:list where each entry names a singlegit: { host, org, repo, ref_type }plus top-levelmatch/since/retain. See the Quickstart above andsourcerer.example.yml. - Indices: backing indices are renamed
sourcerer-v1-*tosourcerer-v2-*and content is keyed by(git.host, git.org, git.repo, git.commit, file.path). There is no automatic migration - runsourcerer setupto create the v2 templates, then re-index. The oldsourcerer-v1-*indices can be deleted once you have re-indexed. - Citations:
sourcerer setup --config sourcerer.ymlreads the config'shosts:section and generates one citation skill per host so the agent formats links correctly for each provider. Runsetupagain whenever you add or customize a host.
Upgrading from v2 to v3
v3.0.0 adds incremental (ref-addressed) branch indexing (update: incremental, see above). This
is a breaking change to the backing indices, with no config schema change:
- Indices: backing indices are renamed
sourcerer-v2-*tosourcerer-v3-*. There is no automatic migration - runsourcerer setupto create the v3 templates, then re-index every source. The oldsourcerer-v2-*indices can be deleted once you have re-indexed. - Agent Builder tools: content tools (
sourcerer.code.*,sourcerer.files.*) replace theirgit_commitparam withgit_ref(a commit SHA or a branch/tag name);git_commitsurvives as an optional filter alongsidegit_refandgit_ref_type. Runsourcerer setupagain to push the updated tool definitions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

