npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@anureo/sdk

v0.3.16

Published

Runtime core of the Anureo SDK: unified HarnessRuntime and HarnessSession over any adapter, enforcing AHP semantics

Readme

@anureo/sdk

@anureo/sdk runs agent sessions through a harness adapter. Applications use it to submit input, stream events, collect results, and control native executions. The SDK validates AHP requests and events, tracks which execution handles each submission, and owns session observation and cleanup. The adapter provides the native execution and reports its progress.

This guide describes the revised workspace API. The published 0.2.0 release has a different lifecycle API. See the workspace guide and the lifecycle migration notes.

Quick start

This example requires an authenticated Codex CLI on PATH and the Codex adapter. For a streaming version, run bun run example from the workspace root or read the greeting example.

import { createClient } from '@anureo/sdk'
import { createCodexAdapter } from '@anureo/adapter-codex'

const client = await createClient({
  adapter: createCodexAdapter({ command: 'codex' }),
  identity: { adapterId: 'codex', runtimeConfigId: 'local' },
})

try {
  const session = await client.sessions.create({ cwd: process.cwd() })
  const turn = await session.submit({ input: 'Say hello in one sentence.' })
  const result = await turn.result()

  if (result.status === 'failed') throw new Error(result.error.message)
  if (result.status === 'interrupted') throw new Error('Turn interrupted')
  console.log(result.text)

  await session.close()
} finally {
  await client.dispose()
}

Application API

Import the application API and its types from @anureo/sdk.

Client

| API | Purpose | | --- | --- | | createClient(options, wait?) | Initialize an adapter and return a Client ready to open sessions. | | new Client(options), client.initialize(wait?) | Construct a client without I/O, then negotiate adapter capabilities explicitly. | | client.identity | Read the adapter and runtime configuration IDs used to validate session bindings. | | client.inputHookRevision | Read the version of the active hook policy. Unconfigured clients return undefined. | | client.sessions.create(options, wait?) | Open a new session with a fresh binding. | | client.sessions.resume(reference, wait?) | Reopen the session identified by a saved session.reference, when supported. | | client.sessions.fork(reference, { boundary }, wait?) | Open a new session from a specified boundary in an existing session, when supported. | | client.openSession(params, wait?) | Open a session with explicit AHP open parameters and binding. | | client.dispose() | Release the client's sessions and adapter. Call it in finally. |

ClientOptions configures the adapter, client identity, input hooks, runtime hooks, interaction handlers, and retention limits. RuntimeOptions configures timeouts, resource budgets, and host hooks such as ID generation and history redaction.

Input hooks

Register application callbacks through ClientOptions.hooks to transform and validate input before sending it to the backend. The same callbacks apply to session.submit(), turn.steer(), and direct input/submit and turn/steer requests on every session opened through that client.

const client = await createClient({
  adapter,
  identity,
  hooks: {
    inputRevision: 'trim-input-v1',
    transformInput: [
      ({ input }) => input.map(block =>
        block.type === 'text' ? { ...block, text: block.text.trim() } : block,
      ),
    ],
    beforeInput: [
      ({ input }) => input.some(block => block.type !== 'text' || block.text.length > 0)
        ? undefined
        : { action: 'deny' },
    ],
  },
})

InputTransformHook returns replacement blocks or undefined to keep the current blocks. After all transformations, every BeforeInputHook receives a detached snapshot of the final input. Return undefined to continue or { action: 'deny' } to reject with HOOK_DENIED. The root entry point also exports ClientHooks, BeforeInputEvent, and BeforeInputDecision.

Hook handlers run in registration order. Within a session, inputs reach the backend wrapper in the order they enter the hook queue. Each input shares a single budget across queueing and callbacks, set with hooks.timeoutMs and defaulting to 5 seconds. Respect the callback's AbortSignal on cancellation or timeout. Callbacks can read raw application input, so handle it accordingly. The client shares a 32-callback limit and a pending-input byte budget across its sessions. Exhausting either budget rejects with BACKPRESSURE_EXCEEDED.

Hook exceptions and invalid return values produce HOOK_FAILED. An expired hook produces HOOK_TIMEOUT. Both reject before backend handoff with outcomeUnknown: false. Aborting a caller's wait leaves the admitted request running. Closing the session or sending a supported session.interrupt({ cancelQueued: true }) cancels inputs still in the local hook queue. The interrupt receipt includes local cancellation IDs after native acknowledgement. Increase inputRevision when policy behavior changes and consult the workflow resume contract for persisted agent calls.

Native control hooks

On adapters that implement native hooks, hooks.beforeTool takes exact native tool names and a callback. Returning { action: 'deny' } rejects the call. Returning undefined leaves the decision to the normal native permission flow. Invalid decisions, callback failures, and host-side timeout deny a matching call while the native callback channel remains responsive.

hooks.beforeStop receives the current turn ID and the last assistant message, when provided. Return { action: 'continue', prompt } to request one more native continuation of the same text turn, or undefined to let it stop. The continuation prompt accepts up to 4 KiB of UTF-8 text. Native controls use the same hooks.timeoutMs callback budget and inputRevision as input hooks. Both receive an AbortSignal. Check the adapter guide for covered tools, eligible turns, and transport guarantees. Opening a session fails with CAPABILITY_UNSUPPORTED if the adapter cannot provide the configured hooks.

Session

A Session represents a conversation opened through the client.

| API | Purpose | | --- | --- | | session.submit(options, wait?) | Send input and return a Turn once the adapter associates the input with an execution. | | session.review({ target }, wait?) | Start a supported native review and return its associated Turn. | | session.events(options?) | Subscribe to future session events, including submission progress and interaction requests. Subscribe before submitting to observe those events. | | session.id, session.binding, session.reference | Read the session ID, its adapter binding, or a reference for resuming or forking it. | | session.capabilities, session.snapshot | Check the session's current capabilities or read its current privacy-filtered state. | | session.interrupt(options?, wait?) | Request a session-wide interrupt. Pass cancelQueued only when supported. An acknowledgement alone cannot establish that execution stopped or that queued input was withdrawn. | | session.request(method, params, wait?) | Send a typed, lower-level AHP session request for operations such as history reads or manual interaction responses. | | session.close(wait?) | Request native close and release observation and backend resources after the receipt. The receipt reports observationClosed and executionStopped separately. | | session.dispose() | Release local observation and backend resources without asserting that native execution stopped. |

Input accepts a string or an array of AHP input blocks. SubmitOptions also accepts capability-gated delivery, overrides, and outputSchema. Delivery defaults to native, so a backend can queue input or merge it into an existing execution. Two submissions can return handles with the same turn.id. Count the execution and its usage once. Use delivery: 'afterTurn' when session.capabilities.input?.delivery includes afterTurn. The SDK tracks submission IDs internally. submit() waits for an execution association, which can arrive before an acceptance receipt or after the execution has already ended.

Pass a JSON Schema as outputSchema when session.capabilities.turn?.outputSchema is enabled. A successful result carries JSON in result.text. The SDK uses native schemas where available, a direct output tool on Pi, or a session-scoped MCP bridge on supported ACP and Hermes sessions. The structured output example shows how to submit and parse a result.

Configure supported interactions through ClientOptions.interactions. An InteractionHandlers function handles its kind automatically. An explicit key with value undefined enables manual responses through session events and session.request('interaction/respond', params). An omitted kind is unsupported.

Turn

| API | Purpose | | --- | --- | | turn.id | Read the execution ID shared by all handles observing that execution. | | turn.result(wait?) | Wait for the execution's terminal result or read it if already retained. | | turn.events(options?) | Subscribe to future events for this execution. | | turn.steer({ input }, wait?) | Wait for native confirmation that input was appended to this exact execution. Requires session.capabilities.input?.steer?.atomicMatch and rejects stale targets. | | turn.interrupt(wait?) | Request interruption of this exact execution when supported. Use result() to observe its terminal status. | | turn.observe() | Create an independent handle for the same execution. | | turn.dispose() | Stop this handle's waits and subscriptions. Native execution and other handles can continue. |

TurnResult is an immutable snapshot with text, items, and any available usage. Its status is completed, interrupted, or failed. Its text joins final assistant messages outside subagent branches. Member messages remain in items, linked beneath their subagent by parentItemId. An interrupted result can carry a native error reason.

RequestOptions sets a caller's wait deadline and abort signal. Set timeoutMs: null to wait without a deadline; the abort signal and handle disposal still end the wait. Omitting timeoutMs uses the operation's default. A timeout after dispatch can leave the native outcome unknown. Check HarnessSdkError.outcomeUnknown before retrying to avoid duplicate work. EventSubscriptionOptions controls cancellation and per-subscription queue limits.

Adapter API

Adapters import their contracts from @anureo/sdk and use the types in @anureo/protocol for AHP requests, results, and events.

| Contract | Who implements and calls it | | --- | --- | | HarnessAdapter | The adapter implements initialize(), openSession(), and dispose(). The client calls them to negotiate capabilities, open native sessions, and release client-wide resources. | | NativeHookCallbacks | An adapter with native hook coverage implements validateNativeHooks() and consumes the local callbacks supplied to openSession(). It invokes them at the native decision point. | | BackendSession | The adapter returns this from openSession(). Core reads its binding, capabilities, and optional state, and calls execute() and dispose() for native requests and cleanup. SessionMethod identifies requests routed through an open session. | | SessionEventSink | Core supplies this to the adapter at open. The adapter calls emit() or tryEmit() to publish events, bindSubmission() to associate input with an execution, and fail() to report observation failure. EventScope supplies turn or item context for an event. | | NativeInteractionResponder | The adapter supplies this callback to sink.requestInteraction(). Core calls it to deliver a response or request cancellation. The adapter calls sink.resolveInteraction() when the native peer has already settled a request. | | StructuredOutputToolPort, StructuredOutputToolDefinition, StructuredOutputToolResult | An adapter can expose a tool port on BackendSession. Core calls configure() to install or disable the tool. The adapter presents the definition and calls its execute() to validate a candidate. |

HarnessAdapter.outputBridgeTransport() lets an adapter opt into the session MCP bridge. SessionEventSink.projectOutput() is an optional hook for privacy-filtering output before final schema validation. See the port definitions for ordering, failure, and ownership contracts.

Supporting exports

| Purpose | Import path | Exports | | --- | --- | --- | | Errors and caller waits | @anureo/sdk | HarnessSdkError carries a safe code and outcome metadata. sdkError() normalizes a failure. waitForRequest() applies a caller-scoped wait using RequestOptions. | | Unattended approvals | @anureo/sdk | approveWithNarrowestScope() can be explicitly registered as interactions.approval. It chooses allow-once, then session, then rule grants, and rejects when none is offered. Clients never enable it automatically. | | Host logging | @anureo/sdk | LogTape's configure, configureSync, getLogger, drain, dispose, disposeSync, reset, and resetSync, plus Config, LogLevel, LogRecord, Logger, and Sink. The application configures logging sinks. | | Native subprocesses | @anureo/sdk/process or @anureo/sdk | spawnHarnessProcess() launches and owns stdio subprocess I/O and cleanup. The module also exports ProcessPortError, ProcessExit, HarnessProcess, and HarnessProcessOptions. | | Bounded buffering | @anureo/sdk/queue or @anureo/sdk | BoundedEventQueue provides a bounded, single-reader async queue. QueueLimits configures its budgets. | | Model catalog diagnostics | @anureo/sdk/diagnostics | catalogPhase() reports probe timing and outcomes. emitCatalogPhase() publishes a diagnostic, and safeCatalogErrorCode() projects an error to a safe code. CatalogProbeOptions and CatalogProbeEvent describe observers and their events. |

Implementation helpers

The root currently exports NativeIdentityMap for native-to-SDK ID mapping, InteractionRegistry for tracking native interaction responses, and SecretRedactor for filtering marked secrets. @anureo/sdk/structured-output-stdio is an internal package entry that core resolves to launch the stdio bridge subprocess.

Code structure

| Source | Responsibility | | --- | --- | | package.json, src/index.ts | Define the package entry points and assemble the root exports. | | src/client.ts, src/session.ts, src/turn.ts | Implement the application API for opening sessions, dispatching requests, and observing and controlling executions. | | src/client-options.ts, src/types.ts, src/ports.ts | Define public configuration, input, result, and observation types, plus adapter contracts. | | src/errors.ts, src/request.ts | Provide SDK errors, failure normalization, and caller-scoped waits. | | src/lifecycle/ | Supports the application API with event subscriptions, result accumulation, input hook scheduling, and interaction settlement. | | src/adapter/, src/requests/ | Provide native-to-SDK ID mapping and request validation against session bindings and capabilities. | | src/privacy/ | Redacts marked secrets from observed data and bounds retained file change content. | | src/structured-output/ | Wraps adapters for schema validation and manages the direct-tool and MCP fallback paths. | | src/process.ts, src/queue.ts, src/diagnostics.ts | Implement the subprocess, bounded queue, and model catalog diagnostics subpaths. |

Development

cd packages/core
bun run typecheck
bun test src

See the architecture notes for package responsibilities and the AHP v1 schema for wire contracts.