Skip to content

A small, tested block for each job.

What Python ships, in one TypeScript package.

Python ships heapq, bisect, and scipy.stats as standard tools. In TypeScript, teams hand-roll priority queues, maintain WebAssembly bridges, or sort a whole array to read 32 items.

Knotkit is one zero-dependency package: 32 modules behind subpath imports, 16 probability distributions, and hypothesis tests whose p-values match SciPy 1.15.3 to 1e-9. Each structure hands back a typed value you can pass to a service, a test, or a widget that draws what the algorithm does.

Seeded inputs make a run replayable, so the block behind a request can also redraw a figure in a lecture. Where a native Set or Map is the better answer, the module page says so.

schedule.ts
import { minPriorityQueue, numberOrder } from 'knotkit/heap'
// [priority, task]: the lowest priority runs first.
const queue = minPriorityQueue(numberOrder, [
[5, 'render'],
[1, 'parse'],
[3, 'layout'],
])
queue.updateKey(0, 'layout') // a user is now waiting on layout
queue.pop() // 'layout'
queue.pop() // 'parse'
queue.size // 1

Less work shows up in the timings.

A lazy merge can stop after 32 IDs. An indexed queue can update a task in place. See what these choices saved on the recorded workloads. Read the measurements and baselines →

Count the overlap between two bitsets
528×
faster than a manual Set loop
Read the first 32 sorted IDs
408×
faster than materializing and sorting all IDs
Build a queue and update all 1,000 priorities
272×
faster than heap-js linear remove and push
Build 100,000 singleton sets
164×
faster than a Map of Sets

32 modules, one import rule.

Import a subpath and the bundle carries that module alone. Every structure is property-tested against a reference model, the TLA+ models replay against the implementations, and the statistical modules hold their p-values to SciPy 1.15.3 within 1e-9.

Module pages draw their figures from that module's own demo.ts. Where the demo declares inputs, moving one reruns the module in a web worker.

Search modules by task →

Four rules, in every module.

Every structure comes from a factory that hands you a typed value, and these rules decide how that value behaves, in a service and in an explainer alike.

  • Construct a value once

    A value with a rule is checked where it enters, by a constructor such as Probability.make, and carries a branded type from there. No caller re-asserts a number.

    const p = Probability.make(0.95)
  • Pass the seed

    A random source is an argument, not a global, so a probabilistic call cannot run without the one you pass. Record the seed and the draw replays in a test, a benchmark, or someone else’s browser.

    shuffled(splitmix32(42), cards)
  • Errors carry codes

    Every failure is a package error carrying a code from an exported list, so a switch that misses one added in a new release fails the typecheck.

    if (error.code === 'EMPTY') { … }
  • Choose a layout by kind

    The kind string survives serialization and two copies of the package in one bundle, while instanceof survives neither.

    roaringBitset()  // kind: 'roaring'
    denseBitset()    // kind: 'dense'

Read the conventions →

Give your agent the right API on the first try.

The module-selection skill gives your agent the available imports, layout rules, and error codes for the version you installed. Give it a task and let it look up the relevant module before it writes code.

  • /llms.txtdocs in full, abridged, or by topic
  • /modules/heap.mdthe heap page in Markdown
  • knotkit/capabilities.jsonshipped in the package
  • knotkit-selectskill that picks the module

Agent setup →

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.

Run a guide or explore a complete solution.

Enjoying Knotkit? A star on GitHub helps more people find it.