@nebutra/next-unicorn-skill 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.7] - 2026-02-09
9
+
10
+ ### Added
11
+
12
+ - **Code Organization Analysis** — new deterministic module that detects structural code organization issues via filesystem traversal. Claude cannot infer these from knowledge alone.
13
+ - `god-directory` — directory with >15 source files (should split by feature/domain)
14
+ - `mixed-naming-convention` — files in same directory using different naming styles
15
+ - `deep-nesting` — directory tree exceeding 5 levels from `src/`
16
+ - `barrel-bloat` — index file with >10 re-exports
17
+ - `catch-all-directory` — `utils/helpers/shared/common/lib` with >10 files
18
+ - `circular-dependency` — import cycles detected via DFS graph traversal
19
+ - `mixed-export-style` — files mixing default export with 3+ named exports
20
+ - 3 new scanner patterns in `code-organization` domain:
21
+ - `org-deep-relative-import` — imports traversing 3+ parent directories
22
+ - `org-barrel-reexport-wildcard` — `export * from` in index files
23
+ - `org-catch-all-utils-import` — imports from catch-all utils/helpers directories
24
+ - New `code-organization` domain in `VibeCodingDomain` enum (69 total domains)
25
+ - New `codeOrganizationStats` field in `ScanResult` (file counts, naming conventions, circular dep count)
26
+ - New `analyzeCodeOrganization()` standalone export for programmatic use
27
+ - SKILL.md Step 2.7 with Phase A (deterministic) / Phase B (generative) dual-phase design, MUST/MUST NOT decision table, 3 concrete examples, and skip rules
28
+ - 29 new tests (176 total) covering all scanner patterns and structural analysis rules
29
+
30
+ ### Changed
31
+
32
+ - `StructuralFinding.type` extended with 6 new code organization types + optional `metadata` field
33
+ - Code organization analysis runs for ALL projects (not just monorepos, unlike design system analysis)
34
+ - Architecture diagram in SKILL.md updated to reflect two-track scanner (regex + filesystem)
35
+ - Scanner step description expanded to list all `ScanResult` fields explicitly
36
+
8
37
  ## [1.0.3] - 2026-02-09
9
38
 
10
39
  ### Added
package/README.md CHANGED
@@ -7,14 +7,21 @@
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
+ <a href="https://smithery.ai/skills/nebutra/next-unicorn-skill"><img src="https://img.shields.io/badge/Smithery-Next--Unicorn-orange.svg" alt="Smithery" /></a>
10
11
  <a href="https://github.com/Nebutra/Next-Unicorn-Skill/actions/workflows/ci.yml"><img src="https://github.com/Nebutra/Next-Unicorn-Skill/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
11
12
  <a href="https://www.npmjs.com/package/@nebutra/next-unicorn-skill"><img src="https://img.shields.io/npm/v/@nebutra/next-unicorn-skill.svg?color=blue" alt="npm version" /></a>
13
+ <a href="https://www.npmjs.com/package/@nebutra/next-unicorn-skill"><img src="https://img.shields.io/npm/dm/@nebutra/next-unicorn-skill.svg?color=green" alt="npm downloads" /></a>
14
+ <a href="https://github.com/Nebutra/Next-Unicorn-Skill/stargazers"><img src="https://img.shields.io/github/stars/Nebutra/Next-Unicorn-Skill.svg?style=social" alt="GitHub Stars" /></a>
12
15
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" /></a>
13
16
  <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-strict-blue.svg" alt="TypeScript" /></a>
14
17
  <a href="./tests/"><img src="https://img.shields.io/badge/tests-210%20passed-brightgreen.svg" alt="Tests" /></a>
15
18
  <a href="./tests/"><img src="https://img.shields.io/badge/properties-29%20verified-purple.svg" alt="Property Tests" /></a>
16
19
  </p>
17
20
 
21
+ <p align="center">
22
+ <b>English</b> | <a href="./README.zh-CN.md">简体中文</a>
23
+ </p>
24
+
18
25
  <p align="center">
19
26
  <a href="#quick-start">Quick Start</a> &bull;
20
27
  <a href="#features">Features</a> &bull;
@@ -37,7 +44,13 @@ Snyk, Dependabot, and Renovate manage your *existing* dependencies. They can't f
37
44
 
38
45
  ## Quick Start
39
46
 
40
- ### From npmjs.org (recommended)
47
+ ### From Smithery (recommended)
48
+
49
+ Browse and install directly from the Smithery skill registry:
50
+
51
+ > **[Next-Unicorn on Smithery](https://smithery.ai/skills/nebutra/next-unicorn-skill)**
52
+
53
+ ### From npmjs.org
41
54
 
42
55
  ```bash
43
56
  npm install @nebutra/next-unicorn-skill
@@ -147,15 +160,62 @@ Or use as an **MCP SKILL** — provide [`SKILL.md`](./SKILL.md) to your AI agent
147
160
 
148
161
  ## How It Works
149
162
 
163
+ ### Architecture Diagram
164
+
165
+ ```mermaid
166
+ flowchart TB
167
+ subgraph input [Input]
168
+ I[InputSchema JSON]
169
+ end
170
+
171
+ subgraph deterministic [Deterministic Layer — TypeScript]
172
+ V[Zod Validator]
173
+ S[Scanner — 40+ regex patterns across 30 domains]
174
+ SA[Structure Analyzer — monorepo architecture, dependency flow, token layers]
175
+ C7[Context7 Verifier — exponential backoff, query ranking]
176
+ VS[Vuln Scanner — OSV database]
177
+ PC[Peer Checker — semver range validation]
178
+ PR[PR Strategy + Executor]
179
+ end
180
+
181
+ subgraph agent [AI Agent Layer — Claude generalization]
182
+ GA[Gap Analysis — single library / ecosystem / architecture gaps]
183
+ REC[Recommender — ecosystem-level solutions with rationale]
184
+ UX[UX Audit — 8 categories]
185
+ DS{Design System?}
186
+ DSE[Extract from existing code]
187
+ DSS[Scaffold from reference repos]
188
+ end
189
+
190
+ subgraph output [Output]
191
+ O[OutputSchema JSON]
192
+ end
193
+
194
+ I --> V --> S
195
+ S --> SA
196
+ S --> REC
197
+ SA --> GA
198
+ GA --> DS
199
+ DS -->|Existing frontend| DSE
200
+ DS -->|No frontend| DSS
201
+ GA --> O
202
+ REC --> C7 --> O
203
+ S --> PC --> O
204
+ S --> VS --> O
205
+ UX --> O
206
+ O --> PR
150
207
  ```
151
- Input ─> Validator ─> Scanner + Structure Analyzer
152
- ─> Gap Analysis (AI Agent) ─> Recommender (AI Agent) ─> Context7 Verifier
153
- ─> Impact Scorer ─> Conflict Detection ─> Vuln Scanner ─> License Filter
154
- ─> Migration Planner ─> UX Auditor ─> Auto-Updater
155
- ─> Serializer ─> PR Creator ─> Output
156
- ```
157
208
 
158
- **Key architecture**: The scanner detects WHAT is hand-rolled; the structure analyzer detects architectural gaps; the **Recommender** (AI agent or caller) decides WHAT to use. No library recommendations are hardcoded — they are provided dynamically based on project context, ecosystem knowledge, and Context7 verification.
209
+ ### Design Principles
210
+
211
+ | Principle | Implementation |
212
+ |-----------|---------------|
213
+ | **Occam's Razor** | Only 16 TS modules remain — each does something Claude cannot (regex, semver, file I/O, API calls). Scoring, planning, UX audit, PR descriptions are AI-agent-driven. |
214
+ | **No hardcoded recommendations** | Pattern catalog contains zero library names. The `Recommender` callback and `GapRecommendation` are filled by the AI agent at runtime. |
215
+ | **Context7 best practices** | Exponential backoff (3 retries), query parameter for ranking, per-library isolation. Both replacements and gaps are verified. |
216
+ | **Progressive disclosure** | SKILL.md is 111 lines. `references/` files load only when design system gaps are detected. |
217
+ | **Two analysis modes** | **Replacement**: scanner finds hand-rolled code → agent recommends library. **Gap**: agent identifies missing capabilities → verified via Context7. |
218
+ | **Design system support** | Structure analyzer detects missing layers. Two paths: scaffold from 25+ reference repos, or extract spec from existing code (6 principles, 5 phases). |
159
219
 
160
220
  Each stage is a pure function with structured I/O. All external dependencies (Context7, OSV, npm registry, GitHub API) are **injected via interfaces** for testability.
161
221
 
@@ -361,10 +421,37 @@ pnpm build # Compile to dist/
361
421
  | [`design-system-sources.md`](./references/design-system-sources.md) | 25+ curated design system repos for scaffolding (Primer, Polaris, Dub, Supabase, etc.) |
362
422
  | [`design-system-extraction.md`](./references/design-system-extraction.md) | Workflow for extracting a design system from existing code (6 principles, 5 phases) |
363
423
 
424
+ <!-- TODO: P1 — 项目 Logo: 设计一个 Logo 放在 README 顶部,同时用作 GitHub Social Preview -->
425
+ <!-- TODO: P1 — Social Preview / OG Image: 到 GitHub repo Settings → Social preview 上传卡片图 -->
426
+ <!-- TODO: P1 — Demo GIF: 录制 30 秒终端演示动图,放在 Quick Start 上方 -->
427
+ <!-- TODO: P0 — GitHub Topics: 到 GitHub repo Settings → Topics 添加: mcp, ai-agent, claude-code, codebase-analysis, dependency-management, vulnerability-scanning, migration, context7, vibe-coding, skill -->
428
+ <!-- TODO: P2 — Coverage 徽章: 配置 Codecov 或 Coveralls,在 CI 中上传覆盖率报告 -->
429
+ <!-- TODO: P2 — Twitter/X: 创建项目 Twitter 账号或用个人账号发布公告,在 README 添加链接 -->
430
+ <!-- TODO: P2 — Discord: 创建 Discord 服务器,在 README 添加邀请链接徽章 -->
431
+ <!-- TODO: P3 — Awesome Lists: 提交 PR 到 awesome-mcp、awesome-claude-code、awesome-ai-tools 等列表 -->
432
+ <!-- TODO: P3 — Product Hunt: 在 producthunt.com 发布项目 -->
433
+ <!-- TODO: P3 — Hacker News: 发布 Show HN 帖子 -->
434
+ <!-- TODO: P3 — GitHub Discussions: 到 GitHub repo Settings → Features → Discussions 开启 -->
435
+ <!-- TODO: P3 — "Who's Using" 展示区: 有用户后在 README 加 logo 墙 -->
436
+
437
+ ## Star History
438
+
439
+ <a href="https://star-history.com/#Nebutra/Next-Unicorn-Skill&Date">
440
+ <picture>
441
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Nebutra/Next-Unicorn-Skill&type=Date&theme=dark" />
442
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Nebutra/Next-Unicorn-Skill&type=Date" />
443
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Nebutra/Next-Unicorn-Skill&type=Date" />
444
+ </picture>
445
+ </a>
446
+
364
447
  ## Contributing
365
448
 
366
449
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup, architecture overview, and contribution guidelines.
367
450
 
451
+ ## Security
452
+
453
+ See [SECURITY.md](./SECURITY.md) for our security policy and how to report vulnerabilities.
454
+
368
455
  ## Releasing
369
456
 
370
457
  Releases are automated via GitHub Actions:
@@ -384,4 +471,4 @@ See [CHANGELOG.md](./CHANGELOG.md) for version history.
384
471
 
385
472
  ## License
386
473
 
387
- [MIT](./LICENSE) &copy; [TsekaLuk](https://github.com/TsekaLuk)
474
+ [MIT](./LICENSE) &copy; [Nebutra](https://github.com/Nebutra)
@@ -0,0 +1,474 @@
1
+ <p align="center">
2
+ <h1 align="center">Next-Unicorn</h1>
3
+ <p align="center">
4
+ 终结 Vibe Coding 技术债。审计你的代码库,用独角兽级别的<br/>
5
+ 第三方库替换重复造轮子的代码,并输出迁移方案 + "删除代码"清单。
6
+ </p>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://smithery.ai/skills/nebutra/next-unicorn-skill"><img src="https://img.shields.io/badge/Smithery-Next--Unicorn-orange.svg" alt="Smithery" /></a>
11
+ <a href="https://github.com/Nebutra/Next-Unicorn-Skill/actions/workflows/ci.yml"><img src="https://github.com/Nebutra/Next-Unicorn-Skill/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
12
+ <a href="https://www.npmjs.com/package/@nebutra/next-unicorn-skill"><img src="https://img.shields.io/npm/v/@nebutra/next-unicorn-skill.svg?color=blue" alt="npm version" /></a>
13
+ <a href="https://www.npmjs.com/package/@nebutra/next-unicorn-skill"><img src="https://img.shields.io/npm/dm/@nebutra/next-unicorn-skill.svg?color=green" alt="npm downloads" /></a>
14
+ <a href="https://github.com/Nebutra/Next-Unicorn-Skill/stargazers"><img src="https://img.shields.io/github/stars/Nebutra/Next-Unicorn-Skill.svg?style=social" alt="GitHub Stars" /></a>
15
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" /></a>
16
+ <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-strict-blue.svg" alt="TypeScript" /></a>
17
+ <a href="./tests/"><img src="https://img.shields.io/badge/tests-210%20passed-brightgreen.svg" alt="Tests" /></a>
18
+ <a href="./tests/"><img src="https://img.shields.io/badge/properties-29%20verified-purple.svg" alt="Property Tests" /></a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <a href="./README.md">English</a> | <b>简体中文</b>
23
+ </p>
24
+
25
+ <p align="center">
26
+ <a href="#快速开始">快速开始</a> &bull;
27
+ <a href="#功能特性">功能特性</a> &bull;
28
+ <a href="#工作原理">工作原理</a> &bull;
29
+ <a href="#方案对比">方案对比</a> &bull;
30
+ <a href="#api-接口">API 接口</a> &bull;
31
+ <a href="#示例">示例</a> &bull;
32
+ <a href="#贡献指南">贡献指南</a>
33
+ </p>
34
+
35
+ ---
36
+
37
+ ## 为什么选择 Next-Unicorn?
38
+
39
+ 每个代码库都会逐渐积累本应使用成熟第三方库的手写实现。自制的日期格式化器、DIY 日志器、临时状态机、草率的 i18n 方案——这些都是 **Vibe Coding 技术债**。
40
+
41
+ Snyk、Dependabot 和 Renovate 管理的是你*已有*的依赖。它们无法发现你写了但*应该替换为*依赖的代码,也无法发现项目*完全缺失*的能力。
42
+
43
+ **Next-Unicorn 三管齐下** —— 替换分析、缺口分析和依赖管理 —— 所有推荐均通过 [Context7 MCP](https://context7.com) 进行真实文档验证。
44
+
45
+ ## 快速开始
46
+
47
+ ### 从 Smithery 安装(推荐)
48
+
49
+ 在 Smithery 技能市场中浏览并直接安装:
50
+
51
+ > **[Next-Unicorn on Smithery](https://smithery.ai/skills/nebutra/next-unicorn-skill)**
52
+
53
+ ### 从 npmjs.org 安装
54
+
55
+ ```bash
56
+ npm install @nebutra/next-unicorn-skill
57
+ # 或
58
+ pnpm add @nebutra/next-unicorn-skill
59
+ ```
60
+
61
+ ### 从 GitHub Packages 安装
62
+
63
+ 先配置 `.npmrc`:
64
+
65
+ ```shell
66
+ echo "@nebutra:registry=https://npm.pkg.github.com" >> .npmrc
67
+ ```
68
+
69
+ 然后安装:
70
+
71
+ ```bash
72
+ npm install @nebutra/next-unicorn-skill
73
+ ```
74
+
75
+ ```typescript
76
+ import { analyze, scanCodebase } from '@nebutra/next-unicorn-skill';
77
+ import type { Recommender, GapRecommendation } from '@nebutra/next-unicorn-skill';
78
+
79
+ // 推荐器:AI 代理决定每个检测结果应使用哪个库
80
+ const recommender: Recommender = (detection) => ({
81
+ library: '@lingui/core',
82
+ version: '^4.0.0',
83
+ license: 'MIT',
84
+ rationale: '编译时 i18n,近乎零运行时开销',
85
+ ecosystem: [
86
+ { library: '@lingui/macro', version: '^4.0.0', role: '标签模板' },
87
+ { library: '@lingui/cli', version: '^4.0.0', role: 'CI 消息提取' },
88
+ ],
89
+ antiPatterns: ['如果在意包体积,避免使用 i18next —— Lingui 会在编译时消除'],
90
+ alternatives: [
91
+ { library: 'next-intl', when: '使用 Next.js App Router 和服务端组件时' },
92
+ ],
93
+ });
94
+
95
+ // 缺口分析:项目应有但未实现的能力
96
+ const gaps: GapRecommendation[] = [
97
+ {
98
+ domain: 'observability',
99
+ description: '未检测到结构化日志',
100
+ recommendedLibrary: {
101
+ name: 'pino', version: '^9.0.0', license: 'MIT',
102
+ rationale: '最快的 Node.js JSON 日志库,支持数据脱敏和子日志器',
103
+ },
104
+ priority: 'critical',
105
+ },
106
+ ];
107
+
108
+ const result = await analyze({
109
+ input: {
110
+ projectMetadata: {
111
+ repoPath: './my-project',
112
+ languages: ['typescript'],
113
+ packageManagers: ['pnpm'],
114
+ currentLibraries: { react: '18.2.0', next: '14.1.0' },
115
+ },
116
+ optimizationGoals: ['减少自定义代码', '提升可维护性'],
117
+ constraints: { licenseAllowlist: ['MIT', 'Apache-2.0', 'ISC'] },
118
+ priorityFocusAreas: ['i18n', 'observability', 'auth-security'],
119
+ },
120
+ context7Client: myContext7Client,
121
+ recommender,
122
+ gaps,
123
+ });
124
+
125
+ if (result.success) {
126
+ console.log(result.prettyJson);
127
+ // result.scanResult — 原始检测结果 + 结构化发现,供 AI 分析使用
128
+ // result.output.gapAnalysis — Context7 验证过的缺口推荐
129
+ }
130
+ ```
131
+
132
+ 或作为 **MCP SKILL** 使用 —— 将 [`SKILL.md`](./SKILL.md) 提供给你的 AI 代理(Claude Code、Kiro、Cursor 等)。
133
+
134
+ ## 功能特性
135
+
136
+ ### 核心分析
137
+
138
+ | 功能 | 描述 |
139
+ |------|------|
140
+ | **基于模式的扫描** | 使用 40+ 正则模式跨 30 个领域检测手写代码(设计系统、认证、状态管理等) |
141
+ | **结构分析** | 检测 Monorepo 架构缺陷:缺失的 Token 层、依赖流向违规、硬编码配置值 |
142
+ | **缺口分析** | AI 代理识别缺失的能力 —— 不仅是手写代码,还包括你应有但没有的东西 |
143
+ | **生态级推荐** | 解决方案包含理由、配套包、反模式和替代方案 |
144
+ | **Context7 验证** | 每条推荐(替换和缺口)均经过指数退避重试验证 |
145
+ | **7 维影响评分** | 可扩展性、性能、安全性、可维护性、功能丰富度、用户体验、UI 美观度 |
146
+ | **分阶段迁移计划** | 低 / 中 / 高风险阶段,含适配器策略 |
147
+ | **删除清单** | 列出每个待删文件和行范围,附预估节省行数 |
148
+ | **UX 完整性审计** | 无障碍、错误/空/加载状态、表单验证、设计系统对齐 |
149
+ | **设计系统支持** | 两条路径:从参考仓库搭建(Primer、Polaris、Supabase、Dub)或从现有代码中提取 |
150
+ | **Monorepo 支持** | 独立检测 npm、pip、cargo、go 工作区 |
151
+
152
+ ### 依赖管理
153
+
154
+ | 功能 | 描述 |
155
+ |------|------|
156
+ | **漏洞扫描** | 通过 OSV 扫描当前和推荐的依赖 —— 防止"升级引入漏洞" |
157
+ | **自动更新依赖** | 基于影响评分的版本升级,通过 Context7 检测破坏性变更 |
158
+ | **自动创建 PR** | GitHub/GitLab PR,包含常规提交标题、影响表格、审查清单 |
159
+ | **迁移 PR** | 包含适配器代码脚手架的 PR,用于替换手写代码 |
160
+
161
+ ## 工作原理
162
+
163
+ ### 架构图
164
+
165
+ ```mermaid
166
+ flowchart TB
167
+ subgraph input [输入]
168
+ I[InputSchema JSON]
169
+ end
170
+
171
+ subgraph deterministic [确定性层 — TypeScript]
172
+ V[Zod 验证器]
173
+ S[扫描器 — 40+ 正则模式覆盖 30 个领域]
174
+ SA[结构分析器 — Monorepo 架构、依赖流向、Token 层]
175
+ C7[Context7 验证器 — 指数退避、查询排序]
176
+ VS[漏洞扫描器 — OSV 数据库]
177
+ PC[Peer 检查器 — semver 范围验证]
178
+ PR[PR 策略 + 执行器]
179
+ end
180
+
181
+ subgraph agent [AI 代理层 — Claude 泛化]
182
+ GA[缺口分析 — 单库 / 生态 / 架构级缺口]
183
+ REC[推荐器 — 生态级解决方案含理由]
184
+ UX[UX 审计 — 8 个类别]
185
+ DS{设计系统?}
186
+ DSE[从现有代码提取]
187
+ DSS[从参考仓库搭建]
188
+ end
189
+
190
+ subgraph output [输出]
191
+ O[OutputSchema JSON]
192
+ end
193
+
194
+ I --> V --> S
195
+ S --> SA
196
+ S --> REC
197
+ SA --> GA
198
+ GA --> DS
199
+ DS -->|有前端| DSE
200
+ DS -->|无前端| DSS
201
+ GA --> O
202
+ REC --> C7 --> O
203
+ S --> PC --> O
204
+ S --> VS --> O
205
+ UX --> O
206
+ O --> PR
207
+ ```
208
+
209
+ ### 设计原则
210
+
211
+ | 原则 | 实现方式 |
212
+ |------|----------|
213
+ | **奥卡姆剃刀** | 仅保留 16 个 TS 模块 —— 每个模块做 Claude 无法做的事(正则、semver、文件 I/O、API 调用)。评分、规划、UX 审计、PR 描述由 AI 代理驱动。 |
214
+ | **不硬编码推荐** | 模式目录中不包含任何库名。`Recommender` 回调和 `GapRecommendation` 由 AI 代理在运行时填充。 |
215
+ | **Context7 最佳实践** | 指数退避(3 次重试),用于排序的查询参数,按库隔离。替换和缺口均经过验证。 |
216
+ | **渐进式披露** | SKILL.md 仅 111 行。`references/` 文件仅在检测到设计系统缺口时加载。 |
217
+ | **双分析模式** | **替换**:扫描器发现手写代码 → 代理推荐库。**缺口**:代理识别缺失能力 → 通过 Context7 验证。 |
218
+ | **设计系统支持** | 结构分析器检测缺失层。两条路径:从 25+ 参考仓库搭建,或从现有代码提取规范(6 原则,5 阶段)。 |
219
+
220
+ 每个阶段都是具有结构化 I/O 的纯函数。所有外部依赖(Context7、OSV、npm 注册表、GitHub API)均通过**接口注入**以保证可测试性。
221
+
222
+ ### 前后对比
223
+
224
+ <table>
225
+ <tr><th>之前(手写实现)</th><th>之后(推荐方案)</th></tr>
226
+ <tr>
227
+ <td>
228
+
229
+ ```tsx
230
+ // 自定义 i18n 散布在 47 个文件中
231
+ const translations = {
232
+ en: { greeting: 'Hello' },
233
+ es: { greeting: 'Hola' },
234
+ };
235
+ function t(key, locale) {
236
+ return translations[locale]?.[key] ?? key;
237
+ }
238
+ // 无复数、无插值、无 RTL 支持
239
+ ```
240
+
241
+ </td>
242
+ <td>
243
+
244
+ ```tsx
245
+ // @lingui/core — Context7 已验证,MIT
246
+ // 生态:@lingui/macro + @lingui/cli
247
+ // 影响:9.2/10 | 风险:低 | 工时:8h
248
+ import { useLingui } from '@lingui/react';
249
+
250
+ export default function Page() {
251
+ const { t } = useLingui();
252
+ return <h1>{t`greeting`}</h1>;
253
+ }
254
+ ```
255
+
256
+ </td>
257
+ </tr>
258
+ <tr>
259
+ <td>
260
+
261
+ ```typescript
262
+ // 使用 console.log 的自定义日志器
263
+ function logRequest(req) {
264
+ console.log(JSON.stringify({
265
+ time: new Date().toISOString(),
266
+ method: req.method,
267
+ url: req.url,
268
+ }));
269
+ }
270
+ // 无日志级别、无脱敏、无轮转
271
+ ```
272
+
273
+ </td>
274
+ <td>
275
+
276
+ ```typescript
277
+ // pino — Context7 已验证,MIT
278
+ // 缺口分析:"未检测到结构化日志"
279
+ // 优先级:关键
280
+ import pino from 'pino';
281
+ const logger = pino({
282
+ level: 'info',
283
+ redact: ['req.headers.authorization'],
284
+ });
285
+ ```
286
+
287
+ </td>
288
+ </tr>
289
+ </table>
290
+
291
+ ## 方案对比
292
+
293
+ | 功能 | Next-Unicorn | Snyk | Dependabot | Renovate |
294
+ |------|:---:|:---:|:---:|:---:|
295
+ | 发现应替换的手写代码 | **支持** | | | |
296
+ | 识别缺失能力(缺口) | **支持** | | | |
297
+ | 结构性架构分析 | **支持** | | | |
298
+ | 推荐新库 | **支持** | | | |
299
+ | 生态级解决方案 | **支持** | | | |
300
+ | 7 维影响评分 | **支持** | | | |
301
+ | Context7 文档验证 | **支持** | | | |
302
+ | 分阶段迁移计划 | **支持** | | | |
303
+ | UX 完整性审计 | **支持** | | | |
304
+ | 设计系统搭建/提取 | **支持** | | | |
305
+ | 删除清单 | **支持** | | | |
306
+ | 漏洞扫描 | **支持** | 支持 | 支持 | |
307
+ | 扫描*推荐库*的漏洞 | **支持** | | | |
308
+ | 自动更新现有依赖 | **支持** | | 支持 | 支持 |
309
+ | 基于影响评分的更新 | **支持** | | | |
310
+ | 自动创建 PR | **支持** | 支持 | 支持 | 支持 |
311
+ | 含适配器代码的迁移 PR | **支持** | | | |
312
+ | 许可证合规 | **支持** | 支持 | | |
313
+ | Monorepo 支持 | **支持** | 支持 | 支持 | 支持 |
314
+
315
+ ## API 接口
316
+
317
+ ### `analyze(options): Promise<AnalyzeResult>`
318
+
319
+ | 选项 | 类型 | 必填 | 描述 |
320
+ |------|------|:----:|------|
321
+ | `input` | `InputSchema` | 是 | 项目元数据、目标、约束、关注领域 |
322
+ | `context7Client` | `Context7Client` | 是 | Context7 MCP 客户端,用于文档验证 |
323
+ | `recommender` | `Recommender` | 是 | 将每个检测结果映射为库推荐(由 AI 代理提供) |
324
+ | `gaps` | `GapRecommendation[]` | 否 | 项目应有但缺失的能力(由 AI 代理识别) |
325
+ | `vulnClient` | `VulnerabilityClient` | 否 | OSV 客户端,用于漏洞扫描 |
326
+ | `registryClient` | `RegistryClient` | 否 | 包注册表客户端,用于自动更新 |
327
+ | `platformClient` | `PlatformClient` | 否 | GitHub/GitLab 客户端,用于 PR 创建 |
328
+ | `gitOps` | `GitOperations` | 否 | Git CLI 操作,用于 PR 创建 |
329
+
330
+ ### `scanCodebase(input): Promise<ScanResult>`
331
+
332
+ 独立扫描器 —— 返回检测结果、工作区信息和结构化发现(设计系统层分析、依赖流向违规)。AI 代理可先调用此接口,再通过 `Recommender` 回调提供推荐。
333
+
334
+ ### `analyzeStructure(repoPath, workspaces): StructuralAnalysis`
335
+
336
+ 独立结构分析器 —— 检测 Monorepo 中缺失的设计系统层、依赖流向违规、硬编码配置值和缺失的共享预设。
337
+
338
+ ### 输出结构
339
+
340
+ ```jsonc
341
+ {
342
+ "recommendedChanges": [...], // 带影响评分的替换推荐
343
+ "gapAnalysis": [...], // (可选)Context7 验证过的缺口推荐
344
+ "filesToDelete": [...], // 迁移后待删除的文件
345
+ "linesSavedEstimate": 1250, // 预估节省的总行数
346
+ "uxAudit": [...], // UX 完整性(8 个类别)
347
+ "migrationPlan": { // 分阶段计划
348
+ "phases": [...], // 低 → 中 → 高风险
349
+ "deletionChecklist": [...] // 含原因的详细条目
350
+ },
351
+ "vulnerabilityReport": {...}, // (可选)漏洞发现 + SARIF
352
+ "updatePlan": {...}, // (可选)评分后的依赖更新
353
+ "pullRequests": {...} // (可选)已创建的 PR 结果
354
+ }
355
+ ```
356
+
357
+ ## Vibe Coding 领域
358
+
359
+ 68 个领域横跨 11 个类别,对齐 ISO/IEC 25010。其中 30 个领域有扫描器模式支持,其余由 AI 代理缺口分析覆盖。
360
+
361
+ | 类别 | 数量 | 示例 |
362
+ |------|:----:|------|
363
+ | UX / 设计 | 14 | `design-system`、`a11y-accessibility`、`forms-ux`、`empty-loading-error-states` |
364
+ | SEO / 国际化 | 5 | `seo`、`i18n`、`content-marketing` |
365
+ | 增长 / 数据 | 7 | `analytics-tracking`、`ab-testing-experimentation` |
366
+ | 前端架构 | 8 | `state-management`、`data-fetching-caching`、`realtime-collaboration` |
367
+ | 后端 / 平台 | 8 | `database-orm-migrations`、`caching-rate-limit`、`feature-flags-config` |
368
+ | 安全 | 5 | `auth-security`、`security-hardening`、`fraud-abuse-prevention` |
369
+ | 可观测性 | 4 | `logging-tracing-metrics`、`error-monitoring` |
370
+ | 交付 / 开发体验 | 6 | `testing-strategy`、`ci-cd-release`、`dependency-management` |
371
+ | 性能 | 3 | `performance-web-vitals`、`cost-optimization` |
372
+ | AI 工程 | 3 | `ai-model-serving`、`rag-vector-search` |
373
+ | 商业 | 3 | `payments-billing`、`marketplace-platform` |
374
+
375
+ > 可通过输入 Schema 中的 `customDomains` 进行扩展。
376
+
377
+ ## 测试
378
+
379
+ ```bash
380
+ pnpm test # 210 个测试(vitest + fast-check)
381
+ pnpm typecheck # TypeScript 严格模式
382
+ pnpm build # 编译到 dist/
383
+ ```
384
+
385
+ **29 个基于属性的测试**验证正确性不变量:
386
+
387
+ - Schema 往返保证(属性 1–3)
388
+ - 检测完备性(属性 4)
389
+ - Context7 验证正确性(属性 5)
390
+ - 评分范围和组合正确性(属性 6–7)
391
+ - 迁移阶段排序和适配器强制(属性 8–10)
392
+ - UX 审计完备性(属性 11)
393
+ - 约束过滤(属性 12–13)
394
+ - JSON 缩进(属性 14)
395
+ - 漏洞扫描(属性 15–18)
396
+ - 更新策略和评分(属性 19–24)
397
+ - PR 策略和格式化(属性 25–29)
398
+
399
+ ## 示例
400
+
401
+ | 场景 | 输入 | 输出 |
402
+ |------|------|------|
403
+ | Next.js 前端 | [`examples/frontend-nextjs/input.json`](./examples/frontend-nextjs/input.json) | [`output.json`](./examples/frontend-nextjs/output.json) |
404
+ | Node.js 后端 | [`examples/backend-node/input.json`](./examples/backend-node/input.json) | [`output.json`](./examples/backend-node/output.json) |
405
+
406
+ ## 模板
407
+
408
+ | 模板 | 用途 |
409
+ |------|------|
410
+ | [`summary-table.md`](./templates/summary-table.md) | 面向利益相关者的对比表 |
411
+ | [`migration-plan.md`](./templates/migration-plan.md) | 分阶段迁移计划 |
412
+ | [`deletion-checklist.md`](./templates/deletion-checklist.md) | 迁移后待删除文件清单 |
413
+ | [`vuln-report.md`](./templates/vuln-report.md) | 漏洞扫描报告 |
414
+ | [`update-plan.md`](./templates/update-plan.md) | 依赖更新计划 |
415
+ | [`prd-template.md`](./templates/prd-template.md) | 面向利益相关者的 PRD |
416
+
417
+ ## 参考资料
418
+
419
+ | 参考 | 用途 |
420
+ |------|------|
421
+ | [`design-system-sources.md`](./references/design-system-sources.md) | 25+ 精选设计系统仓库,用于搭建(Primer、Polaris、Dub、Supabase 等) |
422
+ | [`design-system-extraction.md`](./references/design-system-extraction.md) | 从现有代码提取设计系统的工作流(6 原则,5 阶段) |
423
+
424
+ <!-- TODO: P1 — 项目 Logo: 设计一个 Logo 放在 README 顶部,同时用作 GitHub Social Preview -->
425
+ <!-- TODO: P1 — Social Preview / OG Image: 到 GitHub repo Settings → Social preview 上传卡片图 -->
426
+ <!-- TODO: P1 — Demo GIF: 录制 30 秒终端演示动图,放在快速开始上方 -->
427
+ <!-- TODO: P0 — GitHub Topics: 到 GitHub repo Settings → Topics 添加: mcp, ai-agent, claude-code, codebase-analysis, dependency-management, vulnerability-scanning, migration, context7, vibe-coding, skill -->
428
+ <!-- TODO: P2 — Coverage 徽章: 配置 Codecov 或 Coveralls,在 CI 中上传覆盖率报告 -->
429
+ <!-- TODO: P2 — Twitter/X: 创建项目 Twitter 账号或用个人账号发布公告,在 README 添加链接 -->
430
+ <!-- TODO: P2 — Discord: 创建 Discord 服务器,在 README 添加邀请链接徽章 -->
431
+ <!-- TODO: P3 — Awesome Lists: 提交 PR 到 awesome-mcp、awesome-claude-code、awesome-ai-tools 等列表 -->
432
+ <!-- TODO: P3 — Product Hunt: 在 producthunt.com 发布项目 -->
433
+ <!-- TODO: P3 — Hacker News: 发布 Show HN 帖子 -->
434
+ <!-- TODO: P3 — GitHub Discussions: 到 GitHub repo Settings → Features → Discussions 开启 -->
435
+ <!-- TODO: P3 — "Who's Using" 展示区: 有用户后在 README 加 logo 墙 -->
436
+
437
+ ## Star History
438
+
439
+ <a href="https://star-history.com/#Nebutra/Next-Unicorn-Skill&Date">
440
+ <picture>
441
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=Nebutra/Next-Unicorn-Skill&type=Date&theme=dark" />
442
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=Nebutra/Next-Unicorn-Skill&type=Date" />
443
+ <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=Nebutra/Next-Unicorn-Skill&type=Date" />
444
+ </picture>
445
+ </a>
446
+
447
+ ## 贡献指南
448
+
449
+ 请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md) 了解开发环境搭建、架构概览和贡献指引。
450
+
451
+ ## 安全
452
+
453
+ 请参阅 [SECURITY.md](./SECURITY.md) 了解安全策略和漏洞上报流程。
454
+
455
+ ## 发布
456
+
457
+ 发布通过 GitHub Actions 自动完成:
458
+
459
+ ```bash
460
+ # 打标签发布新版本
461
+ git tag v1.0.5
462
+ git push origin v1.0.5
463
+ # → CI 运行测试 → 创建 GitHub Release → 发布到 npmjs + GitHub Packages
464
+ ```
465
+
466
+ 每次推送到 `main` 分支时,CI 工作流也会自动发布包。
467
+
468
+ > **必需密钥**:`NPM_TOKEN`(npmjs.org 发布令牌)。`GITHUB_TOKEN` 由系统自动提供。
469
+
470
+ 请参阅 [CHANGELOG.md](./CHANGELOG.md) 了解版本历史。
471
+
472
+ ## 许可证
473
+
474
+ [MIT](./LICENSE) &copy; [Nebutra](https://github.com/Nebutra)