@orygn/opa-mcp 0.0.0 → 0.1.0

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 (184) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/LICENSE +21 -0
  3. package/README.md +622 -2
  4. package/dist/config.d.ts +58 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/config.js +72 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/lib/errors.d.ts +18 -0
  9. package/dist/lib/errors.d.ts.map +1 -0
  10. package/dist/lib/errors.js +25 -0
  11. package/dist/lib/errors.js.map +1 -0
  12. package/dist/lib/logger.d.ts +10 -0
  13. package/dist/lib/logger.d.ts.map +1 -0
  14. package/dist/lib/logger.js +57 -0
  15. package/dist/lib/logger.js.map +1 -0
  16. package/dist/lib/opa-cli.d.ts +226 -0
  17. package/dist/lib/opa-cli.d.ts.map +1 -0
  18. package/dist/lib/opa-cli.js +283 -0
  19. package/dist/lib/opa-cli.js.map +1 -0
  20. package/dist/lib/opa-client.d.ts +47 -0
  21. package/dist/lib/opa-client.d.ts.map +1 -0
  22. package/dist/lib/opa-client.js +101 -0
  23. package/dist/lib/opa-client.js.map +1 -0
  24. package/dist/lib/output.d.ts +17 -0
  25. package/dist/lib/output.d.ts.map +1 -0
  26. package/dist/lib/output.js +21 -0
  27. package/dist/lib/output.js.map +1 -0
  28. package/dist/lib/regal-cli.d.ts +65 -0
  29. package/dist/lib/regal-cli.d.ts.map +1 -0
  30. package/dist/lib/regal-cli.js +99 -0
  31. package/dist/lib/regal-cli.js.map +1 -0
  32. package/dist/lib/security.d.ts +16 -0
  33. package/dist/lib/security.d.ts.map +1 -0
  34. package/dist/lib/security.js +64 -0
  35. package/dist/lib/security.js.map +1 -0
  36. package/dist/lib/subprocess.d.ts +26 -0
  37. package/dist/lib/subprocess.d.ts.map +1 -0
  38. package/dist/lib/subprocess.js +72 -0
  39. package/dist/lib/subprocess.js.map +1 -0
  40. package/dist/lib/tool-helpers.d.ts +46 -0
  41. package/dist/lib/tool-helpers.d.ts.map +1 -0
  42. package/dist/lib/tool-helpers.js +73 -0
  43. package/dist/lib/tool-helpers.js.map +1 -0
  44. package/dist/prompts/index.d.ts +4 -0
  45. package/dist/prompts/index.d.ts.map +1 -0
  46. package/dist/prompts/index.js +147 -0
  47. package/dist/prompts/index.js.map +1 -0
  48. package/dist/resources/index.d.ts +12 -0
  49. package/dist/resources/index.d.ts.map +1 -0
  50. package/dist/resources/index.js +107 -0
  51. package/dist/resources/index.js.map +1 -0
  52. package/dist/resources/patterns.d.ts +9 -0
  53. package/dist/resources/patterns.d.ts.map +1 -0
  54. package/dist/resources/patterns.js +375 -0
  55. package/dist/resources/patterns.js.map +1 -0
  56. package/dist/resources/style-guide.d.ts +6 -0
  57. package/dist/resources/style-guide.d.ts.map +1 -0
  58. package/dist/resources/style-guide.js +187 -0
  59. package/dist/resources/style-guide.js.map +1 -0
  60. package/dist/server.d.ts +22 -0
  61. package/dist/server.d.ts.map +1 -0
  62. package/dist/server.js +82 -0
  63. package/dist/server.js.map +1 -0
  64. package/dist/tools/authoring/capabilities.d.ts +11 -0
  65. package/dist/tools/authoring/capabilities.d.ts.map +1 -0
  66. package/dist/tools/authoring/capabilities.js +57 -0
  67. package/dist/tools/authoring/capabilities.js.map +1 -0
  68. package/dist/tools/authoring/check.d.ts +18 -0
  69. package/dist/tools/authoring/check.d.ts.map +1 -0
  70. package/dist/tools/authoring/check.js +71 -0
  71. package/dist/tools/authoring/check.js.map +1 -0
  72. package/dist/tools/authoring/deps.d.ts +8 -0
  73. package/dist/tools/authoring/deps.d.ts.map +1 -0
  74. package/dist/tools/authoring/deps.js +51 -0
  75. package/dist/tools/authoring/deps.js.map +1 -0
  76. package/dist/tools/authoring/format.d.ts +8 -0
  77. package/dist/tools/authoring/format.d.ts.map +1 -0
  78. package/dist/tools/authoring/format.js +44 -0
  79. package/dist/tools/authoring/format.js.map +1 -0
  80. package/dist/tools/authoring/index.d.ts +11 -0
  81. package/dist/tools/authoring/index.d.ts.map +1 -0
  82. package/dist/tools/authoring/index.js +17 -0
  83. package/dist/tools/authoring/index.js.map +1 -0
  84. package/dist/tools/authoring/inspect.d.ts +10 -0
  85. package/dist/tools/authoring/inspect.d.ts.map +1 -0
  86. package/dist/tools/authoring/inspect.js +47 -0
  87. package/dist/tools/authoring/inspect.js.map +1 -0
  88. package/dist/tools/authoring/lint.d.ts +18 -0
  89. package/dist/tools/authoring/lint.d.ts.map +1 -0
  90. package/dist/tools/authoring/lint.js +84 -0
  91. package/dist/tools/authoring/lint.js.map +1 -0
  92. package/dist/tools/authoring/parse.d.ts +7 -0
  93. package/dist/tools/authoring/parse.d.ts.map +1 -0
  94. package/dist/tools/authoring/parse.js +43 -0
  95. package/dist/tools/authoring/parse.js.map +1 -0
  96. package/dist/tools/bundles/build.d.ts +8 -0
  97. package/dist/tools/bundles/build.d.ts.map +1 -0
  98. package/dist/tools/bundles/build.js +87 -0
  99. package/dist/tools/bundles/build.js.map +1 -0
  100. package/dist/tools/bundles/index.d.ts +10 -0
  101. package/dist/tools/bundles/index.d.ts.map +1 -0
  102. package/dist/tools/bundles/index.js +7 -0
  103. package/dist/tools/bundles/index.js.map +1 -0
  104. package/dist/tools/bundles/sign.d.ts +8 -0
  105. package/dist/tools/bundles/sign.d.ts.map +1 -0
  106. package/dist/tools/bundles/sign.js +47 -0
  107. package/dist/tools/bundles/sign.js.map +1 -0
  108. package/dist/tools/evaluation/_shared.d.ts +55 -0
  109. package/dist/tools/evaluation/_shared.d.ts.map +1 -0
  110. package/dist/tools/evaluation/_shared.js +102 -0
  111. package/dist/tools/evaluation/_shared.js.map +1 -0
  112. package/dist/tools/evaluation/bench.d.ts +9 -0
  113. package/dist/tools/evaluation/bench.d.ts.map +1 -0
  114. package/dist/tools/evaluation/bench.js +76 -0
  115. package/dist/tools/evaluation/bench.js.map +1 -0
  116. package/dist/tools/evaluation/compile.d.ts +11 -0
  117. package/dist/tools/evaluation/compile.d.ts.map +1 -0
  118. package/dist/tools/evaluation/compile.js +19 -0
  119. package/dist/tools/evaluation/compile.js.map +1 -0
  120. package/dist/tools/evaluation/eval.d.ts +10 -0
  121. package/dist/tools/evaluation/eval.d.ts.map +1 -0
  122. package/dist/tools/evaluation/eval.js +35 -0
  123. package/dist/tools/evaluation/eval.js.map +1 -0
  124. package/dist/tools/evaluation/index.d.ts +11 -0
  125. package/dist/tools/evaluation/index.d.ts.map +1 -0
  126. package/dist/tools/evaluation/index.js +11 -0
  127. package/dist/tools/evaluation/index.js.map +1 -0
  128. package/dist/tools/evaluation/test.d.ts +28 -0
  129. package/dist/tools/evaluation/test.d.ts.map +1 -0
  130. package/dist/tools/evaluation/test.js +74 -0
  131. package/dist/tools/evaluation/test.js.map +1 -0
  132. package/dist/tools/helpers/describe-policy.d.ts +26 -0
  133. package/dist/tools/helpers/describe-policy.d.ts.map +1 -0
  134. package/dist/tools/helpers/describe-policy.js +76 -0
  135. package/dist/tools/helpers/describe-policy.js.map +1 -0
  136. package/dist/tools/helpers/explain-decision.d.ts +41 -0
  137. package/dist/tools/helpers/explain-decision.d.ts.map +1 -0
  138. package/dist/tools/helpers/explain-decision.js +75 -0
  139. package/dist/tools/helpers/explain-decision.js.map +1 -0
  140. package/dist/tools/helpers/generate-test-skeleton.d.ts +8 -0
  141. package/dist/tools/helpers/generate-test-skeleton.d.ts.map +1 -0
  142. package/dist/tools/helpers/generate-test-skeleton.js +93 -0
  143. package/dist/tools/helpers/generate-test-skeleton.js.map +1 -0
  144. package/dist/tools/helpers/index.d.ts +12 -0
  145. package/dist/tools/helpers/index.d.ts.map +1 -0
  146. package/dist/tools/helpers/index.js +11 -0
  147. package/dist/tools/helpers/index.js.map +1 -0
  148. package/dist/tools/helpers/suggest-fix.d.ts +15 -0
  149. package/dist/tools/helpers/suggest-fix.d.ts.map +1 -0
  150. package/dist/tools/helpers/suggest-fix.js +119 -0
  151. package/dist/tools/helpers/suggest-fix.js.map +1 -0
  152. package/dist/tools/index.d.ts +31 -0
  153. package/dist/tools/index.d.ts.map +1 -0
  154. package/dist/tools/index.js +13 -0
  155. package/dist/tools/index.js.map +1 -0
  156. package/dist/tools/server-management/_shared.d.ts +9 -0
  157. package/dist/tools/server-management/_shared.d.ts.map +1 -0
  158. package/dist/tools/server-management/_shared.js +41 -0
  159. package/dist/tools/server-management/_shared.js.map +1 -0
  160. package/dist/tools/server-management/data.d.ts +4 -0
  161. package/dist/tools/server-management/data.d.ts.map +1 -0
  162. package/dist/tools/server-management/data.js +90 -0
  163. package/dist/tools/server-management/data.js.map +1 -0
  164. package/dist/tools/server-management/decisions.d.ts +4 -0
  165. package/dist/tools/server-management/decisions.d.ts.map +1 -0
  166. package/dist/tools/server-management/decisions.js +87 -0
  167. package/dist/tools/server-management/decisions.js.map +1 -0
  168. package/dist/tools/server-management/index.d.ts +11 -0
  169. package/dist/tools/server-management/index.d.ts.map +1 -0
  170. package/dist/tools/server-management/index.js +11 -0
  171. package/dist/tools/server-management/index.js.map +1 -0
  172. package/dist/tools/server-management/policies.d.ts +4 -0
  173. package/dist/tools/server-management/policies.d.ts.map +1 -0
  174. package/dist/tools/server-management/policies.js +94 -0
  175. package/dist/tools/server-management/policies.js.map +1 -0
  176. package/dist/tools/server-management/status.d.ts +4 -0
  177. package/dist/tools/server-management/status.d.ts.map +1 -0
  178. package/dist/tools/server-management/status.js +82 -0
  179. package/dist/tools/server-management/status.js.map +1 -0
  180. package/dist/types.d.ts +24 -0
  181. package/dist/types.d.ts.map +1 -0
  182. package/dist/types.js +5 -0
  183. package/dist/types.js.map +1 -0
  184. package/package.json +82 -4
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Wrapper around the local `opa` binary.
3
+ *
4
+ * Tool implementations call into this module rather than spawning
5
+ * subprocesses directly. Every method here builds argv with the flags
6
+ * `opa` actually expects so each tool above can ignore CLI minutiae and
7
+ * just describe its inputs.
8
+ *
9
+ * Inline Rego source is always written to a temp file before invocation.
10
+ * The `-` (read-from-stdin) convention some opa subcommands document is
11
+ * unreliable on Windows, where `-` is treated as a literal filename.
12
+ *
13
+ * The methods do not parse stdout into typed result objects — different
14
+ * tools need different shapes of the same output and a one-size parser
15
+ * would force conversions both ways. Stdout is JSON whenever
16
+ * `--format=json` is set, and tools call `JSON.parse` on it themselves.
17
+ */
18
+ import { randomUUID } from 'node:crypto';
19
+ import { rm, writeFile } from 'node:fs/promises';
20
+ import { tmpdir } from 'node:os';
21
+ import { join } from 'node:path';
22
+ import { runBinary } from './subprocess.js';
23
+ /**
24
+ * Wrapper around the local `opa` binary.
25
+ *
26
+ * Methods do not throw on `opa` errors — non-zero exit codes are
27
+ * surfaced on the returned `SpawnResult` so tools can map them to
28
+ * structured error envelopes at their layer. They DO throw on
29
+ * caller-side bugs (e.g. an empty `paths` array passed where one is
30
+ * required), since those represent contract violations.
31
+ */
32
+ export class OpaCli {
33
+ config;
34
+ constructor(config) {
35
+ this.config = config;
36
+ }
37
+ /**
38
+ * Verify the binary is present and report its version.
39
+ * Returns null if the binary is unreachable or output is malformed.
40
+ */
41
+ async version() {
42
+ const result = await this.run(['version']);
43
+ if (result.exitCode !== 0)
44
+ return null;
45
+ const match = /Version:\s*(\S+)/i.exec(result.stdout);
46
+ return match?.[1] ?? null;
47
+ }
48
+ // ─── Authoring ───────────────────────────────────────────────────────
49
+ /**
50
+ * Format Rego source. Stdout contains the formatted output. Reports
51
+ * `exitCode: 0` even when no changes are needed — callers compare
52
+ * input vs output to detect a no-op.
53
+ */
54
+ async fmt(input) {
55
+ return this.withTempSource(input.source, (path) => this.run(['fmt', path]));
56
+ }
57
+ /**
58
+ * Type-check Rego. Returns `exitCode: 0` and empty `stdout` when the
59
+ * policy is valid. On failure, `exitCode` is non-zero and the JSON
60
+ * error report is written to **stderr** (this is OPA's actual
61
+ * behavior — tools must read `stderr`, not `stdout`, for `check`
62
+ * diagnostics). Either inline `source` or one or more `paths` must be
63
+ * provided.
64
+ */
65
+ async check(input) {
66
+ if (!input.source && !input.paths?.length) {
67
+ throw new Error('opa check requires either source or at least one path');
68
+ }
69
+ const args = ['check', '--format=json'];
70
+ if (input.strict)
71
+ args.push('--strict');
72
+ if (input.capabilities)
73
+ args.push('--capabilities', input.capabilities);
74
+ if (input.schemaDir)
75
+ args.push('--schema', input.schemaDir);
76
+ if (input.source !== undefined) {
77
+ return this.withTempSource(input.source, (path) => this.run([...args, path]));
78
+ }
79
+ args.push(...(input.paths ?? []));
80
+ return this.run(args);
81
+ }
82
+ /**
83
+ * Parse Rego source to a JSON AST. Stdout is the AST as JSON.
84
+ */
85
+ async parse(input) {
86
+ return this.withTempSource(input.source, (path) => this.run(['parse', '--format=json', path]));
87
+ }
88
+ /**
89
+ * Inspect a bundle, directory, or single Rego file. Returns its
90
+ * packages, namespaces, manifest, and annotations as JSON on stdout.
91
+ */
92
+ async inspect(input) {
93
+ return this.run(['inspect', '--format=json', input.target]);
94
+ }
95
+ /**
96
+ * Print available capabilities. With `current=true`, prints the
97
+ * capabilities of the running OPA. With a `version`, prints those of
98
+ * a specific named version. Without either, lists available named
99
+ * versions.
100
+ */
101
+ async capabilities(input = {}) {
102
+ const args = ['capabilities'];
103
+ if (input.current)
104
+ args.push('--current');
105
+ if (input.version)
106
+ args.push('--version', input.version);
107
+ return this.run(args);
108
+ }
109
+ /**
110
+ * Static dependency analysis for a Rego ref. Stdout is JSON with the
111
+ * `base` and `virtual` document references the ref depends on.
112
+ */
113
+ async deps(input) {
114
+ if (input.paths.length === 0) {
115
+ throw new Error('opa deps requires at least one path');
116
+ }
117
+ const args = ['deps', '--format=json'];
118
+ for (const path of input.paths) {
119
+ args.push('--data', path);
120
+ }
121
+ args.push(input.ref);
122
+ return this.run(args);
123
+ }
124
+ // ─── Evaluation ──────────────────────────────────────────────────────
125
+ /**
126
+ * Evaluate a query against a policy + input. Stdout is JSON with the
127
+ * standard `{result: [...]}` shape (plus optional explain, profile,
128
+ * coverage, and metrics sections).
129
+ */
130
+ async eval(input) {
131
+ // Inline source becomes a temp file added to --data.
132
+ if (input.source !== undefined) {
133
+ const { source, ...rest } = input;
134
+ void source;
135
+ return this.withTempSource(input.source, (sourcePath) => this.eval({
136
+ ...rest,
137
+ paths: [...(input.paths ?? []), sourcePath],
138
+ }));
139
+ }
140
+ const args = ['eval', '--format=json'];
141
+ for (const path of input.paths ?? [])
142
+ args.push('--data', path);
143
+ if (input.inputPath)
144
+ args.push('--input', input.inputPath);
145
+ if (input.explain)
146
+ args.push('--explain', input.explain);
147
+ if (input.profile)
148
+ args.push('--profile');
149
+ if (input.coverage)
150
+ args.push('--coverage');
151
+ if (input.metrics)
152
+ args.push('--metrics');
153
+ if (input.instrument)
154
+ args.push('--instrument');
155
+ if (input.partial)
156
+ args.push('--partial');
157
+ for (const ref of input.unknowns ?? [])
158
+ args.push('--unknowns', ref);
159
+ if (input.strictBuiltinErrors)
160
+ args.push('--strict-builtin-errors');
161
+ if (input.capabilities)
162
+ args.push('--capabilities', input.capabilities);
163
+ if (input.schemaDir)
164
+ args.push('--schema', input.schemaDir);
165
+ let stdin;
166
+ if (input.input !== undefined) {
167
+ args.push('--stdin-input');
168
+ stdin = JSON.stringify(input.input);
169
+ }
170
+ args.push(input.query);
171
+ return this.run(args, stdin);
172
+ }
173
+ /**
174
+ * Run Rego unit tests. Stdout is JSON with per-test pass/fail.
175
+ */
176
+ async test(input) {
177
+ if (input.paths.length === 0) {
178
+ throw new Error('opa test requires at least one path');
179
+ }
180
+ const args = ['test', '--format=json'];
181
+ if (input.verbose)
182
+ args.push('--verbose');
183
+ if (input.coverage)
184
+ args.push('--coverage');
185
+ if (input.bench)
186
+ args.push('--bench');
187
+ if (input.runPattern)
188
+ args.push('--run', input.runPattern);
189
+ args.push(...input.paths);
190
+ return this.run(args);
191
+ }
192
+ /**
193
+ * Benchmark a query. Stdout is JSON with iteration timing statistics.
194
+ */
195
+ async bench(input) {
196
+ const args = ['bench', '--format=json'];
197
+ for (const path of input.paths ?? [])
198
+ args.push('--data', path);
199
+ if (input.inputPath)
200
+ args.push('--input', input.inputPath);
201
+ if (input.count !== undefined)
202
+ args.push('--count', String(input.count));
203
+ let stdin;
204
+ if (input.input !== undefined) {
205
+ args.push('--stdin-input');
206
+ stdin = JSON.stringify(input.input);
207
+ }
208
+ args.push(input.query);
209
+ return this.run(args, stdin);
210
+ }
211
+ // ─── Bundles ─────────────────────────────────────────────────────────
212
+ /** Build a deployable bundle from policy + data paths. */
213
+ async build(input) {
214
+ if (input.paths.length === 0) {
215
+ throw new Error('opa build requires at least one input path');
216
+ }
217
+ const args = ['build', '-o', input.output];
218
+ if (input.optimize !== undefined)
219
+ args.push('--optimize', String(input.optimize));
220
+ if (input.revision)
221
+ args.push('--revision', input.revision);
222
+ if (input.target)
223
+ args.push('--target', input.target);
224
+ for (const ep of input.entrypoints ?? [])
225
+ args.push('--entrypoint', ep);
226
+ if (input.signingKey)
227
+ args.push('--signing-key', input.signingKey);
228
+ if (input.signingAlg)
229
+ args.push('--signing-alg', input.signingAlg);
230
+ if (input.claimsFile)
231
+ args.push('--claims-file', input.claimsFile);
232
+ if (input.capabilities)
233
+ args.push('--capabilities', input.capabilities);
234
+ args.push(...input.paths);
235
+ return this.run(args);
236
+ }
237
+ /**
238
+ * Sign a bundle. Writes a `.signatures.json` next to the bundle
239
+ * directory.
240
+ */
241
+ async sign(input) {
242
+ const args = ['sign', '--signing-key', input.signingKey];
243
+ if (input.signingAlg)
244
+ args.push('--signing-alg', input.signingAlg);
245
+ if (input.claimsFile)
246
+ args.push('--claims-file', input.claimsFile);
247
+ args.push('--bundle', input.bundle);
248
+ return this.run(args);
249
+ }
250
+ // ─── Low-level escape hatch ──────────────────────────────────────────
251
+ /**
252
+ * Run `opa` with the given argv and optional stdin. Tools should
253
+ * prefer the typed methods above, but this exists for the rare cases
254
+ * the typed surface does not yet cover.
255
+ */
256
+ async run(args, stdin) {
257
+ const opts = {
258
+ args,
259
+ timeoutMs: this.config.subprocessTimeoutMs,
260
+ };
261
+ if (stdin !== undefined)
262
+ opts.stdin = stdin;
263
+ return runBinary(this.config.opaBinary, opts);
264
+ }
265
+ // ─── Internal: temp file management ──────────────────────────────────
266
+ /**
267
+ * Write `source` to a uniquely named `.rego` file in the OS tmp dir,
268
+ * pass its path to `fn`, and remove it on completion (success or
269
+ * failure). The path is unique per call so concurrent invocations do
270
+ * not collide.
271
+ */
272
+ async withTempSource(source, fn) {
273
+ const path = join(tmpdir(), `orygn-opa-mcp-${randomUUID()}.rego`);
274
+ await writeFile(path, source, 'utf8');
275
+ try {
276
+ return await fn(path);
277
+ }
278
+ finally {
279
+ await rm(path, { force: true });
280
+ }
281
+ }
282
+ }
283
+ //# sourceMappingURL=opa-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opa-cli.js","sourceRoot":"","sources":["../../src/lib/opa-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAoJ9D;;;;;;;;GAQG;AACH,MAAM,OAAO,MAAM;IACY;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACvC,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC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server` REST API).
3
+ *
4
+ * Used by tools in the `opa_*` server-management category. CLI-only
5
+ * tools (`rego_*`) do not touch this module.
6
+ *
7
+ * Connection failures map to `OPA_UNREACHABLE`; 401s map to `OPA_AUTH_FAILED`.
8
+ * Per-tool error mapping happens at the call site.
9
+ */
10
+ import type { Config } from '../config.js';
11
+ export declare class OpaUnreachableError extends Error {
12
+ readonly url: string;
13
+ constructor(url: string, cause?: unknown);
14
+ }
15
+ export declare class OpaAuthError extends Error {
16
+ constructor();
17
+ }
18
+ export declare class OpaHttpError extends Error {
19
+ readonly status: number;
20
+ readonly body: unknown;
21
+ constructor(status: number, body: unknown);
22
+ }
23
+ export interface RequestOptions {
24
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
25
+ path: string;
26
+ /**
27
+ * JSON body to serialize. Mutually exclusive with `rawBody`.
28
+ */
29
+ body?: unknown;
30
+ /**
31
+ * Raw string body sent verbatim. Used for endpoints that accept
32
+ * non-JSON content — notably `PUT /v1/policies/{id}` which expects
33
+ * Rego source as `text/plain`.
34
+ */
35
+ rawBody?: string;
36
+ /** Content-Type for `rawBody`. Defaults to `text/plain`. */
37
+ rawContentType?: string;
38
+ query?: Record<string, string | number | boolean | undefined>;
39
+ headers?: Record<string, string>;
40
+ }
41
+ export declare class OpaClient {
42
+ private readonly config;
43
+ constructor(config: Config);
44
+ request<T = unknown>(opts: RequestOptions): Promise<T>;
45
+ private buildUrl;
46
+ }
47
+ //# sourceMappingURL=opa-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opa-client.d.ts","sourceRoot":"","sources":["../../src/lib/opa-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM,EAC3B,KAAK,CAAC,EAAE,OAAO;CAMlB;AAED,qBAAa,YAAa,SAAQ,KAAK;;CAKtC;AAED,qBAAa,YAAa,SAAQ,KAAK;aAEnB,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,OAAO;gBADb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO;CAKhC;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAErC,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IA+D5D,OAAO,CAAC,QAAQ;CAWjB"}
@@ -0,0 +1,101 @@
1
+ export class OpaUnreachableError extends Error {
2
+ url;
3
+ constructor(url, cause) {
4
+ super(`OPA server unreachable at ${url}`);
5
+ this.url = url;
6
+ this.name = 'OpaUnreachableError';
7
+ if (cause !== undefined)
8
+ this.cause = cause;
9
+ }
10
+ }
11
+ export class OpaAuthError extends Error {
12
+ constructor() {
13
+ super('OPA rejected the request with 401 Unauthorized');
14
+ this.name = 'OpaAuthError';
15
+ }
16
+ }
17
+ export class OpaHttpError extends Error {
18
+ status;
19
+ body;
20
+ constructor(status, body) {
21
+ super(`OPA returned HTTP ${status}`);
22
+ this.status = status;
23
+ this.body = body;
24
+ this.name = 'OpaHttpError';
25
+ }
26
+ }
27
+ export class OpaClient {
28
+ config;
29
+ constructor(config) {
30
+ this.config = config;
31
+ }
32
+ async request(opts) {
33
+ const url = this.buildUrl(opts.path, opts.query);
34
+ const headers = {
35
+ Accept: 'application/json',
36
+ ...(opts.headers ?? {}),
37
+ };
38
+ if (this.config.opaToken) {
39
+ headers['Authorization'] = `Bearer ${this.config.opaToken}`;
40
+ }
41
+ let bodyToSend;
42
+ if (opts.rawBody !== undefined) {
43
+ if (opts.body !== undefined) {
44
+ throw new Error('OpaClient.request: pass either `body` or `rawBody`, not both.');
45
+ }
46
+ bodyToSend = opts.rawBody;
47
+ if (!headers['Content-Type']) {
48
+ headers['Content-Type'] = opts.rawContentType ?? 'text/plain';
49
+ }
50
+ }
51
+ else if (opts.body !== undefined) {
52
+ bodyToSend = JSON.stringify(opts.body);
53
+ if (!headers['Content-Type']) {
54
+ headers['Content-Type'] = 'application/json';
55
+ }
56
+ }
57
+ const controller = new AbortController();
58
+ const timer = setTimeout(() => controller.abort(), this.config.httpTimeoutMs);
59
+ const init = {
60
+ method: opts.method,
61
+ headers,
62
+ signal: controller.signal,
63
+ };
64
+ if (bodyToSend !== undefined) {
65
+ init.body = bodyToSend;
66
+ }
67
+ let response;
68
+ try {
69
+ response = await fetch(url, init);
70
+ }
71
+ catch (e) {
72
+ throw new OpaUnreachableError(this.config.opaUrl, e);
73
+ }
74
+ finally {
75
+ clearTimeout(timer);
76
+ }
77
+ if (response.status === 401) {
78
+ throw new OpaAuthError();
79
+ }
80
+ const contentType = response.headers.get('content-type') ?? '';
81
+ const isJson = contentType.includes('application/json');
82
+ const payload = isJson ? await response.json() : await response.text();
83
+ if (!response.ok) {
84
+ throw new OpaHttpError(response.status, payload);
85
+ }
86
+ return payload;
87
+ }
88
+ buildUrl(path, query) {
89
+ const base = this.config.opaUrl.replace(/\/+$/, '');
90
+ const normalizedPath = path.startsWith('/') ? path : `/${path}`;
91
+ const url = new URL(`${base}${normalizedPath}`);
92
+ if (query) {
93
+ for (const [key, value] of Object.entries(query)) {
94
+ if (value !== undefined)
95
+ url.searchParams.set(key, String(value));
96
+ }
97
+ }
98
+ return url.toString();
99
+ }
100
+ }
101
+ //# sourceMappingURL=opa-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opa-client.js","sourceRoot":"","sources":["../../src/lib/opa-client.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAE1B;IADlB,YACkB,GAAW,EAC3B,KAAe;QAEf,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;QAH1B,QAAG,GAAH,GAAG,CAAQ;QAI3B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAC9C,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC;QACE,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IAEnB;IACA;IAFlB,YACkB,MAAc,EACd,IAAa;QAE7B,KAAK,CAAC,qBAAqB,MAAM,EAAE,CAAC,CAAC;QAHrB,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAS;QAG7B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAqBD,MAAM,OAAO,SAAS;IACS;IAA7B,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,KAAK,CAAC,OAAO,CAAc,IAAoB;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEjD,MAAM,OAAO,GAA2B;YACtC,MAAM,EAAE,kBAAkB;YAC1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,cAAc,EAAE,CAAC,CAAC;QAChD,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI,KAAK,KAAK,SAAS;oBAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Format a tool envelope for MCP transport.
3
+ *
4
+ * The MCP SDK expects `{ content: [{ type: 'text', text: string }] }`.
5
+ * We serialize the envelope as JSON and apply size-based truncation.
6
+ */
7
+ import type { ToolEnvelope } from '../types.js';
8
+ export interface McpToolResult {
9
+ [key: string]: unknown;
10
+ content: Array<{
11
+ type: 'text';
12
+ text: string;
13
+ }>;
14
+ isError?: boolean;
15
+ }
16
+ export declare function formatEnvelope<T>(envelope: ToolEnvelope<T>, maxBytes: number): McpToolResult;
17
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAsB5F"}
@@ -0,0 +1,21 @@
1
+ export function formatEnvelope(envelope, maxBytes) {
2
+ let serialized = JSON.stringify(envelope, null, 2);
3
+ if (Buffer.byteLength(serialized, 'utf8') > maxBytes) {
4
+ const truncatedEnvelope = {
5
+ ...envelope,
6
+ truncated: true,
7
+ };
8
+ if (truncatedEnvelope.ok && truncatedEnvelope.data !== undefined) {
9
+ truncatedEnvelope.data = {
10
+ __truncated: true,
11
+ message: 'Response exceeded maxResponseBytes. Re-run with narrower scope, or write the output to a file path you specify.',
12
+ };
13
+ }
14
+ serialized = JSON.stringify(truncatedEnvelope, null, 2);
15
+ }
16
+ return {
17
+ content: [{ type: 'text', text: serialized }],
18
+ isError: !envelope.ok,
19
+ };
20
+ }
21
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,cAAc,CAAI,QAAyB,EAAE,QAAgB;IAC3E,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAEnD,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,QAAQ,EAAE,CAAC;QACrD,MAAM,iBAAiB,GAAoB;YACzC,GAAG,QAAQ;YACX,SAAS,EAAE,IAAI;SAChB,CAAC;QACF,IAAI,iBAAiB,CAAC,EAAE,IAAI,iBAAiB,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACjE,iBAAiB,CAAC,IAAI,GAAG;gBACvB,WAAW,EAAE,IAAI;gBACjB,OAAO,EACL,iHAAiH;aAC/G,CAAC;QACT,CAAC;QACD,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;QAC7C,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE;KACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Config } from '../config.js';
2
+ import { type SpawnResult } from './subprocess.js';
3
+ /** Input for `regal lint`. */
4
+ export interface LintInput {
5
+ /** Inline Rego source. Mutually exclusive with `paths`. */
6
+ source?: string;
7
+ /** Paths to Rego files or directories to lint. */
8
+ paths?: string[];
9
+ /** Path to a Regal config file. */
10
+ configFile?: string;
11
+ /** Disable specific named rules (e.g. `print-or-trace-call`). */
12
+ disable?: string[];
13
+ /** Disable entire rule categories (e.g. `style`, `idiomatic`). */
14
+ disableCategory?: string[];
15
+ /** Enable specific named rules. */
16
+ enable?: string[];
17
+ /** Enable entire rule categories. */
18
+ enableCategory?: string[];
19
+ /** Disable every rule before applying enable* flags. */
20
+ disableAll?: boolean;
21
+ /** Enable every rule (overrides config defaults). */
22
+ enableAll?: boolean;
23
+ /** Glob patterns to skip. */
24
+ ignoreFiles?: string[];
25
+ /**
26
+ * Severity at which Regal returns a non-zero exit code (`error` or
27
+ * `warning`). Defaults to `error` to match Regal's own default.
28
+ */
29
+ failLevel?: 'error' | 'warning';
30
+ }
31
+ /**
32
+ * Wrapper around the local `regal` binary.
33
+ *
34
+ * Like `OpaCli`, methods do not throw on Regal-side errors — the exit
35
+ * code on the returned `SpawnResult` is the signal. Inline source is
36
+ * always written to a temp file because `regal lint` does not read
37
+ * from stdin.
38
+ */
39
+ export declare class RegalCli {
40
+ private readonly config;
41
+ constructor(config: Config);
42
+ /**
43
+ * Verify the binary is present and report its version. Returns null
44
+ * if the binary is unreachable or output is malformed.
45
+ */
46
+ version(): Promise<string | null>;
47
+ /**
48
+ * Lint Rego source. Stdout is JSON when `--format=json` is set
49
+ * (always, here). Either `source` or one or more `paths` must be
50
+ * provided.
51
+ *
52
+ * Regal's exit codes:
53
+ * - 0 — no findings at or above `failLevel`
54
+ * - 3 — findings present
55
+ * - non-zero other — Regal-internal failure (config error, etc.)
56
+ */
57
+ lint(input: LintInput): Promise<SpawnResult>;
58
+ /**
59
+ * Run `regal` with the given argv. Tools should prefer the typed
60
+ * methods above; this is the escape hatch.
61
+ */
62
+ run(args: string[]): Promise<SpawnResult>;
63
+ private withTempSource;
64
+ }
65
+ //# sourceMappingURL=regal-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regal-cli.d.ts","sourceRoot":"","sources":["../../src/lib/regal-cli.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,8BAA8B;AAC9B,MAAM,WAAW,SAAS;IACxB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,qCAAqC;IACrC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,wDAAwD;IACxD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qDAAqD;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C;;;OAGG;IACG,OAAO,IAAI,OAAO,CAA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