extract-requirements
Use when starting an iterate run on human spec collateral — reads the spec, produces per-epic requirement files with proof obligations and behavior scenario cards with stable IDs.
- License 许可
- Apache-2.0
- 所属仓库
- zak-keown/moe
- 最近更新
- 2026-09-05
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- extract-requirements
- description
- Use when starting an iterate run on human spec collateral — reads the spec, produces per-epic requirement files with proof obligations and behavior scenario cards with stable IDs.
02 资源文件 8
- 参考文档extraction-subagent-prompt.md7.2 KB
- 脚本scripts/aggregate_scenarios.mjs13.2 KB
- 脚本scripts/aggregate_stories.mjs10.9 KB
- 脚本scripts/backlink_scenarios.mjs5.2 KB
- 脚本scripts/chunk_spec.mjs9.1 KB
- 脚本scripts/python_compat.mjs2.9 KB
- 脚本scripts/validate_requirements_index.mjs5.3 KB
- 脚本scripts/validate_scenarios.mjs6.2 KB
03 SKILL.md 正文
Extracting Requirements
Overview
Reads arbitrary human spec collateral and produces two artifact sets:
- Per-epic requirement files in
docs/moe/iterations/requirements/— story cards with proof obligations per AC - Behavior scenarios in
docs/moe/iterations/behavior-scenarios.md— reusable observable-behavior contracts with stable IDs
Uses a chunking + parallel-dispatch + aggregation pipeline so that no single agent holds the entire spec in context. Handles specs from a single page up to ~100K tokens across dozens of files.
When to Use
Invoked by iterate during bootstrap, or standalone when you need to regenerate requirements from human spec collateral.
Script Location
All scripts referenced below live in this skill's scripts/ directory, next to this SKILL.md file.
Key Concept: Spec Taxonomy
The spec directory structure drives proof seam classification. Resolve skills/_shared/behavior-evidence-formats.md relative to this loaded document for the full taxonomy. Summary:
| Spec directory | Default proof seam |
|---|---|
test-vectors/ |
unit |
contracts/ |
integration |
domains/ |
integration or app-level |
journeys/ |
e2e |
Extraction subagents use the appropriate prompt variant based on source file location.
Pipeline
1. Inventory
Enumerate the spec files without reading full contents:
Resolve skills/extract-requirements/scripts/chunk_spec.mjs relative to this loaded document, then invoke it as node "<resolved-chunk_spec.mjs>" <spec-path>.
This produces a JSON array of chunks. Each chunk has source_file, heading, start_line, end_line, content, and estimated_tokens. Small files (< 4K tokens) are kept whole. Larger files are split by ## headings, or ### if sections are still too large.
Classify each chunk by spec taxonomy: note whether the source file is under journeys/, contracts/, domains/, or test-vectors/. This determines which extraction prompt variant to use.
2. Dispatch extraction subagents
For each chunk (or batch of small chunks), dispatch an extraction subagent using the appropriate template from extraction-subagent-prompt.md:
- Chunks from
journeys/→ use the Journey Extraction prompt variant - All other chunks → use the Standard Extraction prompt variant
Pass the chunk content inline — do NOT make the subagent read the file.
Payload integrity: If your platform has output token limits that could truncate the chunk before it reaches the subagent prompt, stage each chunk individually and verify the subagent received the complete content (e.g., by checking that the extracted stories reference lines from the full range of the chunk). Partial payloads are easy to miss and cause silent under-extraction.
Dispatch strategy:
-
Dispatch subagents in waves of 3-5 (runtime agent thread limits are typically 6; keep headroom). Do not fan out all chunks at once.
-
Persist immediately: as soon as each subagent returns, write its output to a temp file (e.g., a scratch directory under the project root) before dispatching more work. Subagent results that only exist in conversation state can be lost if the session fails.
-
Wait semantics: loop until every dispatched agent in the wave has reached a final state, persisting each result as it arrives.
OpenCode's
tasktool call blocks until the subagent returns its result in the tool response — there is no separate polling step. Read the returned result directly; for multiple independenttaskdispatches issued in one turn, each result arrives before you continue. -
Close completed agents promptly to free thread slots for the next wave.
-
Track completion: maintain a checklist of chunk-to-agent mappings. After all waves finish, verify every chunk produced a persisted output file. Re-dispatch any missing chunks before proceeding.
3. PAR omission review
Before aggregation, run a PAR omission review. The sole job of this review is to find requirements AND scenarios that the extraction subagents dropped.
For each chunk (or batch of chunks), dispatch two reviewers in parallel following skills/_shared/parallel-adversarial-review.md, resolved relative to this loaded document:
- Give each reviewer the original chunk text and the extracted stories + scenarios for that chunk
- Prompt: "Compare the source text against the extracted stories and scenarios. Find every requirement, acceptance criterion, behavioral constraint, or observable behavior in the source that is NOT represented by any extracted story or scenario. Score 5 points for each omission found. Pay special attention to: (a) ACs missing proof obligations, (b) observable behavior with no scenario, (c) journey steps that were summarized or skipped."
- Aggregate findings across both reviewers
- For each confirmed omission: either add a new story/scenario to the extraction output or document why it's intentionally excluded
This pass is required, not optional. Extraction subagents optimize for what they notice; omission reviewers optimize for what's missing.
4. Aggregate stories
Run the story aggregation script on all extracted story JSONs (including any added by the omission review):
Resolve skills/extract-requirements/scripts/aggregate_stories.mjs relative to this loaded document, then invoke it as node "<resolved-aggregate_stories.mjs>" -o docs/moe/iterations/requirements/ <json-file-1> <json-file-2> ....
The script combines stories, deduplicates matching theme + trimmed title + body identities (never blank titles), groups them into epics, assigns stable STORY/EPIC IDs, and outputs per-epic files with proof obligations preserved.
5. Aggregate scenarios
Run the scenario aggregation script:
Resolve skills/extract-requirements/scripts/aggregate_scenarios.mjs relative to this loaded document, then invoke it as node "<resolved-aggregate_scenarios.mjs>" -o docs/moe/iterations/behavior-scenarios.md --stories-dir docs/moe/iterations/requirements/ <json-file-1> <json-file-2> ....
The script combines, deduplicates by title, assigns stable SCENARIO/JOURNEY IDs, resolves story title references to STORY-IDs, and outputs behavior-scenarios.md.
6. Consolidate epics
Same as before: review the epic list, merge near-duplicates, re-run aggregation. See the consolidation rules in the original extraction skill documentation.
Additional consolidation check: after merging, verify that scenario owning_story_titles still resolve correctly. If stories were deduplicated during re-aggregation, re-run scenario aggregation to update resolved refs.
7. Back-link scenarios to stories
After both aggregations complete, run the back-linking script to update per-epic story files with scenario references:
Resolve skills/extract-requirements/scripts/backlink_scenarios.mjs relative to this loaded document, then invoke it as node "<resolved-backlink_scenarios.mjs>" docs/moe/iterations/behavior-scenarios.md docs/moe/iterations/requirements/.
The script reads scenario → owning-story mappings from behavior-scenarios.md and appends scenario:SCENARIO-NNNN or scenario:JOURNEY-NNNN to AC lines in the epic files that have observable behavioral impact. AC lines that already have scenario refs are skipped.
This creates the bidirectional link: stories → scenarios (via AC lines) and scenarios → stories (via owning_stories field).
8. Coverage ledger
Build a coverage ledger that maps every spec chunk to its extracted stories AND scenarios. This is the traceable proof that extraction is complete.
For each chunk from the inventory (step 1):
- List the chunk:
source_file,heading,start_line–end_line - List every story ID whose
**Sources:**field cites overlapping lines in that file - List every scenario ID whose
**Sources:**field cites overlapping lines in that file - Classify the chunk:
- covered — stories with ACs that correspond to normative content AND scenarios for observable behavior
- story-only — stories exist but observable behavior has no scenario (needs scenario)
- non-normative — chunk contains only meta-commentary, table of contents, or boilerplate (explain why)
- duplicate — chunk's requirements are covered by stories citing a different source
- gap — normative content with no corresponding story
Hard gates:
- If any chunk is classified as gap, extraction is incomplete. Re-extract and repeat.
- If any chunk is classified as story-only and contains observable behavior, extraction is incomplete. Add scenarios for the missing observable behavior.
Journey coverage check: every journey spec file MUST produce at least one JOURNEY-NNNN scenario that preserves the complete step sequence. If a journey file only produced stories (no journey scenario), that is a gap.
9. Initialize behavior corpus index
Create the initial docs/moe/iterations/behavior-corpus.md from the scenario list:
# Behavior Corpus
| Scenario ID | Title | Proof seam | Run cadence | Command | Owning stories |
|---|---|---|---|---|---|
Populate with all scenarios. Set run cadence:
- Journey scenarios →
sentinel(they run every iteration) - Surface scenarios →
iteration(default, refined during scoping)
Set command to TBD — the implementing iterations will fill these in.
10. Validate
Resolve skills/extract-requirements/scripts/validate_requirements_index.mjs
as <resolved-validate_requirements_index.mjs> and
skills/extract-requirements/scripts/validate_scenarios.mjs as
<resolved-validate_scenarios.mjs>, relative to this loaded document. Then run:
node "<resolved-validate_requirements_index.mjs>" docs/moe/iterations/requirements/
node "<resolved-validate_scenarios.mjs>" docs/moe/iterations/behavior-scenarios.md docs/moe/iterations/requirements/
If validation fails, inspect the output, fix formatting issues, and re-validate.
11. Commit
git add docs/moe/iterations/requirements/
git add docs/moe/iterations/behavior-scenarios.md
git add docs/moe/iterations/behavior-corpus.md
git commit -m "docs: add requirements with proof obligations, behavior scenarios, and corpus index"
Quick Reference
| Step | Tool | Input | Output |
|---|---|---|---|
| Chunk | scripts/chunk_spec.mjs |
spec path | JSON chunks (stdout) |
| Extract | Subagent + extraction-subagent-prompt.md |
chunk content | JSON stories + scenarios (per subagent) |
| Omission review | PAR (source text vs. stories + scenarios) | chunks + stories + scenarios | Missing requirements and scenarios |
| Aggregate stories | scripts/aggregate_stories.mjs -o <dir> |
JSON files | Per-epic .md files with proof obligations |
| Aggregate scenarios | scripts/aggregate_scenarios.mjs -o <file> |
JSON files + stories dir | behavior-scenarios.md |
| Back-link | scripts/backlink_scenarios.mjs |
scenarios + stories | Updated AC lines with scenario refs |
| Coverage ledger | Map chunks → story IDs + scenario IDs | chunk list, stories, scenarios | Gap/covered/story-only per chunk |
| Init corpus | Write corpus index | scenario list | behavior-corpus.md |
| Validate | scripts/validate_requirements_index.mjs + scripts/validate_scenarios.mjs |
.md files | OK or errors |
Deferred to later plans
Hierarchical reduce (specs > 1M tokens), huge-spec decomposition, incremental re-extraction.
04 同仓库更多 Skills
write-skill
Use when creating new skills, editing existing skills, or verifying skills work before deployment
write-plan
Use when you have a spec or requirements for a multi-step task, before touching code
write-clearly
Apply Strunk's timeless writing rules to ANY prose humans will read—documentation, commit messages, error messages, explanations, reports, or UI text. Makes your writing clearer, stronger, and more professional.
windows-vm
Create, manage, or connect to a headless Windows 11 VM running in Docker with SSH access. Use when the user wants to spin up, stop, restart, or SSH into a Windows VM.
verify-completion
Use when about to claim work is complete, fixed, or passing, before committing or creating MRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
using-moe
Use when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions