Skip to content

Commit eb4d5f8

Browse files
authored
Merge pull request #2 from batmn-dev/007-ai-agent-jk-im-batman
feat: migrate to pnpm monorepo with Turborepo and add AI agent context
2 parents 9207a72 + 245897f commit eb4d5f8

File tree

303 files changed

+29333
-2056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+29333
-2056
lines changed

.agents/context/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# AI Context Directory
2+
3+
> Passive knowledge that AI agents can retrieve on-demand. This content is NOT automatically loaded.
4+
5+
## Structure
6+
7+
```
8+
context/
9+
├── research/ # Raw research materials, deep-dive documentation
10+
│ └── *.md # Topic-specific research
11+
├── decisions/ # Architecture Decision Records (ADRs)
12+
│ └── NNN-*.md # Numbered decision records
13+
└── glossary.md # Project-specific terminology
14+
```
15+
16+
## Purpose
17+
18+
This directory contains **reference materials** (passive knowledge) that agents can fetch when needed, but that should NOT be included in every context window.
19+
20+
### vs Skills
21+
22+
| Context (`context/`) | Skills (`skills/`) |
23+
|---------------------|-------------------|
24+
| **WHAT** things are | **HOW** to do things |
25+
| Reference materials | Action-oriented instructions |
26+
| Loaded on-demand | Triggered by user request |
27+
| Background knowledge | Step-by-step procedures |
28+
29+
### vs Workflows
30+
31+
| Context (`context/`) | Workflows (`workflows/`) |
32+
|---------------------|-------------------------|
33+
| Understanding | Execution |
34+
| Research & decisions | Step-by-step procedures |
35+
| Read to learn | Follow to accomplish |
36+
37+
## When to Add Here
38+
39+
Add content to `context/` when:
40+
- It's background research that informs decisions
41+
- It's an Architecture Decision Record (ADR)
42+
- It defines terminology or concepts
43+
- It's too detailed for AGENTS.md but useful for deep dives
44+
45+
## When NOT to Add Here
46+
47+
Don't add content to `context/` when:
48+
- It's a step-by-step procedure → use `workflows/`
49+
- It's a reusable capability → use `skills/`
50+
- It needs to be in every session → use `AGENTS.md` or `.cursor/rules/`
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ADR-001: Use OKLCH Color Space for CSS Variables
2+
3+
## Status
4+
5+
**Accepted** - January 2025
6+
7+
## Context
8+
9+
When setting up the theming system for Usage UI, we needed to choose a color space for CSS variables. Options considered:
10+
- HSL (Hue, Saturation, Lightness)
11+
- RGB/Hex
12+
- OKLCH (OK Lightness, Chroma, Hue)
13+
14+
## Decision
15+
16+
Use **OKLCH** color space for all CSS variables.
17+
18+
```css
19+
:root {
20+
--meter-success: oklch(0.723 0.191 142.5);
21+
--meter-warning: oklch(0.795 0.184 86.047);
22+
--meter-danger: oklch(0.637 0.237 25.331);
23+
}
24+
```
25+
26+
## Rationale
27+
28+
1. **Perceptual uniformity**: OKLCH is perceptually uniform, meaning equal changes in values produce equal perceived changes in color.
29+
30+
2. **shadcn/ui alignment**: shadcn/ui v4+ uses OKLCH as the default color space. Aligning with upstream reduces friction.
31+
32+
3. **Better for programmatic manipulation**: Creating tints/shades and color palettes is more predictable in OKLCH.
33+
34+
4. **Modern browser support**: All modern browsers support OKLCH as of 2024.
35+
36+
## Consequences
37+
38+
### Positive
39+
- Consistent color perception across the theme
40+
- Easy to create harmonious color variations
41+
- Future-proof alignment with CSS standards
42+
43+
### Negative
44+
- Less familiar to developers used to HSL/RGB
45+
- Requires conversion when working with design tools that don't support OKLCH
46+
- Slightly more complex syntax
47+
48+
## Notes
49+
50+
When converting from other color spaces, use tools like:
51+
- [oklch.com](https://oklch.com)
52+
- CSS `color()` function for browser conversion
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# ADR-002: Adopt Lightweight Monorepo Structure
2+
3+
## Status
4+
5+
**Accepted** - January 2025
6+
7+
## Context
8+
9+
Usage UI started as a single Next.js app using the Vercel Registry Starter template. As the project grew to support 20+ components, we needed to decide on the architecture:
10+
11+
1. **Single App**: Keep everything in one Next.js application
12+
2. **Monorepo**: Separate docs site and component registry into packages
13+
3. **Multi-repo**: Separate repositories for docs and components
14+
15+
## Decision
16+
17+
Adopt a **lightweight monorepo** structure using pnpm workspaces and Turborepo.
18+
19+
```
20+
usage-ui/
21+
├── apps/
22+
│ └── www/ # Documentation site
23+
├── packages/
24+
│ └── ui/ # Component registry
25+
├── tooling/ # Shared configs
26+
├── turbo.json
27+
└── pnpm-workspace.yaml
28+
```
29+
30+
## Rationale
31+
32+
### Why Monorepo Over Single App
33+
34+
1. **Industry standard**: Magic UI, Origin UI, shadcn/ui all use monorepo structure
35+
2. **Separation of concerns**: Docs site vs distributable components are distinct
36+
3. **Scalability**: Easier to manage 20+ components with clear boundaries
37+
4. **Independent deployment**: Can deploy docs without rebuilding components
38+
39+
### Why Monorepo Over Multi-repo
40+
41+
1. **Atomic changes**: Can update component + docs in single PR
42+
2. **Shared tooling**: One Biome config, one TypeScript config
43+
3. **Simpler CI/CD**: Single pipeline with Turbo caching
44+
4. **Cross-package testing**: Can test integration between packages
45+
46+
### Why pnpm + Turborepo
47+
48+
1. **pnpm**: Fastest package manager, best monorepo support, disk efficient
49+
2. **Turborepo**: Simple config, excellent caching, Vercel-native integration
50+
51+
## Consequences
52+
53+
### Positive
54+
- Clear separation between distributable code and docs
55+
- Turbo caching speeds up CI/CD significantly
56+
- Changesets enables proper versioning
57+
- Matches industry best practices
58+
59+
### Negative
60+
- More complex initial setup
61+
- Steeper learning curve for contributors
62+
- Requires understanding of workspace protocols
63+
64+
## Implementation Notes
65+
66+
Key files created:
67+
- `pnpm-workspace.yaml` - Workspace definition
68+
- `turbo.json` - Build orchestration
69+
- `.changeset/config.json` - Version management
70+
- `lefthook.yml` - Git hooks
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# ADR-003: Dual Primitive Strategy (Radix + Base)
2+
3+
## Status
4+
5+
**Accepted** - January 2025
6+
7+
## Context
8+
9+
When building meter components, we needed to decide how to handle accessibility primitives:
10+
11+
1. **Radix-only**: All components use Radix UI primitives
12+
2. **Base-only**: All components use plain HTML with manual ARIA
13+
3. **Dual versions**: Provide both Radix and Base versions
14+
15+
## Decision
16+
17+
Implement **dual versions** for core meter components:
18+
- `usage-meter.tsx` - Radix-based (full accessibility)
19+
- `usage-meter-base.tsx` - Lightweight (no Radix)
20+
21+
## Rationale
22+
23+
### Why Not Radix-Only
24+
25+
1. **Bundle size**: Some users prioritize minimal bundle size
26+
2. **Simple use cases**: Not all meters need full keyboard nav
27+
3. **Framework flexibility**: Some frameworks don't work well with Radix
28+
29+
### Why Not Base-Only
30+
31+
1. **Accessibility compliance**: Many projects require WCAG compliance
32+
2. **Complex interactions**: Radix handles edge cases we'd miss
33+
3. **shadcn alignment**: shadcn/ui uses Radix for all interactive components
34+
35+
### Why Dual Versions
36+
37+
1. **User choice**: Let users pick based on their requirements
38+
2. **Documentation value**: Shows both accessible and minimal patterns
39+
3. **Gradual adoption**: Users can start with base, upgrade to Radix
40+
41+
## Implementation
42+
43+
```
44+
packages/ui/src/components/registry/usage-meter/
45+
├── usage-meter.tsx # Radix Progress primitive
46+
├── usage-meter-base.tsx # div with role="progressbar"
47+
└── index.ts # Exports both
48+
```
49+
50+
### When to Create Both Versions
51+
52+
| Component Type | Radix | Base |
53+
|----------------|-------|------|
54+
| Core meters |||
55+
| Cards (use shadcn Card) |||
56+
| Indicators (simple display) |||
57+
| Charts (Tremor-based) |||
58+
59+
## Consequences
60+
61+
### Positive
62+
- Maximum flexibility for users
63+
- Clear accessibility story
64+
- Smaller bundle for simple use cases
65+
66+
### Negative
67+
- More code to maintain
68+
- Must keep both versions in sync
69+
- Documentation complexity
70+
71+
## Notes
72+
73+
The base version MUST include manual ARIA attributes:
74+
```tsx
75+
<div
76+
role="progressbar"
77+
aria-valuenow={value}
78+
aria-valuemin={0}
79+
aria-valuemax={max}
80+
aria-valuetext={`${percentage}%`}
81+
/>
82+
```
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# ADR-004: Hybrid Monorepo Migration Approach
2+
3+
## Status
4+
5+
**Accepted** - January 2025
6+
7+
## Context
8+
9+
When migrating Usage UI from single-app to monorepo structure, we needed to choose between:
10+
11+
1. **CLI Scaffold**: Use `npx shadcn@latest init` with monorepo preset to generate correct configs
12+
2. **Manual Migration**: Manually restructure directories and create configs
13+
3. **Hybrid Approach**: Use CLI to generate reference configs, manually migrate code
14+
15+
Key considerations:
16+
- 46+ shadcn components already installed with customizations
17+
- Custom theme (OKLCH colors, nature palette)
18+
- Git history preservation important for accountability
19+
- Configuration errors are common and hard to debug
20+
21+
## Decision
22+
23+
Adopt a **hybrid migration approach**:
24+
25+
1. Generate a reference monorepo using shadcn CLI in a temp directory
26+
2. Use reference configs as authoritative source
27+
3. Execute migration manually to preserve git history
28+
4. Validate structure with automated checks
29+
30+
## Rationale
31+
32+
### Why Not CLI Scaffold
33+
34+
- Loses all git history
35+
- Requires manually copying 46+ components
36+
- Custom theme would need re-implementation
37+
- High risk of missing customizations
38+
39+
### Why Not Pure Manual
40+
41+
- shadcn monorepo config is complex (components.json aliases, exports)
42+
- Easy to make subtle errors in turbo.json, tsconfig.json paths
43+
- No authoritative reference for correct configuration
44+
- Higher chance of "works on my machine" issues
45+
46+
### Why Hybrid
47+
48+
| Benefit | How It Helps |
49+
|---------|--------------|
50+
| Correct configs | Reference from CLI is guaranteed correct |
51+
| Preserved history | Manual moves keep git blame |
52+
| Validation | Can diff against reference |
53+
| Customizations kept | Copy files, don't regenerate |
54+
55+
## Implementation
56+
57+
### Reference Generation
58+
59+
```bash
60+
mkdir -p /tmp/shadcn-monorepo-reference
61+
cd /tmp/shadcn-monorepo-reference
62+
pnpm dlx shadcn@latest init # Select "Next.js (Monorepo)"
63+
```
64+
65+
Reference files to use:
66+
- `turbo.json` — Build orchestration
67+
- `pnpm-workspace.yaml` — Workspace definition
68+
- `apps/web/components.json` — App-level shadcn config
69+
- `packages/ui/components.json` — Package-level shadcn config
70+
- `packages/ui/package.json` — Exports configuration
71+
72+
### Migration Execution
73+
74+
See [execute-monorepo-migration.md](../../workflows/execute-monorepo-migration.md) for step-by-step workflow.
75+
76+
### Validation
77+
78+
See [monorepo-validation skill](../../skills/monorepo-validation/SKILL.md) for automated structure checks.
79+
80+
## Consequences
81+
82+
### Positive
83+
84+
- Git history preserved for all components
85+
- Configs match shadcn CLI expectations exactly
86+
- Automated validation catches drift
87+
- Documented process is repeatable
88+
89+
### Negative
90+
91+
- More steps than pure CLI scaffold
92+
- Requires understanding of both approaches
93+
- Reference must be regenerated if shadcn CLI changes
94+
95+
### Mitigations
96+
97+
- Workflow documentation reduces complexity
98+
- Validation script catches most errors
99+
- Reference can be cached or checked into `.references/` if needed
100+
101+
## Related
102+
103+
- [ADR-002: Adopt Lightweight Monorepo Structure](./002-monorepo-structure.md) — Why monorepo
104+
- [MONOREPO-MIGRATION.md](../../MONOREPO-MIGRATION.md) — Detailed migration guide

0 commit comments

Comments
 (0)