Sources
dotagents._sources
Overlay repos: where overlays add / sync fetch an overlay from.
A repo is always a collection of overlays, the place that answers "give
me overlay <name>". Two shapes:
- a directory of overlays -- each subdirectory is an overlay,
<dir>/<name>/(a checkout of therepobranch'soverlays/, any folder); - a registry -- a JSON / TOML / YAML document mapping
<name-or-alias>to the source of that one overlay. Either the whole document is the mapping, or itsoverlayskey is.
A source is one overlay: the directory that is its root.
Repos and sources are both written as a spec::
<location>[@<ref>][#<path>]
<location> is a local path, an http(s):// URL, or a git repository
(anything git clone accepts: https://…/x.git, git@host:org/x.git,
ssh://…, a local …/x.git; prefix git+ to force git for a URL that
does not end in .git). <ref> (git only) is a branch, tag or commit --
default the remote's default branch. <path> is a path inside the location.
What the path names differs: for a repo it is the collection -- a
directory (of overlays) or a registry file, the checkout root when absent;
for a source it is the overlay's root directory, and when absent the
repository root is the overlay.
A scheme:// location that is not git is a uripath path (pathapi's
URI layer). With the uri extra installed (dotagents-cli[uri];
[sftp], [s3] and [repo] add the sftp:, s3: and
github: / gitlab: / repo: schemes) any scheme uripath speaks works
the way a local path does: an http(s):// directory listing, an sftp,
s3, dav or github tree is a directory of overlays (as a repo) or
one overlay (as a source), a file is a registry; so is an archive --
zip:<archive-uri>!/<inner> (tar:, archive:), the archive local or
at any URL. What is remote is
materialized into <user store>/.cache/overlays/uri/ (synced once per
process) and used from there. file:// is a local path, no copy. Without
the extra an http(s):// location can still be a registry file (fetched
with the standard library); anything else says which extra it needs.
A source written as a relative path (./python, ../shared/net,
overlays/rust) is relative to the registry it is in: the registry file's
directory for a local file, for a registry inside a git checkout the same
repository at the same ref with the path joined onto the registry file's
directory (overlays/reg.toml saying ./rust means
<repo>@<ref>#overlays/rust), and for a registry at a URL the URL beside
it (https://h/cfg/reg.json saying ./rust means https://h/cfg/rust).
A relative git location (../shared.git@v2) is another repository, found
the way a relative submodule URL is: beside the registry's repository, or
beside the registry file when that is local or at a URL.
Repos are consulted in order, and the first that offers a name wins:
--repo values as given, then $AGENTS_OVERLAYS_REPO_<KEY> sorted by
KEY, then $AGENTS_OVERLAYS_REPO (the default repo), then
<project store>/dotagents.{json,toml,yaml,yml}, then the user store's.
Repos load lazily, in that order, so a git repo late in the list is never
cloned for a name an earlier one had.
Git checkouts live under <user store>/.cache/overlays/<repo>-<hash>/ (one
per repository and ref) and are refreshed (fetch + checkout) once per process; a fetch that
fails against an existing checkout is a warning, and the checkout is used as
it is. The cache root carries a .gitignore of *, so a store kept in git
never records a checkout. Credentials embedded in a repo URL never reach a log
line, a cache directory name or a checkout's .git/config.
Failures are typed: :class:OverlayNotFound when every repo loaded and none
offers the name, :class:SourceError for everything else (a repo that cannot
be read, cloned or parsed). Both are SystemExit subclasses, so an uncaught
one still ends a command with its message; a caller that wants to tolerate a
missing name catches only :class:OverlayNotFound.
GIT_SSL_REVOKE_DEFAULT = 'best-effort'
module-attribute
GIT_SSL_REVOKE_KEY = 'git_ssl_revoke'
module-attribute
GIT_SSL_REVOKE_VALUES = ('best-effort', 'true', 'false')
module-attribute
NO_SOURCE_MESSAGE = 'error: no overlay source: pass --repo <repo>, set AGENTS_OVERLAYS_REPO, or add a dotagents.{json,toml,yaml} registry to the store.'
module-attribute
REGISTRY_FILE_STEM = 'dotagents'
module-attribute
REGISTRY_FILE_SUFFIXES = ('.json', '.toml', '.yaml', '.yml')
module-attribute
REPO_ENV_DEFAULT = 'AGENTS_OVERLAYS_REPO'
module-attribute
REPO_ENV_PREFIX = 'AGENTS_OVERLAYS_REPO_'
module-attribute
CompositeSource(specs, cache)
Bases: object
The repos in precedence order, loaded lazily; the first offering a name
wins. This is what the overlay commands talk to (available /
overlay_dir / root).
Source code in src/dotagents/_sources.py
891 892 893 894 | |
cache = cache
instance-attribute
root
property
specs = list(specs)
instance-attribute
__repr__()
Source code in src/dotagents/_sources.py
969 970 | |
available(on_error=None)
Every name the repos offer, first-offered order. A repo that fails
to load raises -- unless on_error(spec, exc) is given, which is
called for it instead so the other repos are still listed.
Source code in src/dotagents/_sources.py
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
find_repo(record)
The spec in this chain that IS the repo record describes
(:func:source_record), or None -- it carries any credential the
redacted record lacks.
Source code in src/dotagents/_sources.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
locate(name)
(overlay dir, repo spec): :meth:overlay_dir plus which repo
of the chain offered it (what add records as the overlay's source).
Source code in src/dotagents/_sources.py
955 956 957 958 959 960 961 962 963 964 965 966 967 | |
only(spec)
A source of just the repo spec, sharing this one's cache (so a
repo already fetched this process is not fetched again).
Source code in src/dotagents/_sources.py
934 935 936 937 | |
overlay_dir(name)
The directory of overlay name from the first repo offering it.
:class:OverlayNotFound when no repo does; a repo that cannot be
loaded is a :class:SourceError, never "not found".
Source code in src/dotagents/_sources.py
928 929 930 931 932 | |
repos()
Source code in src/dotagents/_sources.py
907 908 | |
DirRepo(root, origin=None)
Bases: object
A directory of overlays: <root>/<name>/ is the overlay.
Source code in src/dotagents/_sources.py
559 560 561 | |
origin = origin or str(self.root)
instance-attribute
root = Path(root)
instance-attribute
__repr__()
Source code in src/dotagents/_sources.py
594 595 | |
available()
Overlay names the directory offers -- the ONE discovery rule
(:meth:Overlay.discover), so __pycache__ / dotdirs are never listed.
Source code in src/dotagents/_sources.py
563 564 565 566 | |
has(name)
Source code in src/dotagents/_sources.py
578 579 | |
overlay_dir(name)
The source dir for name: the literal dir, its normalized form, or
any available overlay whose NORMALIZED name matches -- so a source dir
named my_overlay resolves for add my_overlay / add my-overlay
alike.
Source code in src/dotagents/_sources.py
581 582 583 584 585 586 587 588 589 590 591 592 | |
OverlayNotFound
Bases: SourceError
Every repo consulted loaded fine and none offers the overlay asked for -- the one failure a caller may treat as "absent".
RegistryRepo(origin, entries, cache, base=None)
Bases: object
A registry: entries map names (or aliases) to specs, materialized on
demand through cache. base is where the registry document lives
(see :func:resolve_relative); None leaves a relative entry as the
process sees it.
Source code in src/dotagents/_sources.py
604 605 606 607 608 609 610 611 | |
base = base
instance-attribute
cache = cache
instance-attribute
entries = entries
instance-attribute
origin = origin
instance-attribute
root
property
__repr__()
Source code in src/dotagents/_sources.py
645 646 | |
available()
Source code in src/dotagents/_sources.py
622 623 | |
has(name)
Source code in src/dotagents/_sources.py
625 626 | |
key_for(name)
Source code in src/dotagents/_sources.py
617 618 619 620 | |
overlay_dir(name)
Source code in src/dotagents/_sources.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
SourceCache(root, logger=None, ssl_revoke=GIT_SSL_REVOKE_DEFAULT)
Bases: object
What the commands fetch, under root: git clones, one per repository
location AND ref (two registry entries naming the same repository at
different refs -- @main for one overlay, @dev for another -- must
each see their own tree, since the commands resolve every source before
copying any), and materializations of uripath paths under uri/
(a remote directory synced down, a remote file copied), each refreshed
once per process.
Source code in src/dotagents/_sources.py
269 270 271 272 273 | |
logger = logger
instance-attribute
root = Path(root)
instance-attribute
ssl_revoke = ssl_revoke
instance-attribute
checkout(spec)
The working tree for spec at its ref (the repository root;
spec.path is the caller's to join), cloned or refreshed as needed.
Source code in src/dotagents/_sources.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
materialize(spec)
The local path a url spec resolves to: the path itself for
file://; otherwise the remote (location joined with path)
brought into the cache -- a directory synced (deletions mirrored), a
file copied -- once per process. Needs the uri extra for anything
but file://; a missing remote is an error naming it (redacted).
Source code in src/dotagents/_sources.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
repo_dir(location, ref=None)
Source code in src/dotagents/_sources.py
386 387 388 389 390 391 392 | |
SourceError
Bases: SystemExit
A repo or source could not be read, fetched, cloned or parsed.
A SystemExit (its message is the exit message), so a caller that does
not handle it still ends with a one-line error rather than a traceback.
Spec(kind, location, ref=None, path=None)
Bases: object
A parsed spec. kind is "git", "url" or "dir".
Source code in src/dotagents/_sources.py
116 117 118 119 120 | |
__slots__ = ('kind', 'location', 'ref', 'path')
class-attribute
instance-attribute
kind = kind
instance-attribute
location = location
instance-attribute
path = path
instance-attribute
ref = ref
instance-attribute
__eq__(other)
Source code in src/dotagents/_sources.py
122 123 124 | |
__repr__()
Source code in src/dotagents/_sources.py
126 127 | |
display()
The spec, userinfo dropped from the location -- safe for messages.
Source code in src/dotagents/_sources.py
129 130 131 132 133 134 135 136 | |
env_repos(environ=None)
The AGENTS_OVERLAYS_REPO_<KEY> values ordered by KEY, then the
default AGENTS_OVERLAYS_REPO if set.
Source code in src/dotagents/_sources.py
867 868 869 870 871 872 873 874 875 876 877 | |
git_ssl_revoke(*stores)
The first git_ssl_revoke set in stores' config (the project
store before the user store), else the default. Any other value raises
:class:SourceError naming the file.
Source code in src/dotagents/_sources.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
is_relative(spec)
A spec meaningful only against the registry it came from: a dir
spec whose location is a relative path, or a git spec whose location
is one (../shared.git -- not a URL, not scp-like host:path).
Source code in src/dotagents/_sources.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
load_repo(spec_text, cache)
A :class:DirRepo or :class:RegistryRepo for a spec: what the spec
resolves to decides -- a directory is a directory of overlays, a file is a
registry, an http(s):// location is fetched as a registry. A
pre-parsed :class:Spec (a store's own registry path) is used as is, so a
# or @ in a local path is never read as spec grammar.
Source code in src/dotagents/_sources.py
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 | |
locate(spec, cache)
The local path a spec resolves to: a git checkout (plus path), or a
local path (plus path). Raises when it does not exist.
Source code in src/dotagents/_sources.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
parse_document(text, suffix, origin)
The name -> spec mapping of a registry document (the whole document,
or its overlays key).
Source code in src/dotagents/_sources.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
parse_spec(text)
Parse <location>[@<ref>][#<path>]. See the module docstring.
Source code in src/dotagents/_sources.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
record_display(record)
Source code in src/dotagents/_sources.py
840 841 842 | |
redact(text)
text with the userinfo of every scheme://user:pass@host removed
(up to the LAST @ of the authority, so a raw @ in a password goes
too) and every URL query value masked (?access_token=***).
Source code in src/dotagents/_sources.py
139 140 141 142 143 144 | |
registry_files(*stores)
<store>/dotagents.<suffix> for each store that has one (first suffix
present per store), in the order given.
Source code in src/dotagents/_sources.py
852 853 854 855 856 857 858 859 860 861 862 863 864 | |
resolve(specs, *, cache_root, stores, environ=None, logger=None, allow_empty=False)
The source the commands use: specs (--repo values), the env
repos, then the stores' registry files. Raises when
there is nothing at all, unless allow_empty: then an empty source
answers every name with :class:OverlayNotFound.
Source code in src/dotagents/_sources.py
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
resolve_relative(spec, base, *, origin, key)
spec made absolute against base, the place its registry lives,
when it is a relative path; any other spec, or no base, comes back as is.
base is a dir spec (the registry file's directory), a git spec
(the repository, ref and the registry file's directory inside it -- the
entry stays in the same repository at the same ref), or a url spec
(the registry's URL: the entry is the URL beside it).
Source code in src/dotagents/_sources.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
source_record(spec)
The repo spec as an install record keeps it: a local path made
absolute (a --repo given relative to the cwd must still resolve from
anywhere), the location REDACTED (a record lives in the store, which may be
kept in git), and lossy set when redaction dropped something -- such a
record identifies the repo but cannot be fetched from by itself.
Source code in src/dotagents/_sources.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | |
spec_from_record(record)
The :class:Spec of a :func:source_record, or None if malformed.
Source code in src/dotagents/_sources.py
825 826 827 828 829 830 831 832 833 834 835 836 837 | |
uri_path_class()
uripath.URIPath when the uri extra (pathapi-uri) is
installed, else None -- the switch between "any scheme uripath speaks"
and the standard-library http(s) registry fetch.
Source code in src/dotagents/_sources.py
191 192 193 194 195 196 197 198 199 | |
url_scheme(location)
Source code in src/dotagents/_sources.py
214 215 | |