Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
node_modules/
npm-debug.log
lib/
63 changes: 63 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# CLAUDE.md

## Build & Test Commands

- **Build:** `npm run build` — compiles TypeScript (`src/*.ts`) to JavaScript (`lib/*.js`) with declarations
- **Test:** `npm test` — runs the full test suite via vitest
- **Type check:** `npx tsc --noEmit` — type check without emitting

Source language is TypeScript (`.ts` files) with async/await for async control flow.

## Architecture

Framed msgpack-RPC library for Node.js used by Keybase. Messages are msgpack-encoded and length-prefixed (framed).

### Class Hierarchy

```
Packetizer — frame-level read/write (length-prefixed msgpack)
└─ Dispatch — RPC message routing (invoke/response/notify), handler registry
└─ Transport — TCP/TLS/Unix socket connection management
└─ RobustTransport — auto-reconnect with call queuing
```

### Key Modules

| File | Role |
|------|------|
| `transport.ts` | `Transport` (single connection) and `RobustTransport` (auto-reconnect + queue) |
| `dispatch.ts` | `Dispatch` — RPC invoke/response/notify routing; `Response` helper |
| `packetizer.ts` | Framing: length-prefix encoding/decoding over a byte ring buffer |
| `client.ts` | `Client` — thin wrapper; binds a program name to a transport for `invoke`/`notify` |
| `server.ts` | `Server`, `SimpleServer`, `ContextualServer`, `Handler` — listener-based servers |
| `listener.ts` | `Listener` — TCP/TLS server socket accepting connections, spawns Transports |
| `pack.ts` | Msgpack encode/decode abstraction (supports `@msgpack/msgpack`, `purepack`, `msgpack`) |
| `ring.ts` | `Ring` — circular byte buffer for the packetizer |
| `errors.ts` | Error types: `EofError`, `UnknownMethodError` |
| `log.ts` | Logging infrastructure |
| `debug.ts` | Debug message tracing |
| `lock.ts` | Promise-based `Lock` with `acquire()`/`release()` |

### RPC Protocol (msgpack arrays)

- **Invoke:** `[0, seqid, method, param]`
- **Response:** `[1, seqid, error, result]`
- **Notify:** `[2, method, param]` (fire-and-forget)
- **Invoke Compressed:** `[4, seqid, ctype, method, param]` (gzip via pako)

### Entry Point

`src/main.ts` → `lib/main.js` — re-exports all public classes and the version.

### Async API

All async operations use Promises/async-await:
- `client.invoke(method, args)` → `Promise<{error, result}>`
- `client.invoke_compressed(method, ctype, args)` → `Promise<{error, result}>`
- `transport.connect()` → `Promise<Error | null>`
- `listener.listen()` → `Promise<void>`
- `listener.close()` → `Promise<void>`

### Tests

Tests use vitest with sequential execution (tests share ports). Test files are in `test/*.test.ts`.
59 changes: 0 additions & 59 deletions Cakefile

This file was deleted.

103 changes: 0 additions & 103 deletions lib/client.js

This file was deleted.

Loading