Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

my-harness

A modular, zero-dependency TypeScript AI Agent Harness, LLM Evaluation Harness, and Software Testing Harness — usable as a CLI, an embeddable SDK, or a clean reference architecture to hack on.

Runs natively on Bun (>=1.1) and Node.js (>=22.18 native TypeScript), with first-class support for both cloud APIs and locally downloaded models.

Architecture

src/
├── index.ts                 # Unified SDK exports
├── cli.ts                   # CLI: demo, models, chat, run, eval, test
├── agent/                   # 1. AI Agent Harness
│   ├── harness.ts           # Core AgentHarness loop (run + stream, hooks, budgets)
│   ├── types.ts             # Messages, ToolDefinitions, Events, Providers
│   ├── context.ts           # Token estimation & 2-stage context compaction
│   ├── permissions.ts       # Rule-based allow / deny / ask approval engine
│   ├── session.ts           # Append-only JSONL persistence (resume + fork)
│   ├── subagent.ts          # Scoped child agent delegation with depth limits
│   ├── mcp.ts               # Lightweight JSON-RPC 2.0 stdio MCP client
│   ├── tools/
│   │   ├── registry.ts      # JSON Schema validation, timeouts, error capture
│   │   └── builtins.ts      # Sandboxed read/write/edit/list/grep/shell tools
│   └── providers/
│       ├── local.ts         # Ollama, LM Studio, llama.cpp, MLX, vLLM, direct .gguf, discovery, XML tool fallback
│       ├── openai.ts        # OpenAI-compatible Chat Completions (streaming + tools)
│       ├── anthropic.ts     # Anthropic Messages API
│       ├── gemini.ts        # Google Gemini API
│       └── mock.ts          # Scriptable deterministic mock provider
├── eval/                    # 2. LLM Evaluation & Benchmark Harness
│   ├── runner.ts            # Concurrent EvalRunner, pass@k trials, isolated temp workspaces, baseline diffs
│   └── graders.ts           # exactMatch, contains, regex, usedTool, fileExists, fileContains, maxTurns, llmJudge
└── testing/                 # 3. Software Testing Harness
    └── harness.ts           # describe/test/hooks, expect(), createSpy(), withTempWorkspace()

Quick Start

# 1. Run the offline end-to-end demo (agent + auto-checkpoints + diff + subagent + eval + benchmark matrix)
bun run demo

# 2. Launch the built-in local Web Dashboard (chat, live tool trace, local models, sessions, evals)
bun run ui

# 3. Create a starter harness.config.json in your workspace (permissions, MCP servers, local model defaults)
bun run init

# 4. Run the multi-model benchmark matrix (optionally export an HTML report)
bun run benchmark
bun run src/cli.ts benchmark --html benchmark-report.html

# 5. Run the full test suite (works on both Bun and Node!)
bun run test
node tests/run.ts

# 6. Discover locally downloaded models & running local inference servers
bun run models

Using Local Downloaded Models

my-harness supports local models out of the box in 3 ways:

1. Discover what you already have downloaded

bun run src/cli.ts models
# Optionally scan a custom folder of .gguf files:
bun run src/cli.ts models --models-dir ~/Downloads

2. Run against a local server (Ollama, LM Studio, llama.cpp, MLX, vLLM)

# Ollama (native /api/chat with streaming & tool calling)
bun run src/cli.ts chat --provider ollama --model qwen2.5-coder:7b

# LM Studio (default http://127.0.0.1:1234/v1)
bun run src/cli.ts chat --provider lmstudio --model local-model

# Apple Silicon MLX (mlx_lm.server on :8080) or llama-server
bun run src/cli.ts chat --provider mlx --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

# Add --prompt-tools for older/smaller local models without native function calling:
bun run src/cli.ts chat --provider ollama --model llama3.2:3b --prompt-tools

3. Run a downloaded .gguf file directly (auto-managed llama-server)

bun run src/cli.ts chat --model-path ~/models/qwen2.5-coder-7b-q4_k_m.gguf

LocalGgufProvider spawns llama-server on an ephemeral localhost port, waits for /health, streams completions & tool calls, and cleanly shuts down the process on exit.

Using Cloud Models

# OpenAI / Anthropic / Gemini (auto-detected from env vars or explicit --provider)
ANTHROPIC_API_KEY=... bun run src/cli.ts chat
OPENAI_API_KEY=...    bun run src/cli.ts run "Summarize README.md"
GEMINI_API_KEY=...    bun run src/cli.ts run "List all TypeScript files"

SDK Usage

import {
  AgentHarness,
  LocalProviders,
  PermissionPresets,
  ToolRegistry,
  createBuiltinTools,
} from "./src/index.ts";

const harness = new AgentHarness({
  provider: LocalProviders.ollama({ defaultModel: "qwen2.5-coder:7b" }),
  workspaceDir: process.cwd(),
  tools: new ToolRegistry().registerAll(createBuiltinTools()),
  permissions: PermissionPresets.readOnly(),
});

const result = await harness.run("Find any TODO comments in src/");
console.log(result.output);

See examples/custom-agent.ts, examples/local-model.ts, and examples/eval-suite.ts for runnable examples.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages