x-pack/platform/packages/shared/kbn-elastic-agent-condition-language/README.md
Syntax validator for Elastic Agent's condition expression language which is evaluated by the Elastic Agent to conditionally include agent inputs and streams.
See https://www.elastic.co/docs/reference/fleet/dynamic-input-configuration#condition-syntax.
import {
validateAgentConditionExpression,
type AgentConditionSyntaxError,
} from '@kbn/elastic-agent-condition-language';
const errors = validateAgentConditionExpression("${host.platform} == 'linux'");
// → [] when valid, [{ line, column, message }, ...] when malformed
interface AgentConditionSyntaxError {
line: number; // 1-based
column: number; // 0-based (Monaco consumers add +1)
message: string;
}
Empty or whitespace-only input returns [] — consistent with the agent treating an absent condition as "no condition".
The build script resolves the latest tagged release of elastic/elastic-agent via the GitHub API, fetches internal/pkg/eql/Eql.g4, and generates the TypeScript parser in src/parser/.
yarn build:parser
This runs scripts/build_parser.js, which:
Eql.g4.EqlLexer.ts → eql_lexer.ts, etc.) and rewrites the sibling imports inside each file.// @ts-nocheck to each generated .ts.Eql.g4.Prerequisites:
antlr4 npm runtime version in Kibana's root package.json).Install the ANTLR tool on macOS:
brew install antlr
…or download the jar from https://www.antlr.org/download.html and alias antlr to a shell wrapper that invokes it.
@ts-nocheckANTLR4's TypeScript target emits code that doesn't strictly satisfy Kibana's stricter tsconfig rules. @ts-nocheck skips type checking on those files only — application code that uses the parser (in src/validate.ts) is fully type-checked.
The src/parser/ directory is also added to .eslintignore so generated files aren't linted.