/spectra:spectrafrom spectra
Reverse-engineers source code into structured Chinese spec documents via AST analysis and LLM. Supports single files, directories, or modules.
Ships in spectra. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
$ARGUMENTS
You MUST consider the user input before proceeding (if not empty).
通过 AST 静态分析 + LLM 混合三阶段流水线,将源代码逆向工程为结构化的 9 段式中文 Spec 文档。TypeScript/JavaScript 项目享有 AST 增强的精确分析,接口定义 100% 来自 AST 提取。
Interpret $ARGUMENTS to determine the analysis target:
src/auth/login.tssrc/auth/ — analyze all TS/JS source files recursively--deep flag: Include function bodies in LLM context for deeper analysisIf the target doesn't exist, ERROR with suggestions based on project structure.
Execute the analysis pipeline using the globally installed spectra CLI:
spectra generate $TARGET_PATH --deep
如果需要自定义输出目录:
spectra generate $TARGET_PATH --deep --output-dir specs
Pipeline stages:
specs/*.spec.mdIf pipeline succeeds, report:
Spec 生成完成: specs/<name>.spec.md
分析摘要:
- 文件数: N
- 总行数: N LOC
- 导出 API: N 个
- Token 消耗: N
- 置信度: high|medium|low
- 警告: <warnings list>
后续步骤:
- 审查生成的 Spec 文档
- 使用 /spectra-batch 批量生成全项目 Spec
- 使用 /spectra-diff 检测 Spec 漂移
If pipeline fails, fall back to manual analysis following the sections below.
If the CLI pipeline is unavailable, perform manual analysis:
specs/<target-name>.spec.mdEach generated spec must contain these 9 sections in Chinese:
[推断: 理由],模糊代码用 [不明确: 理由]specs/ 写入输出,绝不修改源代码所有 spec 文档的正文内容必须使用中文撰写。 具体规则:
## 1. 意图、## 2. 接口定义panoramic-query — 架构分析 + 自然语言问答panoramic-query MCP 工具支持四种 operation:
| operation | 说明 | 必填参数 |
|---|---|---|
cross-package | 跨包依赖分析(monorepo 项目) | projectRoot |
architecture-ir | 架构信息模型(IR)提取 | projectRoot |
overview | 架构概览文档生成 | projectRoot |
natural-language | 自然语言问答(FR-009) | projectRoot + question |
natural-language operation(F5 新增)通过自然语言问题查询项目架构,支持 5 类典型问题:调用关系、调用路径、设计决策映射、技术债、流程归属。
参数:
operation(必填):"natural-language"projectRoot(必填):项目根目录绝对路径question(必填):问题文本(operation=natural-language 时必填;空字符串会被拒绝)返回:JSON 格式的 QnAAnswer 结构:
answer(string):LLM 生成的回答文本citations(Citation[]):溯源引用列表(100% 覆盖率,每条含三字段)
specPath:引用来源的 spec 文件路径(repo-relative)lineRange:{ startLine, endLine }(1-based,含边界)excerpt:原文摘要(≤ 200 字符)nodeId(可选):对应 graph 节点 IDsimilarity(可选):余弦相似度得分(RAG 精排路径)tokenUsage:{ input, output, overBudget }(overBudget=true 时已超 $0.05 硬限额,但不阻断调用)durationMs:问答耗时(毫秒)fallbackMode(可选):'rag-only' | 'bfs-only' | 'graph-insufficient'(降级模式)前置条件:需先运行 spectra batch 生成 specs/_meta/graph.json。
典型调用:
{
"operation": "natural-language",
"projectRoot": "/absolute/path/to/project",
"question": "什么模块调用了认证逻辑?"
}
单模块生成完成后,若项目已跑过 spectra batch,则 specs/_meta/graph.json 会提供 6 个 MCP 图查询工具供 AI 助手调用:
graph_query:按关键词查询相关模块和子图({ question: "认证模块", depth: 2 })graph_node:查询指定节点的详情和邻居({ id: "src/auth/login.ts" });v2.0 起返回额外的 semanticEdges 字段(见下)graph_path:查找两个节点间的最短路径({ source, target })graph_community:列出某社区的节点({ communityId: "0" })graph_god_nodes:识别度数最高的枢纽节点({ limit: 10 })graph_hyperedges:查询超边(Hyperedges),表达 3+ 节点共同参与的架构流程或概念群(见下)使用场景:通过 /spectra 生成单模块 spec 后,想追问"这个模块被谁调用了"、"从 A 到 B 的依赖路径是什么"、"项目里哪个模块最核心"等结构性问题,即可使用这些工具。
graph_hyperedges查询 graph.json 中的超边(Hyperedges),表达 3+ 节点共同参与的架构流程或概念群。需要先运行 spectra batch --hyperedges 生成含超边的图谱。
参数(均可选):
label(string):按 hyperedge label 模糊匹配(子串,大小写不敏感)node_id(string):按节点 ID 精确匹配(返回 nodes 数组中含此 ID 的 hyperedge)limit(number):返回数量上限(默认返回全部匹配的超边)返回:hyperedge 列表,每条含 id / label / nodes / rationale / confidence,以及 total(匹配总数)和 filtered(是否使用了过滤参数)
典型调用:
{ "label": "Ingestion Pipeline" }
{ "node_id": "src/auth/login.ts" }
{}
使用场景:
node_id 过滤)graph_node v2.0 新增:semanticEdges 字段v2.0 起,graph_node 响应额外返回 semanticEdges 数组,列出与当前节点关联的所有语义边(references / conceptually_related_to / rationale_for)。
每条语义边包含:
type:边类型(references / conceptually_related_to / rationale_for)direction:相对当前节点的方向(outgoing / incoming)peer:对端节点 IDevidenceText:证据文本(可选)evidenceSource:证据来源(格式 "path:startLine-endLine",可选)confidence:置信度(EXTRACTED / INFERRED / AMBIGUOUS)节点无关联语义边时,semanticEdges 返回空数组(不报错)。
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub connor-git-yaml/cc-plugin-market --plugin spectra3 skills in this plugin
/spectra-batchUse this skill when the user asks to:
- Generate specs for an entire project or codebase
- Document all modules systematically
- Create a complete specification index for the project
- Batch process multiple modules for spec generation
This skill generates an architecture overview index, then iterates through modules producing individual .spec.md files.
/spectra-diffUse this skill when the user asks to:
- Compare code against its spec to find drift
- Check if spec is still in sync with code
- Find new behaviors not documented in spec
- Identify spec items that no longer exist in code
- Validate spec accuracy after code changes
Useful after code changes to keep specs current, or before refactoring to understand what's changed.
Other plugins' skills for the same job