monag

NL-DSL-LLM translation contract

Purpose

Define the binding contract by which a large language model may extend the rule-based natural-language front end of the Monag observation DSL (monag.dsl, schema monag.dsl/v1). The contract is normative: any implementation that does not satisfy a MUST clause below is non-conforming, regardless of how useful its output appears.

Scope

The contract covers translation of a free-form Polish or English observation request into exactly one canonical OBSERVE ... query, executed by the existing read-only domain scanners. It does not cover generation of reports, aggregation across statements, mutation of any state, or network observation beyond what the rule engine already performs. The LLM is a translation aid only; it never selects data sources beyond the six declared domains.

Content

1. Resolution order

  1. The rule engine (monag.dsl.parse) MUST be consulted first and its result returned unchanged when it resolves the input. This path MUST NOT spawn a subprocess or contact any provider (engine rule).
  2. An LLM MUST be consulted only when the rule engine returns no query AND a provider command is configured (engine llm).
  3. With no configured provider, behavior MUST be identical to the pre-LLM releases: an unmappable input yields an error result (engine none).

2. Provider protocol

3. Output contract

4. Grammar (monag.dsl/v1)

OBSERVE <domain> [HOURS <n>] [STATE <open|merged|all>] [LIMIT <n>] [UNPUSHED_ONLY] [WORKTREES_ONLY]
domain := prs | audit | status | resume | usage | catalog

The provider prompt MUST enumerate the domains and parameters and MUST instruct the model to answer either with one grammar-conforming line or with OBSERVE none.

5. Provenance and failure semantics

6. Reference implementation

src/monag/dsl_llm.py implements this contract (resolve, execute). monag query, monag shell, panel /api/query and the MCP monag_query tool route through it; conformance tests live in tests/test_dsl_llm.py.

Limitations

The contract applies only to translation into canonical queries for the six declared domains (prs, audit, status, resume, usage, catalog). It does not mutate repository state or access private network endpoints beyond the local execution boundary.

Next actions

Maintain integration with semcod/algocode for AST-level symbol inspection and duplicate detection in query generation, and monitor provider timeouts in production.

Evidence

Rule-first short-circuit, provider translation, fenced/multi-line/unparseable rejection, timeout and disabled-by-default behavior are asserted by the unit suite; ./project/governance-check.sh gates the material delta.