Skip to content

Getting started

Run your first example in the browser or build the package for your own project.

Open Change the priority of queued work and click Run. The queue moves the layout task to the front when its priority changes, then returns it first.

Knotkit is preparing its first npm release. To use it in your project today, build a package tarball from a checkout. You’ll need Bun to build it and npm to pack it.

Terminal window
git clone https://github.com/jkomyno/knotkit.git
cd knotkit
bun install --frozen-lockfile
bun run build
npm pack ./packages

In your project, install the tarball using its absolute path. Use the filename printed by npm pack.

Terminal window
npm install /path/to/knotkit/knotkit-0.1.0.tgz

Knotkit is ESM only. With TypeScript, use 5.x or later and set moduleResolution to "bundler" or "nodenext".

Node.js 22.12 or later.

Import the capability you need directly from a subpath such as knotkit/heap, knotkit/bitset, or knotkit/sampling. Your bundler can start from that subpath and include its dependencies.

import { minBinaryHeap, numberOrder } from 'knotkit/heap'
const heap = minBinaryHeap(numberOrder, [30, 1, 50, 20])
heap.peek() // 1
heap.pop() // 1
heap.size // 3

minBinaryHeap creates a heap, and numberOrder tells it how to compare numbers. Orderings, random sources, and hash functions are inputs to the operations that need them, so you can replay a workload with the same inputs.

Use the exported error class and its code to handle a specific failure. Calling pop() on an empty heap raises HeapInvalidInputError with the code EMPTY.

import { HeapInvalidInputError, minBinaryHeap, numberOrder } from 'knotkit/heap'
const empty = minBinaryHeap(numberOrder)
try {
empty.pop()
} catch (error) {
if (!(error instanceof HeapInvalidInputError) || error.code !== 'EMPTY') {
throw error
}
// Handle the empty heap.
}

Each module page lists its error codes. Conventions covers errors, layouts, and seeding in one place.

Paste this into Claude Code, Cursor, Codex, or any agent that can run commands:

Prompt · set up Knotkit
Set up Knotkit in this project.

1. Follow https://knotkit.jkomyno.dev/getting-started.md#install-from-source to build and install the package. Use "bundler" or "nodenext" module resolution in TypeScript.
2. Run `npx skills add jkomyno/knotkit --skill knotkit-select` to install the skill that picks a module for a task.
3. Add this to AGENTS.md (or CLAUDE.md):

   Knotkit: pick a module from node_modules/knotkit/capabilities.json, then read node_modules/knotkit/<name>/README.md. Import from 'knotkit/<name>'; there is no root import. Create structures with the exported factory functions, branch on error.code, and pass seeds and orderings explicitly.

If something is unclear, read https://knotkit.jkomyno.dev/llms.txt.