The CodeWork agent harness: durable sessions and threads, the agent loop, tools, plugins, MCP and sandboxes, built on Effect. The codework CLI and RPC server boot it to run agents, and you can embed it to run them in your own Node process.
Note
This is an early release. Expect breaking changes between minor versions.
pnpm add @codeworksh/harness [email protected]effect is a peer dependency pinned to an exact version. Node 24.14.1 or newer is required.
The public surface is the Effect SDK at @codeworksh/harness/effect. The root export is empty for now.
import { Effect } from "effect";
import { Harness, Session } from "@codeworksh/harness/effect";
const program = Effect.gen(function* () {
const session = yield* Session.create({
directory: process.cwd(),
model: { provider: "openai", id: "gpt-5.5" },
thinkingLevel: "high",
});
// Stores the prompt, runs the main thread and waits until it is idle.
yield* session.main.run("Summarize this repository in one paragraph.");
const { usage } = yield* session.main.info;
console.log(`${session.id}: ${usage.input} in, ${usage.output} out, $${usage.cost}`);
});
await program.pipe(
// `home` holds settings, the model catalog and the database. It defaults to ~/.codework.
Effect.provide(Harness.layer({ home: ".codework" })),
Effect.scoped,
Effect.runPromise,
);API keys come from the process environment (here OPENAI_API_KEY), and the model catalog is kept in <home>/models.gen.json. See models.
A session is one durable event log, and its threads live inside it. session.main is the main thread. A thread handle can prompt (store and return), run (store and wait), interrupt, resume, fork and configure, and exposes events() and history(). Every run, prompt and durable event is stored, so Session.attach({ sessionId }) reaches a thread again after a restart, and Control.Service's resumeUnfinished picks up runs a crash cut off, as the RPC server does at start.
The harness is the agent itself. It owns the loop, prompt assembly, tool execution, the plugin catalog and installer, MCP clients, sandbox drivers and mounts, settings, and the SQLite store every run and durable event lands in.
It depends on @codeworksh/aikit for every model call and on @codeworksh/plugin for the plugin, tool and sandbox contracts, and on @codeworksh/schema for the ids, records and events it persists. It never imports the CLI, the RPC server or anything under apps/. That keeps it a library that never knows how it is reached, so the RPC server, in-process codework run and ACP all boot the same harness.
Third parties extend it with plugins built against @codeworksh/plugin, not against this package. Pass them to Harness.layer({ plugins }), or list them in a settings file's plugins block. Remote sandboxes load from the @codeworksh/harness/sandboxes/vercel and @codeworksh/harness/sandboxes/daytona subpaths through Harness.layer({ sandboxes }), with their provider SDK installed beside it.
src/effect.tsis the public SDK barrel.src/effect/harness.tsbuildsHarness.layer: its options and the service wiring.src/effect/session.tscreates, attaches and relinks sessions and returns session and thread handles.src/control.tsstarts, joins and stops work: prompt, run, interrupt and resume.src/runnerholds execution, the per-thread coordinator, the loop, retries and the one boundary to aikit.src/eventis the durable event log and its projectors.src/pluginloads, installs and runs plugins, including the built-in tools and prompt.src/sandboxandsrc/sandboxeshold the driver registry, mounts and the bundled drivers.src/mcpruns MCP servers and exposes their tools.src/settingsreads and merges settings files.src/dbis the SQLite store and its migrations.
pnpm check # vp check
pnpm test # vp test
pnpm build # vp packpnpm test:sandbox:e2e runs the remote sandbox suites and needs provider credentials. See testing.
- Runtime: sessions, threads, runs and durability.
- Services: Effect services, layers and errors.
- Sandboxes, settings and plugins.
Report issues in the CodeWork repository.