Summary
New top-level Click command that runs the full Phase 1 + Phase 2 discovery pipeline and writes draft specs to .specleft/specs/_discovered/. Supports --dry-run, --format json, --language filtering, and a promote subcommand.
Depends on: #126, #134, #135
New file
src/specleft/commands/discover.py
Register in src/specleft/cli/main.py:
from specleft.commands.discover import discover
cli.add_command(discover)
Command signature
specleft discover [OPTIONS] [PROJECT_ROOT]
Options:
--format [table|json] Output format (default: auto-detect TTY)
--dry-run Preview without writing any files
--output-dir PATH Override default staging dir (.specleft/specs/_discovered/)
--language TEXT Limit to language: python, typescript (repeatable)
--specs-dir PATH Existing specs dir for traceability matching
[default: resolved via resolve_specs_dir()]
--pretty Indented JSON output
Table output (TTY)
Scanning project...
✓ Python (pytest) — 142 test functions
✓ TypeScript (Jest) — 38 test functions
✓ API routes — 24 routes
✓ Docstrings — 67 items
✓ Git history — 200 commits
Generating draft specs...
┌──────────────────────────┬───────────┬───────────────────────────────────────────────┐
│ Feature │ Scenarios │ Written to │
├──────────────────────────┼───────────┼───────────────────────────────────────────────┤
│ user-authentication │ 8 │ .specleft/specs/_discovered/user-auth….md │
│ payment-processing │ 5 │ .specleft/specs/_discovered/payment-p….md │
└──────────────────────────┴───────────┴───────────────────────────────────────────────┘
14 features, 47 scenarios written to .specleft/specs/_discovered/
Review drafts, then promote with: specleft discover promote
JSON output
{
"features": [
{
"feature_id": "user-authentication",
"name": "User Authentication",
"scenario_count": 8,
"output_file": ".specleft/specs/_discovered/user-authentication.md",
"confidence": 0.8
}
],
"total_features": 14,
"total_scenarios": 47,
"output_dir": ".specleft/specs/_discovered",
"dry_run": false,
"errors": []
}
discover promote subcommand
specleft discover promote [OPTIONS] [FEATURE_ID...]
Copies draft specs from .specleft/specs/_discovered/ to .specleft/specs/
(or --specs-dir). Files remain in _discovered/ after promotion (drafts are not deleted).
Options:
--all Promote every file in the staging dir
--specs-dir PATH Destination dir [default: resolve_specs_dir()]
--overwrite Replace existing spec if it already exists
--dry-run Preview without writing
Acceptance criteria
Documentation updates
All docs must be updated as part of this issue — not deferred.
docs/cli-reference.md
Add a new top-level ## Discover section before ## Status, containing:
### specleft discover — full flag reference, table output example, JSON schema
### specleft discover promote — flag reference, behaviour description (draft files remain in staging after promotion)
README.md
- Quick Start — replace
Path 2: Bulk-generate feature specs from a PRD with a new Path 2: Discover specs from existing code block:
specleft discover
specleft discover promote --all
specleft status
- AI Agents section — add
specleft discover --format json alongside the existing agent commands
docs/getting-started.md
Add a Discover specs from existing code section after the existing Create Specs section:
specleft discover
specleft discover promote --all
Include a one-sentence explanation of the staging area (.specleft/specs/_discovered/).
docs/SKILL.md
Add a ## Discovery section with the full agent-facing command signatures:
specleft discover --format json [PROJECT_ROOT] [--dry-run] [--language python|typescript] [--output-dir PATH] [--specs-dir PATH]
specleft discover promote --format json [--all] [FEATURE_ID...] [--specs-dir PATH] [--overwrite] [--dry-run]
Summary
New top-level Click command that runs the full Phase 1 + Phase 2 discovery pipeline and writes draft specs to
.specleft/specs/_discovered/. Supports--dry-run,--format json,--languagefiltering, and apromotesubcommand.Depends on: #126, #134, #135
New file
src/specleft/commands/discover.pyRegister in
src/specleft/cli/main.py:Command signature
Table output (TTY)
JSON output
{ "features": [ { "feature_id": "user-authentication", "name": "User Authentication", "scenario_count": 8, "output_file": ".specleft/specs/_discovered/user-authentication.md", "confidence": 0.8 } ], "total_features": 14, "total_scenarios": 47, "output_dir": ".specleft/specs/_discovered", "dry_run": false, "errors": [] }discover promotesubcommandAcceptance criteria
specleft discover --dry-runprints table/JSON with no files writtenspecleft discover --format jsonexits 0 and output is valid JSON matching the schema abovespecleft discoverwrites files to.specleft/specs/_discovered/by defaultspecleft discover --output-dir /tmp/outwrites to/tmp/outinsteadspecleft discover promote --allcopies all draft files to.specleft/specs/specleft discover promote user-authenticationcopies only that feature--overwriteerrors[]but command still exits 0--format jsonoutput is valid JSON even when all miners errortests/cli/test_discover.pyusingCliRunner+tmp_pathDocumentation updates
All docs must be updated as part of this issue — not deferred.
docs/cli-reference.mdAdd a new top-level
## Discoversection before## Status, containing:### specleft discover— full flag reference, table output example, JSON schema### specleft discover promote— flag reference, behaviour description (draft files remain in staging after promotion)README.mdPath 2: Bulk-generate feature specs from a PRDwith a new Path 2: Discover specs from existing code block:specleft discover --format jsonalongside the existing agent commandsdocs/getting-started.mdAdd a Discover specs from existing code section after the existing Create Specs section:
Include a one-sentence explanation of the staging area (
.specleft/specs/_discovered/).docs/SKILL.mdAdd a
## Discoverysection with the full agent-facing command signatures:features/feature-spec-discovery.mdto cover the functionality introduced by this issue