BaseVFS. Define readdir, read and stat,
and ls, cat, grep, find, head, wc and the other read commands work
on the service. Custom VFS lists every method, with
examples for a writable VFS and for grep on the service’s own search.
Write one
readdir returns each child’s FileStat with name set to the base name.
The mount keeps the listing and answers a later stat from it, so ls -l
costs one request. Use path.vfs_path to address the service and
path.virtual for the workspace path. Set FileStat.size to the length of
the bytes read returns, or None when it is unknown.
Add functions as the service grows
Every other function is optional. Define one, and the commands that need it start working; leave it out, and those commands answerOperation not supported.
The mount mode still decides whether a write may run.
read may return an
async iterator of bytes for a large file, and write receives one when a
program’s output streams into the mount.
Plug in the service’s search
files_containing and lines_containing hand Mirage the service’s own search.
grep and rg ask them which files or lines can hold the text and read only
those; they still match every line themselves, so the output is the same as a
full read. before_full_walk can refuse a command that would walk the whole tree.
For example, an S3 bucket whose objects are indexed in Elasticsearch under
their keys, by whatever indexes the bucket (such as a function on S3 events).
Subclass the built-in S3VFS and answer from the index:
grep -rlw outage /s3/ reads only the objects Elasticsearch names. Elasticsearch
ignores case, so it may name more than grep prints; grep checks each line and
drops the rest. grep -rl outage without -w gets None and reads every
object, so outages still matches. The mount is read-only because a write
through Mirage would leave the index behind. The answer is only as complete
as the index: grep skips an object written elsewhere that Elasticsearch has
not indexed yet, so return None while the indexer lags.
- Answer more files than needed, never fewer: an extra file costs one read,
a missing one is a wrong answer. Return
Nonewhenever the answer may be incomplete, such as a truncated result or an index that lags writes. - A search that matches only whole words, as Elasticsearch does, returns
Noneunlesswhole_wordis set, and setswhole_word_search = Trueso the mount’s VFS.md tells the agent to usegrep -w. - Set
searchableto the globs the search covers, such as("*/*.json",); a file outside them is always read. walk_limitcaps how many files one command walks, 1000 by default.
Use it in YAML
A workspace YAML mounts the class by its file and name:vfs: jira instead, register the class once: