@manta-eu/cli
v0.25.0
Published
CLI that keeps what a Manta datastore holds in line with files you track in git: your app's vocabulary, shapes and rules
Readme
@manta-eu/cli
The manta CLI keeps what a Manta datastore holds in line with files you track in git. It covers your app's
vocabulary (the classes and properties your app adds to the knowledge graph), the SHACL shapes for those classes, the
Datalog rules that derive new facts from them, redirect handlers that open your app's entities in it, and Horns.
Documentation: developers.manta.eu
Push your vocabulary
Keep the vocabulary as a Turtle file in your repo, under a namespace your app owns:
@prefix todo: <https://todomvc.example/vocab#> .
todo:Todo a rdfs:Class ; rdfs:label "Todo" ; rdfs:comment "Something to do." .
todo:title a rdf:Property ; rdfs:domain todo:Todo ; rdfs:range xsd:string ; rdfs:label "Title" .Then make the datastore hold exactly what it declares:
pnpm manta ontology push manta/ontology.ttl --datastore your-datastore --name todomvc \
--namespace https://todomvc.example/vocab#- Declarative. The datastore ends up with the triples the file declares, and nothing it no longer declares. Running it again changes nothing, so it fits a CI step after every merge.
- Your own graph. Each
--namegets its own named graph, described as anowl:Ontologywhosedcterms:identifieris the name, so a push never touches the realm's ontology or another app's vocabulary. The realm's ontology is redeployed independently, and your vocabulary survives that. Ontology coverage skips these graphs, so your vocabulary is never counted as data. - Your own namespace.
--namespacenames the namespace your app owns. Every term the file declares must be under it. - Dry run.
--dry-runreports how many triples would be added and removed, and writes nothing. - Blank nodes. Triples on blank nodes (a list, a nested description) cannot be compared between pushes, so a file with any is rewritten on every push. The result is the same graph.
manta ontology delete --datastore your-datastore --name todomvc removes the vocabulary.
Push your shapes
SHACL shapes describe a class's properties, so manta-codegen can generate typed schemas for it. Keep them in a second
file, pushed under the same --name as your vocabulary:
@prefix todo: <https://todomvc.example/vocab#> .
todo:TodoShape a sh:NodeShape ;
sh:targetClass todo:Todo ;
sh:property [ sh:path todo:title ; sh:datatype xsd:string ; sh:maxCount 1 ] .pnpm manta shapes push manta/shapes.ttl --datastore your-datastore --name todomvc- One shapes graph. Your shapes land in the datastore's shapes graph next to the realm's, so every reader of shapes
sees them. Each one is tagged with your
--name, a push replaces only the shapes tagged with it, and a realm deploy keeps them. - Kept outside the datastore too. Each push also stores a copy next to the datastore's uploads, and a realm deploy puts it back, so a rebuilt datastore gets your shapes again. Only the shapes are stored: on a rebuilt datastore, push your vocabulary again before you push or delete shapes as a custom app. A deploy puts your shapes back without checking them again, so a realm shape added later for one of your classes sits next to yours until you push again.
- Classes nobody else shapes. A shape may target your own classes or the classes your data brings in, such as one Manta inferred from an upload; a shape you push for that class takes over from the inferred one the next time Manta syncs the upload shapes. A class the realm's own shapes or another app's shapes already cover is refused, so your shapes can never make the realm's or another app's data fail validation.
- Your own names. Name your shapes in your app's own namespace. A name in a namespace Manta uses (the realm's own,
an integration's such as
meta:, or RDF, RDFS, OWL, XSD or SHACL), or one the realm or another app already uses, is refused. - Shape predicates only. A shapes file may use RDF, RDFS, OWL, XSD, SHACL and Dublin Core predicates, and its own.
Manta's own predicates, such as the tags that tell app and upload shapes apart, are refused, except
relay:writeLifecycle: mark a propertyrelay:ReadOnlyorrelay:CreateOnlyto say what a write may not change. A property the datastore's rules derive is pushedrelay:ReadOnlywhatever the file says. - Declarative. Nothing the file no longer declares is left behind, and a second push of the same file writes nothing.
--dry-runreports what would change. - Your app's shapes only. A custom app pushes or deletes shapes with its machine token, and only for a vocabulary name it pushed itself. An operator may manage any app's shapes.
manta shapes delete removes your shapes. Delete them before your vocabulary: manta ontology delete is refused while
shapes pushed under the same --name are still in the datastore.
The vocabulary push keeps the prefixes your file declares for your own namespace, so manta-codegen names your schemas
after them (todo.ts). Declare your namespace with its prefix in the vocabulary before you push shapes for it.
Push your rules
Keep your Datalog rules in a .dlog file, each one named by a # s: line in your own namespace. Use the realm's
prefixes without declaring them, and declare your own with a PREFIX line. The push stores each name in your own prefix
as its full IRI, so a realm deploy can still recommit your rules under the realm's prefixes.
PREFIX todo: <https://todomvc.example/vocab#>
# s: todo:Rule_Done
todo:isDone[?todo, true] :-
todo:Todo[?todo], todo:completed[?todo, true] .pnpm manta rules push manta/rules.dlog --datastore your-datastore --name todomvcA custom app's machine token pushes rules once an admin turns on Rule writes for the app. The app pushes and deletes only the rules named after a vocabulary it pushed itself. An operator's own login pushes rules for every name.
- Committed, not only staged. The push makes the file your app's whole live rule set in one transaction: new rules are added, changed ones replaced, and the ones the file no longer holds removed. The datastore starts deriving at once.
- Survives a deploy. Your rules are owned by your app, and a realm deploy only replaces the realm's own.
- Dry run.
--dry-runreports how many rules would be added, changed and removed, and commits nothing.
manta rules delete withdraws all of your app's rules.
Name the rule packs your rules read
Manta's shared rule packs (core, marketing, creative-fatigue, ...) derive predicates your rules can build on.
Name each pack your rules read with --packs:
pnpm manta rules push manta/rules.dlog --datastore your-datastore --name journey --packs core,marketing,creative-fatigue- Turned on per datastore. A pack the realm offers as optional is turned on in the datastore in the same transaction that commits your rules, and its rules start loading. A pack the realm runs in every datastore is already on. The push reports each pack it turned on. A custom app's machine token turns on only the packs its rules read; an operator's login turns on every pack it names.
- Checked against the rules. A push is refused when a rule reads a predicate or class of a pack the datastore does not run and the push does not name. The refusal names each predicate and its pack.
- Kept on. A later push that leaves a pack out does not turn it off, and a pack update from Manta keeps your rules.
Test your rules
manta rules test loads your rules and each test case's facts into a throwaway datastore on Manta's staging
deployment, and compares what the rules derive with what you expect. A case is a folder with a given.trig (the facts
to load), an expect.trig (the facts the rules must derive) and an optional absent.trig (facts they must not).
expect.trig is exact for each predicate it names: any other fact with that predicate fails the case.
pnpm manta rules test manta/rules.dlog --cases manta/rules-tests --datastore your-datastore \
--api-url https://staging-app.hiremanta.com --keycloak-url https://staging-auth.hiremanta.comThe command exits with 1 when a case fails, so it can run in CI with a custom app's machine token. The test writes
nothing to --datastore: it only has to be a datastore the token is granted. A passing test does not run the checks a
push runs; use manta rules push --dry-run for those.
Grant access to your classes
An authorization says which role or app may read, add to or change one of your classes. Keep them in a Turtle file,
pushed under the same --name as your vocabulary:
@prefix todo: <https://todomvc.example/vocab#> .
todo:EditorsWriteTodos a acl:Authorization ;
acl:agentGroup todo:Editors ;
acl:mode acl:Read, acl:Write ;
acl:accessToClass todo:Todo .
todo:Editors schema:identifier "editor" ; rdfs:label "Editor" .pnpm manta authorizations push manta/authorizations.ttl --datastore your-datastore --name todomvcA custom app's machine token pushes authorizations with Rule writes, under the name of a vocabulary the app pushed itself. An operator's own login works for every name.
- Your own classes only.
acl:accessToClassnames a class your vocabulary declares. A grant covers the class it names, not its subclasses. - Roles and apps by identifier.
acl:agentGroupnames a role,acl:agentan app, each with theschema:identifierit signs in with. Declare your own roles and apps in the file, or point at a role the realm ships by its IRI; a role the realm ships may not be declared again under another IRI.acl:agentClass :Operatorgrants the realm's operators; no otheracl:agentClassis accepted. - Writes need a grant. Manta takes a write to one of your classes only from a role or app an authorization grants it.
- Survives a deploy. Each authorization is tagged with your
--name; a push replaces only yours and a realm deploy keeps them.--dry-runreports what would change.
manta authorizations delete removes them. Delete them before your vocabulary.
Push your redirect handlers
A redirect handler makes Manta's /redirect?iri=… links open the entities of the classes it names in your app, instead
of on their upstream platform or in the data explorer. Its query reads, from the entity bound to ?this, the values the
URL template needs:
[] a :RedirectHandler ;
:handlesClass todo:Todo ;
:redirectUrlTemplate "https://todomvc.example/todos/{id}" ;
:redirectQuery "SELECT ?id WHERE { ?this schema:identifier ?id }" .pnpm manta redirect-handlers push manta/redirect-handlers.ttl --datastore your-datastore --name todomvc- Your app's URLs only. The template's origin must be one of the app's redirect URLs or its home URL.
- For your own app. A machine token registers handlers for its own app. An operator names the app with
--app <client ID>. - Declarative. A push replaces the handlers under
--name;--dry-runreports what would change.
manta redirect-handlers delete removes them. The
custom apps guide covers the rest.
Push your message templates
Keep your app's Mustache templates in one folder. Each file's name, without .mustache, names its template under your
vocabulary's namespace, as the realm names its own: report-email.mustache becomes <namespace>ReportEmailTemplate.
A rule can then copy its :templateSource onto the messages that use it, as for a realm template.
pnpm manta templates push manta/templates --datastore your-datastore --name todomvc- After your vocabulary. Push the vocabulary of the same
--namefirst. A custom app may push templates only for a vocabulary it pushed itself. - Your own names. A push is refused when another app or the realm already registers a template under the same IRI, or when two files in the folder would get the same name.
- Declarative. A push replaces the templates under
--name;--dry-runreports what would change.
manta templates delete removes them. Delete them before your vocabulary.
Push your memory schema templates
A memory schema template gives every datastore a kind of memory your app needs, as the realm's memory-schemas.ttl
does. Each datastore copies a template the first time it reads its memory schemas. Later pushes update the copies
nobody edited, and an admin reviews an update to an edited copy.
pnpm manta memory-schemas push manta/memory-schemas.ttl --datastore your-datastore --name todomvc- Your namespace. Each class (
rdfs:subClassOf :Memory), shape and property path is under your vocabulary's namespace. Push the vocabulary first. - The realm's checks. The file passes the same structural checks as the realm's templates: one label, description
and
:defaultMemoryKindper class, onesh:NodeShapeper class, inline property shapes with onesh:path, a supportedsh:datatypeorsh:nodeKind sh:IRI, a distinct integersh:order, andsh:maxCount 1on key properties. - Declarative. A push replaces the templates under
--name;--dry-runcounts the templates it would add, change and remove.
manta memory-schemas delete removes the templates. Copies a datastore already made stay, and show that their template
was removed. Delete them before your vocabulary.
Push your chat guide
The Manta chat starts from the realm's role, analytics and no-knowledge-graph sections. Your app can supply its own, so what the chat knows about your terms and rules ships with your app:
pnpm manta chat-guide push manta/chat-guide --datastore your-datastore --name todomvc- The folder.
role.md,analytics.mdandno-knowledge-graph.md, in Markdown. For a file you leave out, the chat uses the section another app in the datastore pushed, or else the realm's. Each section is at most 16 KiB. - One app per section. A section another app already supplies in the datastore is refused.
- Your name. Push the vocabulary named
--namefirst. The app needs Rule writes, as for rules. - Declarative. A push replaces the sections under
--name;--dry-runcounts the sections it would add, change and remove. A chat picks up a push within five minutes.
manta chat-guide delete removes the sections, and the chat goes back to the realm's. Delete them before your
vocabulary.
The command targets hiremanta.com production unless --api-url, --keycloak-url and --keycloak-realm name another
deployment, as for manta-codegen.
Push everything at once
A manta.json manifest names your app and the path of each file, relative to the manifest:
{
"name": "todomvc",
"namespace": "https://todomvc.example/vocab#",
"app": "todomvc-app",
"vocabulary": "manta/ontology.ttl",
"shapes": "manta/shapes.ttl",
"authorizations": "manta/authorizations.ttl",
"redirectHandlers": "manta/redirect-handlers.ttl",
"templates": "manta/templates",
"memorySchemas": "manta/memory-schemas.ttl",
"chatGuide": "manta/chat-guide",
"rules": "manta/rules.dlog",
"rulePacks": ["core", "marketing"]
}Every key but name is optional. manta push pushes the files in that order, the vocabulary first and the rules last.
chatGuide names the folder manta chat-guide push takes. rulePacks lists the shared rule packs your rules read, as
--packs does, so a manifest with rulePacks must name its rules too:
pnpm manta push --manifest manta.json --datastore your-datastore
pnpm manta push --manifest manta.json --all-datastores- Every datastore. With
--all-datastores, an operator's token reaches every datastore of the realm, and a custom app's machine token the datastores the app is granted. The command pushes to four datastores at a time and reports each one. A failure stops that datastore and not the others, and makes the command exit with an error. - New datastores. After an operator's
--all-datastorespush that at least one datastore took, Manta keeps the files as the app's bundle, and each datastore that took the push records its version. Before its first chat turn or plan, a datastore with no record of a bundle takes it. A datastore keeps the version it recorded, so a later--datastorepush to it stays, and a datastore the fan-out could not reach takes the newer bundle only at the next--all-datastorespush. Redirect handlers stay out of the bundle: their app must reach the datastore, so push them to each datastore it reaches. An operator removes a bundle withDELETE /app-bundles/<name>; the datastores keep the files they took. - Safe to repeat. An unchanged file changes nothing, as with each command above.
--dry-runreports what would change and saves no bundle.
Publish a Horn
Keep one Horn per folder, with a horn.json document and any written view sources in views/<id>.tsx.
The document's slug identifies the Horn and its datastoreId must match --datastore.
Omit about to keep existing links, including desks attached in Manta. Set about to a list to replace the links, or to [] to clear them.
manta horns push requires a custom app with Machine access, the publish-horns permission, and access to the target
datastore. Set MANTA_CLIENT_SECRET to the app's client secret, including for local runs and --dry-run.
For GitHub Actions, store MANTA_CLIENT_SECRET as a secret in the deployment environment and set MANTA_CLIENT_ID and
MANTA_DATASTORE as environment variables there. In a job that uses that environment, add this step after checkout and
CLI installation. Run the job after an approved PR merges into the protected branch.
- name: Publish the overview Horn
env:
MANTA_CLIENT_SECRET: ${{ secrets.MANTA_CLIENT_SECRET }}
MANTA_CLIENT_ID: ${{ vars.MANTA_CLIENT_ID }}
MANTA_DATASTORE: ${{ vars.MANTA_DATASTORE }}
run: >-
pnpm manta horns push horns/overview --datastore "$MANTA_DATASTORE"
--client-id "$MANTA_CLIENT_ID" --accept-reviewed-codePass --accept-reviewed-code only from a trusted checkout after a person has reviewed the exact TSX being published.
The flag records review for written views that lack a valid review. The CLI reuses a published review when the view ID
and TSX source match.
A publisher limited to one customer datastore can publish self-contained Horns. Horns that pin shared library items require access to the realm library so the server can verify their dependency locks.
Use --api-url to target a different Manta deployment and --keycloak-url and --keycloak-realm for its
login settings. Include the mount path in --api-url if the service is mounted under a path prefix.
--dry-run reads the current Horn and reports whether a push would create it, update it, or leave it unchanged.
It also lists any written views that still need acceptance.
Creating or updating a Horn saves a revision. If the Horn changes between the read and save, or readback differs from the published content, the command fails so you can inspect the current revision before pushing again. A push can replace a Studio edit that was already present when the CLI read the Horn.
What the API checks
The whole push is refused, and nothing is written, when a Turtle file:
- is not valid Turtle, declares nothing, or is larger than 1 MiB;
- declares a term outside
--namespace, or names a namespace that overlaps one another app's vocabulary already claims; - declares a term the realm ontology or another app's vocabulary already describes;
- writes a predicate the platform derives, such as
:isTrusted; - gives your namespace a prefix name Manta already uses, such as
meta:.
A shapes file is also refused when it declares no sh:NodeShape, uses sh:targetNode, sh:targetSubjectsOf or
sh:targetObjectsOf, or targets a class the realm's own shapes already cover.
An authorizations file is also refused when it uses a predicate other than rdf:type, acl:mode,
acl:accessToClass, acl:agentGroup, acl:agent, acl:agentClass (for :Operator only), schema:identifier and
rdfs:label, grants a mode other than
acl:Read, acl:Append or acl:Write, grants a class your vocabulary does not declare, names something outside your
namespace or something the realm ships, or carries rdfs:isDefinedBy the realm ontology. A datastore the realm has
not deployed its access rules to refuses every authorizations file.
A rules file is refused when a rule has no # s: name or shares one, uses a prefix the file does not declare, declares
a prefix the realm's rules do not, binds a prefix differently from the datastore's rules, is not valid Datalog, derives a predicate the platform protects or a
variable predicate, names an action the datastore cannot run, or takes a name in a namespace Manta owns or one
another owner already holds. It is also refused when --packs names a pack the realm does not offer, or a rule reads a
predicate of a pack the datastore does not run and --packs does not name. A custom app's push is also refused when
--packs would turn on a pack its rules do not read.
--name is 1 to 64 lowercase letters, digits and dashes, and may not end in ontology, which marks the realm
ontology. --namespace is an http(s) IRI ending in # or /, and may not overlap a namespace Manta already owns: the
realm's own vocabulary, an integration's (such as meta: or shopify:), or RDF, RDFS, OWL, XSD, SHACL and the other
vocabularies the platform uses.
Log in
Login works as it does for manta-codegen and manta-upload: all three register the same commands from
@manta-eu/auth, and share one stored login. Log in once with manta login. In CI, set MANTA_CLIENT_SECRET for a
service account token instead.
Writing a vocabulary needs an operator's login, or a custom app's machine token when the app may write data. A token
a custom app issued to one of its users only reads, so it is refused. A vocabulary a custom app pushes records the app as
its dcterms:creator, and only that app, or an operator, may change or delete it.
