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

gentzen

v1.0.0

Published

Formal reasoning for agents

Downloads

1

Readme

Who This Is For: Agent Pre-Condition Validation

The Agent Safety Problem

You're building agent systems that take real actions in the world. Before any agent runs, you need to prove the world is in a safe state. But current approaches are brittle, error-prone, and impossible to audit.

The Pain Points You're Experiencing:

🔥 Boolean Soup: Your pre-condition checks look like this:

if (user.isAuthenticated && !system.maintenanceMode && 
    (user.hasRole('admin') || (user.hasRole('user') && !user.isRestricted)) &&
    system.healthCheck() && !rateLimit.exceeded) {
    // Let agent run
}

🔥 No Audit Trail: When an agent is blocked, you get: "Access denied" - but why?

🔥 Fragile Logic: One wrong && vs || and your agents misbehave in production

🔥 Scattered Conditions: Pre-condition logic is buried across multiple files and functions

🔥 Testing Nightmare: How do you test all combinations of 10+ boolean conditions?

What This Is

This system enables declarative logical reasoning by:

  • Defining logical scenarios in YAML files.
  • Connecting to real data through JavaScript resolver functions.
  • Performing formal proof search using natural deduction rules.
  • Providing verifiable conclusions about complex logical conditions.

Development

# Clone/download this repository. Then...
cd <your repo>
yarn install

Basic Usage

import { join } from 'node:path';
import { runGentzenReasoning } from '../main.js';

const WD = import.meta.dirname;

console.log('🧪 Minimal example - just the basics...\n');

// Simplest possible usage
const results = await runGentzenReasoning(
    join(WD, './scenarios/mixed-scenario.yaml'),
    { resolversPath: join(WD, './resolvers') }
);

console.log(`✅ ${results.summary.provenTargets}/${results.summary.totalTargets} targets proven`);

Scenario Files (examples/scenarios/mixed-scenario.yaml):

propositions:
  - ProcessOrder
  - SendAlert
  - ScheduleMaintenance

steps:
  # Business logic: Customer + Payment.
  - rule: alpha
    subtype: and
    from:
      - CustomerIsVIP
      - PaymentProcessed

  # Combined business decision
  - rule: alpha
    subtype: implies
    from:
      - (CustomerIsVIP ∧ PaymentProcessed)
      - ProcessOrder

# Provable targets.
targets:
  - (CustomerIsVIP ∧ PaymentProcessed)
  - ProcessOrder

Resolver Functions (examples/resolvers/factResolvers.js):

export const travelFactResolvers = {
    CustomerIsVIP: () => true,
    PaymentProcessed: () => true,
    SystemHealthy: () => true,
    IsBusinessHours: () => false  
};

Run Example:

node examples/demo-minimal.js

Core Features

  • Formula Parsing: Full AST-based formula parser with operator precedence.
  • Auto-Negation: False resolvers automatically create negated facts (e.g., false~FactName).
  • Natural Deduction Rules: Five implemented rules for logical derivation.
  • YAML Scenarios: Declarative scenario definition with step-by-step reasoning.
  • Resolver Discovery: Automatic discovery of resolver functions.
  • Comprehensive Testing: Unit and integration tests covering all functionality.

Logical Rules Available

  1. Alpha Rule (AND/IMPLIES):

    • alpha + subtype: and → Creates conjunction: (A ∧ B)
    • alpha + subtype: implies → Creates implication: (A → B)
  2. Beta Rule (OR):

    • beta → Creates disjunction: (A ∨ B)
  3. Contraposition:

    • contraposition → From (A → B) derives (~B → ~A)
  4. Double Negation:

    • doubleNegation + subtype: introductionA becomes ~~A
    • doubleNegation + subtype: elimination~~A becomes A
  5. Equivalence:

    • equivalence → Creates biconditional: (A ↔ B)

API

runGentzenReasoning(scenarioPath, options)

Parameters:

  • scenarioPath (string): Path to YAML scenario file
  • options (object):
    • verbose (boolean): Enable detailed output.
    • customResolvers (object): Direct resolver functions.
    • resolversPath (string): Path to auto-discover resolvers.
    • validate (boolean): Enable scenario validation.

Returns: Results object with targets, summary, availableFacts, etc.

Auto-Negation System

When resolvers return false, the system automatically makes negated facts available:

const resolvers = {
    UserLoggedIn: () => true,        // Creates: UserLoggedIn
    MaintenanceMode: () => false,    // Creates: ~MaintenanceMode  
    SystemOnline: () => false        // Creates: ~SystemOnline
};

This enables reasoning with negative conditions:

targets:
  - (UserLoggedIn ∧ ~MaintenanceMode)  # Provable!

Testing

yarn test                 # All tests
yarn test:unit           # Unit tests only  
yarn test:integration    # Integration tests only
yarn test:verbose        # Detailed output

Logical Operators

  • (AND): Both conditions must be true
  • (OR): Either condition can be true
  • (IMPLIES): If-then logical implication
  • (EQUIVALENT): If-and-only-if (biconditional)
  • ~ (NOT): Negation
  • ~~ (DOUBLE NEGATION): Classical logic double negation

Operator Aliases: The parser accepts multiple formats for conditionals:

  • AND: , AND, &
  • OR: , OR, |
  • IMPLIES: , IMPLIES, ->