Repository navigation
Description
Refs #1139 (the derived facts), #1258 (search reports the graph's derived surface), #4359, #4360, INTENTIUS/behold#906.
Question
Should chant own a catalog of semantic capabilities, with each lexicon supplying the rules that derive them? An agent could then turn a person's question ("what in prod can be reached on SSH from the internet?") into chant search terms without guessing attribute names. If so, what should a capability be, and who writes the rules?
This is research. Write the comparison and a recommendation for the maintainer. Nothing is built here.
Why ask
Two derived facts are what turn a multi-hop question into one search term, and they are part of why chant's arm does well on aws-bench (ec2-multiregion):
effectiveIngress: the security-group rules that reach an instance, including through its launch template.internetFacing: the instance's subnet routes to an internet gateway.
Both are in packages/core/src/graph-effective.ts (#1139). They are hand-coded in core, cover EC2 only, and select nodes by CloudFormation kind (isKind(n, "SecurityGroup") matches ...::SecurityGroup). So:
- A stock Terraform root gets neither. The terraform lexicon's kinds are
aws_instanceandaws_security_group, so the folds never run on them. - Every new fact is a change to core, not to the lexicon that knows the substrate.
- An agent finds a fact only after it exists.
--explainandderivedSurface(chant search should report the graph's derived surface #1258) say which derived attributes a graph carries. Nothing says what a fact means, which questions it answers, or which lexicons supply it. So the agent cannot map a person's words onto it ahead of time.
The idea
A catalog. Each capability has:
- a stable name and a one-line meaning ("internet-reachable: a path exists from the internet to this resource");
- parameters, where it has any (a port, a protocol);
- the search term or terms it adds;
- for each lexicon, a rule that derives it from that lexicon's graph, or a statement that the lexicon cannot.
Candidates beyond the two that exist:
- stores data;
- encrypted at rest;
- publicly readable;
- grants access to (an identity's reach);
- crosses a network boundary;
- runs code;
- holds a secret.
The catalog is published where agents look: the MCP search tool's description, chant search --capabilities, and the agent docs. An agent then reads it once, instead of rediscovering attribute names on every question.
What to find out
- The shape. Is a capability a derived attribute, as today, or a named query that expands to terms? What does each choice do to
--explain's universe counts and near-misses? - Ownership. Rules in each lexicon, behind a core interface, against keeping them in core. The terraform lexicon needs the AWS rules on
aws_*kinds. Can one rule serve CloudFormation and Terraform kinds of the same resource, or does each lexicon carry its own? - Live, declared and snapshot. Today's folds run on all three (Separate observation from folding, so a fold can run over a snapshot #1271, Deep snapshots: record the property trees the folds need, not just identity #1267). Which capabilities need live data to be true, and how does a capability say it was computed from declared data only?
- The vocabulary. Which capabilities the first version ships. Start from questions people ask: aws-bench's eight, behold#906's seven, and the security questions an agent gets most often.
- The evidence. Run aws-bench with the catalog in the agent's context and without it. Compare pass rate, tokens and tool calls against the current chant arm. The catalog has to pay for its own tokens.
Who uses it
behold draws a query an agent ran (INTENTIUS/behold#907). The catalog is what makes the agent's query right in the first place. Agents using chant search without behold benefit the same way.
Acceptance criteria (research)
Part of INTENTIUS/behold#908 (step 6 waits on this ruling). #4362 makes today's two facts work on Terraform kinds in the meantime.
- A comment on this issue holds the measurement from the rule-language comment above: the three capabilities (what an identity can reach, exfiltration paths, blast radius), each written in every candidate language, against one AWS estate in its CloudFormation and its Terraform form. The table covers expressibility, lines of rule, correctness against hand-checked answers, evaluation time, and what
--explaincan print. - The comment ends with a recommended rule language and a first vocabulary.
- Implementation issues for the recommendation are filed and linked once the maintainer has ruled, not before.
- No production code merges under this issue.
Activity
lex00 commentedon Oct 23, 2026
The rule language is the main question
The graph query only reaches people through this layer. Nobody types a path query. They ask "what can reach the customer database?", and the capability turns that into one. So the further the catalog goes past simple facts, the more its rules need a real graph query language, and the language a rule is written in is the first decision here, before the vocabulary.
Why simple rules won't last
graph-effective.tsis a TypeScript traversal: instance, subnet, association, route table, route, gateway. Each new capability is new code in core, and the same rule has to be written again for Terraform kinds that differ only in their labels.The questions people care about combine capabilities and follow paths of any length:
internet-reachableand assumes a role thatgrants access toa data store thatholds a secret. Three capabilities, joined along one path.The search grammar cannot express these, even with transitive edges (#4359). They need pattern matching over paths, with capabilities referring to other capabilities.
Rules as declared patterns
If each capability's rule is a declared graph pattern rather than code:
AWS::EC2::SecurityGroupandaws_security_group).--explainprints the path each match took, which an agent can quote and behold can draw (research: an agent asks about the estate and behold draws the answer - live in the open tab, as a screenshot, or both behold#907).Three candidate languages
@ladybugdb/core)Here LadybugDB would be the engine that evaluates rules, not a surface people query. Engine and dialect are separate choices. A Cypher-subset rule could also be evaluated by an in-house matcher, which would keep the rules portable even if the engine changes.
The measurement that decides
Write the three capabilities above (what an identity can reach, exfiltration paths, blast radius) in each candidate language, against one AWS estate in both its CloudFormation and its Terraform form. For each language, compare:
--explaincan print for a match.The cheapest language that expresses all three wins. If none of the cheaper ones can, that is the case for Cypher on an optional engine, with the simpler capabilities still evaluated without it.
lex00 commentedon Oct 23, 2026
Measurement: the rule language
This is the measurement asked for in "The rule language is the main question": the three capabilities written in each of the three candidate languages, run against one AWS estate in its CloudFormation form and its Terraform form, and scored against answers checked by hand. It ends with a recommendation and a first vocabulary. The ruling is the maintainer's. Nothing here is filed for implementation, and no production code merged.
All of it is prototype code in an unpushed chant worktree (
chant-worktrees/research-4361/scratch-4361/, branched from main at 201931e). LadybugDB@ladybugdb/core0.21.2 was installed only in a scratch directory.The estate
The terralith at scale 4 and aws-bench's estate have no path that all three capabilities can exercise. The terralith's policies grant on
*and on bucket ARNs the estate doesn't declare, and aws-bench's one role holds a Deny and an AWS-managed ARN. So I wrote a small estate, "ledger", twice: as a chant aws project (CloudFormation) and as a stock.tfroot. Each form names the same 38 resources. It is built so that a rule that cuts corners gets a wrong answer:AWS::EC2::SecurityGroupIngress/aws_vpc_security_group_ingress_rule);webServer, which gets its open group (22 and 443 from 0.0.0.0/0) only through its launch template.adminBoxsits in the public subnet but admits nothing from the internet, andworkeris private;reporterhas a function URL withAuthType NONE, andbatchhas none;webRole -> deployRole). One goes by ARN string (batchRole -> arn:...:role/audit);data-classification=restricted(in TF through alocal), a DynamoDB table, a secret, and an RDS instance in a group that admits the app group.Answers by hand: identity reach is 13 (role, resource) pairs. Exfiltration is 3 (compute, store) pairs:
webServer -> customerDataandwebServer -> dbSecret, both throughdeployRole, plusreporter -> customerData. Blast radius is 15 members from three starts: 10 fromwebServer, 2 fromreporter, 3 frombatch.What all three languages read
chant's IR cannot serve as a rule surface for these questions as it stands, in any of the three languages:
webPolicyreferencesdeployRolethroughPolicyDocument. It doesn't say which statement does it, with which actions, or as resource or as principal."${jsonencode({...})}").aws_iam_role_policy_attachment) where CloudFormation has a direct reference.AWS::EC2::Instance, while TF kinds are allTerraform::Resource, with the type in the address.So every language reads the same lexicon-neutral view, built by a per-lexicon mapping and adapter (
view.ts, 168 lines):Instance,Role,SecurityGroup, ...),viaAttrto edge name (SubnetId/subnet_id->subnet), and a few attributes.statement,resource,principal,ingressandsourceedges. It turns link resources into edges and resolves an ARN that names a declared role. TF policies are read with the lexicon's ownreadJsonencode(..., { unknownLeaves: true }).That cost is the same whichever language wins, and it is where the per-lexicon work lives. With the mapping in place, the rules themselves needed 0 changed lines for Terraform, in every language.
The table
->can-assume*); optional hops (->template?); a back-reference that closes a cycle (the trust check ends ata); node-set conditions ([@holds-secret]); label and edge alternation;=,inand IAM-glob~attribute testsEXISTSfor node-set conditions;* SHORTESTfor closures (its lower bound must be 1, so a 0-hop case is a second statement)deployRoletrust edgeCOPY FROM; 325 s byUNWIND)--explaincan printnodes(p)of oneMATCH. Across derived capabilities the author carries evidence by hand (list_concat), and my C evidence lost the ingress-rule hop innetworkTimes are from Node 24.13 on an M-series Mac. The 58k figure uses 1000 disjoint copies of the TF ledger view, because no real estate here is large enough to show growth. The view itself takes 0.4 to 2.7 ms on every real estate and is left out of the table. On the aws-bench estate,
internet-reachablereturnslaunchTemplateServerandwebServerin both forms, one of them only through its launch template, which is aws-bench's SSH answer. The terralith returns no reach, for the reason given above, but the rules walk all of it.Three notes on correctness:
Subreference (Sub`${assets.Arn}/*`,{{resolve:secretsmanager:${Ref(secret)}}}) becomes{"$intrinsic": true}with no edge. The rows above that score full marks use a ~10-line local patch tograph-ir.ts(never pushed). I filed that gap as graph IR: a reference inside a CloudFormation Sub becomes an edge, not an opaque intrinsic #4373. The TF form needed nothing, because hcl2json resolves"${aws_s3_bucket.assets.arn}/*".MATCHwith a property filter on each rel finds 1 row on 5, 10 or 100 disjoint copies of a 6-node chain, where it should find 5, 10 or 100. With 4 hops it finds 2. The repro is below. In the prototype, the same multi-part pattern gave 0 or 1 rows depending on the order of its parts. AMERGEof a self-loop silently creates nothing. Its variable-length steps don't enforce distinct relationships (a 2-hop->()<-pattern counts the same edge twice), and$startsis refused as a parameter name. C matches the hand answers on the one-copy estate only because I rewrote its rules around each of these.Deny, IAMCondition,Resource: "*"ordata.aws_iam_policy_document. The estate has none of the first three on a path that matters, so the rules leave them out. Adding Deny needs negation in B (see below).LadybugDB repro (scratch dir,
node repro3.mjs 10)The rules in B, the language I recommend
These 16 lines are all of B. The same file ran unchanged against both forms. A capability with one variable is a node set, used as
[@name]. A capability with two is a named edge, followed as->name, and it carries the hops that proved it.Here is what
--explainprinted for one exfiltration match from B, on the Terraform form. The CloudFormation form reads the same with logical ids.An agent can quote that path, and behold can draw it (behold#907). It includes the trust statement that makes the assume-role hop real.
The prototype spells a step
->name?. In #4359's landed grammar (arrow, depth, qualifier, target), the same step would be->{0,1}[e=template]and->*[e=can-assume]. That way rules andchant searchshare one path syntax, and a capability becomes a search term:cap:internet-reachablefor a node set, or->[cap=reaches]for an edge.The same capabilities in C (Cypher, 45 lines) and A (TypeScript, 74 lines)
C is
c-rules.cypherin the prototype directory. One node tableR(id, label, ...)and one rel tableE(name, ev). Each binary capability isMERGE (a)-[e:E {name: 'grants'}]->(b) ON CREATE SET e.ev = properties(nodes(p), 'id'). Each node set is a witness edgeE {name: '@holds-secret'}, and conditions on it areEXISTS { MATCH (c)-[:E {name: '@internet-reachable'}]->(:R) }. Blast is a* SHORTEST 1..30overpivotedges,UNION ALLthe grants of each role reached.A is
a-ts.ts: helper closures over an edge index (out,inc,is), the same functions as the B rules, and BFS forreachesandblast, with each path built by hand. Today'sgraph-effective.tsscansir.edgeslinearly on every lookup. The prototype did the same at first and took 136 s at 58k nodes, then 176 ms once it had an index.Recommendation
Rule language: B, a small path-pattern language that extends #4359's search grammar. Core evaluates it with its own matcher over the IR. Each lexicon ships its rules and its label mapping as data.
B is the cheapest of the three that expresses all three capabilities. It took 16 lines against Cypher's 45 and TypeScript's 74. One file served both lexicons.
--explaingets every hop with no work from the rule author, and the run time is well under a millisecond on every real estate.Its cost is a matcher to build and keep correct. In the prototype that was 132 lines. A production version with error messages, the additions below and tests is plausibly a few hundred lines. The prototype's matcher is naive: it tries every node as a start for every rule. That still gave 394 ms at 58k nodes, and an index by label would cut it.
Cypher on LadybugDB should not evaluate rules. On this measurement it returned wrong answers to a plain multi-hop
MATCH, which is disqualifying for security questions until upstream fixes it. It also adds a 20 MB native dependency and a ~140 ms floor on every run, so it can't be the default under behold#906's "just works". The B rules could be translated to Cypher mechanically if an optional export (behold#906) ever wants them, so choosing B leaves that door open.TypeScript stays as the language of each lexicon's adapter (statements as nodes, link resources as edges, ARN-by-name resolution). It stops being the language of capabilities.
What B needs before it ships, all found by this measurement:
[!@cap]and!->edge. It is needed forattached-to-nothing(aws-bench's unused security groups and both negative questions) and for an explicitDenyoverriding anAllow.open-ingress(c; port), sotcp:22is an argument rather than a constant.Condition,Resource: "*"), so a fact computed from declared references says so in search's provenance line, as core: fold internetFacing and effectiveIngress onto Terraform's AWS kinds, not only CloudFormation's #4362 does.Where the catalog is published
The issue body proposed the MCP
searchtool's description. That tool searches the resource-type catalog, not the estate, so it's the wrong place (behold#908, "Design check: chant workspace and the read contract", finding 5). I recommend publishing the catalog through chant's read contract (ws-017,reference/workspace-read-contract.mdx), like every other document behold, hud and agents read:A contract document,
capabilities. It carriescontract,$schemaandchant, with failures aserror: { code, message }. Its schema goes undersrc/workspace/(for examplecapabilities.schema.json), and it is listed in the contract table and the conformance suite. One entry per capability gives:nameand a one-linemeaning;shape, eithersetoredge;params;search, the term it adds (cap:internet-reachable);answers, the questions it serves in people's words;depth:declared,liveoreither;lexicons, a map from lexicon tosupportedor a reason code such ascapability-not-derivable;rule, the rule text.chant search --capabilities --jsonprints it.Served by a chant MCP tool (for example
capabilities) that wraps the same document, asworkspace-graphandworkspace-lsalready do. behold passes the document through unchanged. An agent reads it once per session. The token cost of putting it in context is what the aws-bench run below measures.How rules evaluate across a declared workspace
chant workspace graphreads each member under its own toolchain and composes the results with<member>/<id>ids. Edges between members exist only through declared links. I recommend splitting the work at the view:chant graph. Their output (labels, statement and rule sub-nodes, derived edges) travels in the member's graph document at a detail tier, and is cached by the member's stamp like any other member read.platformgranted a bucket indata, an ARN that names a role in another member) can only cross over edges in the composed graph. So the composer needs a resolution pass for ARN and name references across members, emitted as edges withmemberon each end. Today those pairs are joined only through declared links.Evaluating rules per member and taking the union would miss exactly the cross-member exfiltration and blast paths the questions are about. It would also put the join in the reader, which ws-052 rules out. The capability results then belong in the workspace form of search (behold#908's proposal B,
chant workspace search), with each match carrying<member>/<id>and its path.First vocabulary
This starts from aws-bench's eight questions, behold#906's seven, and the security questions people ask most. B expressed every rule below that this measurement wrote. The rest need the negation and parameters listed above.
internet-facingopen-ingress(port?, proto?)effectiveIngressterminternet-reachable(port?)internet-facingandopen-ingress, or a function URL with no auth. Load balancers and API gateways come laterattached-to-nothingin-default-vpcstores-dataholds-secretencrypted-at-restpublicly-readable*and no public-access blockruns-ascan-assumegrants(action?)andreaches(action?)reachesiscan-assume*thengrantsnetworkexfiltratesinternet-reachable->runs-as->reaches->holds-secretblastpivot*(runs-as, can-assume, network), then what each identity reached is grantedbehold#906's question 5 (find resources by attribute) is what the catalog serves. Questions 1 to 4 and 6 are search features (#4359, #4358, #4360) rather than capabilities. Question 7 (choudoufu ownership) could be a later
owned-byset over thelive-plan -jsonread.Deferred to the end-of-run test pass
Item 5 of the issue, the aws-bench run with the catalog in the agent's context and without it, was not run, by the run's rule. The run I propose:
ec2-multiregionplus its negatives, k=3. One is today'schantarm (chant-ec2-multiregion-search-v2,briefing-chant-snapshot.md). The other ischant-catalog: the same source, with a briefing that appends thecapabilitiesdocument aschant search --capabilitiesprints it. Until that exists, a hand-written block of the vocabulary above stands in.MATRIX_NEGATIVES=1 just matrix 3 ../aws-bench chant chant-catalog.Filed while doing this: #4373, a feature to resolve references inside a CloudFormation
Subinto edges.lex00 commentedon Oct 23, 2026
Maintainer ruling (2026-10-23)
capabilitiesread-contract document served by chant's MCP (behold#908's read-contract ruling).Implementation: #4375. Part of INTENTIUS/behold#908.
lex00 commentedon Oct 23, 2026
Research done and ruled. Implementation is #4375.