indexion-sdd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

indexion SDD (Spec-Driven Development)

indexion SDD(规范驱动开发)

Bridge indexion's quantitative spec alignment tools with SDD agent workflows (cc-sdd, codex, etc.).
Provides: RFC/document → SDD draft, spec↔impl drift detection, and a validation loop that feeds indexion's quantitative results into agent-driven qualitative review.
将indexion的定量规范对齐工具与SDD代理工作流(cc-sdd、codex等)相结合。
提供以下功能:从RFC/文档生成SDD草稿、规范与实现的漂移检测,以及将indexion的定量结果输入到代理驱动的定性评审中的验证循环。

When to Use

使用场景

  • User wants to implement an RFC or specification as a library/package
  • User asks to verify spec-to-implementation conformance
  • User wants to set up a SDD project with cc-sdd + codex + indexion
  • User says "run the SDD loop" or "validate against the spec"
  • After
    codex spec-impl
    completes, to check for drift before merging
  • 用户希望将RFC或规范实现为库/包
  • 用户要求验证规范与实现的一致性
  • 用户想要搭建结合cc-sdd + codex + indexion的SDD项目
  • 用户提出“运行SDD循环”或“对照规范验证”的需求
  • codex spec-impl
    完成后,合并前检查是否存在漂移

Important

重要提示

  • Set cc-sdd
    --lang
    to match the implementation language, not the spec language.
    If code is in English, use
    --lang en
    . Mismatched languages break
    spec align diff
    vocabulary matching.
  • 设置cc-sdd的
    --lang
    参数以匹配实现语言,而非规范语言
    。如果代码是英文的,使用
    --lang en
    。语言不匹配会破坏
    spec align diff
    的词汇匹配功能。

Process: RFC → Implementation → Validation

流程:RFC → 实现 → 验证

Step 0: Project Setup

步骤0:项目初始化

bash
undefined
bash
undefined

Create project directory

创建项目目录

mkdir my-rfc-impl && cd my-rfc-impl
mkdir my-rfc-impl && cd my-rfc-impl

Install cc-sdd for your agent — set lang to match the code language

为你的代理安装cc-sdd — 设置语言以匹配代码语言

npx cc-sdd@latest --codex-skills --lang en --yes # codex (skills mode) npx cc-sdd@latest --claude-skills --lang en --yes # claude (skills mode)
npx cc-sdd@latest --codex-skills --lang en --yes # codex(技能模式) npx cc-sdd@latest --claude-skills --lang en --yes # claude(技能模式)

Initialize project (language-specific)

初始化项目(根据语言选择对应命令)

e.g., cargo init, npm init, moon new, etc.

例如:cargo init, npm init, moon new等

Initialize git

初始化git

git init && git add -A && git commit -m "init"

**Verify indexion is available** before proceeding. The drift gate
(Step 2.5) and validation loop (Step 3) depend on it:

```bash
indexion --version                       # must be installed
indexion kgf edges <any-source-file>     # must detect language and show edges
If
indexion
is not installed, install it first. If the KGF for your spec format is not recognized, update
indexion
to a version that includes it. See Step 2.7 for the fallback when this cannot be resolved.
git init && git add -A && git commit -m "init"

**继续前请确认indexion可用**。漂移检查门限(步骤2.5)和验证循环(步骤3)依赖于该工具:

```bash
indexion --version                       # 必须已安装
indexion kgf edges <any-source-file>     # 必须能检测语言并显示关联信息
如果未安装indexion,请先安装。如果你的规范格式对应的KGF未被识别,请将indexion更新到包含该KGF的版本。若无法解决,请参考步骤2.7的备选方案。

Step 1: Specification → SDD Draft (indexion)

步骤1:规范 → SDD草稿(indexion)

Fetch the specification document (RFC, ISO standard, etc.) and prepare it:
bash
undefined
获取规范文档(RFC、ISO标准等)并准备:
bash
undefined

For RFC: save as markdown or .rfc.txt

对于RFC:保存为markdown或.rfc.txt格式

indexion spec draft --output .kiro/specs/<feature>/requirements.md rfc_document.md
indexion spec draft --output .kiro/specs/<feature>/requirements.md rfc_document.md

For ISO/IEC standards: extract text from PDF with cleanup, then draft

对于ISO/IEC标准:从PDF提取文本并清理,然后生成草稿

python3 scripts/extract_iso_text.py spec.pdf <start_page> <end_page> spec.spec.txt indexion spec draft --output .kiro/specs/<feature>/requirements.md spec.spec.txt
python3 scripts/extract_iso_text.py spec.pdf <start_page> <end_page> spec.spec.txt indexion spec draft --output .kiro/specs/<feature>/requirements.md spec.spec.txt

Create spec.json (set requirements.generated=true, approved=true)

创建spec.json(设置requirements.generated=true, approved=true)


The output uses `### Requirement N:` and `#### N.M:` hierarchy matching
cc-sdd's expected ID format. The agent's `$kiro-spec-requirements` phase will
further refine into EARS format with acceptance criteria.

**Supported specification formats:**
| Format | Extension | KGF spec |
|--------|-----------|----------|
| RFC plaintext | `.rfc.txt` | `rfc-plaintext` |
| ISO/IEC technical document | `.spec.txt` | `technical-document` |
| Markdown (README, etc.) | `.md` | `markdown` |

输出采用`### Requirement N:`和`#### N.M:`的层级结构,匹配cc-sdd预期的ID格式。代理的`$kiro-spec-requirements`阶段会进一步将其细化为带有验收标准的EARS格式。

**支持的规范格式:**
| 格式 | 扩展名 | KGF规范 |
|--------|-----------|----------|
| RFC纯文本 | `.rfc.txt` | `rfc-plaintext` |
| ISO/IEC技术文档 | `.spec.txt` | `technical-document` |
| Markdown(README等) | `.md` | `markdown` |

Step 1.5: Specification Fidelity Check (indexion)

步骤1.5:规范保真度检查(indexion)

After writing requirements, verify they cover the source specification:
bash
undefined
编写需求后,验证其是否覆盖源规范:
bash
undefined

Check requirements ↔ original spec alignment

检查需求与原始规范的对齐情况

(spec align now accepts document files as impl when no code files are found)

(当未找到代码文件时,spec align现在接受文档文件作为实现端)

indexion spec align diff .kiro/specs/<feature>/requirements.md spec.spec.txt
--format markdown --threshold 0.3
indexion spec align diff .kiro/specs/<feature>/requirements.md spec.spec.txt
--format markdown --threshold 0.3

SPEC_ONLY items = requirements not covered by original spec

SPEC_ONLY项 = 未被原始规范覆盖的需求

DRIFTED items = requirements using different vocabulary from original spec

DRIFTED项 = 使用与原始规范不同词汇的需求


**Traceability chain:** `spec align` works between documents at the
same abstraction level. For full traceability, check each adjacent pair:

```bash

**可追溯链:** `spec align`在同一抽象层级的文档间生效。如需完整可追溯性,请检查每一对相邻文档:

```bash

1. Source spec ↔ requirements (fidelity)

1. 源规范 ↔ 需求(保真度)

indexion spec align diff requirements.md source-spec.spec.txt --threshold 0.3
indexion spec align diff requirements.md source-spec.spec.txt --threshold 0.3

2. Requirements ↔ design (design coverage)

2. 需求 ↔ 设计(设计覆盖度)

indexion spec align diff requirements.md design.md --threshold 0.3
indexion spec align diff requirements.md design.md --threshold 0.3

3. Requirements ↔ implementation (impl coverage) — after $kiro-impl

3. 需求 ↔ 实现(实现覆盖度) — 在$kiro-impl之后执行

indexion spec align diff requirements.md src/ --threshold 0.3

Do NOT align source spec directly against design or code — the vocabulary
spaces differ too much (normative spec language vs. software design vs.
code identifiers). Each hop bridges one abstraction gap.

**Semantic fidelity review (not automatable):**

`spec align` checks vocabulary overlap, but cannot detect requirements
that **invert** the source spec's intent while using the same vocabulary.
A common failure mode:

- Source spec: "The DCTDecode filter **shall decode** JPEG data into samples"
- Requirements draft: "For DCTDecode, the decoder **shall return** an error
  indicating the filter is not yet supported"

Both mention "DCTDecode", "filter", "shall" — vocabulary matches, so
`spec align` reports MATCHED. But the requirement says the opposite of
what the spec demands. This creates a hidden gap that only surfaces when
E2E tests fail (Step 2.9).

**After `spec draft` generates requirements, review for these patterns:**

- `"not yet supported"`, `"not implemented"`, `"placeholder"`, `"stub"`
  — these indicate the draft punted on a spec requirement
- `"shall return an error"` for something the source spec says `"shall
  decode/process/convert"` — intent inversion
- Requirements that group multiple spec features into a single "unsupported"
  bucket — each spec feature deserves its own requirement

Fix these before proceeding to Step 2. Leaving them creates a false sense
of spec conformance that only E2E testing can expose.
indexion spec align diff requirements.md src/ --threshold 0.3

**请勿直接将源规范与设计或代码对齐**——词汇空间差异过大(规范性规范语言 vs 软件设计 vs 代码标识符)。每一步仅跨越一个抽象层级的差距。

**语义保真度评审(无法自动化):**

`spec align`仅检查词汇重叠情况,无法检测到**颠倒**源规范意图但使用相同词汇的需求。常见失败模式:

- 源规范:"DCTDecode过滤器**必须将**JPEG数据解码为样本"
- 需求草稿:"对于DCTDecode,解码器**必须返回**错误信息,表明该过滤器暂不支持"

两者均提及"DCTDecode"、"filter"、"shall"——词汇匹配,因此`spec align`报告为MATCHED。但需求表达的含义与规范要求完全相反。这种隐藏差距只有在端到端测试失败时才会暴露(步骤2.9)。

**`spec draft`生成需求后,请检查以下模式:**

- `"not yet supported"`、`"not implemented"`、`"placeholder"`、`"stub"`
  —— 这些表示草稿未处理某条规范需求
- 对于源规范要求`"必须解码/处理/转换"`的内容,需求中写`"必须返回错误"`——意图颠倒
- 将多个规范功能合并为单个"不支持"项的需求——每个规范功能都应拥有独立的需求

在进入步骤2前修复这些问题。遗留问题会造成规范一致性的假象,只有端到端测试才能揭露。

Step 2: Agent SDD Phases (codex / claude)

步骤2:代理SDD阶段(codex / claude)

cc-sdd v3+ uses skills mode (
$kiro-spec-*
commands).
Non-interactive execution with indexion gates between phases:
bash
FEATURE=<feature>
SPEC_DIR=.kiro/specs/$FEATURE
REPORT_DIR=.indexion/sdd-reports/$FEATURE
mkdir -p $REPORT_DIR
cc-sdd v3+使用技能模式(
$kiro-spec-*
命令)。
各阶段间结合indexion门限的非交互式执行:
bash
FEATURE=<feature>
SPEC_DIR=.kiro/specs/$FEATURE
REPORT_DIR=.indexion/sdd-reports/$FEATURE
mkdir -p $REPORT_DIR

Helper: approve a phase in spec.json

辅助函数:在spec.json中批准某个阶段

approve() { jq --arg p "$1" '.approvals[$p].approved = true' $SPEC_DIR/spec.json > /tmp/spec.json && mv /tmp/spec.json $SPEC_DIR/spec.json; }
approve() { jq --arg p "$1" '.approvals[$p].approved = true' $SPEC_DIR/spec.json > /tmp/spec.json && mv /tmp/spec.json $SPEC_DIR/spec.json; }

--- Design ---

--- 设计阶段 ---

codex exec --full-auto --json -C . "$kiro-spec-design $FEATURE -y" > $REPORT_DIR/design.jsonl approve design
codex exec --full-auto --json -C . "$kiro-spec-design $FEATURE -y" > $REPORT_DIR/design.jsonl approve design

Verify requirements ↔ design

验证需求与设计的对齐情况

indexion spec align diff $SPEC_DIR/requirements.md $SPEC_DIR/design.md
--format markdown --threshold 0.3 | tee $REPORT_DIR/req-design-align.md git add $SPEC_DIR && git commit -m "spec: design for $FEATURE"
indexion spec align diff $SPEC_DIR/requirements.md $SPEC_DIR/design.md
--format markdown --threshold 0.3 | tee $REPORT_DIR/req-design-align.md git add $SPEC_DIR && git commit -m "spec: design for $FEATURE"

--- Tasks ---

--- 任务阶段 ---

codex exec --full-auto --json -C . "$kiro-spec-tasks $FEATURE -y" > $REPORT_DIR/tasks.jsonl git add $SPEC_DIR && git commit -m "spec: tasks for $FEATURE"
codex exec --full-auto --json -C . "$kiro-spec-tasks $FEATURE -y" > $REPORT_DIR/tasks.jsonl git add $SPEC_DIR && git commit -m "spec: tasks for $FEATURE"

--- Impl Phase A: Types & Structures ---

--- 实现阶段A:类型与结构 ---

Phase A implements type definitions, error types, data structures,

阶段A实现类型定义、错误类型、数据结构

and public API surface. No logic implementations yet.

以及公共API接口。暂不实现逻辑。

cat > $REPORT_DIR/impl-phase-a.md << 'PHASE_A_EOF'
cat > $REPORT_DIR/impl-phase-a.md << 'PHASE_A_EOF'

Context

背景

You are implementing Phase A (Types & Structures) of the <FEATURE> feature. Read
.kiro/specs/<FEATURE>/tasks.md
for task details and
.kiro/specs/<FEATURE>/design.md
for the design.
你正在实现<FEATURE>功能的阶段A(类型与结构)。 阅读
.kiro/specs/<FEATURE>/tasks.md
获取任务详情, 以及
.kiro/specs/<FEATURE>/design.md
获取设计方案。

Phase A Scope

阶段A范围

In this phase, implement ONLY:
  • Public type definitions (structs, enums, type aliases)
  • Error types
  • Constants and configuration structures
  • Public API function signatures with placeholder bodies
  • Test scaffolding (test files with placeholder tests)
Do NOT implement:
  • Parsing, conversion, or transformation logic
  • Algorithm implementations
  • Complex function bodies beyond trivial constructors/accessors
本阶段仅实现:
  • 公共类型定义(结构体、枚举、类型别名)
  • 错误类型
  • 常量和配置结构
  • 带有占位实现的公共API函数签名
  • 测试脚手架(包含占位测试的测试文件)
请勿实现:
  • 解析、转换或转换逻辑
  • 算法实现
  • 超出 trivial 构造函数/访问器的复杂函数体

Per-Task Drift Gate

逐任务漂移门限

After completing each task and committing, run:
bash
indexion spec align diff .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --format markdown --threshold 0.3
indexion spec align status .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --threshold 0.3 --fail-on drifted
If DRIFTED items remain for the requirement your task addresses, fix them (add spec vocabulary to public declaration doc comments) and re-commit.
When all tasks are done,
spec align status --fail-on drifted
must exit 0.
完成每个任务并提交后,运行:
bash
indexion spec align diff .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --format markdown --threshold 0.3
indexion spec align status .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --threshold 0.3 --fail-on drifted
如果当前任务对应的需求仍存在DRIFTED项,请修复(在公共声明的文档注释中添加规范词汇)并重新提交。
所有任务完成后,
spec align status --fail-on drifted
必须返回0。

Important

重要提示

Commit your work after completing tasks. Do not leave changes uncommitted. PHASE_A_EOF
sed -i '' "s/<FEATURE>/$FEATURE/g; s/<pkg>/$PKG/g" $REPORT_DIR/impl-phase-a.md
codex exec --full-auto --json -C .
"$(cat $REPORT_DIR/impl-phase-a.md)" > $REPORT_DIR/impl-phase-a.jsonl
完成任务后提交工作。请勿保留未提交的更改。 PHASE_A_EOF
sed -i '' "s/<FEATURE>/$FEATURE/g; s/<pkg>/$PKG/g" $REPORT_DIR/impl-phase-a.md
codex exec --full-auto --json -C .
"$(cat $REPORT_DIR/impl-phase-a.md)" > $REPORT_DIR/impl-phase-a.jsonl

Wait for Phase A to complete before running the gate

运行门限前等待阶段A完成

indexion spec align status $SPEC_DIR/requirements.md src/$PKG/
--threshold 0.3 --fail-on drifted git add . && git commit -m "impl: Phase A types for $FEATURE"
indexion spec align status $SPEC_DIR/requirements.md src/$PKG/
--threshold 0.3 --fail-on drifted git add . && git commit -m "impl: Phase A types for $FEATURE"

--- Impl Phase B: Logic & Algorithms ---

--- 实现阶段B:逻辑与算法 ---

Phase B implements actual processing logic. The Phase A types

阶段B实现实际处理逻辑。阶段A的类型定义

are already committed, so Phase B focuses on function bodies.

已提交,因此阶段B专注于函数体实现。

cat > $REPORT_DIR/impl-phase-b.md << 'PHASE_B_EOF'
cat > $REPORT_DIR/impl-phase-b.md << 'PHASE_B_EOF'

Context

背景

You are implementing Phase B (Logic & Algorithms) of the <FEATURE> feature. Phase A (type definitions) is already committed. Read the existing type definitions in
src/<pkg>/
and the design in
.kiro/specs/<FEATURE>/design.md
.
你正在实现<FEATURE>功能的阶段B(逻辑与算法)。 阶段A(类型定义)已提交。阅读
src/<pkg>/
中的现有类型定义 以及
.kiro/specs/<FEATURE>/design.md
中的设计方案。

Phase B Scope

阶段B范围

In this phase, implement:
  • Parsing logic (readers, decoders, interpreters)
  • Conversion and transformation algorithms
  • Validation logic beyond basic type construction
  • Integration between types (connecting readers to data structures)
  • Complete test implementations with real assertions
Every requirement that describes processing, conversion, interpretation, or validation MUST have a corresponding function implementation — not just a type definition.
本阶段实现:
  • 解析逻辑(读取器、解码器、解释器)
  • 转换和变换算法
  • 基础类型构造之外的验证逻辑
  • 类型间的集成(将读取器与数据结构连接)
  • 带有真实断言的完整测试实现
每一条描述处理、转换、解释 或验证的需求都必须有对应的函数实现—— 不能仅停留在类型定义层面。

SHALLOW Resolution Rule

SHALLOW解决规则

SHALLOW is detected when a requirement matches a type definition in a file that has no non-trivial function implementations (>4 lines). To resolve:
Add functions to the SAME FILE where the type is defined.
Do NOT put logic in a separate file — SHALLOW checks per-file. If a type is defined in one file and its methods are in a different file, the type's file still has no functions and triggers SHALLOW.
Examples of functions that resolve SHALLOW:
  • A method on the type with >4 lines of logic (match arms, loops, validation, computation)
  • A constructor that does non-trivial work (parsing, validation)
Examples that do NOT resolve SHALLOW (too trivial, ≤4 lines):
  • A default constructor that just returns a struct literal
  • A one-liner boolean accessor
当需求匹配到某个文件中的类型定义,但该文件没有非trivial的函数实现(>4行)时,会被检测为SHALLOW。解决方法:
将函数添加到类型定义所在的同一文件中。
请勿将逻辑放在单独的文件中——SHALLOW是按文件检查的。如果类型在一个文件中定义,而其方法在另一个文件中,则类型所在文件仍会因无函数而触发SHALLOW。
可解决SHALLOW的函数示例:
  • 类型上带有>4行逻辑的方法(匹配分支、循环、 验证、计算)
  • 执行非trivial工作的构造函数(解析、验证)
无法解决SHALLOW的示例(过于简单,≤4行):
  • 仅返回结构体字面量的默认构造函数
  • 单行布尔访问器

Per-Task Drift Gate (with shallow detection)

逐任务漂移门限(含SHALLOW检测)

After completing each task and committing, run:
bash
indexion spec align diff .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --format markdown --threshold 0.3
indexion spec align status .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --threshold 0.3 --fail-on any
The
--fail-on any
gate includes SHALLOW detection: if a requirement matched only to type definitions with no function implementations in the same file, it is flagged as SHALLOW. You must add function implementations to resolve SHALLOW items.
If DRIFTED, SPEC_ONLY, or SHALLOW items remain, fix them before proceeding.
When all tasks are done,
spec align status --fail-on any
must exit 0 with Shallow: 0.
完成每个任务并提交后,运行:
bash
indexion spec align diff .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --format markdown --threshold 0.3
indexion spec align status .kiro/specs/<FEATURE>/requirements.md src/<pkg>/ --threshold 0.3 --fail-on any
--fail-on any
门限包含SHALLOW检测:如果需求仅匹配到类型定义,且同一文件中无函数实现,则会被标记为SHALLOW。你必须添加函数实现来解决SHALLOW项。
如果仍存在DRIFTED、SPEC_ONLY或SHALLOW项,请修复后再继续。
所有任务完成后,
spec align status --fail-on any
必须返回0,且Shallow: 0。

Important

重要提示

Commit your work after completing tasks. Do not leave changes uncommitted. PHASE_B_EOF
sed -i '' "s/<FEATURE>/$FEATURE/g; s/<pkg>/$PKG/g" $REPORT_DIR/impl-phase-b.md
codex exec --full-auto --json -C .
"$(cat $REPORT_DIR/impl-phase-b.md)" > $REPORT_DIR/impl-phase-b.jsonl & CODEX_PID=$!

**Monitor impl progress:**

```bash
完成任务后提交工作。请勿保留未提交的更改。 PHASE_B_EOF
sed -i '' "s/<FEATURE>/$FEATURE/g; s/<pkg>/$PKG/g" $REPORT_DIR/impl-phase-b.md
codex exec --full-auto --json -C .
"$(cat $REPORT_DIR/impl-phase-b.md)" > $REPORT_DIR/impl-phase-b.jsonl & CODEX_PID=$!

**监控实现进度:**

```bash

Real-time event stream

实时事件流

tail -f $REPORT_DIR/impl.jsonl | jq -r ' if .type == "item.completed" and .item.type == "agent_message" then "MSG: " + (.item.text[:120]) elif .type == "item.completed" and .item.type == "command_execution" then "CMD: " + (.item.command[:60]) + " -> " + (.item.exit_code|tostring) else empty end'
tail -f $REPORT_DIR/impl.jsonl | jq -r ' if .type == "item.completed" and .item.type == "agent_message" then "MSG: " + (.item.text[:120]) elif .type == "item.completed" and .item.type == "command_execution" then "CMD: " + (.item.command[:60]) + " -> " + (.item.exit_code|tostring) else empty end'

Stall detection

停滞检测

ps -p $CODEX_PID -o cputime,%cpu lsof -p $CODEX_PID 2>/dev/null | grep tcp
ps -p $CODEX_PID -o cputime,%cpu lsof -p $CODEX_PID 2>/dev/null | grep tcp

Resume after interruption

中断后恢复

codex exec resume --last

**Operational notes:**

- Always use `--json` with file redirect + `tail -f`. Piping through
  `| tail` suppresses all output until completion.
- For long prompts, write to a file and use `$(cat file.md)`. Shell
  HEREDOC with `$()` can cause stdin blocking.
- Use `/loop` (Claude Code) to poll `git log --oneline -1` + `ps`
  every 60-120s during long impl runs.
codex exec resume --last

**操作注意事项:**

- 始终结合`--json`与文件重定向 + `tail -f`。通过`| tail`管道会抑制所有输出,直到执行完成。
- 对于长提示,写入文件并使用`$(cat file.md)`。使用`$()`的Shell HEREDOC可能导致标准输入阻塞。
- 在长时间实现运行期间,使用`/loop`(Claude Code)每60-120轮询一次`git log --oneline -1` + `ps`。

Step 2.5: Per-Task Drift Gate (indexion)

步骤2.5:逐任务漂移门限(indexion)

After each
$kiro-impl
task commit, run spec alignment to verify the task closed its corresponding requirement gap. Do NOT proceed to the next task if the requirement addressed by the current task is still DRIFTED, SPEC_ONLY, or SHALLOW.
Phase A gate (types only — SHALLOW is expected and tolerated):
bash
indexion spec align status $SPEC_DIR/requirements.md src/ --threshold 0.3 --fail-on drifted
Phase B gate (logic — SHALLOW must be zero):
bash
indexion spec align diff $SPEC_DIR/requirements.md src/ --format markdown --threshold 0.3
indexion spec align status $SPEC_DIR/requirements.md src/ --threshold 0.3 --fail-on any
SHALLOW detection: When a requirement matches only to type/struct/enum declarations in a file that contains no non-trivial function implementations (>4 lines),
spec align
classifies it as SHALLOW. This catches two patterns:
  1. Codex writes type definitions to satisfy vocabulary matching but omits the actual processing logic that the requirement demands.
  2. Codex adds logic in a separate file from the type definition. SHALLOW checks per-file, so a type in one file with methods only in another file still triggers SHALLOW on the type's file.
Resolution: Add methods to the same file where the type is defined. Trivial functions (constructors, one-liner accessors ≤4 lines) do not count. See Phase B prompt template for examples.
When including this gate in a Codex prompt, instruct the agent to run these commands after each task commit and fix any flagged items before proceeding. Example instruction block for the prompt:
After completing each task (commit), run:
  indexion spec align diff ... --threshold 0.3
  indexion spec align status ... --threshold 0.3 --fail-on any
If DRIFTED, SPEC_ONLY, or SHALLOW items remain for the requirement
your task addresses, fix them before moving to the next task.
- DRIFTED: add spec vocabulary to public declaration doc comments
- SPEC_ONLY: implement the missing requirement
- SHALLOW: add non-trivial function implementations (>4 lines) to the
  SAME FILE where the matched type is defined. Do not add logic in a
  separate file — SHALLOW checks per-file.
When all tasks are done, spec align status --fail-on any must exit 0
with Shallow: 0.
每次
$kiro-impl
任务提交后,运行规范对齐以验证任务是否填补了对应的需求差距。如果当前任务对应的需求仍为DRIFTED、SPEC_ONLY或SHALLOW,请不要进入下一个任务。
阶段A门限(仅类型——SHALLOW是预期且可接受的):
bash
indexion spec align status $SPEC_DIR/requirements.md src/ --threshold 0.3 --fail-on drifted
阶段B门限(逻辑——SHALLOW必须为零):
bash
indexion spec align diff $SPEC_DIR/requirements.md src/ --format markdown --threshold 0.3
indexion spec align status $SPEC_DIR/requirements.md src/ --threshold 0.3 --fail-on any
SHALLOW检测: 当需求仅匹配到文件中的类型/结构体/枚举声明,且该文件没有非trivial的函数实现(>4行)时,
spec align
会将其归类为SHALLOW。这会捕获两种模式:
  1. Codex编写类型定义以满足词汇匹配,但省略了需求要求的实际处理逻辑。
  2. Codex在单独的文件中添加逻辑,而非类型定义所在文件。 SHALLOW按文件检查,因此类型在一个文件、方法仅在另一个文件的情况,仍会在类型所在文件触发SHALLOW。
解决方法: 将方法添加到类型定义所在的同一文件中。Trivial函数(构造函数、单行访问器≤4行)不算数。请参考阶段B提示模板中的示例。
在Codex提示中包含此门限时,指示代理在每个任务提交后运行这些命令,并在继续前修复所有标记项。提示中的示例指令块:
完成每个任务(提交)后,运行:
  indexion spec align diff ... --threshold 0.3
  indexion spec align status ... --threshold 0.3 --fail-on any
如果当前任务对应的需求仍存在DRIFTED、SPEC_ONLY或SHALLOW项,请修复后再进入下一个任务。
- DRIFTED:在公共声明的文档注释中添加规范词汇
- SPEC_ONLY:实现缺失的需求
- SHALLOW:在匹配类型所在的**同一文件**中添加非trivial的函数实现(>4行)。请勿在单独文件中添加逻辑——SHALLOW按文件检查。
所有任务完成后,spec align status --fail-on any必须返回0,且Shallow: 0。

Step 2.6: Phase B Iteration (SHALLOW Resolution Rounds)

步骤2.6:阶段B迭代(SHALLOW解决轮次)

Phase B rarely resolves all SHALLOW items in a single Codex session. Common causes:
  • Codex adds logic in a new file instead of the type definition file
  • Codex adds trivial constructors/accessors (≤4 lines) that don't count
  • New type definitions are added without corresponding logic
Iteration protocol:
After each Phase B session completes:
  1. Run the SHALLOW audit:
    bash
    indexion spec align status $SPEC_DIR/requirements.md src/$PKG/ \
      --threshold 0.3 --fail-on shallow
  2. If
    Shallow: 0
    , proceed to E2E verification (Step 2.9).
  3. If SHALLOW > 0, identify the specific items:
    bash
    indexion spec align diff $SPEC_DIR/requirements.md src/$PKG/ \
      --format markdown --threshold 0.3 | grep SHALLOW
  4. Write a targeted round prompt that:
    • Lists the remaining SHALLOW items explicitly
    • Names the exact files that need functions added
    • States the rule: add functions to the same file as the type
    • Specifies what methods to add (not just "fix SHALLOW")
  5. Launch the next round:
    bash
    codex exec --full-auto --json -C . \
      "$(cat $REPORT_DIR/round-N.md)" > $REPORT_DIR/round-N.jsonl &
Typical: 2-3 rounds. Round 1 adds core logic, Round 2 forces same-file methods, Round 3 catches remaining edge cases.
阶段B很少能在单次Codex会话中解决所有SHALLOW项。常见原因:
  • Codex在新文件中添加逻辑,而非类型定义文件
  • Codex添加trivial构造函数/访问器(≤4行),不算有效实现
  • 添加了新的类型定义,但未添加对应的逻辑
迭代流程:
每次阶段B会话完成后:
  1. 运行SHALLOW审计:
    bash
    indexion spec align status $SPEC_DIR/requirements.md src/$PKG/ \
      --threshold 0.3 --fail-on shallow
  2. 如果
    Shallow: 0
    ,进入端到端验证(步骤2.9)。
  3. 如果SHALLOW > 0,识别具体项:
    bash
    indexion spec align diff $SPEC_DIR/requirements.md src/$PKG/ \
      --format markdown --threshold 0.3 | grep SHALLOW
  4. 编写针对性的轮次提示,内容包括:
    • 明确列出剩余的SHALLOW项
    • 指出需要添加函数的具体文件
    • 声明规则:将函数添加到类型所在的同一文件
    • 指定要添加的方法(不只是“修复SHALLOW”)
  5. 启动下一轮:
    bash
    codex exec --full-auto --json -C . \
      "$(cat $REPORT_DIR/round-N.md)" > $REPORT_DIR/round-N.jsonl &
典型情况:2-3轮。第一轮添加核心逻辑,第二轮强制同一文件方法,第三轮捕获剩余边缘情况。

Step 2.7: Stall Detection and Recovery

步骤2.7:停滞检测与恢复

Codex processes can stall (lost API connection, blocked review loop, etc.). This is common during long Phase B sessions.
Detection:
bash
undefined
Codex进程可能停滞(API连接丢失、评审循环阻塞等)。这在长时间阶段B会话中很常见。
检测方法:
bash
undefined

Check process vitals

检查进程状态

ps -p $CODEX_PID -o cputime,%cpu,etime lsof -p $CODEX_PID 2>/dev/null | grep tcp
ps -p $CODEX_PID -o cputime,%cpu,etime lsof -p $CODEX_PID 2>/dev/null | grep tcp

Stall indicators (all must be true):

停滞指标(需全部满足):

- CPU time not increasing over 2+ checks

- 2次以上检查中CPU时间未增加

- 0.0% CPU

- CPU占用率0.0%

- No TCP connections

- 无TCP连接

- JSONL event count not increasing

- JSONL事件计数未增加


**Recovery — never commit manually:**

When a stall is confirmed:

1. Kill the process: `kill $CODEX_PID`
2. Check what was completed: `git log`, `git status`, `git diff --cached`
3. If uncommitted work exists and tests pass, generate indexion reports:
   ```bash
   indexion spec align diff $SPEC_DIR/requirements.md src/ \
     --format markdown --threshold 0.3 -o $REPORT_DIR/align-current.md
   indexion spec verify --spec="$SPEC_DIR/requirements.md" src/ \
     --format md -o $REPORT_DIR/verify-current.md
  1. Write a resume prompt file that:
    • States which tasks are committed and which have uncommitted work
    • Includes the indexion reports as current-state evidence
    • Instructs Codex to verify and commit uncommitted work, then continue
    • Requires the per-task drift gate (Step 2.5) for all remaining tasks
  2. Restart:
    codex exec --full-auto --json -C . "$(cat $REPORT_DIR/resume-prompt.md)" > $REPORT_DIR/impl-resume.jsonl &
Never commit implementation code manually. All commits must come from the Codex agent. If you commit manually, you bypass the SDD protocol (RED→GREEN evidence, review, verification) and invalidate the workflow.

**恢复——切勿手动提交:**

确认停滞后:

1. 终止进程:`kill $CODEX_PID`
2. 检查已完成的工作:`git log`, `git status`, `git diff --cached`
3. 如果存在未提交的工作且测试通过,生成indexion报告:
   ```bash
   indexion spec align diff $SPEC_DIR/requirements.md src/ \
     --format markdown --threshold 0.3 -o $REPORT_DIR/align-current.md
   indexion spec verify --spec="$SPEC_DIR/requirements.md" src/ \
     --format md -o $REPORT_DIR/verify-current.md
  1. 编写恢复提示文件,内容包括:
    • 说明哪些任务已提交,哪些有未提交的工作
    • 将indexion报告作为当前状态证据包含在内
    • 指示Codex验证并提交未提交的工作,然后继续
    • 要求对所有剩余任务执行逐任务漂移门限(步骤2.5)
  2. 重启:
    codex exec --full-auto --json -C . "$(cat $REPORT_DIR/resume-prompt.md)" > $REPORT_DIR/impl-resume.jsonl &
切勿手动提交实现代码。所有提交必须来自Codex代理。如果手动提交,会绕过SDD协议(RED→GREEN证据、评审、验证),使工作流失效。

Step 2.8: Drift Gate Proxy (when Codex cannot run indexion)

步骤2.8:漂移门限代理(当Codex无法运行indexion时)

Codex runs
indexion
commands inside the impl project directory. If
indexion
is not installed, is too old, or lacks required KGF specs, the drift gate commands will fail or timeout inside Codex.
Prevention (recommended): Verify in Step 0 that
indexion
works in the project directory before starting the SDD run:
bash
indexion --version
indexion kgf edges <any-project-file>   # should show edges, not errors
If
indexion
is not available or broken, install or update it first.
Fallback — orchestrator-side drift gate:
If
indexion
cannot be fixed before the run (e.g., a required KGF spec is not yet released), the orchestrator runs the drift gate externally:
  1. Tell Codex to skip drift gate commands in the impl prompt:
    The `indexion` binary is not available in this environment.
    Skip drift gate commands. The orchestrator will run them externally.
  2. After each Codex commit, the orchestrator runs:
    bash
    indexion spec align diff $SPEC_DIR/requirements.md src/ \
      --format markdown --threshold 0.3
    indexion spec align status $SPEC_DIR/requirements.md src/ \
      --threshold 0.3 --fail-on any
  3. If DRIFTED/SPEC_ONLY items appear, run the vocab fix step (Step 3.5) with the externally generated reports.
--specs-dir
caveat:
When running the indexion binary directly (not via the project's build tool), it may not find KGF specs automatically. Pass
--specs-dir
explicitly:
bash
indexion spec align diff ... --specs-dir /path/to/indexion/kgfs
Without this,
spec align
may return "No alignment data found" because the requirement document format is unrecognized.
Codex在实现项目目录内运行
indexion
命令。如果
indexion
未安装、版本过旧或缺少所需的KGF规范,漂移门限命令会在Codex内失败或超时。
预防措施(推荐): 在步骤0中确认
indexion
在项目目录中可用后再启动SDD运行:
bash
indexion --version
indexion kgf edges <any-project-file>   # 应显示关联信息,而非错误
如果
indexion
不可用或损坏,请先安装或更新。
备选方案——编排器端漂移门限:
如果在运行前无法修复
indexion
(例如所需的KGF规范尚未发布),编排器可在外部运行漂移门限:
  1. 告知Codex在实现提示中跳过漂移门限命令:
    此环境中无法使用`indexion`二进制文件。
    跳过漂移门限命令。编排器会在外部运行这些命令。
  2. 每次Codex提交后,编排器运行:
    bash
    indexion spec align diff $SPEC_DIR/requirements.md src/ \
      --format markdown --threshold 0.3
    indexion spec align status $SPEC_DIR/requirements.md src/ \
      --threshold 0.3 --fail-on any
  3. 如果出现DRIFTED/SPEC_ONLY项,使用外部生成的报告执行词汇修复步骤(步骤3.5)。
--specs-dir
注意事项:
直接运行indexion二进制文件(而非通过项目构建工具)时,它可能无法自动找到KGF规范。需显式传递
--specs-dir
bash
indexion spec align diff ... --specs-dir /path/to/indexion/kgfs
否则,
spec align
可能会返回"No alignment data found",因为需求文档格式未被识别。

Step 2.9: E2E Verification (post-SHALLOW)

步骤2.9:端到端验证(SHALLOW解决后)

After all SHALLOW items are resolved (
Shallow: 0
), verify that the implementation actually works end-to-end.
spec align
only checks vocabulary — it cannot confirm functional correctness.
Write E2E tests that exercise the full pipeline against real input data:
bash
undefined
所有SHALLOW项解决后(
Shallow: 0
),验证实现是否真正端到端可用。
spec align
仅检查词汇——无法确认功能正确性。
编写端到端测试,使用真实输入数据测试完整流程:
bash
undefined

Example E2E pattern:

端到端测试示例模式:

1. Load a real input file (not just synthetic fixtures)

1. 加载真实输入文件(不只是合成测试数据)

2. Run the full processing pipeline end-to-end

2. 运行完整处理流程

3. Assert the output matches expected results

3. 断言输出与预期结果匹配


**Common E2E failure modes after SHALLOW=0:**
- Type definitions exist and logic functions exist, but the pipeline
  raises errors on real input (missing encoding tables, unsupported
  font types, etc.)
- All tests pass on synthetic fixtures but fail on real files because
  fixtures don't exercise the full code path
- Functions are implemented but not wired into the top-level API

If E2E tests fail, write additional Codex prompts targeting the specific
failure. The spec align gate ensures the vocabulary stays aligned while
Codex fixes the implementation.

**SHALLOW=0后端到端测试常见失败模式:**
- 类型定义和逻辑函数存在,但真实输入触发流程错误(缺少编码表、不支持的字体类型等)
- 所有测试在合成数据上通过,但在真实文件上失败,因为测试数据未覆盖完整代码路径
- 函数已实现,但未连接到顶层API

如果端到端测试失败,编写针对具体失败的Codex提示。规范对齐门限确保在Codex修复实现时词汇保持对齐。

Step 2.10: Parallel Feature Execution

步骤2.10:并行功能执行

Multiple features can run in parallel Codex sessions:
bash
for FEATURE in feature-a feature-b feature-c; do
  codex exec --full-auto --json -C . \
    "$(cat $REPORT_DIR/$FEATURE/impl-phase-b.md)" \
    > $REPORT_DIR/$FEATURE/impl-phase-b.jsonl 2>&1 &
  echo "$FEATURE: $!"
done
Caveats:
  • Multiple Codex sessions may edit overlapping files (e.g., multiple features write to
    src/graphics/
    ). Git will auto-merge unless the same lines are modified.
  • If sessions commit in different branches, merge conflicts are the orchestrator's responsibility.
  • Monitor all sessions with
    /loop
    — check event counts, commits, and process vitals for each PID.
  • Stalls are more common with parallel sessions (API rate limits). Use Step 2.7 detection per-session.
多个功能可在并行Codex会话中运行:
bash
for FEATURE in feature-a feature-b feature-c; do
  codex exec --full-auto --json -C . \
    "$(cat $REPORT_DIR/$FEATURE/impl-phase-b.md)" \
    > $REPORT_DIR/$FEATURE/impl-phase-b.jsonl 2>&1 &
  echo "$FEATURE: $!"
done
注意事项:
  • 多个Codex会话可能编辑重叠文件(例如多个功能写入
    src/graphics/
    )。Git会自动合并,除非同一行被修改。
  • 如果会话在不同分支提交,合并冲突由编排器负责处理。
  • 使用
    /loop
    监控所有会话——检查每个PID的事件计数、提交和进程状态。
  • 并行会话更容易出现停滞(API速率限制)。对每个会话使用步骤2.7的检测方法。

Step 3: Validation Loop (indexion + agent)

步骤3:验证循环(indexion + 代理)

This is where indexion adds value beyond pure agent review.
bash
undefined
这是indexion超越纯代理评审的价值所在。
bash
undefined

Quantitative analysis only (no agent)

仅定量分析(无代理)

indexion spec verify --spec='.kiro/specs/<feature>/requirements.md' src/lib/ --format md indexion spec align diff .kiro/specs/<feature>/requirements.md src/lib/ --format markdown --threshold 0.3 indexion spec align status .kiro/specs/<feature>/requirements.md src/lib/ --threshold 0.3 --fail-on any
indexion spec verify --spec='.kiro/specs/<feature>/requirements.md' src/lib/ --format md indexion spec align diff .kiro/specs/<feature>/requirements.md src/lib/ --format markdown --threshold 0.3 indexion spec align status .kiro/specs/<feature>/requirements.md src/lib/ --threshold 0.3 --fail-on any

Full loop: indexion quantitative + agent qualitative + auto-fix

完整循环:indexion定量分析 + 代理定性评审 + 自动修复

./scripts/sdd-validate.sh <feature> # validate only ./scripts/sdd-validate.sh <feature> --fix # validate + auto-fix NO-GO tasks

The validation script:
1. Runs `spec verify` (vocabulary gap between spec and impl)
2. Runs `spec align diff` (requirement-level drift)
3. Runs `spec align trace` (traceability matrix)
4. Runs `spec align status` (CI-style pass/fail)
5. Injects all reports into the agent's `validate-impl` prompt
6. Agent produces GO/NO-GO decision with specific task numbers
7. On `--fix`, automatically re-runs `spec-impl` for failing tasks
./scripts/sdd-validate.sh <feature> # 仅验证 ./scripts/sdd-validate.sh <feature> --fix # 验证 + 自动修复NO-GO任务

验证脚本执行以下操作:
1. 运行`spec verify`(规范与实现间的词汇差距)
2. 运行`spec align diff`(需求级漂移)
3. 运行`spec align trace`(可追溯性矩阵)
4. 运行`spec align status`(CI式通过/失败)
5. 将所有报告注入代理的`validate-impl`提示
6. 代理生成带有具体任务编号的GO/NO-GO决策
7. 使用`--fix`时,自动重新运行失败任务的`spec-impl`

Step 3.5: Vocabulary Alignment Fix (indexion + agent)

步骤3.5:词汇对齐修复(indexion + 代理)

After
$kiro-validate-impl
passes but
spec align
shows DRIFTED/SPEC_ONLY, the implementation is functionally correct but lacks spec vocabulary in doc comments. This step closes that gap.
Note:
$kiro-validate-impl
(cc-sdd) does not invoke indexion's spec align internally. This step bridges the two tools.
bash
undefined
$kiro-validate-impl
通过,但
spec align
显示DRIFTED/SPEC_ONLY时,说明实现功能正确,但公共文档注释中缺少规范词汇。此步骤填补该差距。
注意:
$kiro-validate-impl
(cc-sdd)不会内部调用indexion的spec align。此步骤连接两个工具。
bash
undefined

1. Generate alignment reports

1. 生成对齐报告

indexion spec align diff .kiro/specs/<feature>/requirements.md src/
--format markdown --threshold 0.3 -o .indexion/sdd-reports/align-diff.md indexion spec verify --spec='.kiro/specs/<feature>/requirements.md' src/
--format md -o .indexion/sdd-reports/verify-gaps.md
indexion spec align diff .kiro/specs/<feature>/requirements.md src/
--format markdown --threshold 0.3 -o .indexion/sdd-reports/align-diff.md indexion spec verify --spec='.kiro/specs/<feature>/requirements.md' src/
--format md -o .indexion/sdd-reports/verify-gaps.md

2. Write a prompt file (avoid HEREDOC — use file to prevent stdin blocking)

2. 编写提示文件(避免HEREDOC——使用文件防止标准输入阻塞)

cat > .indexion/sdd-reports/vocab-fix-prompt.md << 'EOF' The spec alignment tool reports that several requirements are DRIFTED, SPEC_ONLY, or SHALLOW. For each item, determine whether it is:
  1. Implementation gap (SPEC_ONLY) — the spec requirement is not implemented at all. Add the missing implementation and tests.
  2. Vocabulary gap (DRIFTED) — the implementation exists but spec vocabulary is missing from public doc comments. Add spec terms to public declarations.
  3. Depth gap (SHALLOW) — the requirement matched to type definitions only, with no function implementations in the same file. Add the actual processing/parsing/conversion logic that the requirement demands.
Your task:
  • Read the alignment report below.
  • For each DRIFTED or SPEC_ONLY requirement, search the codebase for related keywords from that requirement. If related code exists, it is a vocabulary gap — add doc comments. If no related code exists, it is an implementation gap — implement it.
  • The alignment tool only extracts vocabulary from public declarations. Doc comments on private functions are invisible to the tool.
  • Run the project's formatter and test suite after editing.
  • Commit your changes. Do not leave changes uncommitted.
cat > .indexion/sdd-reports/vocab-fix-prompt.md << 'EOF' 规范对齐工具报告显示多项需求为DRIFTED、 SPEC_ONLY或SHALLOW。对于每个项,判断其属于:
  1. 实现差距(SPEC_ONLY)——规范需求完全未实现。添加缺失的实现和测试。
  2. 词汇差距(DRIFTED)——实现存在,但公共文档注释中缺少规范词汇。在公共声明中添加规范术语。
  3. 深度差距(SHALLOW)——需求仅匹配到类型定义,同一文件中无函数实现。添加需求要求的实际处理/解析/转换逻辑。
你的任务:
  • 阅读下方的对齐报告。
  • 对于每个DRIFTED或SPEC_ONLY需求,在代码库中搜索该需求的相关关键词。如果存在相关代码,则为词汇差距——添加文档注释。如果不存在相关代码,则为实现差距——实现该需求。
  • 对齐工具仅从公共声明中提取词汇。私有函数的文档注释对工具不可见。
  • 编辑后运行项目的格式化工具和测试套件。
  • 提交更改。请勿保留未提交的更改。

Spec Align Diff Report

规范对齐差异报告

EOF cat .indexion/sdd-reports/align-diff.md >> .indexion/sdd-reports/vocab-fix-prompt.md echo -e "\n## Vocabulary Gap Report" >> .indexion/sdd-reports/vocab-fix-prompt.md head -40 .indexion/sdd-reports/verify-gaps.md >> .indexion/sdd-reports/vocab-fix-prompt.md
EOF cat .indexion/sdd-reports/align-diff.md >> .indexion/sdd-reports/vocab-fix-prompt.md echo -e "\n## 词汇差距报告" >> .indexion/sdd-reports/vocab-fix-prompt.md head -40 .indexion/sdd-reports/verify-gaps.md >> .indexion/sdd-reports/vocab-fix-prompt.md

3. Run agent with the prompt file

3. 使用提示文件运行代理

codex exec --full-auto --json -C .
"$(cat .indexion/sdd-reports/vocab-fix-prompt.md)" \
.indexion/sdd-reports/vocab-fix.jsonl &
codex exec --full-auto --json -C .
"$(cat .indexion/sdd-reports/vocab-fix-prompt.md)" \
.indexion/sdd-reports/vocab-fix.jsonl &

4. Monitor (optional)

4. 监控(可选)

tail -f .indexion/sdd-reports/vocab-fix.jsonl | jq -r ' if .type == "item.completed" and .item.type == "agent_message" then "MSG: " + (.item.text[:120]) elif .type == "item.completed" and .item.type == "command_execution" then "CMD: " + (.item.command[:50]) + " -> " + (.item.exit_code|tostring) else empty end'
tail -f .indexion/sdd-reports/vocab-fix.jsonl | jq -r ' if .type == "item.completed" and .item.type == "agent_message" then "MSG: " + (.item.text[:120]) elif .type == "item.completed" and .item.type == "command_execution" then "CMD: " + (.item.command[:50]) + " -> " + (.item.exit_code|tostring) else empty end'

5. Re-check alignment after agent completes

5. 代理完成后重新检查对齐情况

indexion spec align status .kiro/specs/<feature>/requirements.md src/
--threshold 0.3 --fail-on any

**Key constraints:**
- The prompt does NOT dictate specific vocabulary to add. It provides the
  alignment reports and lets the agent determine what to fix.
- The agent must target public declarations only — private function doc
  comments are invisible to `spec align`.
- Typical: 1-2 fix cycles. If SPEC_ONLY persists, the agent may need
  guidance that the relevant public API entry point should carry the
  vocabulary (e.g. a top-level `open` function documents the full flow).

**Known blind spots:**

- **CLI entry points with no public API:** Main/entry-point modules
  often have no public declarations — all functions are private to the
  module. `spec align` extracts vocabulary only from public declarations,
  so entry-point modules always show Matched: 0 / SPEC_ONLY for all
  requirements. **Workaround:** split CLI logic into a library module
  that exposes public functions, with the entry point as a thin
  dispatcher. Align requirements against the library, not the entry point.

- **Empty doc comments:** Codex often writes doc comment syntax without
  any actual text content. These are invisible to `spec align` because
  they contain no vocabulary. The vocab fix prompt must explicitly
  instruct the agent: "Do not leave doc comments empty. Every public
  declaration must have a doc comment that describes its purpose using
  terminology from the requirements."

- **Internal-only modules (private functions):** When implementation
  logic is entirely private (not public), `spec align` cannot see it.
  This is common in filter/codec packages where a public pipeline
  function dispatches to private decoders. SHALLOW triggers on the
  type file even though logic exists. **Workaround:** either promote
  key internal functions to public (they become testable API surface),
  or consolidate spec vocabulary into the public pipeline function's
  doc comment so the requirement matches there instead.

- **Literal requirements vs. identifier matching:** Requirements that
  reference project-specific literals (package names, table numbers,
  configuration keys) will show as DRIFTED if the implementation doc
  comments don't mention the exact literal. This is usually a sign
  that the **requirements contain project-specific details that don't
  belong there** — fix the requirements to use generic descriptions,
  or accept that the vocab fix agent must propagate these literals.

- **"Fallback" framing vs. spec-mandated implementation:** When the
  agent proposes a "fallback" for an unsupported feature, verify
  whether the feature is actually required by the source specification.
  Example: TrueType font cmap table parsing was proposed as a
  "fallback" but is in fact mandated by the spec for TrueType font
  encoding resolution. Framing spec requirements as fallbacks creates
  incorrect priority and may lead to incomplete implementation.

- **Vocabulary match ≠ functional correctness:** DRIFTED=0 and
  SHALLOW=0 confirm vocabulary alignment but cannot verify that the
  implementation actually works. E2E tests (text extraction from real
  files, visual rendering comparison) are essential to catch:
  - Type definitions that compile but never execute
  - Processing pipelines that raise errors on real input
  - Coordinate transforms that produce wrong output
  - Font/encoding paths that silently return empty results
indexion spec align status .kiro/specs/<feature>/requirements.md src/
--threshold 0.3 --fail-on any

**关键约束:**
- 提示不指定要添加的具体词汇。它提供对齐报告,让代理决定修复内容。
- 代理必须仅针对公共声明——私有函数的文档注释对`spec align`不可见。
- 典型情况:1-2次修复循环。如果SPEC_ONLY持续存在,代理可能需要指导,告知相关公共API入口点应携带词汇(例如顶层`open`函数记录完整流程)。

**已知盲点:**

- **无公共API的CLI入口点:** 主/入口点模块通常无公共声明——所有函数对模块私有。`spec align`仅从公共声明提取词汇,因此入口点模块始终显示Matched: 0 / SPEC_ONLY。**解决方法:** 将CLI逻辑拆分为暴露公共函数的库模块,入口点作为轻量调度器。将需求与库对齐,而非入口点。

- **空文档注释:** Codex常编写文档注释语法但无实际文本内容。这些对`spec align`不可见,因为它们不含词汇。词汇修复提示必须明确指示代理:"请勿保留空文档注释。每个公共声明必须有使用需求术语描述其用途的文档注释。"

- **仅内部模块(私有函数):** 当实现逻辑完全私有(非公共)时,`spec align`无法检测到。这在过滤器/编解码器包中很常见,其中公共流水线函数调度到私有解码器。即使逻辑存在,类型文件仍会触发SHALLOW。**解决方法:** 要么将关键内部函数提升为公共(成为可测试的API),要么将规范词汇整合到公共流水线函数的文档注释中,使需求在该处匹配。

- **字面需求与标识符匹配:** 引用项目特定字面量(包名、表号、配置键)的需求,如果实现文档注释未提及完全相同的字面量,会显示为DRIFTED。这通常表明**需求包含不属于此处的项目特定细节**——修复需求以使用通用描述,或接受词汇修复代理必须传播这些字面量。

- **" fallback "框架与规范强制实现:** 当代理为不支持的功能提出"fallback"时,验证该功能是否确实是源规范要求的。示例:TrueType字体cmap表解析被提议为"fallback",但实际上是TrueType字体编码解析的规范强制要求。将规范需求框架化为fallback会创建错误的优先级,可能导致实现不完整。

- **词汇匹配≠功能正确性:** DRIFTED=0和SHALLOW=0确认词汇对齐,但无法验证实现是否真正可用。端到端测试(从真实文件提取文本、视觉渲染比较)对于捕获以下问题至关重要:
  - 可编译但从未执行的类型定义
  - 真实输入触发错误的处理流程
  - 产生错误输出的坐标变换
  - 静默返回空结果的字体/编码路径

Step 4: Documentation Drift Detection (plan reconcile)

步骤4:文档漂移检测(plan reconcile)

After implementation, use
plan reconcile
to detect drift between implementation code and its documentation (README, doc comments, etc.):
bash
undefined
实现完成后,使用
plan reconcile
检测实现代码与其文档(README、文档注释等)间的漂移:
bash
undefined

Detect impl ↔ documentation drift

检测实现与文档间的漂移

indexion plan reconcile --format md src/lib/
indexion plan reconcile --format md src/lib/

Restrict to specific docs

限制为特定文档

indexion plan reconcile --format md --doc 'README.md' src/lib/

`plan reconcile` complements `spec align` in the SDD workflow:
- **spec align**: requirements.md ↔ implementation code (spec conformance)
- **plan reconcile**: implementation code ↔ documentation (doc freshness)

Use `spec align` for pre-merge gates (CI). Use `plan reconcile` for
ongoing documentation maintenance after the feature ships.
indexion plan reconcile --format md --doc 'README.md' src/lib/

`plan reconcile`在SDD工作流中补充`spec align`:
- **spec align**:requirements.md ↔ 实现代码(规范一致性)
- **plan reconcile**:实现代码 ↔ 文档(文档新鲜度)

将`spec align`用作预合并门限(CI)。将`plan reconcile`用于功能发布后的持续文档维护。

Step 5: Visual E2E Verification (pixel diff)

步骤5:可视化端到端验证(像素差异)

For projects that produce visual output (PDF rendering, SVG export, image processing), vocabulary-based spec align is insufficient. Add pixel-level comparison against reference renderings.
Pipeline:
  1. Generate output from the library (e.g.,
    pdf svg input.pdf output.svg
    )
  2. Rasterize to PNG at a fixed DPI (
    rsvg-convert
    ,
    puppeteer
    , etc.)
  3. Generate reference PNG from an established tool (
    pdftoppm
    , etc.)
  4. Compare with
    pixelmatch
    — report diff percentage
Thresholds:
  • < 0.01%: pixel-perfect (font AA differences only)
  • < 0.1%: minor glyph positioning differences
  • < 1%: visible text drift or image placement issues
  • 1%: structural rendering failure
Iterative improvement: Visual precision requires multiple rounds. Each round fixes one category (font mapping → glyph positioning → image CTM → colour conversion). Track all PDFs per round to catch regressions — fixing one PDF must not break another.
Known limitations of visual diff:
  • Font antialiasing differs between rasterizers (rsvg-convert vs pdftoppm)
  • Sub-pixel rendering is platform-dependent
  • 0.01% may be the practical floor for cross-rasterizer comparison
对于生成视觉输出的项目(PDF渲染、SVG导出、图像处理),基于词汇的spec align不足以验证。添加与参考渲染的像素级比较。
流程:
  1. 从库生成输出(例如
    pdf svg input.pdf output.svg
  2. 以固定DPI栅格化为PNG(使用
    rsvg-convert
    puppeteer
    等)
  3. 使用成熟工具生成参考PNG(例如
    pdftoppm
  4. 使用
    pixelmatch
    比较——报告差异百分比
阈值:
  • < 0.01%:像素级完美(仅字体抗锯齿差异)
  • < 0.1%:轻微字形定位差异
  • < 1%:可见文本漂移或图像放置问题
  • 1%:结构渲染失败
迭代改进: 视觉精度需要多轮迭代。每轮修复一类问题(字体映射 → 字形定位 → 图像CTM → 颜色转换)。跟踪每轮的所有PDF以捕获回归——修复一个PDF不得破坏另一个。
视觉差异的已知限制:
  • 不同栅格化工具的字体抗锯齿不同(rsvg-convert vs pdftoppm)
  • 子像素渲染依赖平台
  • 0.01%可能是跨栅格化工具比较的实际下限

Individual Commands

单独命令

spec draft — RFC/Document → SDD Requirements Draft

spec draft — RFC/文档 → SDD需求草稿

bash
indexion spec draft <source-file-or-dir>
indexion spec draft --output requirements.md --format markdown rfc.md
indexion spec draft --profile sdd-requirement rfc.md
OptionDefaultDescription
--output, -o
stdoutOutput file path
--format
markdownOutput format: markdown, json
--profile
sdd-requirementDraft profile (KGF spec name)
--max-requirements
64Maximum requirements to extract
--specs-dir
autoKGF specs directory
bash
indexion spec draft <source-file-or-dir>
indexion spec draft --output requirements.md --format markdown rfc.md
indexion spec draft --profile sdd-requirement rfc.md
选项默认值描述
--output, -o
stdout输出文件路径
--format
markdown输出格式:markdown, json
--profile
sdd-requirement草稿配置文件(KGF规范名称)
--max-requirements
64提取的最大需求数量
--specs-dir
autoKGF规范目录

spec verify — Vocabulary Gap Check

spec verify — 词汇差距检查

bash
indexion spec verify --spec='requirements.md' src/lib/ --format md
OptionDefaultDescription
--spec
(required)Spec document glob (repeatable)
--format
jsonOutput format: json, md, github-issue
--focus
allToken kind filter: ident, text, vocab, all
--max-candidates
200Maximum items in output
-o, --output
stdoutOutput file path
bash
indexion spec verify --spec='requirements.md' src/lib/ --format md
选项默认值描述
--spec
(必填)规范文档通配符(可重复)
--format
json输出格式:json, md, github-issue
--focus
all令牌类型过滤器:ident, text, vocab, all
--max-candidates
200输出中的最大项数
-o, --output
stdout输出文件路径

spec align diff — Requirement-Level Drift

spec align diff — 需求级漂移

bash
indexion spec align diff requirements.md src/lib/ --format markdown --threshold 0.3
Reports: MATCHED, DRIFTED, SPEC_ONLY (spec with no impl match), IMPL_ONLY (impl with no spec match), SHALLOW (matched to type-only stubs without function implementations).
bash
indexion spec align diff requirements.md src/lib/ --format markdown --threshold 0.3
报告内容:MATCHED、DRIFTED、SPEC_ONLY(无实现匹配的规范)、IMPL_ONLY(无规范匹配的实现)、SHALLOW(仅匹配到无函数实现的类型存根)。

spec align trace — Traceability Matrix

spec align trace — 可追溯性矩阵

bash
indexion spec align trace requirements.md src/lib/ --format json --threshold 0.3
Generates requirement → implementation mapping for auditing.
bash
indexion spec align trace requirements.md src/lib/ --format json --threshold 0.3
生成需求→实现的映射,用于审计。

spec align status — CI Gate

spec align status — CI门限

bash
indexion spec align status requirements.md src/lib/ --fail-on any --threshold 0.3
bash
indexion spec align status requirements.md src/lib/ --fail-on any --threshold 0.3

Exit code non-zero on failure when used with --fail-on

使用--fail-on时,失败会返回非零退出码


| `--fail-on` | Description |
|-------------|-------------|
| `none` | Always pass |
| `drifted` | Fail if any DRIFTED |
| `spec-only` | Fail if any SPEC_ONLY |
| `shallow` | Fail if any SHALLOW (type-only stubs without function implementations) |
| `any` | Fail on DRIFTED, SPEC_ONLY, SHALLOW, or CONFLICT |

| `--fail-on` | 描述 |
|-------------|-------------|
| `none` | 始终通过 |
| `drifted` | 存在任何DRIFTED则失败 |
| `spec-only` | 存在任何SPEC_ONLY则失败 |
| `shallow` | 存在任何SHALLOW(无函数实现的仅类型存根)则失败 |
| `any` | 存在DRIFTED、SPEC_ONLY、SHALLOW或CONFLICT则失败 |

spec align watch — Watch Mode

spec align watch — 监听模式

bash
indexion spec align watch --mode=diff requirements.md src/lib/
indexion spec align watch --mode=status requirements.md src/lib/
Reruns alignment when spec or implementation inputs change.
bash
indexion spec align watch --mode=diff requirements.md src/lib/
indexion spec align watch --mode=status requirements.md src/lib/
当规范或实现输入变化时重新运行对齐。

spec align suggest — Reconciliation Suggestions

spec align suggest — 协调建议

bash
indexion spec align suggest requirements.md src/lib/ --format tasks --agent codex
Generates actionable suggestions to close spec↔impl gaps.
bash
indexion spec align suggest requirements.md src/lib/ --format tasks --agent codex
生成填补规范与实现差距的可操作建议。

Threshold

阈值

Use
--threshold 0.3
for SDD alignment commands. The default
0.6
is too high because SDD acceptance criteria are short text matched against code + doc comments, not full-document similarity.
SDD对齐命令使用
--threshold 0.3
。默认值
0.6
过高,因为SDD验收标准是短文本与代码+文档注释匹配,而非全文档相似度。

Multi-Language Support

多语言支持

The SDD pipeline works with any language that has a KGF spec.
SDD流程适用于任何拥有KGF规范的语言。

KGF Requirements for SDD

SDD的KGF要求

For spec align to work, the language's KGF must:
  1. Capture doc comments in declares edges
    doc
    must be non-empty
  2. Use correct PEG alternative ordering — DocComment must be after declaration rules in the Item alternatives
  3. Handle NL between doc and keyword
    NL?
    or
    NL*
    after
    doc:DocComment?
Verify with:
indexion kgf edges <file>
— if declares edges lack
doc=
, the KGF needs fixing.
为使spec align正常工作,语言的KGF必须:
  1. 在declares关联中捕获文档注释——
    doc
    必须非空
  2. 使用正确的PEG备选顺序——DocComment必须在Item备选中的声明规则之后
  3. 处理文档与关键字之间的换行——
    doc:DocComment?
    后添加
    NL?
    NL*
使用
indexion kgf edges <file>
验证——如果declares关联缺少
doc=
,则KGF需要修复。