Skip to content

Commit 8b3a2d0

Browse files
DaYePythonclaude
andcommitted
docs: add per-package READMEs for npm
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b87c1f6 commit 8b3a2d0

4 files changed

Lines changed: 130 additions & 0 deletions

File tree

‎.changeset/three-readmes-docs.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@lanhu-context/cli': patch
3+
'@lanhu-context/core': patch
4+
'@lanhu-context/mcp': patch
5+
---
6+
7+
docs: 为三个包新增 npm README(安装、命令/能力概览、MCP 客户端配置与上游迁移说明)

‎packages/cli/README.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# @lanhu-context/cli
2+
3+
> 把蓝湖(Lanhu)设计稿 URL 转成 AI 可直接消费的前端实现上下文——管道式 CLI,bin:`lanhu` / `lanhu-context`。
4+
5+
[仓库主页 / 完整文档](https://github.com/DaYePython/lanhu-context)([English](https://github.com/DaYePython/lanhu-context/blob/main/README.md))
6+
7+
## 安装
8+
9+
```bash
10+
npm i -g @lanhu-context/cli
11+
lanhu doctor # 自检环境/凭据,exit 0 = 就绪
12+
```
13+
14+
凭据配置(`LANHU_TOKEN` 是已登录 lanhuapp.com 会话的整段浏览器 Cookie):
15+
16+
```bash
17+
lanhu auth set
18+
lanhu auth test "$URL" # exit 0 = token 有效
19+
```
20+
21+
## 命令
22+
23+
| 命令 | 用途 |
24+
| --- | --- |
25+
| `parse` / `meta` / `schema` | 解析 URL ID / 设计稿元数据 / DDS schema |
26+
| `html` | 渲染 HTML+CSS(可选 `--tailwind --tw-version <3\|4>`) |
27+
| `tokens` | 提取 design tokens(`--format json\|css`) |
28+
| `assets` | 切图映射;`--download` 并发幂等下载 |
29+
| `preview` | 预览图(`-o <file>` 落盘 / `-o -` 直出 PNG) |
30+
| `context` | 一键组装 `context.md` + `preview.png` |
31+
| `auth` / `doctor` | 凭据管理与六项自检 |
32+
| `mcp` | 启动 MCP server(stdio / streamable HTTP) |
33+
34+
## 用法示例
35+
36+
```bash
37+
lanhu context "https://lanhuapp.com/web/#/item/project/detailDetach?tid=...&pid=...&image_id=..." \
38+
--json --out-dir .lanhu.local
39+
40+
lanhu assets "$URL" --download -o src/assets/my-page --json
41+
```
42+
43+
约定:`--json` 输出统一 envelope(`ok`/`data`/`error`/`warnings`/`meta`)+ 分类退出码;附属阶段(tokens/preview)失败降级为 warning 不拖垮核心产物;落盘幂等(written/skipped/overwritten)。
44+
45+
面向 AI Agent 的完整用法(skills、排障、退出码索引)见仓库 [skills/lanhu-context-cli](https://github.com/DaYePython/lanhu-context/tree/main/skills/lanhu-context-cli)。
46+
47+
## 协议
48+
49+
MIT

‎packages/core/README.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# @lanhu-context/core
2+
3+
> lanhu-context 的纯逻辑核心:URL 解析、蓝湖 API client、DDS schema→HTML、design tokens、context 管道。零 CLI/MCP 依赖。
4+
5+
[仓库主页 / 完整文档](https://github.com/DaYePython/lanhu-context)
6+
7+
一般情况下你不需要直接安装本包——终端使用请装 [`@lanhu-context/cli`](https://www.npmjs.com/package/@lanhu-context/cli),MCP 客户端集成请看 [`@lanhu-context/mcp`](https://www.npmjs.com/package/@lanhu-context/mcp)。本包面向想在自己的 Node.js 程序里嵌入蓝湖设计稿处理链路的开发者。
8+
9+
## 安装
10+
11+
```bash
12+
npm i @lanhu-context/core
13+
```
14+
15+
## 提供的能力
16+
17+
- **URL 解析** —— `lanhuapp.com` 设计稿详情 URL → `{ teamId, projectId, docId }`
18+
- **蓝湖 API client** —— 主站 + DDS 两套 client(Cookie 凭据、浏览器伪装、HTTP 200 空 payload 业务错误识别)
19+
- **schema→HTML** —— DDS schema 渲染 HTML+CSS,可选 css-to-tailwind(v3/v4)转换与失败回退
20+
- **Design tokens** —— 从 Sketch JSON 提取结构化 token 条目,支持 CSS variables 格式化输出
21+
- **切图下载** —— 并发幂等下载器(内容 hash 三态 written/skipped/overwritten)
22+
- **context 管道** —— 组装 `context.md`(HTML 代码 + 切图映射 + tokens + 实现指引)与预览图
23+
- **分级错误模型** —— `fatal` / `degraded` / `notice` 三级严重性 + 结构化错误码 `{code, severity, message, hint}`
24+
25+
## 协议
26+
27+
MIT

‎packages/mcp/README.md‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# @lanhu-context/mcp
2+
3+
> lanhu-context 的 MCP 兼容层:在 `@lanhu-context/core` 之上提供 `get_design_context` 工具,对外契约与上游 [lanhu-context-mcp](https://github.com/refinist/lanhu-context-mcp) 完全一致。
4+
5+
[仓库主页 / 完整文档](https://github.com/DaYePython/lanhu-context)
6+
7+
## 快速使用(推荐走 CLI)
8+
9+
最简单的方式是通过 [`@lanhu-context/cli`](https://www.npmjs.com/package/@lanhu-context/cli) 启动:
10+
11+
```bash
12+
npx -y -p @lanhu-context/cli lanhu mcp --stdio # stdio(MCP 客户端拉起子进程)
13+
npx -y -p @lanhu-context/cli lanhu mcp --http --port 5200 # streamable HTTP(POST /mcp)
14+
```
15+
16+
MCP 客户端配置示例:
17+
18+
```json
19+
{
20+
"mcpServers": {
21+
"lanhu-context": {
22+
"command": "npx",
23+
"args": ["-y", "-p", "@lanhu-context/cli", "lanhu", "mcp", "--stdio"],
24+
"env": { "LANHU_TOKEN": "<已登录 lanhuapp.com 的整段浏览器 Cookie>" }
25+
}
26+
}
27+
}
28+
```
29+
30+
## 与上游 lanhu-context-mcp 的关系
31+
32+
- **契约一致**:工具名 `get_design_context`、入参 `{url}`、inline/files 两种 mode、resource_link 返回、isError + STOP 错误文本——从上游 npm 包迁移即插即用。
33+
- **默认行为差异**:附属阶段(tokens/preview/Tailwind 回退)失败不再整体报错,改为在返回文本末尾附 `warnings:` 段;传 `--compat-strict`(或 `compatStrict` 选项)可恢复上游"任一失败全停"语义。
34+
35+
迁移对照与排障见仓库 [skills/lanhu-context-mcp](https://github.com/DaYePython/lanhu-context/blob/main/skills/lanhu-context-mcp/SKILL.md)。
36+
37+
## 编程使用
38+
39+
```ts
40+
import { createServer, startServer } from "@lanhu-context/mcp";
41+
```
42+
43+
`createServer` 返回注册好 `get_design_context` 的 MCP server 实例;`startServer` 支持 stdio 与 streamable HTTP 两种 transport。
44+
45+
## 协议
46+
47+
MIT

0 commit comments

Comments
 (0)