cubix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cubix

Cubix

Cubix components are source files the project owns. They are copied into the app by the
cubix-ui
CLI from the registry at
https://cubixflow.ir/r
, then edited like any other code. Never install Cubix components from npm and never hand-write a component that the registry already provides.
Public readiness contract: a component is installable only when it has Base UI, React Aria, and Radix UI sources, docs, and a registry entry. If
cubix-ui search
does not list a name, or
add
returns 404, it is on the roadmap - do not invent a stub and do not paste unfinished source from the monorepo.
Cubix 组件是由项目自主管理的源文件。它们通过
cubix-ui
CLI 从
https://cubixflow.ir/r
上的注册表复制到应用中,随后可以像其他代码一样编辑。切勿从 npm 安装 Cubix 组件;如果注册表已经提供某个组件,切勿手动编写。
公开可用性规范:组件只有在具备 Base UI、React Aria 和 Radix UI 源码、文档及注册表条目时,才可安装。如果
cubix-ui search
未列出某个名称,或
add
返回 404,则说明该组件仍在路线图中——不要臆造占位实现,也不要粘贴 monorepo 中未完成的源代码。

1. Read project context first

1. 先读取项目上下文

Before generating UI, resolve the project configuration:
bash
npx cubix-ui@latest info --json
If the CLI is unavailable, read
cubix.json
at the project root. The fields that matter:
FieldUse it for
base
Primitive backend:
base
(Base UI),
radix
(Radix UI), or
aria
(React Aria). Never mix bases in one project.
aliases.ui
Import path for components, usually
@/components/cubix
.
aliases.utils
Import path for
cn()
, usually
@/lib/utils
.
tailwind.css
The global stylesheet that holds the design tokens.
rsc
When
true
(Next.js App Router), add
"use client"
only to files that use hooks, state, or event handlers.
iconLibrary
Icon package to import from, usually
lucide-react
.
If there is no
cubix.json
, initialize the project before adding anything (see section 2).
生成 UI 前,先解析项目配置:
bash
npx cubix-ui@latest info --json
如果 CLI 不可用,请读取项目根目录下的
cubix.json
。需要关注的字段如下:
字段用途
base
基础组件后端:
base
(Base UI)、
radix
(Radix UI)或
aria
(React Aria)。同一项目中绝不能混用不同 base。
aliases.ui
组件的导入路径,通常为
@/components/cubix
。
aliases.utils
cn()
的导入路径,通常为
@/lib/utils
。
tailwind.css
存放设计令牌的全局样式表。
rsc
为
true
时(Next.js App Router),仅在使用 hooks、state 或事件处理器的文件中添加
"use client"
。
iconLibrary
要导入的图标包,通常为
lucide-react
。
如果不存在
cubix.json
,请先初始化项目,然后再添加任何内容(参见第 2 节)。

2. Use the CLI, not hand-written copies

2. 使用 CLI,而不是手写副本

bash
undefined
bash
undefined

Existing app: configure tokens, cubix.json, and lib/utils.ts

Existing app: configure tokens, cubix.json, and lib/utils.ts

npx cubix-ui@latest init
npx cubix-ui@latest init

New app: scaffold a framework, then configure Cubix

New app: scaffold a framework, then configure Cubix

npx cubix-ui@latest init -t next # also: vite, start, react-router, astro npx cubix-ui@latest init -t next --base radix
npx cubix-ui@latest init -t next # also: vite, start, react-router, astro npx cubix-ui@latest init -t next --base radix

Discover before you build

Discover before you build

npx cubix-ui@latest search -q dialog npx cubix-ui@latest view dialog
npx cubix-ui@latest search -q dialog npx cubix-ui@latest view dialog

Add components (dependencies and registry dependencies are resolved)

Add components (dependencies and registry dependencies are resolved)

npx cubix-ui@latest add button dialog select npx cubix-ui@latest add button --base aria npx cubix-ui@latest add button --dry-run npx cubix-ui@latest add button --overwrite

Rules:

- Search the registry before creating a new component. Only add names that search returns.
- Prefer Text Field / Email Field / Phone Field over a generic Input when those are what the registry publishes.
- Respect the package manager already used by the project (`pnpm dlx`, `yarn dlx`, `bunx --bun`, or `npx`).
- Use `--base` only when the user explicitly wants a different base than `cubix.json`.
- Use `--dry-run` to preview when files may already exist, and `--overwrite` only with the user's consent, because it replaces local edits.
npx cubix-ui@latest add button dialog select npx cubix-ui@latest add button --base aria npx cubix-ui@latest add button --dry-run npx cubix-ui@latest add button --overwrite

规则:

- 创建新组件前,先搜索注册表。只添加搜索结果中返回的名称。
- 如果注册表提供 Text Field / Email Field / Phone Field,应优先使用它们,而不是通用 Input。
- 尊重项目已在使用的包管理器(`pnpm dlx`、`yarn dlx`、`bunx --bun` 或 `npx`)。
- 仅当用户明确希望使用与 `cubix.json` 不同的 base 时,才使用 `--base`。
- 当文件可能已存在时,使用 `--dry-run` 预览;只有在用户同意时才使用 `--overwrite`,因为它会替换本地编辑。

3. Compose components correctly

3. 正确组合组件

Import from the
ui
alias with named exports:
tsx
import { Button } from "@/components/cubix/button"
import { Field, FieldLabel, FieldDescription } from "@/components/cubix/field"
import { Input } from "@/components/cubix/input"
Every base exposes the same visual API. To render a component as another element, pass
render
and set
nativeButton={false}
when the target is not a
<button>
:
tsx
import Link from "next/link"

<Button nativeButton={false} render={<Link href="/docs" />}>
  Read the docs
</Button>
On the Radix base,
asChild
is also accepted. Prefer
render
so code stays portable across bases.
Conventions every Cubix part follows, and that new code must follow too:
  • A
    data-slot
    attribute on every part, for example
    data-slot="card-header"
    .
  • className
    merged through
    cn()
    from the
    utils
    alias.
  • Visual variants defined with
    cva
    and exported next to the component.
  • Accessible states: keyboard operation, a visible
    focus-visible
    ring,
    aria-invalid
    for errors, and
    disabled
    handling.
从
ui
别名使用具名导出进行导入:
tsx
import { Button } from "@/components/cubix/button"
import { Field, FieldLabel, FieldDescription } from "@/components/cubix/field"
import { Input } from "@/components/cubix/input"
每种 base 都提供相同的视觉 API。若要将组件渲染为另一个元素,请传入
render
;当目标元素不是
<button>
时,设置
nativeButton={false}
:
tsx
import Link from "next/link"

<Button nativeButton={false} render={<Link href="/docs" />}>
  Read the docs
</Button>
在 Radix base 上,也支持
asChild
。优先使用
render
,这样代码在不同 base 之间保持可移植性。
每个 Cubix 组成部分都遵循以下约定,新代码也必须遵循:
  • 每个部分都需要一个
    data-slot
    属性,例如
    data-slot="card-header"
    。
  • 通过
    utils
    别名中的
    cn()
    合并
    className
    。
  • 使用
    cva
    定义视觉变体,并与组件一同导出。
  • 无障碍状态:支持键盘操作、可见的
    focus-visible
    焦点环、错误状态使用
    aria-invalid
    ,并处理
    disabled
    状态。

4. Style with tokens only

4. 仅使用令牌进行样式设计

Use the semantic Tailwind tokens defined in the stylesheet from
tailwind.css
. They switch automatically in dark mode.
PurposeTokens
Surfaces
bg-background
,
bg-card
,
bg-popover
,
bg-muted
,
bg-accent
Text
text-foreground
,
text-muted-foreground
,
text-card-foreground
,
text-primary-foreground
Actions
bg-primary
,
bg-secondary
,
bg-destructive
Lines and focus
border-border
,
border-input
,
ring-ring
Charts and sidebar
chart-1
to
chart-5
,
sidebar-*
Never use hex, rgb, or palette classes such as
bg-zinc-900
or
text-[#333]
in product UI. To re-brand, change the CSS variables (oklch values) in the stylesheet instead of overriding components.
Prefer logical properties (
ps-*
,
pe-*
,
ms-*
,
me-*
,
start-*
,
end-*
,
text-start
) so layouts work in right-to-left locales.
使用在
tailwind.css
所指向的样式表中定义的语义化 Tailwind 令牌。它们会在深色模式下自动切换。
用途令牌
表面
bg-background
、
bg-card
、
bg-popover
、
bg-muted
、
bg-accent
文本
text-foreground
、
text-muted-foreground
、
text-card-foreground
、
text-primary-foreground
操作
bg-primary
、
bg-secondary
、
bg-destructive
线条与焦点
border-border
、
border-input
、
ring-ring
图表与侧边栏
chart-1
到
chart-5
、
sidebar-*
绝不要在产品 UI 中使用 hex、rgb 或调色板类,例如
bg-zinc-900
或
text-[#333]
。若要更换品牌视觉,应修改样式表中的 CSS 变量(oklch 值),而不是覆盖组件。
优先使用逻辑属性(
ps-*
、
pe-*
、
ms-*
、
me-*
、
start-*
、
end-*
、
text-start
),以确保布局适配从右到左的语言环境。

5. Agent and chat interfaces

5. Agent 与聊天界面

Several agent surfaces are still on the roadmap. Before using any of them, confirm the name appears in
cubix-ui search
. Ready building blocks today include things like
attachment
,
branch
, and the standard form/overlay primitives. Do not hand-roll Conversation / Prompt Input / Thinking replacements from memory if search does not list them yet.
When an agent surface is public, handle every state: empty conversation, streaming, error, and stopped generation, not only the happy path.
多个 Agent 界面仍在路线图中。使用其中任何一个之前,请确认其名称出现在
cubix-ui search
的结果中。目前可用的构建块包括
attachment
、
branch
和标准表单/浮层原语等。如果搜索结果尚未列出它们,不要凭记忆手动编写 Conversation / Prompt Input / Thinking 的替代实现。
当某个 Agent 界面公开可用时,必须处理所有状态:空对话、流式输出、错误和生成已停止,而不能只处理正常路径。

6. Authoring registry items

6. 编写注册表条目

To publish your own items, describe them in a source
registry.json
, then build the JSON the CLI consumes:
bash
npx cubix-ui@latest build ./registry.json -o ./public/r
Each item needs a
name
, a
type
such as
registry:ui
or
registry:block
, its
files
, and accurate
dependencies
(npm packages) and
registryDependencies
(other Cubix items). Validate against
https://cubixflow.ir/schema/registry.json
and
https://cubixflow.ir/schema/registry-item.json
.
要发布自己的条目,请在源文件
registry.json
中描述这些条目,然后构建供 CLI 使用的 JSON:
bash
npx cubix-ui@latest build ./registry.json -o ./public/r
每个条目都需要
name
、
type
(例如
registry:ui
或
registry:block
)、
files
,以及准确的
dependencies
(npm 包)和
registryDependencies
(其他 Cubix 条目)。请根据
https://cubixflow.ir/schema/registry.json
和
https://cubixflow.ir/schema/registry-item.json
进行校验。

7. Optional: Cubix MCP

7. 可选:Cubix MCP

When the host supports MCP over HTTP, connect any client to the same public URL:
https://cubixflow.ir/api/mcp
  • Cursor - project
    .cursor/mcp.json
    or
    ~/.cursor/mcp.json
    :
json
{
  "mcpServers": {
    "cubix": {
      "url": "https://cubixflow.ir/api/mcp"
    }
  }
}
  • Codex -
    codex mcp add cubix --url https://cubixflow.ir/api/mcp
    (or
    [mcp_servers.cubix]
    with
    url
    in
    ~/.codex/config.toml
    )
  • Claude -
    claude mcp add --transport http cubix https://cubixflow.ir/api/mcp
Tools:
list_components
,
search_components
,
get_component
,
get_component_demo
,
get_install_command
. Prefer these for discovery, then still run
cubix-ui add
(or the command from
get_install_command
) so owned source lands correctly. Docs: https://cubixflow.ir/docs/mcp
当宿主支持通过 HTTP 使用 MCP 时,可以将任意客户端连接到同一个公开 URL:
https://cubixflow.ir/api/mcp
  • Cursor — 项目中的
    .cursor/mcp.json
    或用户目录中的
    ~/.cursor/mcp.json
    :
json
{
  "mcpServers": {
    "cubix": {
      "url": "https://cubixflow.ir/api/mcp"
    }
  }
}
  • Codex —
    codex mcp add cubix --url https://cubixflow.ir/api/mcp
    (或在
    ~/.codex/config.toml
    中通过
    [mcp_servers.cubix]
    设置
    url
    )
  • Claude —
    claude mcp add --transport http cubix https://cubixflow.ir/api/mcp
工具:
list_components
、
search_components
、
get_component
、
get_component_demo
、
get_install_command
。优先使用这些工具进行检索,然后仍应运行
cubix-ui add
(或
get_install_command
返回的命令),以确保项目自有源代码正确落盘。文档:https://cubixflow.ir/docs/mcp

Reference

参考