npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nobulex/covenant-lang

v0.2.1

Published

Cedar-inspired covenant DSL: lexer, parser, AST, compiler for behavioral specifications

Readme

@nobulex/covenant-lang

Cedar-inspired DSL for behavioral specifications. Provides a complete pipeline from source text to enforcement function: source -> tokens -> AST -> enforcement function.

The covenant language lets you define what an AI agent is permitted and forbidden to do, with optional conditions and requirements.

Installation

npm install @nobulex/covenant-lang

Requirements: Node.js >= 18

Dependencies: @nobulex/core-types

Quick Usage

import { tokenize, parse, compile, parseSource } from '@nobulex/covenant-lang';

// Full pipeline: source -> tokens -> AST -> enforcement function
const source = `
  covenant SafeTransfer {
    forbid transfer (amount > 500);
    permit api_call;
    require counterparty.compliance_score >= 0.9;
  }
`;

const tokens = tokenize(source);
const spec = parse(tokens);
const enforce = compile(spec);

const decision = enforce({ action: 'transfer', params: { amount: 600 } });
console.log(decision.action); // 'block'

// Or use the convenience function:
const spec2 = parseSource(source);

DSL Syntax

covenant <Name> {
  permit <action>;
  permit <action> (<field> <op> <value>);
  forbid <action>;
  forbid <action> (<field> <op> <value>);
  require <field> <op> <value>;
}

Effects: permit, forbid

Operators: >, <, >=, <=, ==, !=

Values: strings (quoted), numbers, booleans

Example

covenant DataGuard {
  permit read;
  permit write (size <= 1048576);
  forbid delete;
  forbid transfer (amount > 10000);
  require caller.trust_score >= 0.8;
}

API Reference

Functions

tokenize(source: string): Token[]

Lexes source text into a stream of tokens. Throws LexerError on invalid input.

import { tokenize } from '@nobulex/covenant-lang';

const tokens = tokenize('covenant Foo { permit read; }');
// Returns array of Token objects

parse(tokens: Token[]): CovenantSpec

Parses a token stream into a CovenantSpec AST. Throws ParseError on invalid grammar.

import { tokenize, parse } from '@nobulex/covenant-lang';

const spec = parse(tokenize('covenant Foo { permit read; forbid write; }'));
console.log(spec.name);       // 'Foo'
console.log(spec.statements); // [{effect:'permit', action:'read', ...}, ...]

compile(spec: CovenantSpec): EnforcementFn

Compiles a CovenantSpec into an enforcement function. The function evaluates an ActionContext and returns an EnforcementDecision.

import { parseSource, compile } from '@nobulex/covenant-lang';

const enforce = compile(parseSource('covenant X { forbid delete; permit read; }'));
const decision = enforce({ action: 'delete', params: {} });
console.log(decision.action); // 'block'

serialize(spec: CovenantSpec): string

Serializes a CovenantSpec back to DSL source text.

import { parseSource, serialize } from '@nobulex/covenant-lang';

const spec = parseSource('covenant Foo { permit read; }');
const source = serialize(spec);
// 'covenant Foo {\n  permit read;\n}'

parseSource(source: string): CovenantSpec

Convenience function that combines tokenize and parse in one call.

import { parseSource } from '@nobulex/covenant-lang';

const spec = parseSource('covenant MyAgent { permit read; forbid delete; }');

Classes

LexerError

Thrown when the lexer encounters invalid input.

ParseError

Thrown when the parser encounters invalid grammar.

Types

Token

A single lexer token.

| Field | Type | Description | | -------- | ----------- | -------------------------- | | type | TokenType | The token classification | | value | string | The raw token text |

TokenType

Enum of all token types: keywords (covenant, permit, forbid, require), operators, literals, punctuation, and EOF.

ActionContext

Input to an enforcement function.

| Field | Type | Description | | -------- | ------------------------- | ---------------------- | | action | string | The action name | | params | Record<string, unknown> | Action parameters |

EnforcementFn

type EnforcementFn = (ctx: ActionContext) => EnforcementDecision;

Re-exported Types (from @nobulex/core-types)

  • CovenantSpec
  • CovenantStatement
  • CovenantCondition
  • CovenantRequirement
  • CovenantEffect
  • ComparisonOperator
  • EnforcementDecision

License

MIT