InternalsPackages

@unbound/agent-runtime

@unbound/agent-runtime

Agent runtime primitives for running Claude sessions with structured state, encryption, and queueing.

This package is used by clients and services that need to spawn Claude processes, manage session state transitions, and handle encrypted message flow.

What It Provides

  • Claude process wrapper with structured stream events
  • Session lifecycle state machine (pendingactivepausedended)
  • Session manager for multi-session orchestration
  • Message queue with ordering, retry, and acks
  • Session encryption helpers for payload protection

Primary Exports

ExportPurpose
ClaudeProcess / createClaudeProcessSpawn and stream Claude CLI output
Session / createSessionState-aware session wrapper
SessionManager / createSessionManagerManage multiple sessions
MessageQueue / createMessageQueueOrdered, ackable message queue
EncryptionManager / SessionEncryptionEncrypt/decrypt session messages
PairwiseEncryptionManagerPairwise device session encryption

Example

import {
  createSessionManager,
  createClaudeProcess,
  createSession,
  createMessageQueue,
} from "@unbound/agent-runtime";

const manager = createSessionManager({ maxConcurrent: 1 });
const queue = createMessageQueue({ maxInFlight: 8 });

const process = createClaudeProcess({
  cwd: process.cwd(),
  model: "claude-3-7-sonnet",
});

const session = createSession({
  id: crypto.randomUUID(),
  process,
  queue,
});

manager.register(session);

Module Layout

src/
├── process.ts     # ClaudeProcess implementation
├── session.ts     # Session state machine
├── manager.ts     # SessionManager
├── queue.ts       # MessageQueue with acks
├── encryption.ts  # Session + pairwise encryption
└── types.ts       # Shared types + schemas

Development

pnpm -C packages/agent-runtime build
pnpm -C packages/agent-runtime test
@unbound/agent-runtime