Skip to content

Commit 959b15f

Browse files
corvid-agentclaude
andcommitted
docs: document --ai flag, aiCommand/aiTimeout config, and LOC coverage from PR #19
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 564d952 commit 959b15f

3 files changed

Lines changed: 80 additions & 52 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- **Spec generation documentation**`specsync generate` now has a dedicated README section and expanded AI agents guide covering the full LLM workflow: generate → fill → validate → fix → enforce.
13-
- Custom template documentation (`specs/_template.spec.md`) explaining how teams control generated spec structure.
14-
- JSON output shape reference for `check` and `coverage` commands.
15-
- Integration patterns table (pre-commit hooks, PR bots, CI coverage gates).
12+
- **`specsync generate --ai`**AI-powered spec generation. Reads source code, sends it to an LLM, and generates specs with real content (Purpose, Public API tables, Invariants, Error Cases) instead of template stubs. Configurable via `aiCommand` and `aiTimeout` in `specsync.json`, or `SPECSYNC_AI_COMMAND` env var. Defaults to Claude CLI, works with any LLM that reads stdin and writes stdout.
13+
- **LOC coverage tracking**`specsync coverage` now reports lines-of-code coverage alongside file coverage. JSON output includes `loc_coverage`, `loc_covered`, `loc_total`, and `uncovered_files` with per-file LOC counts sorted by size.
14+
- **Flat file module detection**`generate` and `coverage` now detect single-file modules (e.g., `src/config.rs`) in addition to subdirectory-based modules.
15+
- `aiCommand` and `aiTimeout` config options in `specsync.json`.
1616

1717
### Changed
1818

1919
- Rewrote README for density — every line carries new information, no filler.
20-
- Elevated "For AI Agents" from a bullet list to a full "Spec Generation" section with usage examples and workflow guidance.
20+
- Documented `generate --ai` workflow, AI command configuration, and LOC coverage in README and docs site.
2121
- Streamlined docs site pages to complement rather than duplicate the README.
2222
- Updated CHANGELOG with previously missing 1.1.1 and 1.1.2 entries.
2323

README.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ specsync init # Create specsync.json config
101101
specsync check # Validate specs against code
102102
specsync coverage # Show file/module coverage
103103
specsync generate # Scaffold specs for unspecced modules
104+
specsync generate --ai # AI-powered specs (reads code, writes content)
104105
specsync watch # Re-validate on every file change
105106
```
106107

@@ -246,7 +247,7 @@ specsync [command] [flags]
246247
|---------|-------------|
247248
| `check` | Validate all specs against source code **(default)** |
248249
| `coverage` | File and module coverage report |
249-
| `generate` | Scaffold specs for modules missing one |
250+
| `generate` | Scaffold specs for modules missing one (`--ai` for AI-powered content) |
250251
| `init` | Create default `specsync.json` |
251252
| `watch` | Live validation on file changes (500ms debounce) |
252253

@@ -313,7 +314,9 @@ Create `specsync.json` in your project root (or run `specsync init`):
313314
"requiredSections": ["Purpose", "Public API", "Invariants", "Behavioral Examples", "Error Cases", "Dependencies", "Change Log"],
314315
"excludeDirs": ["__tests__"],
315316
"excludePatterns": ["**/__tests__/**", "**/*.test.ts", "**/*.spec.ts"],
316-
"sourceExtensions": []
317+
"sourceExtensions": [],
318+
"aiCommand": "claude -p --output-format text",
319+
"aiTimeout": 120
317320
}
318321
```
319322

@@ -327,36 +330,49 @@ Create `specsync.json` in your project root (or run `specsync init`):
327330
| `excludeDirs` | `string[]` | `["__tests__"]` | Directories excluded from coverage |
328331
| `excludePatterns` | `string[]` | Common test globs | File patterns excluded from coverage |
329332
| `sourceExtensions` | `string[]` | All supported | Restrict to specific extensions (e.g., `["ts", "rs"]`) |
333+
| `aiCommand` | `string?` | `claude -p ...` | Command for `generate --ai` (reads stdin prompt, writes stdout markdown) |
334+
| `aiTimeout` | `number?` | `120` | Seconds before AI command times out per module |
330335

331336
---
332337

333338
## Spec Generation
334339

335-
`specsync generate` scans your source directories, finds modules without spec files, and scaffolds `*.spec.md` files for each one — frontmatter populated, source files listed, all required sections stubbed.
340+
`specsync generate` scans your source directories, finds modules without spec files, and scaffolds `*.spec.md` files for each one.
336341

337342
```bash
338-
specsync generate # Scaffold specs for all unspecced modules
343+
specsync generate # Scaffold template specs for all unspecced modules
344+
specsync generate --ai # Use AI to generate filled-in specs from source code
339345
specsync coverage # See what's still missing
340346
```
341347

342-
### How it works
348+
### Template mode (default)
343349

344-
1. Runs coverage analysis to find modules with no corresponding spec
345-
2. For each unspecced module, discovers all source files (excluding tests)
346-
3. Generates a spec using your custom template (`specs/_template.spec.md`) or the built-in default
347-
4. Writes `specs/<module>/<module>.spec.md` with `module`, `files`, `version: 1`, `status: draft` pre-filled
350+
Uses your custom template (`specs/_template.spec.md`) or the built-in default. Generates frontmatter + stubbed sections with TODOs.
348351

349-
### Custom templates
352+
### AI mode (`--ai`)
350353

351-
Drop a `_template.spec.md` in your specs directory. The generator replaces `module`, `version`, `status`, `files`, and the `# Title` heading — everything else stays as-is. Use this to enforce your team's spec structure.
354+
Reads your source code, sends it to an LLM, and generates specs with real content — Purpose, Public API tables, Invariants, Error Cases, all filled in from the code. No manual filling required.
355+
356+
The AI command is resolved in order:
357+
1. `"aiCommand"` in `specsync.json`
358+
2. `SPECSYNC_AI_COMMAND` environment variable
359+
3. `claude -p --output-format text` (default, requires [Claude CLI](https://docs.anthropic.com/en/docs/claude-code))
360+
361+
Any command that reads a prompt from stdin and writes markdown to stdout works:
362+
363+
```json
364+
{ "aiCommand": "claude -p --output-format text" }
365+
{ "aiCommand": "ollama run llama3" }
366+
```
367+
368+
Set `"aiTimeout"` in `specsync.json` to control per-module timeout (default: 120 seconds).
352369

353370
### Designed for AI agents
354371

355-
The generate command is the entry point for LLM-powered spec workflows. A coding agent can:
372+
The generate command is the entry point for LLM-powered spec workflows:
356373

357374
```bash
358-
specsync generate # scaffold specs for new modules
359-
# LLM fills in Purpose, Public API, Invariants... # agent writes the content
375+
specsync generate --ai # AI writes specs from source code
360376
specsync check --json # validate, get structured feedback
361377
# LLM fixes errors from JSON output # iterate until clean
362378
specsync check --strict --require-coverage 100 # enforce full coverage in CI
@@ -375,7 +391,7 @@ Every output format is designed for machine consumption:
375391
{ "passed": false, "errors": ["..."], "warnings": ["..."], "specs_checked": 12 }
376392
377393
// specsync coverage --json
378-
{ "file_coverage": 85.33, "files_covered": 23, "files_total": 27, "modules": [{"name": "helpers", "has_spec": false}] }
394+
{ "file_coverage": 85.33, "files_covered": 23, "files_total": 27, "loc_coverage": 79.12, "loc_covered": 4200, "loc_total": 5308, "modules": [...] }
379395
```
380396

381397
---
@@ -385,6 +401,7 @@ Every output format is designed for machine consumption:
385401
```
386402
src/
387403
├── main.rs CLI entry + output formatting
404+
├── ai.rs AI-powered spec generation (prompt builder + command runner)
388405
├── types.rs Data types + config schema
389406
├── config.rs specsync.json loading
390407
├── parser.rs Frontmatter + spec body parsing

docs/ai-agents.md

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,62 @@ SpecSync is built for LLM-powered coding tools — structured output, machine-re
1919

2020
---
2121

22-
## Generate Specs Automatically
22+
## AI-Powered Generation (`--ai`)
2323

24-
`specsync generate` is the starting point for AI-driven spec workflows. It finds every module without a spec file and scaffolds one — frontmatter populated, source files listed, required sections stubbed with TODOs.
24+
`specsync generate --ai` reads your source code, sends it to an LLM, and generates specs with real content — not just templates with TODOs. Purpose, Public API tables, Invariants, Error Cases — all filled in from the code.
2525

2626
```bash
27-
specsync generate
27+
specsync generate --ai
28+
# Generating specs/auth/auth.spec.md with AI...
29+
# │ ---
30+
# │ module: auth
31+
# │ ...
2832
# ✓ Generated specs/auth/auth.spec.md (3 files)
29-
# ✓ Generated specs/payments/payments.spec.md (2 files)
3033
```
3134

32-
### What gets generated
35+
### Configuring the AI command
3336

34-
For each unspecced module, you get a ready-to-fill spec:
37+
The AI command is resolved in order:
38+
1. `"aiCommand"` in `specsync.json`
39+
2. `SPECSYNC_AI_COMMAND` environment variable
40+
3. `claude -p --output-format text` (default, requires Claude CLI)
3541

36-
```yaml
37-
---
38-
module: auth
39-
version: 1
40-
status: draft
41-
files:
42-
- src/auth/service.ts
43-
- src/auth/middleware.ts
44-
db_tables: []
45-
depends_on: []
46-
---
42+
Any command that reads a prompt from stdin and writes markdown to stdout works:
43+
44+
```json
45+
{
46+
"aiCommand": "claude -p --output-format text",
47+
"aiTimeout": 300
48+
}
4749
```
4850

49-
Plus all required sections (Purpose, Public API, Invariants, Behavioral Examples, Error Cases, Dependencies, Change Log) with TODO placeholders.
51+
```json
52+
{
53+
"aiCommand": "ollama run llama3",
54+
"aiTimeout": 60
55+
}
56+
```
57+
58+
If AI generation fails for a module, it falls back to template generation automatically.
5059

51-
### Custom templates
60+
### Template mode (no `--ai`)
5261

53-
Place `_template.spec.md` in your specs directory to control the generated structure. The generator replaces `module`, `version`, `status`, `files`, and the `# Title` heading — your template controls everything else.
62+
Without `--ai`, `specsync generate` scaffolds template specs — frontmatter populated, required sections stubbed with TODOs. Place `_template.spec.md` in your specs directory to control the generated structure.
5463

5564
---
5665

57-
## End-to-End AI Workflow
66+
## End-to-End Workflow
5867

5968
```bash
60-
# 1. Bootstrap: scaffold specs for all unspecced modules
61-
specsync generate
62-
63-
# 2. Fill: LLM reads source code, fills in each spec's content
64-
# (Purpose, Public API tables, Invariants, etc.)
69+
# One command: AI reads code, writes specs
70+
specsync generate --ai
6571

66-
# 3. Validate: check specs against code, get structured errors
72+
# Validate the generated specs against code
6773
specsync check --json
6874

69-
# 4. Fix: LLM reads JSON errors, corrects specs or flags code issues
75+
# LLM fixes errors from JSON output, iterates until clean
7076

71-
# 5. Enforce: CI gate with full coverage
77+
# CI gate with full coverage
7278
specsync check --strict --require-coverage 100
7379
```
7480

@@ -113,11 +119,15 @@ Each step produces machine-readable output. No human in the loop required (thoug
113119
"file_coverage": 85.33,
114120
"files_covered": 23,
115121
"files_total": 27,
116-
"modules": [{ "name": "helpers", "has_spec": false }]
122+
"loc_coverage": 79.12,
123+
"loc_covered": 4200,
124+
"loc_total": 5308,
125+
"modules": [{ "name": "helpers", "has_spec": false }],
126+
"uncovered_files": [{ "file": "src/helpers/utils.ts", "loc": 340 }]
117127
}
118128
```
119129

120-
Use `modules` with `has_spec: false` to identify what `generate` would scaffold.
130+
Use `modules` with `has_spec: false` to identify what `generate` would scaffold. `uncovered_files` shows LOC per uncovered file, sorted by size — prioritize the largest gaps.
121131

122132
---
123133

@@ -178,6 +188,7 @@ None
178188
|---------|---------|-----|
179189
| **Pre-commit hook** | `specsync check --strict` | Block commits with spec errors |
180190
| **PR review bot** | `specsync check --json` | Parse output, post as PR comment |
181-
| **Bootstrap coverage** | `specsync generate` | Scaffold after adding new modules |
191+
| **Bootstrap coverage** | `specsync generate --ai` | AI writes specs from source code |
192+
| **Template scaffold** | `specsync generate` | Scaffold templates after adding new modules |
182193
| **AI code review** | `specsync check --json` | Feed errors to LLM for spec updates |
183194
| **Coverage gate** | `specsync check --strict --require-coverage 100` | CI enforces full coverage |

0 commit comments

Comments
 (0)