Skip to content

harness-kit

harness-kit is the framework the Kerpeten CLI is built on. It is a TypeScript library for Bun. Use it to build your own model harness or command-line program.

bun add @kerpetensh/harness-kit @asenajs/ioc zod

A harness is a model that works on one request with a set of tools. In the kit it is a class:

@Harness({ name: "summary", tools: [ReadLinesTool], permissions: ["files:read"] })
export class SummaryHarness extends HarnessBase<string, Summary> {
protected readonly output = summaryOutput;
protected readonly finalizeRequest = "Give the summary now.";
protected instructions(): string {
return "Read the file with read_lines, then summarize it in one sentence.";
}
protected context(path: string): string {
return `The file is ${path}.`;
}
}

A first program builds the whole program around this class.

To use Kerpeten itself, start at Getting started.

Each part is a class with a decorator. The container builds the parts, and the kit checks when it starts that they fit.

Kind What it is
Capability Reaches outside the program: files, the network, another program
Tool Something a model can call
Harness Runs a model with tools on one request and gives a typed answer
Flow step One step of a workflow
Workflow A chain of flow steps
CLI A program whose commands are workflows
Page What it covers
A first program The smallest working program, from a capability to a run with a model.
Components The kinds, how a class takes another, and the check at the start. A harness must list every permission its tools use. A tool, a flow step or a command that is listed but not registered stops the start, with an error that names it.
Runs and permissions A workflow opens a run. In a run, a tool gets a capability only when the permission group of the run gives the capability’s permission.
Workflows, commands and the CLI Flow steps over a typed state: the compiler checks that each flow step finds the fields it reads. Commands, the command line and exit codes.
Tools, harnesses and contexts How a tool fails and how a harness runs. A run has two deadlines and can have a tool call limit. A run that a limit cuts short still asks the model for its final answer, and the result says why it stopped.
Skills Skills in the Agent Skills format: a source for each place they come from, and a library that lists them for the model, reads a file once and checks it against its listing.
Models The second entry point, with adapters for Anthropic, OpenAI, OpenRouter and a ChatGPT plan through the AI SDK.
Starting programs ProcessCapability, collect, stream, standard input and the time limit.
Testing Test runs, doubles and a scripted model.
  • The package is @kerpetensh/harness-kit, version 0.5.0. The source is at github.com/KerpetenSH/harness-kit.
  • It is young. It was built for Kerpeten and taken out of it, and the API may change before 1.0.
  • The doc comments in the source are the reference. When a page here and the code disagree, the code is right.

bun add @kerpetensh/harness-kit @asenajs/ioc zod installs the kit and the two packages it always needs.

The kit runs on Bun 1.4 or newer. It is written for Bun, not for Node.js: ProcessCapability, for one, starts programs with Bun.spawn.

The kit is built on the IoC container @asenajs/ioc. It has no dependencies of its own. Every package it imports is a peer dependency: your program installs it and imports it too, and both sides must use the same copy.

Package Version Needed for
@asenajs/ioc ^0.2.0 always
zod ^4.6.7 always
ai ^7.0.179 the ai-sdk entry point
@ai-sdk/anthropic ^4.0.107 the ai-sdk entry point
@ai-sdk/openai ^4.0.122 the ai-sdk entry point
@openrouter/ai-sdk-provider ^3.1.0 the ai-sdk entry point

The four model packages are optional. Install them when you use the model adapters:

bun add ai @ai-sdk/anthropic @ai-sdk/openai @openrouter/ai-sdk-provider

The ai-sdk entry point imports all four, so it needs all four, also when your program calls one provider only.

Import What it holds
@kerpetensh/harness-kit The decorators, the base classes, the container setup, runs, permissions, workflows and the CLI. It imports no model package.
@kerpetensh/harness-kit/ai-sdk The model adapters: AiSdkAdapter, the provider adapters and ChatGptAdapter.

Inject, Service and OnStart are not part of the kit. Import them from @asenajs/ioc.

import { Inject, OnStart, Service } from "@asenajs/ioc";
import { Capability, CapabilityBase, Tool, Use } from "@kerpetensh/harness-kit";
import { AiSdkAdapter } from "@kerpetensh/harness-kit/ai-sdk";

A program can also bring its own model adapter and leave the ai-sdk entry point out. A harness takes any object with the LlmAdapter interface of the main entry point. See Models.

tsconfig.json needs two things:

  • "experimentalDecorators": true, because the decorators are TypeScript’s older decorators,
  • the Bun types, from the package @types/bun.

emitDecoratorMetadata is not needed.

{
"compilerOptions": {
"target": "ESNext",
"module": "Preserve",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"types": ["bun"],
"experimentalDecorators": true
}
}

Two things go wrong without an error from the compiler.

Bun reads the decorator setting from the working directory

Section titled “Bun reads the decorator setting from the working directory”
  • Cause. When Bun runs TypeScript from source, it takes the decorator setting from the tsconfig.json of the directory it is started in. The one beside the file does not count.
  • What you see. Started from another directory, the same source runs with standard decorators. The program fails while its classes are defined, for example with TypeError: Properties can only be defined on Objects. This was seen with Bun 1.4.5.
  • What to do. Start the program from the project directory, name the tsconfig.json with bun --tsconfig-override=<path>, or ship compiled output.

tsc output needs useDefineForClassFields: false

Section titled “tsc output needs useDefineForClassFields: false”
  • Cause. With the default for ES2022 and newer targets, tsc writes every declared field into the class. A field written that way hides the getter that @Use and @RunValue put there.
  • What you see. The field reads undefined.
  • What to do. When you compile your program to JavaScript with tsc, set "useDefineForClassFields": false. Running the TypeScript files with Bun needs no such setting.