1实现原理 · 为什么它能做到
核心是自带目录内的本地 BM25 检索引擎:纯 Python 标准库实现、零第三方依赖、零运行时网络;数据文件用 __file__ 相对定位,技能目录即知识库,拷贝到任何插件根都能跑。
import csv import difflib import re from pathlib import Path from math import log from collections import defaultdict
命中判定 = BM25 分数 + 词覆盖度双阈值,低置信时主动 abstain(返回空而非弱数据);SKILL.md 同侧强制『0 命中→重试一次→仍空则明示来自内置默认』,双保险防编造。
abstain = (top_score <= threshold["min_score"] or coverage < threshold["min_coverage"] or (threshold["min_margin"] > 0 and top_score - runner_up_score < threshold["min_margin"]))
17 个检索域 + 22 个技术栈由 CSV_CONFIG/栈 CSV 声明式驱动(每域限定 search_cols 与 output_cols),检索=在指定 CSV 的限定列上打分,天然防无关字段噪音。
"style": { "file": "styles.csv",
--design-system 不是拼接而是编排管线:以产品域先定类别 → 套 ui-reasoning.csv 的推理规则 → 对 style/color/landing/typography 做加权多域检索 → 产出成套 pattern/风格/色板/字体/效果/反模式。
This aggregates product/style/color/landing/typography matches, applies reasoning rules from `ui-reasoning.csv`, and returns pattern, style, colors, typography, effects, and anti-patterns to avoid.
决策规则是受限 DSL 而非代码:reasoning_contract.py 只做确定性解析改写并显式声明『永不执行数据』,action 前缀白名单校验(constraint/style/pattern/mode),被投毒最多导致规则匹配错而非任意代码执行。
"""Return deterministic mutations and an audit trail; never execute data."""
持久化用『Master + Overrides』模式且写盘保守:--persist 须同时给 --output-dir,safe_slug 消毒项目名([a-z0-9_-],防路径穿越),temp+NamedTemporaryFile+os.link 原子排他发布——已有 MASTER.md 默认跳过,--force 才覆盖并须用户显式授权。
def safe_slug(name, fallback: str = "default") -> str:
工作流契约把『禁猜』写成查询纪律:Step1 探测真实栈(package.json/pubspec.yaml/*.xcodeproj 等,探测不到就问,禁止硬编码默认栈)→ Step2 设计系统 → Step3 按需域检索 → Step4 栈指引;query 单一主导意图 + 2-5 词 + 一个约束。
If nothing is detectable and stack guidance matters, ask the user. **Never assume a stack**
2核心能力
3外部依赖
| 类型 | 依赖 |
|---|---|
| network | 运行时零外联(search.py/core.py/design_system.py/reasoning_contract.py 均无网络模块——import 审计全标准库) |
| network | 维护期(仓库 CI refresh-catalogs.yml,非 skill 运行时、不随 skill 分发):Google Fonts Developer API 快照 |
| network | 维护期:官方 google/fonts 仓库许可证元数据 sparse clone |
| package | 维护期:npm 安装 pin 版 @phosphor-icons/core 与 @phosphor-icons/react(--ignore-scripts)导出图标清单 |
4风险提醒 风险提醒:蓝色 · 知晓即可
- 静态知识库有保质期:版本类数据(栈行、字体/图标快照)会随真实发布过期,离线部署无法自愈。 — freshnessPolicy needs-review 90 天/manual 365 天;catalog-summary verifiedAt 2026-08-26,commit 2026-09-06
- 内容非认证:溯源到实体级而非逐行;风格/配色/推理规则本质是作者整理的主观启发式。 — data-provenance.json records 粒度(entity 级)
- 下游盲从风险:返回的 code 示例/反模式文本由 agent 直接落码;SKILL 仅声明 'recommendations, never instructions',不设防的宿主会照抄反例。 — injection_surface:内容/供应链型,非执行型
- 检索可解释性依赖 agent 自律:域自动检测可能误路由(SKILL 自认 'font' 同中 typography 与 google-fonts),须执行 Verify-the-returned-domain 契约。 — SKILL.md Query Contract 'Verify the returned domain/category, top result identity, and fit…before applying'
5第二遍独立确认
- [ok] 运行时零网络 — search.py 头 import(argparse/json/sys/io + 本地三模块)与 core/design_system/reasoning_contract 的 import 全为标准库;scripts/ 全树 grep requests/urllib/socket/http/curl/wget 零命中(tests 内 URL 为数据校验用字面量)。
- [ok] 功能声明数字 vs 实际数据行数 — 行级计数:styles 88(50 active+29 supplemental+9 deprecated=可检索 79)、products/ui-reasoning/colors 192、typography 74、google-fonts 1934、ux-guidelines 119、icons 105、motion 17、charts 25、landing 34、stacks 22 文件 1260 行——与 description 及 catalog-summary.json 完全一致,无夸大。
- [ok] 持久化写盘面(防穿越/原子/不覆盖) — design_system.py 精读:safe_slug 只留 [a-z0-9_-]、NamedTemporaryFile 写入 + os.link 排他发布、FileExistsError 默认跳过、--force 分支才覆盖;与 SKILL.md 'skips writing and leaves it untouched unless you also pass --force' 一致。
- [ok] 决策规则无执行面 — reasoning_contract.py 无 eval/exec/subprocess/动态 import;ALLOWED_CONDITIONS/ACTION_PREFIXES/TOKEN_RE 白名单 + ValueError;docstring 'never execute data.'。
- [ok] 凭证/env 读取 — 运行时唯一 env 读取 = design_system.py:615 COLORTERM;无 keychain/.env/密钥文件访问;CI 工作流使用的 GOOGLE_FONTS_API_KEY 为 GitHub secrets(仓库侧,非本机)。
- [ok] 外部依赖真实性 — 3 条『维护期』条目逐一在 .github/workflows/refresh-catalogs.yml 65/91/121-123 行找到真实调用点;运行时外部依赖为空。
- [ok] stars/活跃度/commit — GitHub API:stars 126346、pushed_at 2026-09-06T11:29:23Z、MIT;本地 git HEAD == pin 4aad0584d92131626b16d4ff4d77f0455385013c(2026-09-06 18:29:23 +0700)。
- [ok] 分级校准(六档范式) — 运行自带 stdlib 本地脚本 + 显式触发本地写、无网络外发、无凭证 → blue(旧文件曾记 green,按 2026-09-09 统一分档准则校准为 blue);reason 已重写。
6结论
7d01e476eb54034d…4aad0584d9