Skip to content

Commit 216bfea

Browse files
📝 docs: refresh README and add AGENTS.md
1 parent d0ad154 commit 216bfea

2 files changed

Lines changed: 205 additions & 69 deletions

File tree

‎AGENTS.md‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# AGENTS.md
2+
3+
Guidance for coding agents working **in** this repository. Downstream users of the package should
4+
read <https://streamdown.lobehub.com/skills.md> and <https://streamdown.lobehub.com/llms.txt> instead.
5+
6+
## Overview
7+
8+
`@lobehub/streamdown` is an ESM-only, headless React 19 component that renders streaming markdown:
9+
block splitting and caching, smooth per-character reveal, a fade animation and a LaTeX guard, built
10+
on `react-markdown`, `marked` and `remend`. It has two entries, `@lobehub/streamdown` and
11+
`@lobehub/streamdown/profiler`. The docs site (<https://streamdown.lobehub.com>) is built with
12+
`@lobehub/docs-kit` (the `lobedocs` CLI) from `docs/` and the `index.mdx` files under `src/`.
13+
Single pnpm package, Node >= 22.22 for the docs site.
14+
15+
| Path | What lives there |
16+
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------- |
17+
| `src/index.ts` | Main entry; every public export is listed here |
18+
| `src/Streamdown.tsx` | The component and `StreamdownProps`; wires lexer, queue, smoother and rehype plugins |
19+
| `src/types.ts` | Shared public unions (`StreamSmoothingPreset`, `StreamAnimationGranularity`) |
20+
| `src/blockLexer.ts` | Block splitting with `marked`, frozen prefix, `remend` on the open tail |
21+
| `src/useStreamQueue.ts` | Block states (`revealed` / `animating` / `streaming` / `queued`) and char delay |
22+
| `src/useSmoothStreamContent.ts` | Reveal pacing; `PRESET_CONFIG` holds the `realtime` / `balanced` / `silky` presets |
23+
| `src/rehypeStreamAnimated.ts`, `src/streamAnimationMeta.ts` | Rehype plugin that wraps newly revealed text, and per-block animation timing |
24+
| `src/styles.tsx` | Fade keyframes, `STREAM_FADE_DURATION`, `STREAMDOWN_ANIMATED_CLASS` |
25+
| `src/CachedMarkdown.tsx`, `src/StreamTail.tsx` | Memoized per-block renderer; streaming tail element |
26+
| `src/latex.ts`, `src/fenceState.ts` | LaTeX preprocessing / `isLastFormulaRenderable`; `findOpenFenceLanguage` |
27+
| `src/internal.ts` | Shared internal helpers; never exported from an entry |
28+
| `src/profiler/` | The `./profiler` entry (`index.ts`, `profiler.ts`, `StreamdownProfilerProvider.tsx`) |
29+
| `src/Streamdown/`, `src/profiler/index.mdx` | Docs only: component pages and `demos/` (not part of the published build) |
30+
| `docs/`, `docs.config.ts` | Guide pages (`docs/guide/*.mdx`), landing page (`docs/home/`), changelog, site config |
31+
| `public/`, `wrangler.jsonc` | Static assets for the site; Cloudflare Pages config (`dist/`) |
32+
33+
## Using Skills
34+
35+
Skills follow the `.agents/skills/<name>/SKILL.md` convention: read the whole `SKILL.md` (and any
36+
`reference/` files it links) before starting a task it covers, then follow it.
37+
38+
This repository does not commit any skills yet. The docs site was built with two docs-kit skills
39+
that are maintained in [lobehub/lobe-ui](https://github.com/lobehub/lobe-ui/tree/master/.agents/skills):
40+
41+
| Skill | Use it when |
42+
| ----------------------- | ------------------------------------------------------------------------------------------------ |
43+
| `using-docs-kit` | Writing or fixing `index.mdx` pages, demos, `<Api>` tables, `docs.config.ts`, or a failing build |
44+
| `building-landing-home` | Changing the landing page in `docs/home/` built from `@lobehub/ui/awesome` |
45+
46+
If you add skills to this repo, put them under `.agents/skills/` and list them here. The site's
47+
`skills.md` and `llms.txt` are generated by `lobedocs build` for downstream users; never edit them
48+
by hand.
49+
50+
## Writing Docs
51+
52+
- **Component pages**: only files named `index.mdx` under `src` (`atomDirs`) become pages; the URL
53+
comes from the folder: `src/Streamdown/index.mdx` → `/components/streamdown`,
54+
`src/profiler/index.mdx` → `/components/profiler`.
55+
- **Guide pages**: `docs/guide/<name>.mdx` with `title` + `description`, listed in `publicDocs` and
56+
`themeConfig.navItems` in `docs.config.ts`. They are served at `/guide/<name>`.
57+
- **Frontmatter**: `title`, `description` (one or two plain sentences; feeds search and llms.txt),
58+
`category` on component pages (`General`), optional `order`. A PascalCase `title` makes the page
59+
header show `import { Title } from '@lobehub/streamdown'`, which is why the profiler page is
60+
titled `Streamdown Profiler`.
61+
- **Demos**: must live under `src/**/demos/`. One default export per file, import the library by
62+
package name (`@lobehub/streamdown`, `@lobehub/streamdown/profiler`; `docs.config.ts` aliases them
63+
to `src`). Shared demo helpers (simulated stream, samples, `StreamPane`, `ProfilerPanel`) are in
64+
`src/Streamdown/demos/shared/`. Guide pages import demos with a relative path, e.g.
65+
`import Latex from '../../src/Streamdown/demos/Latex.tsx?demo';`. Demos that import local helpers
66+
need `editable={false}`; the playground uses `StoryBook` + `useControls` from
67+
`@lobehub/ui/storybook` with `layout="bare"`.
68+
- **API tables**: `<Api name="Streamdown" />` and `<Api name="StreamdownProfilerProvider" />` read
69+
props from TypeScript. JSDoc on props becomes the description, and a JSDoc `@default` must equal
70+
the runtime default in the destructuring or the build fails.
71+
- **Links**: use site pathnames (`/guide/latex`, `/components/streamdown#api`); the build audits
72+
every internal link and `#hash`.
73+
- **Preview and check**: `pnpm dev`, then `pnpm build:site`, which runs every docs audit. Restart
74+
the dev server after editing `docs.config.ts`.
75+
76+
## Adding to the Library
77+
78+
- **New prop**: add it to `StreamdownProps` in `src/Streamdown.tsx` with JSDoc, destructure it with
79+
its default in `Streamdown`, and thread it to where it is used (`StreamdownBlocks`, the smoother or
80+
the lexer). Props that are not destructured flow into react-markdown `Options`. Add a test to
81+
`src/Streamdown.test.tsx`, then document it in `src/Streamdown/index.mdx` (and the README's
82+
Common Options table if it is commonly used).
83+
- **remark / rehype plugins**: user plugins arrive through `remarkPlugins` / `rehypePlugins`.
84+
Built-in per-block plugins are appended in `resolveBlockPlugins` in `src/Streamdown.tsx`
85+
(that is how `rehypeStreamAnimated` is added). Put a new plugin in its own `src/<name>.ts` with a
86+
colocated `src/<name>.test.ts`, and export it from `src/index.ts` if users should compose it.
87+
- **Animation**: the fade CSS lives in `src/styles.tsx`; which nodes animate and when lives in
88+
`src/rehypeStreamAnimated.ts` (wrapping) and `src/streamAnimationMeta.ts` (timing). Keep the
89+
`prefers-reduced-motion` rule working.
90+
- **Block processing**: splitting and freezing are in `src/blockLexer.ts` (`FROZEN_TYPES`), block
91+
states in `src/useStreamQueue.ts`, pacing presets in `src/useSmoothStreamContent.ts`. Lexer
92+
changes must keep `src/blockLexer.test.ts` green: it compares incremental lexing to a full lex at
93+
every step of the docs samples in `src/Streamdown/demos/shared/samples.ts`.
94+
- **Profiler metrics**: `src/profiler/profiler.ts`; export new public types from
95+
`src/profiler/index.ts`.
96+
- **Tests**: colocated `src/**/*.test.{ts,tsx}` (vitest, jsdom, globals). Vitest aliases
97+
`@lobehub/streamdown` to `src`.
98+
- **Exports**: public API goes through `src/index.ts` or `src/profiler/index.ts`. Both are the
99+
`tsdown` entries (`tsdown.config.ts`) and the `exports` in `package.json`. A new subpath entry
100+
needs a `tsdown` entry, a `package.json` export and the alias regex in `vitest.config.ts`
101+
(which only maps the root and `/profiler`). Runtime dependencies are externalized from
102+
`dependencies` / `peerDependencies`, so add new ones there.
103+
104+
## Commands
105+
106+
```bash
107+
pnpm install # also runs husky and `lobedocs typegen` (prepare)
108+
pnpm dev # docs dev server (lobedocs dev)
109+
pnpm lint # eslint on src/, docs/ and docs.config.ts
110+
pnpm type-check # tsc (library, demos and docs)
111+
pnpm test # vitest run; `pnpm test:coverage` is what CI runs
112+
pnpm build # tsdown → es/
113+
pnpm build:site # lobedocs build → dist/ (with all docs audits)
114+
pnpm deploy:site # build:site + wrangler pages deploy; maintainers only
115+
```
116+
117+
CI (`.github/workflows/test.yml`) runs lint, type-check, test:coverage, build and build:site.
118+
119+
## Commits and Releases
120+
121+
- Commit messages are gitmoji + conventional commit, enforced by commitlint in the `commit-msg`
122+
hook: `✨ feat: ...`, `🐛 fix: ...`, `⚡️ perf: ...`, `📝 docs: ...`, `🔧 chore: ...`,
123+
`✅ test: ...`, `♻️ refactor: ...`. Never use `--no-verify`.
124+
- Every push to `main` runs semantic-release (`.github/workflows/release.yml`), which publishes to
125+
npm. `feat` releases a minor, `fix` and `perf` release a patch, and a breaking change a major.
126+
Use those types only for changes to the published library in `src/` (excluding docs and demos);
127+
docs, demos, CI and tooling changes use `docs`, `chore`, `ci`, `test` or `refactor`.
128+
- Never bump the version or edit `CHANGELOG.md` by hand; the release job does it.

0 commit comments

Comments
 (0)