@anureo/adapter-ahp
v0.3.16
Published
External AHP harnesses over stdio or WebSocket for the Anureo SDK. Requires Bun or compatible TypeScript build tooling.
Maintainers
Readme
@anureo/adapter-ahp
Adapter connecting the Anureo SDK to external harnesses that implement AHP over stdio or WebSocket. These harnesses can themselves be built with the Anureo SDK.
Part of the Anureo SDK workspace. Install with
npm install @anureo/adapter-ahp.
Usage
The examples below use the revised workspace API, which differs from the published 0.2.0 API. The protocol major remains 1, but external peers must upgrade together and reject mismatched lifecycle capabilities during initialization.
import { createClient } from '@anureo/sdk'
import { createAhpAdapter } from '@anureo/adapter-ahp'
const client = await createClient({
adapter: createAhpAdapter({ command: 'my-harness', args: ['serve'] }),
identity: { adapterId: 'ahp', runtimeConfigId: 'local' },
})
try {
const session = await client.sessions.create({ cwd: process.cwd() })
const turn = await session.submit({ input: 'Inspect the workspace.' })
console.log(await turn.result())
await session.close()
} finally {
await client.dispose()
}A standalone revised-v1 reference harness lives in examples/reference.ts; its stdio and WebSocket paths are exercised by the adapter tests.
Behavior the adapter enforces
- Version handshake.
initializenegotiates major 1 and requiresprotocolContract: "native-lifecycle"in both directions; every request and result is validated against the protocol schema before use. - Sequence integrity. Events carry
(sessionId, streamId, seq). A gap in the sequence is repaired only when the harness negotiatedx-anureo/event-replay@1(viax-anureo/events/read); otherwise the stream fails withSOURCE_SEQUENCE_GAPinstead of presenting a hole as complete history. - Session metadata. Delivered through the negotiated
x-anureo/session-metadata@1extension; the adapter always requests it and ignores duplicated metadata from other channels. - Interactions.
interaction/requestedis answered throughinteraction/respond/interaction/cancel; the adapter forwards the answer over the wire and surfaces remote resolutions (interaction/resolved) without double-answering. - Unknown notifications. Native notifications outside the AHP event set are converted to safe
noticeevents with the raw (redacted) payload attached — a future-proofing harness cannot crash the host. - Connection loss. A closed transport fails every open session sink and rejects pending responses with
outcomeUnknown-carrying errors; no session continues silently on a dead wire.
Exports
| Entry | Contents |
|---|---|
| @anureo/adapter-ahp | createAhpAdapter, AhpAdapterOptions, AhpAdapter, AhpWire, AhpTransport, createStdioTransport, createWebSocketTransport |
| @anureo/adapter-ahp (wire) | AhpWire — the JSON-RPC 2.0 client with per-request timeouts, frame-size limits (maxFrameBytes, default 8 MiB), pending-request limits (maxPending, default 256), and notification backlog bounds (maxNotifications, default 2048) |
createWebSocketTransport deliberately restricts addresses: ws: is only accepted for loopback hosts (127.0.0.1, localhost, [::1]), credentials, query strings, and fragments in URLs are rejected, and the socket's buffered amount is bounded — remote or authenticated transports must bring their own factory via options.connect.
Development
cd packages/adapter/ahp
bun run typecheck
bun test testsDocumentation
- AHP v1 protocol — the wire contract
- Architecture
AHP v1 lifecycle revision
The lifecycle design updates AHP v1 and package root entries in place. Root migration and local validation are complete: the root implementation and tests use the revised lifecycle, and parallel versioned entries have been removed. Local conformance and clean-install checks have passed. See the design and implementation plan.
