Plocate
Wrap plocate to build, refresh, query, and
expire a fast filesystem index — so extensions and agents resolve paths
without walking directory trees. This model owns the index lifecycle and
cache-freshness policy: staleness is native swamp TTL (the index resource's
lifetime = maxAge), so an expired index simply stops resolving until
rebuilt. Transport defaults to local, with toolbox/podman/commandPrefix
escape hatches and an Ansible-style become to stack sudo for system builds.
Methods
- build / refresh — rebuild every root's DB in one execution; write the
aggregate
indexinstancemain(lifetime =maxAge). - refresh_all — fan-out: rebuild every root in ONE execution / one lock;
write one
indexper root (slugged path name) plus aggregatemain. - status — stat DB mtimes host-side, compute
stalevsmaxAge; no rebuild. - clear — delete the user DB(s) (verified inside
dbDir) and mark the index cleared. Never touches the system DB. - query — match against the index and persist a CEL-referenceable
resultsinstance (q-<label>).refreshIfStaleself-heals a stale index first;scope: "system"queries the read-only system DB.
Quickstart
swamp model create @kneel/plocate rpm-index \
--global-arg roots='["/home/neil/dev/fedora/rpms/swamp"]'
swamp model method run rpm-index build
swamp model method run rpm-index query --arg pattern='.spec' --arg label=specsConsume the results with CEL (prefer data.latest(...); its 2nd arg is the
instance name — main for the index, q-<label> for a query):
data.latest("rpm-index", "q-specs").attributes.matchesSelected examples
Fan-out over matches — index a corpus once, then let another model iterate the matches instead of walking directories:
# consuming model's forEach source:
data.latest("rpm-index", "q-specs").attributes.matchesPre-flight existence gate — a deploy check confirms a built asset exists
before acting, no filesystem crawl in the hot path:
swamp model method run artifacts query \
--arg pattern='app-v2.3.1.tar.gz' --arg limit=1 \
--arg refreshIfStale=true --arg label=asset# gate the deploy step on a nonzero match count:
data.latest("artifacts", "q-asset").attributes.count > 0Agent "where is X" — instant path resolution by name or regex, self-healing if the index went stale:
swamp model method run home-index query \
--arg pattern='plocate.*\.ts$' --arg regex=true \
--arg refreshIfStale=true --arg label=find-plocateFull docs — deployment requirements, transport + become, the global-argument
reference, and the complete 12-example catalog (nightly refresh_all cron,
multi-root queries, cross-model CEL wiring, backup verification):
https://github.com/NeilHanlon/swamp-plocate
Global Arguments
| Argument | Type | Description |
|---|---|---|
| roots | array | Directories to index. One plocate DB is built per root; roots are queryable together (db1:db2). |
| dbDir | string | Directory holding user-owned plocate DBs. '~' is expanded to $HOME. |
| maxAge | string | Freshness threshold. Drives the `index` resource lifetime (native staleness) and refreshIfStale self-heal. |
| requireVisibility | union | plocate updatedb --require-visibility. 0 = report all files without a visibility check (user corpus DBs). |
| prunePaths | array | Paths to omit from the index (updatedb --prunepaths). |
| pruneNames | array | Directory names to omit from the index (updatedb --prunenames). |
| runtime | enum | Transport for running plocate/updatedb. 'local' runs on PATH; toolbox/podman hop into a container. |
| container | string | Container name — required when runtime is 'toolbox' or 'podman'. |
| commandPrefix | array | Escape hatch: verbatim transport prefix (e.g. ['ssh','host'] or ['nsenter',...]). Overrides `runtime` when non-empty. |
| become | boolean | Ansible-style privilege escalation: prepend 'sudo' after the transport prefix. Per-method `become` overrides this. |
| systemDb | string | Path to a system-wide plocate DB, for read-only queries with scope:'system'. |
| plocateBin | string | plocate binary name/path on the transport target. |
| updatedbBin | string | plocate's updatedb binary name/path on the transport target. |
| metadata | record |
| Argument | Type | Description |
|---|---|---|
| become? | boolean | Override the global `become` for this build (sudo on the transport target). |
| Argument | Type | Description |
|---|---|---|
| become? | boolean | Override the global `become` for this refresh. |
| Argument | Type | Description |
|---|---|---|
| become? | boolean | Override the global `become` for this rebuild. |
| Argument | Type | Description |
|---|---|---|
| pattern | string | Search pattern (glob-ish substring by default; regexp when regex:true). |
| limit? | number | Stop after N matches (plocate -l). |
| regex | boolean | Interpret pattern as a basic regexp (plocate --regexp). |
| ignoreCase | boolean | Case-insensitive match (plocate -i). |
| refreshIfStale | boolean | If the user index is older than maxAge, rebuild it before querying (self-heal). Ignored for scope:'system'. |
| scope | enum | 'user' queries the per-root corpus DBs; 'system' queries the read-only systemDb. |
| label? | string | Stable name for the persisted results instance, referenced as data.latest("<model>", "q-<label>"). Defaults to a deterministic hash of the query args. |
Resources
- Has README or module doc2/2earned
- README has a code example1/1earned
- README is substantive1/1earned
- Most symbols documented1/1earned
- No slow types (deprecated)1/1earned
- Dependencies pass trust audit2/2earned
- Has description1/1earned
- Platform support declared (or universal)2/2earned
- License declared1/1earned
- Verified public repository2/2earned