npm.io
0.6.0 • Published 19h ago

@anteriorai/srg-compiler

Licence
SEE LICENSE IN LICENSE
Version
0.6.0
Deps
0
Vulns
0
Weekly
0

@anteriorai/srg-compiler

Compiles .srg files to executable JSON format compatible with the Python symbolic_reasoning runtime.

Public preview. This package is an early public release of Anterior's symbolic reasoning tooling. It is being published to support transparency, research discussion, and early experimentation while the broader open-source repository is prepared for release.

Future releases may be made available under updated licensing terms. Until then, use of this package is governed by the license included with this release.

This release should not be treated as a supported product, a stable API, or a complete reference implementation. It is provided "as is," without warranties of any kind. Users are responsible for evaluating correctness, security, compliance, and suitability for their own use case.

Installation

npm install @anteriorai/srg-compiler

Usage

Programmatic API
import { compile, compileFile } from '@anteriorai/srg-compiler';

// Compile from string
const source = `
predicate is_adult: "Is patient 18 or older?"
outcome approved: "Approved"
is_adult => approved
`;

const json = await compile(source);

// Compile from file
const json2 = await compileFile('policy.srg');
CLI
# Compile a .srg file
npx srg-compile policy.srg

# Specify output file
npx srg-compile policy.srg --output result.json

# Pretty print JSON
npx srg-compile policy.srg --pretty

Output Format

The compiler outputs JSON that matches the JSON schema SRG model exactly:

{
  "edges": {...},
  "nodes": {...},
  "predicates": {...},
  "aggregators": {...},
  "outcomes": {...},
  "policy_context": null
}

This JSON can be directly loaded by Python:

from symbolic_reasoning.models import SRG

srg = SRG.model_validate_json(json_string)

Development

Building from Source
# Install dependencies
npm install

# Build the compiler
npm run build

The build process compiles TypeScript to dist/.

Dependencies

This package depends on:

  • @anteriorai/srg-parser: Parses .srg files to AST. Handles all syntax parsing and tree-sitter integration.
  • @anteriorai/srg-types: Provides TypeScript types for the SRG JSON schema. The compiler imports these types directly (e.g., import type * as SRG from '@anteriorai/srg-types')