# keryn forge query

Describes Keryn 0.5.2 and keryn-rules 0.8.0.

> keryn forge query: Forge over compiled code: scan a jar, class directory or .NET assembly with every shipped rule (findings, SARIF, gate); facts, KSQL queries, graph export (local only)

Source: https://keryn.dev/docs/reference/cli/forge-query/

> **Caution: Next release: keryn forge query**
> On main; not in Keryn 0.5.2, the latest release.

Forge over compiled code: scan a jar, class directory or .NET assembly with every shipped rule (findings, SARIF, gate); facts, KSQL queries, graph export (local only).

```text
keryn forge query <bundles.json> <rule.ksql> [--limits <limits.json>]
```

## Options

```text
Usage: keryn forge capabilities
       keryn forge analyze <path...> [--bundle <bundles.json>...] [--out <bundles.json>]
       keryn forge query <bundles.json> <rule.ksql> [--limits <limits.json>]
       keryn forge dfd <bundles.json>
       keryn forge export <bundles.json>
       keryn forge scan <jar|class directory|dll>... [--sarif <file>] [--json <file>] [--markdown <file>] [--fail-on error|warning|none]
                        [--accept-missing-deps all|<prefix,...>] [--partition-prefix <path prefix>] [--engine-json <file>]
                        [--allow-incomplete] [--limits <limits.json>] [--timestamp <iso>]
  Forge builds one semantic security graph from fact bundles (source IR, tsc facts, JVM .class/.jar, LLVM .ll) and answers KSQL
  queries over it. Everything runs locally in the vendored keryn-engines wasm; files are read from disk, nothing is uploaded.
  capabilities   frontends and features this build has, with their status
  analyze        read the files under each <path>, hand them to the frontends and print {bundles, stats, unclaimed}; --bundle adds
                 pre-made bundles; --out writes the JSON there (summary on stderr) so 'query' and 'export' can read it
  query          run a rule file against the graph rebuilt from the bundles: a keryn.dev/ksql-result/v1 document (verdict per source/sink
                 pair: flow, unknown, no_flow; unknown is never clean). --limits takes a JSON file of analysis limits
  dfd            the data-flow / authority projection and the trust-canvas document derived from the bundles ({projection, trust_model})
  export         the canonical keryn.dev/forge-graph/v1 document (byte-identical across native and wasm)
  scan           analyse the compiled inputs and run every shipped rule: each flow is a finding at proof level 3 with its path, written
                 through the ordinary report writers. A pair that could not be decided (unknown) is never clean: it is counted in coverage
                 with its reason and the run is incomplete, as are a rule cut short, a referenced class that is not among the inputs
                 (--accept-missing-deps all treats libraries you left out as outside the program) and an input no frontend reads.
                 --partition-prefix org/acme/web/ analyses each class under that prefix (with its inner classes) as its own program
                 together with every input outside it, and merges the results: taint cannot pass between two such classes through a
                 shared helper. Input names are relative to the directory given. --engine-json writes the engine's own document.
                 A .NET assembly needs the full-producer module (vendor/keryn-engines-forge-full). Exit 0 when the gate passes; 1 findings
                 at or above --fail-on; 3 incomplete coverage or budget exhaustion; 4 engine failure. --allow-incomplete accepts
                 incomplete report coverage. With --exit-warn, a passing gate with warnings or accepted incomplete coverage exits 10.
  Exit 0; 2 usage or caller error (invalid_input, schema_mismatch, parse, type, unsupported); 3 budget_exhausted; 4 internal, cancelled,
  or 'forge exports not built' (this build does not include the Forge engine; use a release build). The error code is printed on stderr as 'keryn: forge: <code>: ...'.
```

## Examples

```sh
# A keryn.dev/ksql-result/v1 document: flow, unknown, no_flow. Unknown is never clean.
keryn forge query bundles.json rule.ksql
```

## Exit codes

| Code | Meaning |
|---|---|
| 0 | ok |
| 2 | usage or caller error |
| 3 | budget exhausted |
| 4 | internal error |
