BaseVFS. Override 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
parseConfigWithSchema refuses an unknown key by name, and secretStr()
keeps the token out of logs and snapshots. The subpath import needs
npm install @struktoai/mirage-core.
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.vfsPath to address the service and
path.virtual for the workspace path. Set FileStat.size to the length of
the bytes read returns, or null when it is unknown.
Add functions as the service grows
Every other function is optional. Override 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 iterable 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
filesContaining and linesContaining 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. beforeFullWalk 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).
Extend 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 null 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 null 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
nullwhenever 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
nullunlessopts.wholeWordis set, and setswholeWordSearch = 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. walkLimitcaps 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: