Skip to content

Commit 7c67e3d

Browse files
feat: add cookbook report tool for auditing recipes and SVG assets
- Introduced a new tool `cookbook-report` to audit SpiceSharp cookbook recipes. - Implemented checks for required sections in README, netlist directives, and SVG accessibility. - Added command-line interface for running audits with options for output format and skipping freshness checks. - Created a structured report format in JSON and text for audit results. - Developed unit tests to ensure functionality and validate reports against expected outcomes. - Updated documentation to reflect new tool usage and commands.
1 parent 3ead6f6 commit 7c67e3d

19 files changed

Lines changed: 1073 additions & 24 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: cookbook-report
3+
description: Audit SpiceSharp circuit cookbook recipes, SPICE directives, documentation sections, SchemDraw layout topology, accessible SVG metadata, and generated schematic freshness. Use when Codex needs to verify cookbook quality, produce a deterministic JSON health report, diagnose a stale schematic.svg, or check a recipe before committing it.
4+
---
5+
6+
# Cookbook Report
7+
8+
Run the repository-local audit before and after changing cookbook recipes.
9+
Treat it as a read-only quality gate; use `$cookbook-schematic` for fixes to
10+
`schematic.toml` or `schematic.svg`.
11+
12+
## Workflow
13+
14+
1. Install both local tools into the schematic environment if needed:
15+
16+
```powershell
17+
.\tools\cookbook-schematic\.venv\Scripts\python -m pip install `
18+
-e tools\cookbook-schematic -e tools\cookbook-report
19+
```
20+
21+
2. Run the complete audit from the repository root:
22+
23+
```powershell
24+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report
25+
```
26+
27+
3. Use JSON when another tool or agent will consume the result:
28+
29+
```powershell
30+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report `
31+
--format json --output artifacts\cookbook-report.json
32+
```
33+
34+
4. Use `--skip-freshness` only when SchemDraw is unavailable or a quick
35+
structural pass is sufficient. This still validates layout topology and
36+
SVG accessibility but reports schematic freshness as `skipped`.
37+
5. Resolve every error. Review warnings about omitted netlist components or
38+
measurement-table row counts; make intentional omissions clear in the
39+
recipe documentation.
40+
6. Run the cookbook simulation regression suite after the report passes:
41+
42+
```powershell
43+
dotnet test src\SpiceSharpParser.Tests\SpiceSharpParser.Tests.csproj `
44+
--filter 'FullyQualifiedName~CircuitCookbookTests'
45+
```
46+
47+
## Exit behavior
48+
49+
- `0`: no errors; warnings are allowed.
50+
- `1`: audit errors, or warnings with `--warnings-as-errors`.
51+
- `2`: invalid command usage or a missing tool dependency.
52+
53+
Do not hand-edit a stale generated schematic. Invoke `$cookbook-schematic`,
54+
review its visual output, and render from `schematic.toml`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface:
2+
display_name: "Cookbook Report"
3+
short_description: "Audit cookbook recipes and generated SVG assets"
4+
default_prompt: "Use $cookbook-report to check the cookbook and summarize any recipe or generated-asset problems."

‎CIRCUIT_COOKBOOK_PLAN.md‎

Lines changed: 145 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ runnable, measured, and clearly documented designs.
1212

1313
## Existing Foundation
1414

15-
The repository already contains most of the infrastructure needed for this
16-
direction:
15+
The repository contains the infrastructure needed for this direction:
1716

1817
- `SpiceSharpParser.AIExamples` contains 948 unique measured netlists. These
1918
provide candidates for human review and promotion into the cookbook.
2019
- `circuits/a-devices` demonstrates a strong example format: runnable
2120
netlists, `.SAVE`, `.PLOT`, `.MEAS`, explanatory guides, and automated
2221
verification.
22+
- `circuits/cookbook` contains four complete application-oriented recipes
23+
across the pure-SPICE and CustomComponents tracks.
24+
- `tools/cookbook-schematic` renders deterministic, accessible SVG schematics
25+
from a SPICE netlist plus a compact `schematic.toml` layout. Its validator
26+
keeps displayed component and node names synchronized with the netlist.
27+
- `tools/cookbook-report` provides a read-only cookbook quality gate. It checks
28+
required documentation, analysis and output directives, measurement-table
29+
coverage, layout topology, SVG accessibility, and generated schematic
30+
freshness. It can emit stable JSON for CI or another AI tool.
31+
- Repository-local `cookbook-schematic` and `cookbook-report` skills document
32+
the corresponding AI workflows.
2333
- The main documentation is comprehensive about syntax, analyses, and
2434
components, but it is not yet organized around practical things users can
2535
build.
@@ -28,6 +38,24 @@ The accepted AI examples should be treated as a quarry rather than published
2838
as-is. Promoted circuits must receive an independent review of their topology,
2939
equations, assumptions, measurements, and educational value.
3040

41+
## Current Implementation Status
42+
43+
The initial cookbook milestone is complete:
44+
45+
- Rectifier power supply, PWM DAC, ideal-diode power OR, and simple PLL recipes
46+
are present in the user-facing catalog.
47+
- Every current recipe has a runnable `.cir`, full guide, checked-in
48+
`schematic.toml`, generated `schematic.svg`, and accessible `response.svg`.
49+
- All current schematic layouts display every parsed netlist component and
50+
render reproducibly from their checked-in sources.
51+
- The repository-local cookbook report passes without errors or warnings.
52+
- The data-driven `CircuitCookbookTests` suite compiles and simulates all
53+
current recipes and enforces their measurement ranges.
54+
55+
The next circuit should be the BJT audio preamplifier. It expands the
56+
pure-SPICE track with operating-point and AC analysis instead of adding another
57+
transient-only example.
58+
3159
## Cookbook Tracks
3260

3361
Maintain two visible tracks.
@@ -49,7 +77,7 @@ complete applications rather than isolated component behavior.
4977
| Circuit | Foundation | Status | What it demonstrates |
5078
| --- | --- | --- | --- |
5179
| Rectifier, reservoir, and simple regulator | Pure SPICE | Complete | Diodes, ripple, load regulation, startup, and peak current |
52-
| BJT audio preamplifier | Pure SPICE | Planned | Bias point, AC gain, bandwidth, clipping, and Fourier distortion |
80+
| BJT audio preamplifier | Pure SPICE | Next | Bias point, AC gain, bandwidth, clipping, and Fourier distortion |
5381
| PWM-to-analog converter | Pure SPICE | Complete | Switching, settling time, average output, and ripple |
5482
| Transmission-line termination experiment | Pure SPICE | Planned | Reflections, propagation delay, and source/load matching |
5583
| Ideal-diode redundant power input | CustomComponents | Complete | Supply OR-ing, failover, and reverse-current blocking |
@@ -58,31 +86,28 @@ complete applications rather than isolated component behavior.
5886
| Sampled sensor alarm or data recorder | Sample-and-hold plus digital library | Planned | A complete analog-to-digital signal chain |
5987
| Simple phase-locked loop | `PHASEDET`, loop filter, and `MODULATOR` | Complete | A mixed-signal system assembled from existing components |
6088

61-
## Recommended Starting Sequence
89+
## Completed Starting Sequence
90+
91+
The starting sequence established three complementary examples:
6292

6393
1. **Rectifier and filtered DC supply**
64-
Establish the cookbook structure with an accessible, practical pure-SPICE
65-
circuit.
94+
Established the cookbook structure with an accessible, practical
95+
pure-SPICE circuit.
6696

6797
2. **PWM DAC**
68-
Add a compact transient example with clear measurements for output average,
69-
ripple, and settling time.
98+
Added a compact transient example with clear measurements for output
99+
average, ripple, and settling time.
70100

71101
3. **Simple PLL**
72-
Demonstrate that CustomComponents can form a complete mixed-signal system,
102+
Demonstrated that CustomComponents can form a complete mixed-signal system,
73103
rather than only isolated device examples.
74104

75-
This sequence covers nonlinear analog behavior, switching behavior, and a
76-
composed custom-component application without requiring new library features.
77-
78-
The three-circuit starting sequence is complete. The ideal-diode redundant
79-
power input is the first follow-on application. The next recommended addition
80-
is the BJT audio preamplifier, which expands the pure-SPICE track with operating
81-
point and AC analysis instead of adding another transient-only example.
105+
The ideal-diode redundant power input was the first follow-on application. The
106+
next addition is the BJT audio preamplifier.
82107

83-
## Proposed Repository Structure
108+
## Current Repository Structure and Growth Path
84109

85-
Add a user-oriented catalog while initially leaving existing historical and
110+
Keep the user-oriented catalog beside the source while leaving historical and
86111
milestone directories intact.
87112

88113
```text
@@ -93,28 +118,38 @@ circuits/
93118
rectifier-power-supply/
94119
README.md
95120
rectifier-power-supply.cir
121+
schematic.toml
96122
schematic.svg
97123
response.svg
98124
pwm-dac/
99125
README.md
100126
pwm-dac.cir
127+
schematic.toml
101128
schematic.svg
102129
response.svg
103130
custom-components/
104131
ideal-diode-power-or/
105132
README.md
106133
ideal-diode-power-or.cir
134+
schematic.toml
107135
schematic.svg
108136
response.svg
109137
simple-pll/
110138
README.md
111139
simple-pll.cir
140+
schematic.toml
112141
schematic.svg
113142
response.svg
143+
tools/
144+
cookbook-schematic/
145+
cookbook-report/
146+
.agents/skills/
147+
cookbook-schematic/
148+
cookbook-report/
114149
```
115150

116-
The root `circuits/README.md` should be the searchable cookbook catalog. It
117-
should classify circuits by application, required package, analysis type, and
151+
The root `circuits/README.md` is the searchable cookbook catalog. It should
152+
classify circuits by application, required package, analysis type, and
118153
difficulty.
119154

120155
Implementation-oriented examples such as `digital-milestone-a` can remain as
@@ -143,7 +178,10 @@ Every circuit `README.md` should use the same order.
143178
compatibility.
144179

145180
4. **Schematic**
146-
Include a readable SVG with node names matching the netlist.
181+
Include a readable, accessible SVG with component and node names matching
182+
the netlist. Keep layout intent in `schematic.toml`, generate
183+
`schematic.svg` with `cookbook-schematic`, and do not hand-edit the generated
184+
SVG.
147185

148186
5. **Runnable netlist**
149187
Link to the complete `.cir` file. Include only the most instructive excerpt
@@ -162,7 +200,9 @@ Every circuit `README.md` should use the same order.
162200

163201
9. **Expected behavior and measurements**
164202
Identify the important waveforms and compare `.MEAS` results with calculated
165-
targets or documented acceptance ranges.
203+
targets or documented acceptance ranges. Include an accessible
204+
`response.svg` that summarizes the signals and scalar results discussed in
205+
the guide.
166206

167207
10. **Experiments**
168208
Suggest safe parameter changes that help users understand or adapt the
@@ -205,13 +245,91 @@ A cookbook circuit is complete only when it satisfies all of the following:
205245
- The documentation compares simulation with theory or an independent
206246
expectation.
207247
- Saved waveforms and plots correspond to the signals discussed in the guide.
208-
- The schematic and netlist use matching names.
248+
- `schematic.toml` passes topology and netlist-reference validation.
249+
- `schematic.svg` is a fresh renderer output and uses matching component and
250+
node names.
251+
- Both SVG assets have useful accessible title and description metadata.
209252
- The model boundary and significant limitations are explicit.
210253
- Another user can run it by following only the documented instructions.
211254

255+
Run the fast, read-only structural and generated-asset gate first:
256+
257+
```powershell
258+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report
259+
```
260+
261+
Use deterministic JSON when CI or an AI agent needs to consume the result:
262+
263+
```powershell
264+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report `
265+
--format json --output artifacts\cookbook-report.json
266+
```
267+
268+
Then run the compile, simulation, plot, and measurement regression suite:
269+
270+
```powershell
271+
dotnet test src\SpiceSharpParser.Tests\SpiceSharpParser.Tests.csproj `
272+
--filter 'FullyQualifiedName~CircuitCookbookTests'
273+
```
274+
212275
Portable-SPICE claims should be checked with another simulator when practical.
213276
Native LTspice comparison can continue for LTspice A-device examples.
214277

278+
## Tooling Roadmap
279+
280+
Develop the cookbook tooling in small, independently useful layers.
281+
282+
### Complete: schematic source and rendering
283+
284+
`cookbook-schematic` supplies a versioned TOML layout, netlist-aware
285+
validation, deterministic accessible SVG rendering, and a documented AI
286+
workflow. Continue extending its symbol vocabulary only when a real cookbook
287+
circuit needs a conventional symbol that cannot be expressed clearly today.
288+
289+
### Complete: read-only cookbook report
290+
291+
`cookbook-report` discovers recipes and produces deterministic text or JSON. It
292+
checks the static cookbook contract and compares each checked-in schematic with
293+
a fresh render without overwriting repository files.
294+
295+
### Next: recipe manifest and data-driven coverage
296+
297+
Add one small versioned manifest per recipe containing its netlist, required
298+
dialect or custom mappings, analysis types, measurement acceptance ranges, and
299+
catalog metadata. Migrate `CircuitCookbookTests` from hard-coded cases to these
300+
manifests so adding a recipe does not require editing a central C# list.
301+
302+
The report should then compare manifest measurement names with `.MEAS`
303+
statements and the guide's Verified Measurements table.
304+
305+
### Later: structured simulation reports
306+
307+
Add a thin .NET runner that compiles each manifest with the correct dialect and
308+
custom mappings, executes its analyses, and returns versioned JSON containing
309+
diagnostics, plot names, measurement values, and convergence status. Integrate
310+
that output into `cookbook-report` only after the JSON contract is stable.
311+
312+
### Later: deterministic response summaries and catalog generation
313+
314+
Generate `response.svg` from reviewed plot specifications plus structured
315+
simulation results, while retaining visual review as a required step. Generate
316+
the catalog table from recipe manifests once the manifest schema has proved
317+
stable across several additional circuits.
318+
319+
## Immediate Next Steps
320+
321+
1. Add the BJT audio preamplifier with OP, AC, and transient measurements.
322+
2. Define and trial the recipe manifest on the BJT recipe and one existing
323+
pure-SPICE recipe.
324+
3. Migrate the remaining cookbook test cases after the manifest format is
325+
validated.
326+
4. Implement the structured .NET simulation runner and add an opt-in
327+
simulation mode to `cookbook-report`.
328+
5. Add deterministic `response.svg` generation after structured simulation
329+
output and plot specifications are available.
330+
6. Cross-check portable-SPICE recipes with an independent simulator where
331+
practical.
332+
215333
## Keeping the Project Small
216334

217335
Use the following constraints to prevent the cookbook effort from becoming
@@ -234,6 +352,10 @@ feature growth:
234352
- Document expected values and tolerances; let CI report current test counts.
235353
- Prefer one authoritative circuit guide instead of separate requirements,
236354
documentation, and results files unless the design is genuinely complex.
355+
- Keep generated files reproducible from compact, reviewable source files; do
356+
not introduce a new generator without a corresponding freshness check.
357+
- Keep report and validation commands read-only unless their command name and
358+
documentation explicitly promise generation or repair.
237359

238360
## Selection Criteria
239361

‎circuits/README.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ A cookbook circuit must:
3737
- document its calculations, assumptions, experiments, and model boundary;
3838
- pass the data-driven `CircuitCookbookTests` regression suite.
3939

40-
Run the cookbook verification from the repository root:
40+
Run the fast documentation, layout, and generated-asset audit from the
41+
repository root:
42+
43+
```powershell
44+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report
45+
```
46+
47+
Then run the simulation regression suite:
4148

4249
```powershell
4350
dotnet test src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj `

‎tools/cookbook-report/README.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Cookbook report
2+
3+
This repository-local command audits the circuit cookbook without modifying
4+
it. It checks the documented recipe contract, validates SchemDraw layout
5+
topology, verifies accessible SVG metadata, and detects a stale
6+
`schematic.svg` by comparing it with a fresh deterministic render.
7+
8+
## Setup
9+
10+
Install it in the same environment as the schematic renderer:
11+
12+
```powershell
13+
python -m venv tools\cookbook-schematic\.venv
14+
.\tools\cookbook-schematic\.venv\Scripts\python -m pip install `
15+
-e tools\cookbook-schematic -e tools\cookbook-report
16+
```
17+
18+
## Commands
19+
20+
Run the complete audit from the repository root:
21+
22+
```powershell
23+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report
24+
```
25+
26+
Write stable machine-readable output for an AI agent or CI job:
27+
28+
```powershell
29+
.\tools\cookbook-schematic\.venv\Scripts\cookbook-report `
30+
--format json --output artifacts\cookbook-report.json
31+
```
32+
33+
Use `--skip-freshness` for a faster structural check that does not import
34+
SchemDraw. The command exits with 1 when errors are found and 2 for command or
35+
environment failures. Warnings do not fail by default; pass
36+
`--warnings-as-errors` to make them fail.
37+
38+
## Tests
39+
40+
```powershell
41+
.\tools\cookbook-schematic\.venv\Scripts\python -m unittest discover `
42+
-s tools\cookbook-report\tests -v
43+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Read-only audits for SpiceSharp cookbook recipes."""
2+
3+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)