|
| 1 | +# CLAUDE.md |
| 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 | +Libro is a JavaScript + Python hybrid monorepo providing a Notebook product solution with AI capabilities. It supports kernel-level extensibility and defines workflows for large models. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Initial setup (installs dependencies and builds packages) |
| 13 | +pnpm bootstrap |
| 14 | + |
| 15 | +# Start development server (docs/demo site) |
| 16 | +pnpm run docs |
| 17 | + |
| 18 | +# Build all packages |
| 19 | +pnpm run build |
| 20 | + |
| 21 | +# Lint code |
| 22 | +pnpm run lint |
| 23 | + |
| 24 | +# Run all tests |
| 25 | +pnpm run test |
| 26 | + |
| 27 | +# Run tests for a specific package |
| 28 | +pnpm run test:jest --filter=@difizen/libro-core |
| 29 | + |
| 30 | +# Type check |
| 31 | +pnpm run tsc |
| 32 | + |
| 33 | +# Create changeset for version management |
| 34 | +pnpm run changeset |
| 35 | + |
| 36 | +# Run CI checks (lint, typecheck, coverage) |
| 37 | +pnpm run ci:check |
| 38 | +``` |
| 39 | + |
| 40 | +## Architecture |
| 41 | + |
| 42 | +### Dependency Injection Framework |
| 43 | + |
| 44 | +Libro uses `@difizen/mana-app` for dependency injection. Core patterns: |
| 45 | + |
| 46 | +- **ManaModule**: Modules are created using `ManaModule.create().register(...).dependOn(...)` |
| 47 | +- **@singleton / @transient**: Class decorators for DI scope |
| 48 | +- **@inject**: Property/constructor injection |
| 49 | +- **@prop()**: Reactive properties with MobX-like behavior |
| 50 | +- **Contributions**: Use `.contribution(Token)` to register providers, then inject `@inject(Token)` to get all contributions |
| 51 | + |
| 52 | +### Core Package Structure (`@difizen/libro-core`) |
| 53 | + |
| 54 | +- **LibroModule**: Main module that registers core services and depends on sub-modules |
| 55 | +- **LibroService**: Manages notebook views/models, tracks active/focus state, emits events |
| 56 | +- **LibroModel**: Notebook model containing cells and metadata |
| 57 | +- **LibroView**: Notebook view component |
| 58 | +- **LibroCellModule**: Cell system with `CellViewContribution` and `CellModelContribution` for registering cell types |
| 59 | + |
| 60 | +### Cell System |
| 61 | + |
| 62 | +Cells follow a contribution pattern. To add a new cell type: |
| 63 | + |
| 64 | +1. Create `CellViewContribution` - provides the view component |
| 65 | +2. Create `CellModelContribution` - provides factory for the model |
| 66 | +3. Register both in your module |
| 67 | + |
| 68 | +Existing cell types: `code-cell`, `markdown-cell`, `prompt-cell`, `sql-cell`, `raw-cell` |
| 69 | + |
| 70 | +### Kernel Architecture (`@difizen/libro-kernel`) |
| 71 | + |
| 72 | +- **IKernelConnection**: Interface for kernel communication |
| 73 | +- **ExecutableNotebookModel**: Extends NotebookModel with kernel connection support |
| 74 | +- Kernel connection is managed per notebook instance |
| 75 | + |
| 76 | +### Key Packages |
| 77 | + |
| 78 | +| Package | Purpose | |
| 79 | +| ----------------------- | ------------------------------------------------------ | |
| 80 | +| `libro-core` | Core notebook functionality, model/view, cell system | |
| 81 | +| `libro-kernel` | Kernel connection management | |
| 82 | +| `libro-jupyter` | Jupyter protocol implementation, integrates cell types | |
| 83 | +| `libro-lab` | Full lab application combining all features | |
| 84 | +| `libro-ai-native` | AI capabilities (completion, chat, error fixing) | |
| 85 | +| `libro-codemirror` | CodeMirror editor integration | |
| 86 | +| `libro-cofine-editor-*` | Advanced editor features (LSP, textmate) | |
| 87 | +| `libro-rendermime` | MIME type rendering for outputs | |
| 88 | +| `libro-output` | Output display components | |
| 89 | + |
| 90 | +### Build System |
| 91 | + |
| 92 | +- **pnpm** with workspaces for monorepo management |
| 93 | +- **nx** for task orchestration with caching |
| 94 | +- **father** for building individual packages (ESM output to `es/`) |
| 95 | + |
| 96 | +### Version Management |
| 97 | + |
| 98 | +- Uses **changesets** for version management |
| 99 | +- All `@difizen/*` packages are linked together (same version) |
| 100 | +- Run `pnpm run changeset` to create version changes |
| 101 | + |
| 102 | +## Release Process |
| 103 | + |
| 104 | +1. Create changeset: `pnpm run changeset` (or auto-generate for snapshots) |
| 105 | +2. Build: `pnpm run build` |
| 106 | +3. For snapshot release: `sh ./scripts/release-snapshot.sh` |
| 107 | + |
| 108 | +## Commit Convention |
| 109 | + |
| 110 | +Follow Angular commit guidelines: |
| 111 | + |
| 112 | +- `feat(scope): description` - new feature |
| 113 | +- `fix(scope): description` - bug fix |
| 114 | +- `chore(scope): description` - maintenance |
| 115 | + |
| 116 | +## Requirements |
| 117 | + |
| 118 | +- Node.js 20.x |
| 119 | +- pnpm 8.15.6 |
0 commit comments