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

@ankhzet/goap

v1.3.2

Published

Goal-Oriented Action Planning library for TypeScript/JavaScript.

Readme

GoAP

Goal-Oriented Action Planning library for TypeScript/JavaScript.

Overview

GoAP enables autonomous agents to dynamically generate action sequences to achieve goals. Unlike behavior trees or state machines, plans are computed at runtime based on current world state and available actions.

Key features:

  • Automatic plan generation via backward-chaining search
  • Cost-based path selection
  • Dynamic state evaluation at runtime
  • Action hierarchies with preconditions and effects
  • Extensible via TypeScript mixins

Installation

npm install @ankhzet/goap
# or
yarn add @ankhzet/goap
# or
pnpm add @ankhzet/goap

Requires TypeScript 4.0+ or ES2018+ runtime.

Quick Start

import {
  Action,
  ActionEnactor,
  ActionProcessingResult,
  EnactorState,
  GoalActionPlanner,
  GoalActionExecutor,
  StateBitInterface,
  StateInterface
} from 'goap';

// Define state bits
const isHungry: StateBitInterface<Agent> = { name: 'isHungry' };
const hasFood: StateBitInterface<Agent> = { name: 'hasFood' };

// Define actions
class EatAction extends Action<Agent> {
  cost = 1;
  requires = new EnactorState([[isHungry, true]]);
  provides = new EnactorState([[hasFood, true]]);

  process(enactor: Agent): ActionProcessingResult {
    enactor.hunger = 100;
    return ActionProcessingResult.Finished;
  }
}

// Create agent
class Agent extends ActionEnactor(BaseClass) {
  actions = new Set([new EatAction()]);
  state = new EnactorState();
  deriveGoal(): StateInterface<Agent> {
    return new EnactorState([[hasFood, true]]);
  }
}

// Plan and execute
const planner = new GoalActionPlanner<Agent>();
const executor = new GoalActionExecutor<Agent>();

const plan = planner.plan(agent, agent.deriveGoal(), agent.state);
if (plan) {
  agent.acceptSequence(plan);
  // In game loop:
  executor.process(agent, delta);
}

Documentation

Examples

| Domain | Description | |--------|-------------| | Game NPC AI | Survival game with hunger, health, combat, socialization | | Warehouse Robot | Pick-and-deliver logistics with battery management | | Smart Home | Home automation with HVAC, lighting, security | | Autonomous Vehicle | Navigation with routing, obstacle avoidance, parking |

Core Concepts

State

World state is represented as a collection of bits with boolean values:

const state = new EnactorState<Agent>([
  [hasWeapon, true],
  [isHealthy, false]
]);

State bits can be static or dynamic:

const nearEnemy = {
  name: 'nearEnemy',
  isFulfilledBy: (agent) => agent.distanceToEnemy < 10
};

Actions

Actions have preconditions (requires), effects (provides), and cost:

class MyAction extends Action<Agent> {
  cost = 5;
  requires = new EnactorState([[hasAmmo, true]]);
  provides = new EnactorState([[enemyDead, true]]);

  process(enactor: Agent, delta: number): ActionProcessingResult {
    // Execution logic
    return ActionProcessingResult.Finished;
  }
}

Agents

Agents combine state with available actions:

class MyAgent extends ActionEnactor(BaseClass) {
  actions = new Set<ActionInterface<MyAgent>>();
  state = new EnactorState<MyAgent>();

  deriveGoal(): StateInterface<MyAgent> {
    // Compute goal based on current needs
    return new EnactorState([[hasFood, true]]);
  }
}

Planning

The planner finds the cheapest sequence to achieve a goal:

const planner = new GoalActionPlanner<MyAgent>();
const plan = planner.plan(agent, goal, currentState);
// Returns ActionInterface[] or undefined

Execution

The executor runs the planned sequence:

const executor = new GoalActionExecutor<MyAgent>();

// In game loop:
const isActing = executor.process(agent, delta);
if (!isActing) {
  // Replan
}

API Overview

| Class | Purpose | |-------|---------| | EnactorState | Mutable world state | | Action | Base action class | | ActionWithTarget | Action requiring movement | | ActionEnactor | Mixin for action-performing agents | | GoalActionPlanner | Plan generation | | GoalActionExecutor | Plan execution |

See Public API for complete reference.

License

MIT