|
| 1 | +# Guidelines for LLM-Powered Code Assistants |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +BotKit is a TypeScript framework for creating ActivityPub bots, built on top of Fedify. It supports both Deno and Node.js environments and provides a simple API for creating standalone ActivityPub servers that function as bots. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Primary Commands (Deno-based) |
| 12 | +- `deno task check` - Full codebase validation (type check, lint, format check, publish dry-run, version check) |
| 13 | +- `deno task test` - Run Deno tests with network access to hollo.social |
| 14 | +- `deno task test:node` - Run Node.js tests via pnpm |
| 15 | +- `deno task test-all` - Run all checks and tests (check + test + test:node) |
| 16 | +- `deno task coverage` - Generate test coverage report in HTML format |
| 17 | + |
| 18 | +### Build Commands |
| 19 | +- `pnpm build` - Build via npm script (runs tsdown) |
| 20 | +- `pnpm test` - Run Node.js tests after installing dependencies |
| 21 | + |
| 22 | +### Code Quality |
| 23 | +- `deno lint` - Lint TypeScript code |
| 24 | +- `deno fmt` - Format code (excludes .md, .yaml, .yml files) |
| 25 | +- `deno fmt --check` - Check code formatting without modifying files |
| 26 | +- `deno check src/` - Type check source files |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +### Core Module Structure |
| 31 | +- **`src/mod.ts`** - Main entry point, re-exports all public APIs |
| 32 | +- **`src/bot.ts`** - Core Bot interface and createBot function |
| 33 | +- **`src/bot-impl.ts`** - Internal Bot implementation |
| 34 | +- **`src/session.ts`** - Session management for bot operations |
| 35 | +- **`src/message.ts`** - Message types and ActivityPub objects (Note, Article, etc.) |
| 36 | +- **`src/events.ts`** - Event handler type definitions |
| 37 | +- **`src/text.ts`** - Text formatting utilities (mention, hashtag, link, etc.) |
| 38 | +- **`src/emoji.ts`** - Custom emoji handling |
| 39 | +- **`src/reaction.ts`** - Like and reaction implementations |
| 40 | +- **`src/repository.ts`** - Data storage abstractions |
| 41 | +- **`src/follow.ts`** - Follow request handling |
| 42 | + |
| 43 | +### Key Concepts |
| 44 | +- **Bot**: The main bot instance created with `createBot()`, handles events and provides session access |
| 45 | +- **Session**: Scoped bot operations for publishing content and managing state |
| 46 | +- **Message**: ActivityPub objects like Note, Article, Question with rich text support |
| 47 | +- **Repository**: Storage backend abstraction (Memory, KV-based, cached variants) |
| 48 | +- **Event Handlers**: Functions for responding to ActivityPub activities (mentions, follows, likes, etc.) |
| 49 | + |
| 50 | +### Build System |
| 51 | +- Uses `tsdown` for cross-platform builds (Deno → Node.js/npm) |
| 52 | +- Generates ESM (`dist/*.js`) and CommonJS (`dist/*.cjs`) outputs |
| 53 | +- Creates TypeScript definitions for both (`dist/*.d.ts`, `dist/*.d.cts`) |
| 54 | +- Includes Temporal polyfill injection for Node.js compatibility |
| 55 | + |
| 56 | +### Testing |
| 57 | +- Deno tests: `*.test.ts` files, run with `deno task test` |
| 58 | +- Node.js tests: Built output tested in `dist/` directory with Node's built-in test runner |
| 59 | +- Coverage reports available via `deno task coverage` |
| 60 | + |
| 61 | +### Dual Runtime Support |
| 62 | +- Primary development in Deno with `deno.json` configuration |
| 63 | +- Node.js support via `package.json` and tsdown transpilation |
| 64 | +- Separate import maps for each runtime (JSR for Deno, npm for Node.js) |
| 65 | + |
| 66 | +## Development Notes |
| 67 | + |
| 68 | +### When Running Tests |
| 69 | +Always run the full test suite with `deno task test-all` to ensure both Deno and Node.js compatibility. |
| 70 | + |
| 71 | +### When Making Changes |
| 72 | +1. Run `deno task check` before committing to validate all aspects |
| 73 | +2. The build process (`tsdown`) generates dual outputs for both runtimes |
| 74 | +3. Tests should work in both Deno and Node.js environments |
| 75 | +4. **Update documentation**: New features must be documented in the `docs/` directory |
| 76 | +5. **Update changelog**: Any user-facing changes must be recorded in `CHANGES.md` |
| 77 | + |
| 78 | +### File Organization |
| 79 | +- Implementation files: `*-impl.ts` (internal implementations) |
| 80 | +- Test files: `*.test.ts` (both unit and integration tests) |
| 81 | +- Type definitions: Primarily in `events.ts` and exported through `mod.ts` |
| 82 | +- UI components: `src/components/` for JSX/TSX files |
| 83 | +- Documentation: `docs/` directory contains user-facing documentation |
| 84 | +- Changelog: `CHANGES.md` records all user-facing changes |
0 commit comments