@intentius/chant 0.124.44 → 0.124.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/capabilities/aws.paths +148 -0
  2. package/dist/capabilities/base-mappings.json +122 -0
  3. package/dist/capabilities/catalog.d.ts +89 -0
  4. package/dist/capabilities/catalog.d.ts.map +1 -0
  5. package/dist/capabilities/catalog.js +204 -0
  6. package/dist/capabilities/language.d.ts +103 -0
  7. package/dist/capabilities/language.d.ts.map +1 -0
  8. package/dist/capabilities/language.js +335 -0
  9. package/dist/capabilities/matcher.d.ts +65 -0
  10. package/dist/capabilities/matcher.d.ts.map +1 -0
  11. package/dist/capabilities/matcher.js +299 -0
  12. package/dist/capabilities/view.d.ts +207 -0
  13. package/dist/capabilities/view.d.ts.map +1 -0
  14. package/dist/capabilities/view.js +484 -0
  15. package/dist/ci-identity.d.ts +183 -12
  16. package/dist/ci-identity.d.ts.map +1 -1
  17. package/dist/ci-identity.js +362 -53
  18. package/dist/cli/commands/lint.d.ts.map +1 -1
  19. package/dist/cli/commands/lint.js +1 -0
  20. package/dist/cli/handlers/build.d.ts.map +1 -1
  21. package/dist/cli/handlers/build.js +17 -1
  22. package/dist/cli/handlers/declared-graph.d.ts +44 -0
  23. package/dist/cli/handlers/declared-graph.d.ts.map +1 -0
  24. package/dist/cli/handlers/declared-graph.js +87 -0
  25. package/dist/cli/handlers/graph.d.ts +25 -0
  26. package/dist/cli/handlers/graph.d.ts.map +1 -1
  27. package/dist/cli/handlers/graph.js +93 -87
  28. package/dist/cli/handlers/pr-env.d.ts +8 -2
  29. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  30. package/dist/cli/handlers/pr-env.js +127 -225
  31. package/dist/cli/handlers/pr.d.ts +3 -0
  32. package/dist/cli/handlers/pr.d.ts.map +1 -1
  33. package/dist/cli/handlers/pr.js +1 -0
  34. package/dist/cli/handlers/search-count.d.ts +89 -0
  35. package/dist/cli/handlers/search-count.d.ts.map +1 -0
  36. package/dist/cli/handlers/search-count.js +132 -0
  37. package/dist/cli/handlers/search.d.ts +358 -6
  38. package/dist/cli/handlers/search.d.ts.map +1 -1
  39. package/dist/cli/handlers/search.js +1065 -155
  40. package/dist/cli/main.d.ts.map +1 -1
  41. package/dist/cli/main.js +23 -3
  42. package/dist/cli/mcp/server.d.ts.map +1 -1
  43. package/dist/cli/mcp/server.js +3 -0
  44. package/dist/cli/mcp/tools/capabilities.d.ts +7 -0
  45. package/dist/cli/mcp/tools/capabilities.d.ts.map +1 -0
  46. package/dist/cli/mcp/tools/capabilities.js +27 -0
  47. package/dist/cli/mcp/workspace-tools.d.ts +3 -1
  48. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  49. package/dist/cli/mcp/workspace-tools.js +47 -2
  50. package/dist/cli/parse-args.d.ts.map +1 -1
  51. package/dist/cli/parse-args.js +64 -17
  52. package/dist/cli/registry.d.ts +22 -0
  53. package/dist/cli/registry.d.ts.map +1 -1
  54. package/dist/components/cli-support.d.ts +2 -0
  55. package/dist/components/cli-support.d.ts.map +1 -1
  56. package/dist/components/cli-support.js +4 -2
  57. package/dist/components/fan-out-support.d.ts +3 -0
  58. package/dist/components/fan-out-support.d.ts.map +1 -1
  59. package/dist/components/fan-out-support.js +1 -1
  60. package/dist/components/pr-env-ports.d.ts +29 -0
  61. package/dist/components/pr-env-ports.d.ts.map +1 -0
  62. package/dist/components/pr-env-ports.js +77 -0
  63. package/dist/components/pr-env-run.d.ts +254 -0
  64. package/dist/components/pr-env-run.d.ts.map +1 -0
  65. package/dist/components/pr-env-run.js +376 -0
  66. package/dist/components/pr-environment.d.ts +91 -15
  67. package/dist/components/pr-environment.d.ts.map +1 -1
  68. package/dist/components/pr-environment.js +95 -9
  69. package/dist/components/pr-pipeline.d.ts +10 -1
  70. package/dist/components/pr-pipeline.d.ts.map +1 -1
  71. package/dist/config-environments.d.ts +92 -0
  72. package/dist/config-environments.d.ts.map +1 -0
  73. package/dist/config-environments.js +102 -0
  74. package/dist/config.d.ts +24 -84
  75. package/dist/config.d.ts.map +1 -1
  76. package/dist/config.js +9 -96
  77. package/dist/graph-detail.d.ts.map +1 -1
  78. package/dist/graph-detail.js +15 -3
  79. package/dist/graph-effective.d.ts +33 -2
  80. package/dist/graph-effective.d.ts.map +1 -1
  81. package/dist/graph-effective.js +215 -68
  82. package/dist/graph-ir.d.ts +23 -0
  83. package/dist/graph-ir.d.ts.map +1 -1
  84. package/dist/graph-ir.js +130 -0
  85. package/dist/graph-sub-template.d.ts +11 -0
  86. package/dist/graph-sub-template.d.ts.map +1 -0
  87. package/dist/graph-sub-template.js +19 -0
  88. package/dist/lexicon.d.ts +9 -0
  89. package/dist/lexicon.d.ts.map +1 -1
  90. package/dist/lifecycle/observe.d.ts +28 -0
  91. package/dist/lifecycle/observe.d.ts.map +1 -1
  92. package/dist/lifecycle/observe.js +23 -1
  93. package/dist/lint/rule.d.ts +6 -0
  94. package/dist/lint/rule.d.ts.map +1 -1
  95. package/dist/live-endpoint.d.ts +1 -1
  96. package/dist/live-endpoint.d.ts.map +1 -1
  97. package/dist/live-endpoint.js +1 -1
  98. package/dist/observation.d.ts +48 -1
  99. package/dist/observation.d.ts.map +1 -1
  100. package/dist/observation.js +21 -5
  101. package/dist/op/activities/activity-contracts.d.ts +4 -4
  102. package/dist/op/op-waves.d.ts +17 -0
  103. package/dist/op/op-waves.d.ts.map +1 -1
  104. package/dist/op/op-waves.js +23 -1
  105. package/dist/pr-forge.d.ts +15 -1
  106. package/dist/pr-forge.d.ts.map +1 -1
  107. package/dist/pr-forge.js +28 -16
  108. package/dist/pr-requires.d.ts +5 -1
  109. package/dist/pr-requires.d.ts.map +1 -1
  110. package/dist/wave-runtime.mjs +251 -250
  111. package/dist/workspace/capabilities-contract.d.ts +66 -0
  112. package/dist/workspace/capabilities-contract.d.ts.map +1 -0
  113. package/dist/workspace/capabilities-contract.js +107 -0
  114. package/dist/workspace/capabilities.schema.json +229 -0
  115. package/dist/workspace/ci-cloud-identity.d.ts +3 -1
  116. package/dist/workspace/ci-cloud-identity.d.ts.map +1 -1
  117. package/dist/workspace/ci-cloud-identity.js +16 -1
  118. package/dist/workspace/ci-run.d.ts +35 -8
  119. package/dist/workspace/ci-run.d.ts.map +1 -1
  120. package/dist/workspace/ci-run.js +95 -21
  121. package/dist/workspace/ci-secrets.d.ts.map +1 -1
  122. package/dist/workspace/ci-secrets.js +4 -3
  123. package/dist/workspace/compose-graph.d.ts +9 -0
  124. package/dist/workspace/compose-graph.d.ts.map +1 -1
  125. package/dist/workspace/compose-graph.js +3 -1
  126. package/dist/workspace/conformance/index.d.ts +1 -1
  127. package/dist/workspace/conformance/index.d.ts.map +1 -1
  128. package/dist/workspace/conformance/index.js +39 -2
  129. package/dist/workspace/declaration.d.ts +10 -0
  130. package/dist/workspace/declaration.d.ts.map +1 -1
  131. package/dist/workspace/declaration.js +17 -1
  132. package/dist/workspace/declaration.schema.json +36 -1
  133. package/dist/workspace/graph-cache.d.ts +8 -0
  134. package/dist/workspace/graph-cache.d.ts.map +1 -1
  135. package/dist/workspace/graph-cache.js +27 -3
  136. package/dist/workspace/graph-cli.d.ts +39 -2
  137. package/dist/workspace/graph-cli.d.ts.map +1 -1
  138. package/dist/workspace/graph-cli.js +66 -24
  139. package/dist/workspace/graph.schema.json +148 -0
  140. package/dist/workspace/kind-readers.d.ts +3 -0
  141. package/dist/workspace/kind-readers.d.ts.map +1 -1
  142. package/dist/workspace/kind-readers.js +7 -1
  143. package/dist/workspace/member-commands.d.ts +10 -1
  144. package/dist/workspace/member-commands.d.ts.map +1 -1
  145. package/dist/workspace/member-commands.js +17 -1
  146. package/dist/workspace/nested-graph.d.ts +2 -0
  147. package/dist/workspace/nested-graph.d.ts.map +1 -1
  148. package/dist/workspace/nested-graph.js +32 -1
  149. package/dist/workspace/reason-codes.d.ts +10 -0
  150. package/dist/workspace/reason-codes.d.ts.map +1 -1
  151. package/dist/workspace/reason-codes.js +12 -0
  152. package/dist/workspace/search-cli.d.ts +204 -0
  153. package/dist/workspace/search-cli.d.ts.map +1 -0
  154. package/dist/workspace/search-cli.js +466 -0
  155. package/dist/workspace/search-contract.d.ts +56 -0
  156. package/dist/workspace/search-contract.d.ts.map +1 -0
  157. package/dist/workspace/search-contract.js +70 -0
  158. package/dist/workspace/search.schema.json +822 -0
  159. package/package.json +1 -1
  160. package/src/__snapshots__/okf.test.ts.snap +10 -0
  161. package/src/capabilities/aws.paths +148 -0
  162. package/src/capabilities/base-mappings.json +122 -0
  163. package/src/capabilities/catalog.ts +230 -0
  164. package/src/capabilities/language.test.ts +191 -0
  165. package/src/capabilities/language.ts +373 -0
  166. package/src/capabilities/matcher.ts +315 -0
  167. package/src/capabilities/view-compose.test.ts +76 -0
  168. package/src/capabilities/view.ts +631 -0
  169. package/src/ci-identity-targets.test.ts +275 -0
  170. package/src/ci-identity.ts +394 -61
  171. package/src/cli/commands/lint.ts +1 -0
  172. package/src/cli/handlers/build.ts +15 -1
  173. package/src/cli/handlers/declared-graph.ts +99 -0
  174. package/src/cli/handlers/graph.test.ts +94 -3
  175. package/src/cli/handlers/graph.ts +123 -96
  176. package/src/cli/handlers/pr-env.ts +135 -227
  177. package/src/cli/handlers/pr.ts +4 -0
  178. package/src/cli/handlers/search-build-roots.test.ts +144 -0
  179. package/src/cli/handlers/search-count.test.ts +191 -0
  180. package/src/cli/handlers/search-count.ts +165 -0
  181. package/src/cli/handlers/search-json.test.ts +333 -0
  182. package/src/cli/handlers/search-live.test.ts +387 -0
  183. package/src/cli/handlers/search-paths.test.ts +235 -0
  184. package/src/cli/handlers/search.ts +1312 -166
  185. package/src/cli/main.test.ts +28 -3
  186. package/src/cli/main.ts +23 -3
  187. package/src/cli/mcp/server.test.ts +3 -3
  188. package/src/cli/mcp/server.ts +3 -0
  189. package/src/cli/mcp/tools/capabilities.ts +32 -0
  190. package/src/cli/mcp/workspace-tools.e2e.test.ts +21 -1
  191. package/src/cli/mcp/workspace-tools.ts +47 -2
  192. package/src/cli/parse-args.ts +52 -13
  193. package/src/cli/registry.ts +22 -0
  194. package/src/components/cli-support.ts +6 -1
  195. package/src/components/fan-out-support.ts +4 -1
  196. package/src/components/pr-env-ports.ts +89 -0
  197. package/src/components/pr-env-run-bundle.test.ts +54 -0
  198. package/src/components/pr-env-run.test.ts +290 -0
  199. package/src/components/pr-env-run.ts +563 -0
  200. package/src/components/pr-environment.ts +161 -13
  201. package/src/components/pr-pipeline.ts +10 -1
  202. package/src/config-environments.ts +133 -0
  203. package/src/config.ts +37 -124
  204. package/src/graph-detail.ts +15 -3
  205. package/src/graph-effective.ts +226 -75
  206. package/src/graph-ir.test.ts +163 -0
  207. package/src/graph-ir.ts +147 -0
  208. package/src/graph-sub-template.ts +22 -0
  209. package/src/lexicon.ts +10 -0
  210. package/src/lifecycle/observe.test.ts +27 -1
  211. package/src/lifecycle/observe.ts +43 -1
  212. package/src/lint/rule.ts +6 -0
  213. package/src/live-endpoint.ts +1 -1
  214. package/src/observation.test.ts +25 -0
  215. package/src/observation.ts +69 -5
  216. package/src/op/op-waves.ts +38 -1
  217. package/src/pr-forge-bundle.test.ts +1 -1
  218. package/src/pr-forge.ts +44 -17
  219. package/src/pr-requires.test.ts +43 -6
  220. package/src/pr-requires.ts +5 -1
  221. package/src/workspace/capabilities-contract.test.ts +88 -0
  222. package/src/workspace/capabilities-contract.ts +132 -0
  223. package/src/workspace/capabilities.schema.json +229 -0
  224. package/src/workspace/ci-cloud-identity.test.ts +20 -0
  225. package/src/workspace/ci-cloud-identity.ts +14 -1
  226. package/src/workspace/ci-run.test.ts +74 -1
  227. package/src/workspace/ci-run.ts +122 -29
  228. package/src/workspace/ci-secrets.test.ts +1 -1
  229. package/src/workspace/ci-secrets.ts +4 -3
  230. package/src/workspace/compose-graph.ts +10 -1
  231. package/src/workspace/conformance/conformance.e2e.test.ts +14 -1
  232. package/src/workspace/conformance/index.ts +31 -2
  233. package/src/workspace/declaration.schema.json +36 -1
  234. package/src/workspace/declaration.test.ts +7 -0
  235. package/src/workspace/declaration.ts +24 -2
  236. package/src/workspace/graph-cache.ts +27 -3
  237. package/src/workspace/graph-cli.ts +96 -24
  238. package/src/workspace/graph.schema.json +148 -0
  239. package/src/workspace/kind-readers.e2e.test.ts +28 -0
  240. package/src/workspace/kind-readers.test.ts +1 -1
  241. package/src/workspace/kind-readers.ts +7 -1
  242. package/src/workspace/member-commands.ts +22 -1
  243. package/src/workspace/nested-graph.ts +32 -1
  244. package/src/workspace/reason-codes.test.ts +7 -0
  245. package/src/workspace/reason-codes.ts +12 -0
  246. package/src/workspace/search-cli.e2e.test.ts +305 -0
  247. package/src/workspace/search-cli.ts +591 -0
  248. package/src/workspace/search-contract.ts +95 -0
  249. package/src/workspace/search.schema.json +822 -0
@@ -0,0 +1,148 @@
1
+ # Capabilities over AWS resources (#4375, ruled on #4361).
2
+ #
3
+ # Rules read the lexicon-neutral view, not the IR. Labels (Instance, Role,
4
+ # SecurityGroup) and edge names (subnet, sg, statement) come from each
5
+ # lexicon's mapping, so this one file serves CloudFormation (the aws lexicon)
6
+ # and Terraform's AWS provider (the terraform lexicon) alike.
7
+ #
8
+ # name(x) is a node set, tested with [@name]. name(a, b) is an edge, followed
9
+ # with ->name. Parameters follow `;`. The language is in language.ts.
10
+ #
11
+ # `## key: value` lines describe the capability that follows them, for the
12
+ # `capabilities` document: meaning, answers (one per line), depth, search,
13
+ # not-evaluated, and a line per parameter (param-<name>). A rule with no
14
+ # `## meaning` is a helper: other rules use it, the catalog doesn't list it.
15
+
16
+ # ------------------------------------------------------------------ helpers
17
+
18
+ in-sg(x, g) := x ->{0,1}template ->sg g:SecurityGroup
19
+ ingress-of(x, r) := x ->in-sg ->ingress r:IngressRule
20
+ world-open(r) := r:IngressRule[cidrs in ("0.0.0.0/0", "::/0")]
21
+ allows(r, x; action?) := r:Role <-{0,1}attachedTo ->statement :Statement[doc = "permission", effect = "Allow", actions ~ $action] ->resource x
22
+ | r:Role <-principal :Statement[doc = "resource", effect = "Allow", actions ~ $action] ->resource x
23
+ denies(r, x; action?) := r:Role <-{0,1}attachedTo ->statement :Statement[doc = "permission", effect = "Deny", actions ~ $action] ->resource x
24
+ | r:Role <-principal :Statement[doc = "resource", effect = "Deny", actions ~ $action] ->resource x
25
+ pivot(a, b) := a ->(runs-as|can-assume|network) b
26
+
27
+ # ------------------------------------------------------------------ network
28
+
29
+ ## meaning: its subnet routes 0.0.0.0/0 to an internet gateway
30
+ ## answers: which instances are in a public subnet
31
+ ## answers: what sits in a subnet that routes to the internet
32
+ ## depth: either
33
+ ## not-evaluated: a subnet on its VPC's main route table (no explicit association) is not followed
34
+ internet-facing(c) := c:Instance ->subnet :Subnet <-subnet :RouteTableAssociation ->table :RouteTable <-table :Route[dest in ("0.0.0.0/0", "::/0", null)] ->gateway :InternetGateway
35
+ | c:Instance[internetFacing = true]
36
+
37
+ ## meaning: a security group reaching it, directly or through a launch template, admits 0.0.0.0/0 or ::/0
38
+ ## param-port: a port the open rule must cover, such as 22
39
+ ## param-proto: a protocol the open rule must allow, such as tcp; a rule for every protocol (-1) always does
40
+ ## answers: what admits SSH from anywhere
41
+ ## answers: which instances have a security group open to the world
42
+ ## depth: declared
43
+ ## not-evaluated: network ACLs; prefix lists
44
+ open-ingress(c; port?, proto?) := c:Instance|Database|Function|Service ->ingress-of r:IngressRule[@world-open, from <= $port, to >= $port, proto in ($proto, "-1")]
45
+
46
+ ## meaning: internet-facing and open-ingress, or a Lambda function URL with no auth. Load balancers and API gateways come later
47
+ ## param-port: a port the open rule must cover, such as 22
48
+ ## answers: what in prod can be reached on SSH from the internet
49
+ ## answers: which instances are SSH-reachable from the internet
50
+ ## depth: either
51
+ ## not-evaluated: load balancers; API gateways; network ACLs
52
+ internet-reachable(c; port?) := c[@internet-facing, @open-ingress($port)]
53
+ | c:Function <-function :FunctionUrl[authType = "NONE"]
54
+
55
+ ## meaning: no member, attachment or route references it
56
+ ## answers: which security groups are unused
57
+ ## answers: which subnets have no instances or network interfaces
58
+ ## answers: which policies are attached to nothing
59
+ ## depth: either
60
+ attached-to-nothing(x) := x:SecurityGroup !<-sg
61
+ | x:Subnet !<-subnet
62
+ | x:Policy !->attachedTo
63
+ | x:InternetGateway !<-gateway
64
+
65
+ ## meaning: in the account's default VPC
66
+ ## answers: which instances run in the default VPC
67
+ ## answers: which instances are not in the default VPC (negate it: !cap:in-default-vpc)
68
+ ## depth: either
69
+ in-default-vpc(x) := x ->{1,2}(subnet|vpc) :Vpc[isDefault = true]
70
+
71
+ ## meaning: host to host through security-group-to-group ingress
72
+ ## answers: what can this instance reach on the network
73
+ ## depth: declared
74
+ ## not-evaluated: CIDR-to-CIDR reachability inside the VPC; network ACLs
75
+ network(a, y) := a:Instance|Database|Function|Service ->in-sg <-source :IngressRule <-ingress :SecurityGroup <-in-sg y:Instance|Database|Function|Service
76
+
77
+ # ------------------------------------------------------------------ data
78
+
79
+ ## meaning: a bucket, table, database, queue, file system or secret
80
+ ## answers: where is our data
81
+ ## depth: declared
82
+ stores-data(x) := x:Bucket|Table|Database|Queue|FileSystem|Secret|Parameter
83
+
84
+ ## meaning: a secret, an SSM SecureString, or a data store tagged as restricted (the tag keys are the lexicon mapping's classificationTags)
85
+ ## answers: which stores hold secrets or restricted data
86
+ ## depth: declared
87
+ holds-secret(x) := x:Secret
88
+ | x:Parameter[paramType = "SecureString"]
89
+ | x:Bucket|Table|Database|Queue|FileSystem[classification in ("restricted", "secret", "confidential")]
90
+
91
+ ## meaning: encrypted at rest: a database, file system or volume whose encryption attribute is set; S3 buckets, DynamoDB tables, SQS queues and secrets always are
92
+ ## answers: which data stores are not encrypted at rest (negate it: !cap:encrypted-at-rest)
93
+ ## depth: declared
94
+ ## not-evaluated: account-level EBS encryption by default; which key (AWS-owned, AWS-managed or customer-managed)
95
+ encrypted-at-rest(x) := x:Database|FileSystem|Volume[encrypted = true]
96
+ | x:Bucket|Table|Queue|Secret
97
+
98
+ ## meaning: a bucket whose policy allows principal * and no public-access block stops it, or a public ACL
99
+ ## answers: what is public
100
+ ## answers: which buckets can anyone read
101
+ ## depth: declared
102
+ ## not-evaluated: IAM Condition keys; account-level public-access blocks
103
+ publicly-readable(x) := x:Bucket[!blockPublicPolicy = true] !<-blocks :PublicAccessBlock[blockPublicPolicy = true] <-policyOf :ResourcePolicy ->statement :Statement[doc = "resource", effect = "Allow", principals in ("*")]
104
+ | x:Bucket[acl in ("public-read", "public-read-write")]
105
+
106
+ # ------------------------------------------------------------------ identity
107
+
108
+ ## meaning: compute to the role it runs as (instance profile, also through a launch template; Lambda role; ECS task role)
109
+ ## answers: what identity does this instance run as
110
+ ## depth: declared
111
+ runs-as(c, r) := c:Instance|Function|Service|TaskDefinition ->{0,1}template ->{0,1}(profile|task) ->role r:Role
112
+
113
+ ## meaning: role to role, where both the caller's permission and the target's trust allow sts:AssumeRole
114
+ ## answers: which roles can this role become
115
+ ## depth: declared
116
+ ## not-evaluated: IAM Condition keys; Resource "*"; a trust policy that names the account root
117
+ can-assume(a, b) := a:Role <-{0,1}attachedTo ->statement :Statement[doc = "permission", effect = "Allow", actions ~ "sts:AssumeRole"] ->resource b:Role ->statement :Statement[doc = "trust", actions ~ "sts:AssumeRole"] ->principal a
118
+
119
+ ## meaning: role to resource, by an identity policy or a resource policy, with no explicit Deny on the same pair
120
+ ## param-action: an IAM action the grant must cover, such as dynamodb:GetItem
121
+ ## answers: what can this role touch
122
+ ## answers: what can reach the customer database (read it in reverse: <-[cap=grants])
123
+ ## depth: declared
124
+ ## not-evaluated: IAM Condition keys; Resource "*"; NotAction and NotResource; permission boundaries and SCPs; AWS-managed policies, named by ARN only; resources the graph holds but can't resolve, such as an expression naming nothing declared
125
+ grants(r, x; action?) := r:Role ->allows($action) x !<-denies($action) r
126
+
127
+ ## meaning: can-assume any number of times, then grants
128
+ ## param-action: an IAM action the grant must cover, such as s3:GetObject
129
+ ## answers: if this role is compromised, what data can it reach
130
+ ## answers: what can reach the customer database (read it in reverse: <-[cap=reaches])
131
+ ## depth: declared
132
+ ## not-evaluated: IAM Condition keys; Resource "*"; NotAction and NotResource; permission boundaries and SCPs; AWS-managed policies, named by ARN only; resources the graph holds but can't resolve, such as an expression naming nothing declared
133
+ reaches(r, x; action?) := r:Role ->{0,}can-assume ->grants($action) x
134
+
135
+ # ------------------------------------------------------------------ paths
136
+
137
+ ## meaning: internet-reachable compute that runs as a role that reaches a store holding a secret
138
+ ## answers: is there an exfiltration path from the internet to our data
139
+ ## answers: which internet-facing hosts can read restricted data
140
+ ## depth: declared
141
+ ## not-evaluated: IAM Condition keys; Resource "*"; load balancers and API gateways; resources the graph holds but can't resolve, such as an expression naming nothing declared
142
+ exfiltrates(c, x) := c[@internet-reachable] ->runs-as ->reaches x[@holds-secret]
143
+
144
+ ## meaning: what a compromise of it reaches: runs-as, can-assume and network any number of times, then what each identity is granted
145
+ ## answers: what is the blast radius if this host is compromised
146
+ ## depth: declared
147
+ ## not-evaluated: IAM Condition keys; Resource "*"; CIDR-to-CIDR reachability; resources the graph holds but can't resolve, such as an expression naming nothing declared
148
+ blast(s, x) := s ->{0,}pivot ->{0,1}grants x
@@ -0,0 +1,122 @@
1
+ {
2
+ "$comment": "The kinds core's effective-topology folds read (#1139, #4362), as data. These were constants in graph-effective.ts; they stay in core so the folds work on a graph read without its lexicon's plugin. Each lexicon's own mapping (src/capabilities/mapping.json) extends its entry here.",
3
+ "mappings": [
4
+ {
5
+ "lexicon": "aws",
6
+ "types": "kind",
7
+ "refs": "cloudformation",
8
+ "labels": {
9
+ "AWS::EC2::Instance": "Instance",
10
+ "AWS::EC2::LaunchTemplate": "LaunchTemplate",
11
+ "AWS::EC2::SecurityGroup": "SecurityGroup",
12
+ "AWS::EC2::SecurityGroupIngress": { "label": "IngressRule", "style": "cfn" },
13
+ "AWS::EC2::Subnet": "Subnet",
14
+ "AWS::EC2::SubnetRouteTableAssociation": "RouteTableAssociation",
15
+ "AWS::EC2::RouteTable": "RouteTable",
16
+ "AWS::EC2::Route": "Route",
17
+ "AWS::EC2::InternetGateway": "InternetGateway"
18
+ },
19
+ "edges": {
20
+ "Instance": {
21
+ "SecurityGroupIds": "sg",
22
+ "SecurityGroupId": "sg",
23
+ "LaunchTemplate": "template",
24
+ "LaunchTemplateId": "template",
25
+ "SubnetId": "subnet"
26
+ },
27
+ "LaunchTemplate": {
28
+ "LaunchTemplateData": { "SecurityGroup": "sg" },
29
+ "SecurityGroupIds": "sg",
30
+ "SecurityGroupId": "sg"
31
+ },
32
+ "IngressRule": { "GroupId": "-ingress", "SourceSecurityGroupId": "source" },
33
+ "RouteTableAssociation": { "SubnetId": "subnet", "RouteTableId": "table" },
34
+ "Route": { "RouteTableId": "table", "GatewayId": "gateway" }
35
+ },
36
+ "attrs": {
37
+ "Route": { "dest": "DestinationCidrBlock" },
38
+ "IngressRule": { "proto": "IpProtocol", "from": "FromPort", "to": "ToPort", "cidrs": { "all": ["CidrIp", "CidrIpv6"] } }
39
+ },
40
+ "blocks": {
41
+ "SecurityGroup": [
42
+ {
43
+ "attr": "SecurityGroupIngress",
44
+ "label": "IngressRule",
45
+ "edge": "ingress",
46
+ "style": "cfn",
47
+ "attrs": { "proto": "IpProtocol", "from": "FromPort", "to": "ToPort", "cidrs": { "all": ["CidrIp", "CidrIpv6"] } },
48
+ "refs": { "SourceSecurityGroupId": "source" }
49
+ }
50
+ ]
51
+ }
52
+ },
53
+ {
54
+ "lexicon": "terraform",
55
+ "types": "terraform",
56
+ "body": "body",
57
+ "refs": "terraform",
58
+ "labels": {
59
+ "aws_instance": "Instance",
60
+ "aws_launch_template": "LaunchTemplate",
61
+ "aws_security_group": "SecurityGroup",
62
+ "aws_security_group_rule": { "label": "IngressRule", "when": { "type": "ingress" }, "style": "tf-sg-rule" },
63
+ "aws_vpc_security_group_ingress_rule": { "label": "IngressRule", "style": "tf-vpc-rule" },
64
+ "aws_subnet": "Subnet",
65
+ "aws_route_table_association": "RouteTableAssociation",
66
+ "aws_route_table": "RouteTable",
67
+ "aws_route": "Route",
68
+ "aws_internet_gateway": "InternetGateway"
69
+ },
70
+ "edges": {
71
+ "Instance": {
72
+ "vpc_security_group_ids": "sg",
73
+ "security_groups": "sg",
74
+ "launch_template": "template",
75
+ "subnet_id": "subnet"
76
+ },
77
+ "LaunchTemplate": {
78
+ "vpc_security_group_ids": "sg",
79
+ "security_group_names": "sg",
80
+ "network_interfaces": { "SecurityGroup": "sg" }
81
+ },
82
+ "IngressRule": {
83
+ "security_group_id": "-ingress",
84
+ "source_security_group_id": "source",
85
+ "referenced_security_group_id": "source"
86
+ },
87
+ "RouteTableAssociation": { "subnet_id": "subnet", "route_table_id": "table" },
88
+ "Route": { "route_table_id": "table", "gateway_id": "gateway" }
89
+ },
90
+ "attrs": {
91
+ "Route": { "dest": ["destination_cidr_block", "destination_ipv6_cidr_block"] },
92
+ "IngressRule": {
93
+ "proto": ["ip_protocol", "protocol"],
94
+ "from": "from_port",
95
+ "to": "to_port",
96
+ "cidrs": { "all": ["cidr_blocks", "ipv6_cidr_blocks", "cidr_ipv4", "cidr_ipv6"] }
97
+ }
98
+ },
99
+ "blocks": {
100
+ "SecurityGroup": [
101
+ {
102
+ "attr": "ingress",
103
+ "label": "IngressRule",
104
+ "edge": "ingress",
105
+ "style": "tf-inline",
106
+ "attrs": { "proto": "protocol", "from": "from_port", "to": "to_port", "cidrs": { "all": ["cidr_blocks", "ipv6_cidr_blocks"] } },
107
+ "refs": { "security_groups": "source" }
108
+ }
109
+ ],
110
+ "RouteTable": [
111
+ {
112
+ "attr": "route",
113
+ "label": "Route",
114
+ "edge": "-table",
115
+ "attrs": { "dest": ["cidr_block", "ipv6_cidr_block"] },
116
+ "refs": { "gateway_id": "gateway" }
117
+ }
118
+ ]
119
+ }
120
+ }
121
+ ]
122
+ }
@@ -0,0 +1,89 @@
1
+ import type { GraphIR } from "../graph-ir.js";
2
+ import { type Literal, type Rule } from "./language.js";
3
+ import { CapabilityEngine } from "./matcher.js";
4
+ import { type CapabilityMapping, type CapabilityPack, type View } from "./view.js";
5
+ /** Every rule core ships, parsed, with the file each came from. */
6
+ export declare function shippedRules(): {
7
+ rules: Rule[];
8
+ sources: Map<string, string>;
9
+ };
10
+ /** The mappings core's folds need, for a graph read without its lexicon's plugin. */
11
+ export declare function basePacks(): CapabilityPack[];
12
+ /**
13
+ * Register a lexicon's pack for callers that hold no plugin list (the folds,
14
+ * a test). A plugin's `capabilityPack` reaches search without this.
15
+ */
16
+ export declare function registerCapabilityPack(pack: CapabilityPack): void;
17
+ /** Base packs, registered packs, then the packs given: later ones extend earlier ones. */
18
+ export declare function resolvePacks(packs?: CapabilityPack[]): CapabilityPack[];
19
+ /**
20
+ * The capability engine for a graph, built once per graph object. Packs
21
+ * passed on the first call for a graph are the ones it uses.
22
+ */
23
+ export declare function capabilityEngine(ir: GraphIR, packs?: CapabilityPack[]): CapabilityEngine;
24
+ /** Bind a graph to the packs its search was given, before anything asks for a capability. */
25
+ export declare function attachCapabilities(ir: GraphIR, packs: CapabilityPack[]): CapabilityEngine;
26
+ /**
27
+ * Bind a graph to a view built elsewhere (#4378): a workspace's composed
28
+ * view, which each member's own chant mapped. The rules are this chant's.
29
+ */
30
+ export declare function attachView(ir: GraphIR, view: View): CapabilityEngine;
31
+ /**
32
+ * Read `name` or `name(arg, ...)`, as a search term or an edge qualifier
33
+ * spells a capability. An argument is a number, `true`/`false`, or text,
34
+ * quoted or not.
35
+ */
36
+ export declare function parseCapabilityCall(text: string): {
37
+ name: string;
38
+ args: (Literal | undefined)[];
39
+ } | undefined;
40
+ /** Public capabilities: those whose rule carries a `## meaning`. Helpers carry none. */
41
+ export declare function isPublic(rule: Rule): boolean;
42
+ /**
43
+ * Whether a lexicon can supply a capability: its own statement when its
44
+ * mapping makes one, otherwise whether every label one alternative needs
45
+ * is one the mapping labels.
46
+ */
47
+ export declare function lexiconSupport(rule: Rule, mapping: CapabilityMapping | undefined, lexicon: string): "supported" | {
48
+ code: string;
49
+ message: string;
50
+ };
51
+ /** The capabilities a rule uses, directly. */
52
+ export declare function usesOf(rule: Rule): string[];
53
+ /** One capability as the `capabilities` document lists it (#4375). */
54
+ export interface CapabilityEntry {
55
+ name: string;
56
+ meaning: string;
57
+ shape: "set" | "edge";
58
+ params: {
59
+ name: string;
60
+ optional: boolean;
61
+ meaning: string;
62
+ }[];
63
+ /** The search term that asks for it: `cap:<name>` for a set, `->[cap=<name>]` for an edge. */
64
+ search: string;
65
+ answers: string[];
66
+ depth: "declared" | "live" | "either";
67
+ lexicons: Record<string, "supported" | {
68
+ code: string;
69
+ message: string;
70
+ }>;
71
+ notEvaluated: string[];
72
+ /** The capabilities and helpers its rule uses. */
73
+ uses: string[];
74
+ rule: string;
75
+ }
76
+ /**
77
+ * The catalog as the `capabilities` document carries it: every public
78
+ * capability, with whether each lexicon given can supply it, and the helper
79
+ * rules they use. `lexicons` maps each lexicon to its mapping, or to
80
+ * undefined when it ships none.
81
+ */
82
+ export declare function capabilityCatalog(lexicons: Record<string, CapabilityMapping | undefined>): {
83
+ capabilities: CapabilityEntry[];
84
+ helpers: {
85
+ name: string;
86
+ rule: string;
87
+ }[];
88
+ };
89
+ //# sourceMappingURL=catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/capabilities/catalog.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,204 @@
1
+ /**
2
+ * The capability catalog (#4375): the rule files core ships, the packs
3
+ * lexicons contribute, and the engine that evaluates one over a graph.
4
+ *
5
+ * Rules are data: `aws.paths` beside this module, read at run time. It serves
6
+ * every lexicon that maps AWS resources onto the view (the aws lexicon's
7
+ * CloudFormation kinds and the terraform lexicon's AWS provider types), so it
8
+ * lives here rather than in either lexicon. Each lexicon ships its mapping
9
+ * (data) and, where it needs one, an adapter (code), as a `CapabilityPack` on
10
+ * its plugin.
11
+ */
12
+ import { readFileSync } from "node:fs";
13
+ import { parseRules, ruleDependencies } from "./language.js";
14
+ import { CapabilityEngine } from "./matcher.js";
15
+ import { buildView, mergeMappings } from "./view.js";
16
+ import base from "./base-mappings.json" with { type: "json" };
17
+ /** The rule files core ships, by name. */
18
+ const RULE_FILES = ["aws.paths"];
19
+ let rulesCache;
20
+ /** Every rule core ships, parsed, with the file each came from. */
21
+ export function shippedRules() {
22
+ if (rulesCache)
23
+ return rulesCache;
24
+ const rules = [];
25
+ const sources = new Map();
26
+ for (const file of RULE_FILES) {
27
+ const text = readFileSync(new URL(`./${file}`, import.meta.url), "utf-8");
28
+ for (const r of parseRules(text)) {
29
+ rules.push(r);
30
+ sources.set(r.name, file);
31
+ }
32
+ }
33
+ rulesCache = { rules, sources };
34
+ return rulesCache;
35
+ }
36
+ /** The mappings core's folds need, for a graph read without its lexicon's plugin. */
37
+ export function basePacks() {
38
+ return base.mappings.map((mapping) => ({ mapping }));
39
+ }
40
+ const registered = [];
41
+ /**
42
+ * Register a lexicon's pack for callers that hold no plugin list (the folds,
43
+ * a test). A plugin's `capabilityPack` reaches search without this.
44
+ */
45
+ export function registerCapabilityPack(pack) {
46
+ if (!registered.includes(pack))
47
+ registered.push(pack);
48
+ }
49
+ /** Base packs, registered packs, then the packs given: later ones extend earlier ones. */
50
+ export function resolvePacks(packs = []) {
51
+ return [...basePacks(), ...registered, ...packs.filter((p) => !registered.includes(p))];
52
+ }
53
+ const engines = new WeakMap();
54
+ /**
55
+ * The capability engine for a graph, built once per graph object. Packs
56
+ * passed on the first call for a graph are the ones it uses.
57
+ */
58
+ export function capabilityEngine(ir, packs = []) {
59
+ let e = engines.get(ir);
60
+ if (!e) {
61
+ e = new CapabilityEngine(buildView(ir, resolvePacks(packs)), shippedRules().rules);
62
+ engines.set(ir, e);
63
+ }
64
+ return e;
65
+ }
66
+ /** Bind a graph to the packs its search was given, before anything asks for a capability. */
67
+ export function attachCapabilities(ir, packs) {
68
+ engines.delete(ir);
69
+ return capabilityEngine(ir, packs);
70
+ }
71
+ /**
72
+ * Bind a graph to a view built elsewhere (#4378): a workspace's composed
73
+ * view, which each member's own chant mapped. The rules are this chant's.
74
+ */
75
+ export function attachView(ir, view) {
76
+ const e = new CapabilityEngine(view, shippedRules().rules);
77
+ engines.set(ir, e);
78
+ return e;
79
+ }
80
+ /**
81
+ * Read `name` or `name(arg, ...)`, as a search term or an edge qualifier
82
+ * spells a capability. An argument is a number, `true`/`false`, or text,
83
+ * quoted or not.
84
+ */
85
+ export function parseCapabilityCall(text) {
86
+ const m = /^([A-Za-z_][\w-]*)(?:\((.*)\))?$/.exec(text.trim());
87
+ if (!m)
88
+ return undefined;
89
+ const args = m[2] === undefined || m[2].trim() === ""
90
+ ? []
91
+ : m[2].split(",").map((a) => {
92
+ const s = a.trim();
93
+ if (s === "" || s === "_")
94
+ return undefined;
95
+ if (/^-?\d+(\.\d+)?$/.test(s))
96
+ return Number(s);
97
+ if (s === "true" || s === "false")
98
+ return s === "true";
99
+ return s.replace(/^"(.*)"$/, "$1");
100
+ });
101
+ return { name: m[1], args };
102
+ }
103
+ /** Public capabilities: those whose rule carries a `## meaning`. Helpers carry none. */
104
+ export function isPublic(rule) {
105
+ return rule.meta.meaning !== undefined;
106
+ }
107
+ /** Every label a rule needs, through the capabilities it uses, per alternative: any one alternative suffices. */
108
+ function labelsNeeded(rule, byName, seen = new Set()) {
109
+ if (seen.has(rule.name))
110
+ return [[]];
111
+ seen.add(rule.name);
112
+ const out = [];
113
+ for (const alt of rule.alts) {
114
+ // A node of any one of its labels will do, so each label is an option.
115
+ let options = alt.head.labels ? alt.head.labels.map((l) => [l]) : [[]];
116
+ const add = (more) => {
117
+ options = options.flatMap((o) => more.map((m) => [...o, ...m]));
118
+ };
119
+ for (const t of alt.head.tests)
120
+ if (t.kind === "cap" && !t.negated)
121
+ add(labelsNeeded(byName.get(t.cap), byName, new Set(seen)));
122
+ for (const s of alt.steps) {
123
+ if (s.negated)
124
+ continue;
125
+ if (s.node.labels && s.min > 0)
126
+ add(s.node.labels.map((l) => [l]));
127
+ for (const t of s.node.tests)
128
+ if (t.kind === "cap" && !t.negated)
129
+ add(labelsNeeded(byName.get(t.cap), byName, new Set(seen)));
130
+ if (s.min > 0) {
131
+ const edgeRules = s.names.map((n) => byName.get(n.name)).filter((r) => !!r);
132
+ if (edgeRules.length === s.names.length)
133
+ add(edgeRules.flatMap((r) => labelsNeeded(r, byName, new Set(seen))));
134
+ }
135
+ }
136
+ out.push(...options);
137
+ }
138
+ return out;
139
+ }
140
+ /**
141
+ * Whether a lexicon can supply a capability: its own statement when its
142
+ * mapping makes one, otherwise whether every label one alternative needs
143
+ * is one the mapping labels.
144
+ */
145
+ export function lexiconSupport(rule, mapping, lexicon) {
146
+ if (!mapping) {
147
+ return { code: "lexicon-has-no-mapping", message: `the ${lexicon} lexicon ships no capability mapping` };
148
+ }
149
+ const stated = mapping.unsupported?.[rule.name];
150
+ if (stated)
151
+ return stated;
152
+ // A lexicon's mapping extends core's base mapping for it (the folds' kinds).
153
+ const own = mapping;
154
+ const baseFor = basePacks().find((p) => p.mapping.lexicon === own.lexicon)?.mapping;
155
+ if (baseFor)
156
+ mapping = mergeMappings(baseFor, own);
157
+ const { rules } = shippedRules();
158
+ const byName = new Map(rules.map((r) => [r.name, r]));
159
+ const labels = new Set(Object.values(mapping.labels ?? {}).map((s) => (typeof s === "string" ? s : s.label)));
160
+ // Statements and inline blocks are the adapter's own nodes.
161
+ labels.add("Statement");
162
+ for (const specs of Object.values(mapping.blocks ?? {}))
163
+ for (const b of specs)
164
+ labels.add(b.label);
165
+ const options = labelsNeeded(rule, byName);
166
+ if (options.some((o) => o.every((l) => labels.has(l))))
167
+ return "supported";
168
+ const missing = [...new Set(options.flatMap((o) => o.filter((l) => !labels.has(l))))];
169
+ return {
170
+ code: "capability-not-derivable",
171
+ message: `the ${lexicon} mapping labels no ${missing.join(" or ")}`,
172
+ };
173
+ }
174
+ /** The capabilities a rule uses, directly. */
175
+ export function usesOf(rule) {
176
+ const { rules } = shippedRules();
177
+ const names = new Set(rules.map((r) => r.name));
178
+ return [...ruleDependencies(rule)].filter((n) => names.has(n));
179
+ }
180
+ /**
181
+ * The catalog as the `capabilities` document carries it: every public
182
+ * capability, with whether each lexicon given can supply it, and the helper
183
+ * rules they use. `lexicons` maps each lexicon to its mapping, or to
184
+ * undefined when it ships none.
185
+ */
186
+ export function capabilityCatalog(lexicons) {
187
+ const { rules } = shippedRules();
188
+ const list = (s) => (s ?? "").split(/\n|;/).map((x) => x.trim()).filter(Boolean);
189
+ const capabilities = rules.filter(isPublic).map((r) => ({
190
+ name: r.name,
191
+ meaning: r.meta.meaning,
192
+ shape: r.vars.length === 1 ? "set" : "edge",
193
+ params: r.params.map((p) => ({ name: p.name, optional: p.optional, meaning: r.meta[`param-${p.name}`] ?? "" })),
194
+ search: r.vars.length === 1 ? `cap:${r.name}` : `->[cap=${r.name}]`,
195
+ answers: (r.meta.answers ?? "").split("\n").map((x) => x.trim()).filter(Boolean),
196
+ depth: (r.meta.depth ?? "declared"),
197
+ lexicons: Object.fromEntries(Object.entries(lexicons).map(([lex, m]) => [lex, lexiconSupport(r, m, lex)])),
198
+ notEvaluated: list(r.meta["not-evaluated"]),
199
+ uses: usesOf(r),
200
+ rule: r.text,
201
+ }));
202
+ const helpers = rules.filter((r) => !isPublic(r)).map((r) => ({ name: r.name, rule: r.text }));
203
+ return { capabilities, helpers };
204
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The capability rule language (#4375, ruled on #4361).
3
+ *
4
+ * A capability is a named path pattern over the lexicon-neutral view
5
+ * (`./view.ts`). Its steps are #4359's edge terms: an arrow, an optional
6
+ * depth, then what the edge is. A rule file is data, read at run time:
7
+ *
8
+ * # a comment
9
+ * ## meaning: what the capability says, in one line (catalog metadata)
10
+ * in-sg(x, g) := x ->{0,1}template ->sg g:SecurityGroup
11
+ * open-ingress(c; port?, proto?)
12
+ * := c ->in-sg ->ingress :IngressRule[cidrs in ("0.0.0.0/0"), from <= $port]
13
+ * internet-reachable(c; port?)
14
+ * := c[@internet-facing, @open-ingress($port)]
15
+ * | c:Function <-function :FunctionUrl[authType = "NONE"]
16
+ *
17
+ * One variable makes a node set, used as `[@name]`. Two make a named edge,
18
+ * followed as `->name` or `<-name`, which carries the hops that proved it.
19
+ * Parameters come after `;`; a `?` makes one optional, and a test that names
20
+ * an absent parameter is left out. Lines starting `|` add an alternative.
21
+ *
22
+ * A step is `->` or `<-`, an optional depth (`?`, `*`, `+`, `{n}`, `{m,n}`,
23
+ * `{m,}`; a rule may start at 0, which #4359's query grammar refuses), an
24
+ * edge name or `(a|b)`, and an optional node: `var:Label|Label[tests]`.
25
+ * `!->name node` and `!<-name node` are negated steps: the walk stays where
26
+ * it is and goes on only when no such edge leads to such a node.
27
+ *
28
+ * A node test is `attr = v`, `attr != v`, `attr in (v, ...)`, `attr ~ "glob"`,
29
+ * `attr < n` (and `<=`, `>`, `>=`), a bare `attr` (present and not false),
30
+ * or `@cap` / `@cap(args)`. Any test takes a leading `!`. Against a list
31
+ * attribute, a test holds when it holds for any element.
32
+ */
33
+ export type Literal = string | number | boolean | null;
34
+ /** A value in a test or an argument: a literal, or a reference to a parameter. */
35
+ export type Value = {
36
+ lit: Literal;
37
+ } | {
38
+ param: string;
39
+ };
40
+ export type Test = {
41
+ kind: "attr";
42
+ negated: boolean;
43
+ attr: string;
44
+ op: "=" | "!=" | "in" | "~" | "<" | "<=" | ">" | ">=" | "present";
45
+ values: Value[];
46
+ } | {
47
+ kind: "cap";
48
+ negated: boolean;
49
+ cap: string;
50
+ args: Value[];
51
+ };
52
+ export interface NodeSpec {
53
+ v?: string;
54
+ labels?: string[];
55
+ tests: Test[];
56
+ }
57
+ export interface Step {
58
+ dir: "out" | "in";
59
+ negated: boolean;
60
+ /** Edge names: view edges or two-variable capabilities. */
61
+ names: {
62
+ name: string;
63
+ args: Value[];
64
+ }[];
65
+ min: number;
66
+ max: number;
67
+ node: NodeSpec;
68
+ }
69
+ export interface Alternative {
70
+ head: NodeSpec;
71
+ steps: Step[];
72
+ /** 1-based line in the rule file, for messages. */
73
+ line: number;
74
+ }
75
+ export interface Param {
76
+ name: string;
77
+ optional: boolean;
78
+ }
79
+ export interface Rule {
80
+ name: string;
81
+ vars: string[];
82
+ params: Param[];
83
+ alts: Alternative[];
84
+ /** `## key: value` lines above the rule. */
85
+ meta: Record<string, string>;
86
+ line: number;
87
+ /** The rule as written, one alternative per line, comments dropped. */
88
+ text: string;
89
+ }
90
+ /** A rule file the parser cannot read, with the line it failed on. */
91
+ export declare class RuleSyntaxError extends Error {
92
+ readonly line: number;
93
+ constructor(message: string, line: number);
94
+ }
95
+ /**
96
+ * Parse a rule file. Rules may span lines: a line that starts with `|`
97
+ * continues the rule above it, and so does an indented line when the rule's
98
+ * `:=` has nothing after it yet.
99
+ */
100
+ export declare function parseRules(text: string): Rule[];
101
+ /** The capabilities a rule refers to, by name: in `[@cap]` tests and in steps. */
102
+ export declare function ruleDependencies(rule: Rule): Set<string>;
103
+ //# sourceMappingURL=language.d.ts.map