|
| 1 | +# AGENTS.md - Guidelines for AI Coding Agents |
| 2 | + |
| 3 | +This document provides essential information for AI coding agents working on the `git-diff-view` codebase. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +A high-performance Git diff view component library supporting React, Vue, Solid, and Svelte. |
| 8 | + |
| 9 | +- **Language:** TypeScript (strict mode, ESNext target) |
| 10 | +- **Package Manager:** pnpm (v9.12.0+) with workspace monorepo |
| 11 | +- **Build Tool:** Custom rollup-based tool (`project-tool`) with SWC |
| 12 | +- **Styling:** TailwindCSS with PostCSS |
| 13 | + |
| 14 | +## Build/Lint/Test Commands |
| 15 | + |
| 16 | +```bash |
| 17 | +pnpm install # Install dependencies |
| 18 | +pnpm run build:packages # Build all packages |
| 19 | +pnpm run dev:packages # Development mode for packages |
| 20 | +pnpm run lint # Run ESLint: eslint --cache --ext ts,tsx . |
| 21 | +pnpm run lint:fix # Fix lint issues automatically |
| 22 | +pnpm run prettier # Format code with Prettier |
| 23 | +pnpm run clean # Remove dist/dev/.cache directories |
| 24 | +pnpm run release # Full release: lint + prettier + clean + build + release |
| 25 | +``` |
| 26 | + |
| 27 | +### Development Servers |
| 28 | + |
| 29 | +```bash |
| 30 | +pnpm run dev:react # React example (Vite) |
| 31 | +pnpm run dev:vue # Vue example (Vite) |
| 32 | +pnpm run dev:solid # Solid example |
| 33 | +pnpm run dev:svelte # Svelte package dev |
| 34 | +pnpm run dev:cli # CLI dev mode |
| 35 | +``` |
| 36 | + |
| 37 | +### Running Tests |
| 38 | + |
| 39 | +**Note:** No test framework is currently configured. There are no test files or test commands. |
| 40 | + |
| 41 | +## Code Style Guidelines |
| 42 | + |
| 43 | +### Formatting (from .prettierrc) |
| 44 | + |
| 45 | +- **Semicolons:** Always required |
| 46 | +- **Quotes:** Double quotes (`"`) - not single quotes |
| 47 | +- **Indentation:** 2 spaces (no tabs) |
| 48 | +- **Line width:** 120 characters maximum |
| 49 | +- **Trailing commas:** ES5 style (arrays, objects) |
| 50 | + |
| 51 | +### Import Organization |
| 52 | + |
| 53 | +Order imports with blank lines between groups: |
| 54 | +1. External dependencies (npm packages) |
| 55 | +2. Internal monorepo packages (`@git-diff-view/*`) |
| 56 | +3. Local relative imports |
| 57 | +4. Type-only imports (at the end, using `import type`) |
| 58 | + |
| 59 | +```typescript |
| 60 | +import { memo, useEffect } from "react"; |
| 61 | +import { DiffFile, SplitSide } from "@git-diff-view/core"; |
| 62 | +import { useIsMounted } from "../hooks/useIsMounted"; |
| 63 | +import type { DiffHighlighter } from "@git-diff-view/core"; |
| 64 | +``` |
| 65 | + |
| 66 | +### Naming Conventions |
| 67 | + |
| 68 | +| Element | Convention | Examples | |
| 69 | +|---------|------------|----------| |
| 70 | +| Variables/Functions | camelCase | `diffFile`, `getFile`, `parseInstance` | |
| 71 | +| Classes/Interfaces/Types/Enums | PascalCase | `DiffFile`, `SplitLineItem`, `DiffLineType` | |
| 72 | +| React Components | PascalCase | `DiffView`, `DiffSplitView` | |
| 73 | +| Custom Hooks | `use` prefix | `useIsMounted`, `useDomWidth` | |
| 74 | +| Component files | PascalCase | `DiffView.tsx` | |
| 75 | +| Utility files | camelCase | `utils.ts`, `diff-file.ts` | |
| 76 | +| Private class fields | `#` prefix (ES2022) | `#oldFileResult`, `#listeners` | |
| 77 | +| Internal properties | `_` prefix | `_oldFileName`, `_isHidden` | |
| 78 | +| CSS variable names | camelCase + `Name` suffix | `diffFontSizeName`, `emptyBGName` | |
| 79 | + |
| 80 | +### TypeScript Patterns |
| 81 | + |
| 82 | +- Use **interfaces** for object shapes/data structures |
| 83 | +- Use **types** for unions, intersections, and utility types |
| 84 | +- **Avoid `any`:** Use `unknown` with generics: `<T extends unknown>` |
| 85 | +- **Optional chaining:** Use extensively: `diffFile?.clear?.()` |
| 86 | + |
| 87 | +### Export Patterns |
| 88 | + |
| 89 | +**Named exports only - no default exports:** |
| 90 | + |
| 91 | +```typescript |
| 92 | +export const DiffView = InnerDiffView; |
| 93 | +export { SplitSide, DiffModeEnum }; |
| 94 | +export class DiffFile { ... } |
| 95 | +``` |
| 96 | + |
| 97 | +**Barrel exports in `index.ts`:** |
| 98 | + |
| 99 | +```typescript |
| 100 | +export * from "./components/DiffView"; |
| 101 | +export * from "@git-diff-view/core"; |
| 102 | +``` |
| 103 | + |
| 104 | +### Error Handling |
| 105 | + |
| 106 | +Use the `__DEV__` global for development-only warnings/errors: |
| 107 | + |
| 108 | +```typescript |
| 109 | +if (__DEV__) { |
| 110 | + console.warn('[@git-diff-view/core] The composed files are identical...'); |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +- Prefix messages with package name: `[@git-diff-view/core]` |
| 115 | +- Use defensive early returns rather than throwing exceptions |
| 116 | +- `__DEV__` blocks are stripped in production builds |
| 117 | + |
| 118 | +### React-Specific Patterns |
| 119 | + |
| 120 | +- **Memo pattern:** `const MemoedComponent = memo(InternalComponent);` |
| 121 | +- **forwardRef:** Add `displayName` after: `InnerDiffView.displayName = "DiffView";` |
| 122 | +- **Context:** Use `DiffViewContext.Provider` for state management |
| 123 | + |
| 124 | +## Project Structure |
| 125 | + |
| 126 | +``` |
| 127 | +packages/ |
| 128 | + core/ # Core diff parsing engine (@git-diff-view/core) |
| 129 | + react/ # React components (@git-diff-view/react) |
| 130 | + vue/ # Vue components (@git-diff-view/vue) |
| 131 | + solid/ # Solid components (@git-diff-view/solid) |
| 132 | + svelte/ # Svelte components (@git-diff-view/svelte) |
| 133 | + cli/ # CLI tool (@git-diff-view/cli) |
| 134 | + file/ # File comparison engine (@git-diff-view/file) |
| 135 | + utils/ # Shared utilities (@git-diff-view/utils) |
| 136 | + lowlight/ # Lowlight syntax highlighter |
| 137 | + shiki/ # Shiki syntax highlighter |
| 138 | +ui/ |
| 139 | + react-example/ # React demo app (Vite) |
| 140 | + vue-example/ # Vue demo app (Vite) |
| 141 | + solid-example/ # Solid demo app |
| 142 | + svelte-example/ # Svelte demo |
| 143 | +scripts/ # Build scripts (ts-node) |
| 144 | +``` |
| 145 | + |
| 146 | +## Package Dependencies |
| 147 | + |
| 148 | +- `@git-diff-view/core` is the foundation (all framework packages depend on it) |
| 149 | +- Framework packages (react, vue, solid, svelte) wrap the core |
| 150 | +- `@git-diff-view/file` provides file-to-file comparison using the `diff` library |
| 151 | +- Syntax highlighting via `lowlight` (highlight.js) or `shiki` |
| 152 | + |
| 153 | +## ESLint Configuration |
| 154 | + |
| 155 | +- Base config: `project-tool/baseLint` |
| 156 | +- Ignored: `dist`, `dev`, `scripts`, `node_modules`, `next-*-example`, `packages/solid`, `packages/svelte` |
| 157 | + |
| 158 | +## Important Notes |
| 159 | + |
| 160 | +1. **No test infrastructure** - be cautious when modifying core logic |
| 161 | +2. **Multi-framework support** - changes to core affect all framework bindings |
| 162 | +3. **Performance critical** - this library handles large diffs; avoid unnecessary re-renders |
| 163 | +4. **CSS variables** - styling uses CSS custom properties for theming |
| 164 | +5. **Private fields** - use ES2022 `#` syntax for true private fields |
0 commit comments