/spectra:spectra-batchfrom spectra
Generates specification files for an entire project or codebase. Creates an architecture overview index, then iterates through modules producing individual .spec.md files. Supports batch modes: full, reading (skips product docs), and code-only (skips all LLM inference).
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).
Systematically reverse-engineer specs for an entire codebase. Generates an index spec with architecture overview, then iterates through modules producing individual .spec.md files.
Scan the project root to understand structure:
src/ subdirectories, packages in monorepo, major feature foldersspecs/ directory for already-generated specsPresent the analysis plan to the user:
## Spectra Batch Plan
**Project**: <name>
**Type**: <project type>
**Total scope**: N files, ~N LOC
### Modules to analyze (in dependency order):
| # | Module | Files | LOC | Existing Spec? | Priority |
|---|--------|-------|-----|----------------|----------|
| 1 | core/utils | 5 | 320 | No | Foundation |
| 2 | models/ | 8 | 890 | No | Data layer |
| 3 | auth/ | 12 | 1450 | Yes (outdated) | Critical |
| ... | | | | | |
**Estimated effort**: ~N minutes with AI analysis
Proceed with all? Or select specific modules (e.g., "1,3,5" or "auth/ models/")
Wait for user confirmation before proceeding.
Execute the batch pipeline using the globally installed spectra CLI:
spectra batch
如果需要强制重新生成所有 spec:
spectra batch --force
如果需要自定义输出目录:
spectra batch --output-dir specs
如果需要指定运行模式(F5 新增,FR-001):
# 完整模式(默认)
spectra batch --mode=full
# 轻量阅读模式:跳过产品文档层(product-overview、ADR 等),速度更快
spectra batch --mode=reading
# 纯 AST 模式:跳过所有 LLM 推断,仅保留代码结构分析
spectra batch --mode=code-only
--mode 参数说明(FR-001 / FR-007)| 枚举值 | 说明 | 跳过的生成器 |
|---|---|---|
full(默认) | 完整文档生成,包含所有 LLM 推断 | 无 |
reading | 轻量模式,跳过产品文档层 | product-overview、adrs、coverage-audit、docs-bundle |
code-only | 纯 AST 模式,跳过所有 LLM 推断 | architecture-overview、architecture-ir、pattern-hints、event-surface、runtime-topology、product-overview、adrs 等所有 LLM 驱动生成器 |
不传 --mode 时默认为 full(FR-002)。无效 mode 值会在启动时报错退出(FR-005),日志中包含允许的枚举值列表。运行时日志会输出当前 mode(FR-006):[info] batch mode=<full|reading|code-only>。
MCP 工具透传:通过 MCP 工具 batch 调用时,同样支持 mode 参数(FR-007):
{ "mode": "reading" }
如果需要启用 LLM hyperedge 提取(生成超边,用于 graph_hyperedges MCP 工具):
spectra batch --hyperedges
| 选项 / 环境变量 | 类型 | 说明 |
|---|---|---|
--hyperedges | CLI flag | 启用 LLM hyperedge 提取;等价于设置 SPECTRA_HYPEREDGES_ENABLED=true |
SPECTRA_HYPEREDGES_ENABLED | true | false | 环境变量方式控制 hyperedge 提取(默认 false) |
SPECTRA_EMBEDDING_PROVIDER | local | openai | 语义嵌入提供方(默认 local;选 openai 时需要 OPENAI_API_KEY) |
OPENAI_API_KEY | string | 仅当 SPECTRA_EMBEDDING_PROVIDER=openai 时需要提供 |
注意:启用 --hyperedges 会额外调用 LLM 对 design-doc 进行超边提取,会增加 token 消耗和批量运行时间。建议仅在需要架构流程分析时启用。
如果需要生成交互式图谱可视化(F5 新增,FR-018 ~ FR-024):
# 生成 graph.html 可视化文件
spectra batch --html
# 可与 --mode 组合使用
spectra batch --mode=reading --html
--html 参数说明(FR-018 ~ FR-024)--html 会在 batch 完成后,在 <outputDir>/_meta/graph.html 生成单文件离线交互图谱。
| 特性 | 说明 |
|---|---|
| 力导向布局 | 节点数 < 2000 时启用 D3 力导向,节点可拖动 |
| 大图静态模式 | 节点数 ≥ 2000 时切换为静态坐标模式,并显示顶部横幅提示 |
| 搜索/过滤 | 搜索框支持节点名称过滤,匹配节点高亮,其余节点淡出 |
| 跳转 Spec | 点击节点后侧边栏显示详情,含 "打开 Spec 文件" 按钮(指向 .spec.md) |
| Hyperedge 凸包 | 若图谱含超边数据,渲染凸包轮廓并支持悬浮 tooltip |
| 零 CDN | 单文件自包含,所有资源内联,可断网离线使用 |
| 体积警告 | 文件超 5 MB 时输出 [warn] 日志,但不阻断生成 |
After batch completes:
## Batch Spectra Complete
**Generated**: N/M specs
**Index**: specs/_index.spec.md
**Total time**: ~N minutes
### Generated Specs:
- specs/auth.spec.md (high confidence)
- specs/models.spec.md (medium confidence)
- specs/api.spec.md (skipped by user)
### Project-Wide Observations:
- <Cross-module patterns noticed>
- <Shared technical debt themes>
- <Architecture recommendations>
所有 spec 文档的正文内容必须使用中文撰写。 具体规则:
## 1. 意图、## 2. 接口定义| 模块 | 规格 | 用途 | 依赖 |--forceBatch 完成后,Spectra 自动生成 specs/_meta/graph.json 和 specs/_meta/GRAPH_REPORT.md,并暴露 5 个 MCP 图查询工具。在支持 MCP 的 AI 助手中可直接调用:
graph_query — 关键词子图查询按自然语言查询词匹配节点并扩展邻居子图。
graph_query({ question: "认证模块", budget: 30, depth: 2 })graph_node — 单节点详情查询某个节点的详细信息和直接邻居。
graph_node({ id: "src/auth/login.ts", budget: 20 }) 或 graph_node({ keyword: "login" })graph_path — 最短路径查找两个节点间的最短调用/依赖路径。
graph_path({ source: "src/cli/main.ts", target: "src/db/connection.ts" })graph_community — 社区节点查询列出某个社区(模块聚类)的所有节点,识别代码边界。
graph_community({ communityId: "0" })graph_god_nodes — 枢纽节点识别识别图谱中度数最高的核心节点,定位过度耦合或架构瓶颈。
graph_god_nodes({ limit: 10 })What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/spectraUse this skill when the user asks to:
- Generate a spec/specification from existing code
- Document or analyze a module's architecture
- Reverse engineer what a piece of code does
- Create .spec.md documentation for a file, directory, or module
- Understand the intent, interfaces, and business logic of existing code
Supports single files (e.g., src/auth/login.ts), directories (e.g., src/auth/), or entire modules.
/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.
npx claudepluginhub connor-git-yaml/cc-plugin-market --plugin spectraOther plugins' skills for the same job