Package: @craft/ui
Description: Agentic-Native UI Kit
Cross-platform React UI component library for developer tooling interfaces.
React TypeScript Tailwind v4 Radix UI oklch
English | Chinese
@craft/ui is the standalone UI layer extracted from Craft.
It is designed for teams building:
- agent/chat interfaces
- code and diff viewers
- markdown/data renderers
- terminal-style output
- preview overlays for complex content
The package is intentionally platform-agnostic so the same component surface can be reused in both browser React apps and Electron apps.
This kit exists to prevent teams from rebuilding the same UI foundation in every agent product.
- one consistent component surface for both React web apps and Electron apps
- shared visual language across chat, code, markdown, tables, and overlays
- faster shipping with less UI drift between projects
Shadcn is excellent for app primitives, but agent products need additional first-class workflows.
- Shadcn primitives: buttons, inputs, dialogs, layout scaffolding
- Agent-native requirements: thinking-process UI, long-form Markdown rendering, Mermaid visualization
- Delivery requirement: a unified UX that works the same in React and Electron
That is why this project keeps shadcn-style API ergonomics and extends it with agent-native layers.
The implementation direction combines two proven sources:
- API and composability principles inspired by shadcn/ui
- production interaction patterns extracted from Craft Agents OSS
- UI implementation source reference: lukilabs/craft-agents-oss (
Apache-2.0) - Shadcn-compatible API and composition patterns are aligned with shadcn-ui/ui (
MIT) - This repository (
@craft/ui) is licensed underApache-2.0
- Keep API shape Shadcn-compatible for low adoption cost.
- Keep visual language aligned with Craft tokens and spacing rhythm.
- Keep business logic out of UI primitives.
- Keep React + Electron integration friction low.
- Keep package self-contained (no dependency on
@craft-agent/core).
- Full UI primitive layer (
@craft/ui/ui) with Craft-styled defaults - Rich rendering modules:
- syntax-highlighted code viewer (Shiki)
- split and unified diff viewers
- markdown blocks (mermaid/json/table/spreadsheet/diff)
- terminal transcript with ANSI parsing
- fullscreen and modal preview overlays
- Chat-oriented composition components:
- session viewer
- turn card
- inline execution UI
- Tokenized CSS system:
- oklch color model
- 13-level foreground contrast scale
- shared shadows, radii, motion tokens
- Primitive first: keep
src/components/ui/*generic and reusable. - Recipe second: scenario components (cards/chat/overlay) compose primitives, not override them ad hoc.
- One source of truth for style: use token CSS variables in
@craft/ui/styles. - No hidden platform branching: platform differences are explicit via context providers.
| Import Path | Purpose | Typical Use |
|---|---|---|
@craft/ui |
root primitives | tooltip/spinner/icons/dropdowns/preview header |
@craft/ui/ui |
base UI primitives | shadcn-style controls + craft tokens |
@craft/ui/styles |
design tokens | import once at app root |
@craft/ui/types |
app types | message/session/activity typed contracts |
@craft/ui/context |
environment and theme providers | platform-aware wiring for web/electron |
@craft/ui/lib |
pure helpers | parsing/classification/link helpers |
@craft/ui/code-viewer |
code & diff viewers | syntax and patch rendering |
@craft/ui/markdown |
markdown rendering system | LLM output + rich block content |
@craft/ui/overlay |
preview overlays | code/pdf/image/json/mermaid preview |
@craft/ui/terminal |
terminal transcript | command + output rendering |
@craft/ui/cards |
card recipes | action-oriented information cards |
@craft/ui/chat |
chat UI recipes | turn/session composition |
npm install @craft/uiOr:
pnpm add @craft/ui
# or
yarn add @craft/ui| Package | Version |
|---|---|
react |
>= 18 |
react-dom |
>= 18 |
tailwindcss |
>= 4 |
shiki |
^3.21.0 |
react-markdown |
>= 9 |
remark-gfm |
>= 4 |
rehype-raw |
>= 7 |
lucide-react |
>= 0.400 |
clsx |
>= 2 |
tailwind-merge |
>= 2 |
class-variance-authority |
>= 0.7 |
motion |
>= 11 |
@radix-ui/react-tooltip |
>= 1 |
@tailwindcss/typography |
>= 0.5 |
Optional peers are used by specific modules (@radix-ui/react-dialog, react-pdf, @craft-agent/mermaid, etc.).
import '@craft/ui/styles'
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Label } from '@craft/ui/ui'
export function LoginCard() {
return (
<Card className="max-w-sm">
<CardHeader>
<CardTitle>Sign in</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="space-y-1">
<Label htmlFor="email">Email</Label>
<Input id="email" placeholder="team@craft.dev" />
</div>
<Button className="w-full">Continue</Button>
</CardContent>
</Card>
)
}import '@craft/ui/styles'
import { PlatformProvider } from '@craft/ui/context'
import { SessionViewer } from '@craft/ui/chat'
export function App() {
return (
<PlatformProvider actions={{}}>
<main className="h-dvh">
<SessionViewer
session={/* your session data */}
turns={/* your turns */}
/>
</main>
</PlatformProvider>
)
}import { Markdown } from '@craft/ui/markdown'
<Markdown content={markdownText} />import { ShikiCodeViewer } from '@craft/ui/code-viewer'
<ShikiCodeViewer code={source} language="typescript" />import { TerminalOutput } from '@craft/ui/terminal'
<TerminalOutput command="npm run build" output={ansiOutput} />import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from '@craft/ui/ui'
<Table>
<TableHeader>
<TableRow>
<TableHead>Key</TableHead>
<TableHead>Value</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>theme</TableCell>
<TableCell>craft</TableCell>
</TableRow>
</TableBody>
</Table>All visual defaults come from @craft/ui/styles.
- oklch token palette
- foreground contrast ladder (
fg-0tofg-12) - shadow/elevation tokens
- radius and border tokens
- animation keyframes and transitions
Recommendation:
- Import
@craft/ui/stylesonce at app root. - Prefer token classes/variables over page-level hard-coded colors.
- Keep variant definitions in primitive layer (
src/components/ui/*) instead of feature pages.
npm install
npm run buildPreview app:
cd preview
npm install
npm run devQuality gates:
npx tsc --noEmit
cd preview && npm run buildsrc/
├── components/
│ ├── ui/ # Base primitives (shadcn-compatible API + craft defaults)
│ ├── primitives/ # Utility primitives and icon set
│ ├── code-viewer/ # Code/diff rendering
│ ├── markdown/ # Markdown + structured block renderers
│ ├── overlay/ # Fullscreen and modal preview system
│ ├── terminal/ # ANSI parser + transcript UI
│ ├── cards/ # Card recipes
│ └── chat/ # Session/turn chat recipes
├── context/ # Platform and theme providers
├── hooks/ # Shared hooks
├── lib/ # Pure utilities
├── styles/ # Token CSS and motion/elevation styles
├── types/ # Self-contained app types
└── utils/ # Generic helpers (e.g. cn)
- Import from
@craft/ui/uibefore creating one-off local components. - Add/adjust variants in primitives when multiple pages need the same behavior.
- Keep recipe components scenario-focused and composition-driven.
- Use context providers for platform branching, not conditional CSS hacks.
- Keep component demos in
preview/aligned with production usage.
- Verify
@craft/ui/stylesis imported once. - Verify Tailwind v4 pipeline is active.
- Verify peer dependencies are installed.
- Check optional peer dependencies required by that module.
- Example: overlay PDF previews require
react-pdf.
- Confirm the same token CSS version is used.
- Check any app-level CSS reset that may override tokens.
Apache-2.0
- Name: Zihan Huang
- Website: z1han.com
- GitHub: bravohenry