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

autonome-markets

v0.1.0

Published

The Script language behind autonome — a versioned schema for portfolio rules, a deterministic plain-English compiler, and a rule evaluator for cross-asset strategies.

Readme

autonome-markets

The Script language behind autonome.

A versioned schema for portfolio rules, a deterministic plain-English compiler that produces them, and an evaluator that decides whether one fires.

Pure functions only — no network, no execution, no side effects. Runs in the browser, Node, edge runtimes and workers.

npm install autonome-markets zod

zod is a peer dependency, so your application controls the version.


The shape of a Script

WHEN  →  CONDITIONS  →  ACTIONS  →  GUARDS

A trigger says when to evaluate. Conditions narrow it. Actions describe the capital movement. Guards describe what the runtime may never do.


Compile plain English

import { compileIntent } from 'autonome-markets'

const result = compileIntent(
  'If BTC falls 15% from its 30-day high, allocate $1,000 from my Treasury ' +
    'reserve, but keep at least 20% of my portfolio in stable assets.',
)

if (result.ok) {
  console.log(result.definition)
  console.log(result.confidence)   // 0.99
  console.log(result.assumptions)  // defaults it applied, stated plainly
}

The compiler is deterministic and runs entirely locally — there is no model call and nothing leaves the process. When it is unsure it says so rather than inventing a rule:

const vague = compileIntent('make me money somehow')
vague.ok       // false
vague.errors   // ['Could not determine when this Script should run.']

Produced definition:

{
  "version": 1,
  "trigger": { "type": "drawdown", "asset": "BTC", "value": 15, "window": "30d" },
  "conditions": [],
  "actions": [
    { "type": "allocate", "source": "UST", "destination": "BTC", "amount": 1000, "unit": "usd" }
  ],
  "guards": [{ "type": "min_stable_reserve", "value": 20, "unit": "percent" }],
  "metadata": { "compiler": "local-v1", "confidence": 0.99, "benchmark": "BTC" }
}

Validate a definition

Only definitions that satisfy the schema should ever be persisted.

import { validateScriptDefinition, SCRIPT_SCHEMA_VERSION } from 'autonome-markets'

const { ok, definition, errors } = validateScriptDefinition(input)
if (!ok) console.error(errors) // ['actions: Too small: expected array to have >=1 items']

The schema is versioned (SCRIPT_SCHEMA_VERSION) so future runtimes can be introduced without invalidating Scripts that already exist.


Evaluate a rule

evaluateScript is the single implementation of the WHEN → GUARD logic. Point it at whatever market and portfolio data you have.

import { evaluateScript } from 'autonome-markets'

const outcome = evaluateScript(
  definition,
  {
    now: Date.now(),
    price: (symbol) => prices[symbol] ?? null,
    changePct: (symbol, window) => changes[`${symbol}:${window}`] ?? null,
    rollingHigh: (symbol) => highs[symbol] ?? null,
  },
  {
    totalValue: 100_000,
    weights: { BTC: 22, UST: 38, USDC: 20, SPY: 20 },
    stableReservePct: 58,
    lastExecutionAt: null,
    allocatedTodayUsd: 0,
  },
)

outcome.triggered       // true
outcome.guardsPassed    // false
outcome.reason          // 'Maximum BTC allocation reached (31.2%)'
outcome.guardResults    // per-guard pass/fail with a readable detail

Missing data is reported, never assumed: if a price is unavailable the outcome is triggered: false with a reason saying so.


Describe a Script to a human

import { describeTrigger, describeAction, summariseScript } from 'autonome-markets'

describeTrigger(definition.trigger)
// 'BTC falls 15% from its 30D high'

summariseScript(definition)
// 'BTC falls 15% from its 30D high → Allocate $1,000 from UST to BTC'

triggerParts() and actionParts() return label/value pairs if you are rendering the rule as a diagram rather than a sentence.


Statistics

The same functions the autonome backtest report is built from.

import { maxDrawdown, sharpeRatio, annualisedVolatility, periodReturns } from 'autonome-markets'

const returns = periodReturns(equityCurve)
maxDrawdown(equityCurve)                 // -42.04  (negative percent)
annualisedVolatility(returns, 252)       // 33.14
sharpeRatio(returns, 252)                // -0.68

Asset registry

29 assets across equities, crypto, RWAs, commodities and stablecoins, with the provider, chain and contract metadata the compiler resolves symbols against.

import { ASSETS, getAsset } from 'autonome-markets'

getAsset('BTC')?.assetClass   // 'crypto'
getAsset('UST')?.market       // 'Treasuries'
ASSETS.length                 // 29

API surface

| Group | Exports | | --- | --- | | Schema | scriptDefinitionSchema, validateScriptDefinition, SCRIPT_SCHEMA_VERSION, and the trigger/action/guard schemas | | Compiler | compileIntent, LocalScriptCompiler, ASSET_ALIASES | | Runtime | evaluateScript, evaluateTrigger, evaluateGuard, windowDays | | Describe | describeTrigger, describeAction, describeGuard, summariseScript, monitoredAssets | | Registry | ASSETS, getAsset, requireAsset, PRICED_SYMBOLS | | Statistics | maxDrawdown, sharpeRatio, annualisedVolatility, totalReturnPct, and friends | | Formatting | formatCurrency, formatPct, shortenAddress |

Full TypeScript types ship with the package.


What this package does not do

It is a language and a rule engine, not a trading system.

  • No network access, no market data fetching, no API keys.
  • No order placement, venue connection or custody. Execution adapters live in the application, not here.
  • No investment advice. Simulated behaviour is hypothetical and no return is guaranteed.

Links

MIT © autonome