Skip to content

Commands

m4bwav edited this page Oct 4, 2026 · 1 revision

cw.py is the script both skills run. It lives at scripts/cw.py, imports only the Python standard library, and has launchers beside it: cw.ps1 for PowerShell and cw.sh for a POSIX shell. Every transcript here ran from a fresh clone of version 0.8.4 on 2026-10-03, on Windows 11 with Python 3.14.6. They ran again with 3.9.25, which has no renderers installed. Where the two differ, the page says so.

Usage

python scripts/cw.py [--strict] [--json] COMMAND [options]
Command What it does
index Compiles kb/charts/*.md and kb/targets/*.md into kb/index.json and kb/INDEX.md.
validate Checks the knowledge base against kb/SCHEMA.md.
list Lists chart types, optionally by family or target.
show SLUG Prints chosen sections of a chart or target file.
pick Ranks chart types for a question and a data shape.
data FILE Profiles a CSV: column kinds, ranges and a shape guess.
build Writes a chart for one target from a CSV.
render Turns a built spec or script into the final file.
new-chart SLUG Writes a chart file to fill in.
new-target SLUG Writes a target file to fill in.
note SLUG "text" Appends a dated note to a chart or target file.
tested SLUG Records a platform test for a target.
doctor Reports which renderers this machine has.
targets Lists the render targets with their test status.
Global option What it does
--strict Exit 1 when a command reports a problem. Without it, problems are printed and the exit code is 0.
--json JSON output from list and pick. (data and doctor always print JSON.)
-h, --help Help for the script, or for a command after its name.

--strict and --json can go before or after the command name.

Running it with no command:

$ python scripts/cw.py
usage: cw.py [-h] [--strict] [--json]
             {index,validate,list,show,pick,data,build,render,new-chart,new-target,note,doctor,targets,tested} ...
cw.py: error: the following arguments are required: cmd
$ echo $?
2

Python 3.9 wraps the usage line one word earlier, putting the ... on a line of its own.

data

python scripts/cw.py data FILE.csv

With prices.csv from Home:

$ python scripts/cw.py data prices.csv
{
 "file": "prices.csv",
 "rows": 6,
 "columns": [
  {
   "name": "date",
   "kind": "time",
   "non_empty": 6,
   "first": "2026-01-01",
   "last": "2026-06-01"
  },
  {
   "name": "price",
   "kind": "q",
   "non_empty": 6,
   "min": 100.0,
   "max": 115.0
  }
 ],
 "shape_guess": "time,q"
}

How each kind is decided is on How charts are picked and built.

pick

Option What it does
--question "..." The request in plain words.
--shape S The data shape, such as time,q, n,q or time,q*n (*n means several series). data prints a guess.
--series N How many series, checked against each chart's limit.
--categories N How many categories, checked against each chart's limit.
--target T The target, so charts it cannot draw drop down the list.
--top N How many to print. The default is 3.
$ python scripts/cw.py pick --question "line graph, time on x, price on y" --shape time,q
1. line (16.0): Line chart - How does a value change over time, and how do a few series compare as they change?
   why: named in request; goals: line, over time, price, time; shape time,q
2. step (8.25): Step chart - When did a level change, and what was it in between?
   why: goals: over time, price, time; shape time,q
3. ridgeline (7.75): Ridgeline plot - How does the shape of a distribution shift across many ordered groups, such as months, years or dose levels?
   why: goals: line, over time, time; shape time,q

With --json, the same ranking with the goal words it used and a hint for the next step:

$ python scripts/cw.py pick --question "how to show signup drop-off" --top 1 --json
{
 "question": "how to show signup drop-off",
 "goals": [
  "stages",
  "flow",
  "how",
  "signup",
  "drop-off"
 ],
 "shape": null,
 "picks": [
  {
   "slug": "alluvial",
   "name": "Alluvial diagram",
   "score": 6.5,
   "why": [
    "goals: flow, stages",
    "family flow"
   ],
   "warnings": [],
   "family": "flow",
   "question": "How do groups redistribute across the categories of several ordered variables?"
  }
 ],
 "next": "cw.py show <slug> --section when not substitutes; then cw.py build ...; palette and marks: the dataviz skill when present"
}

That pick shows why the skill reads the chart entry before building: the question was about a funnel, and with no --shape the flow charts tie with it on goal words. The scoring is on How charts are picked and built.

show

python scripts/cw.py show SLUG --section when not substitutes

--section takes any of when, not, substitutes, evidence, accessibility, build, notes and all; the default is when not substitutes. --target T with build prints only that target's recipe:

$ python scripts/cw.py show pie --section build --target mermaid
# Pie chart (pie)
family: part-to-whole  shapes: ['n,q']  caps: series 0 / categories 5  evidence: medium  popularity: core

## Build: mermaid
```mermaid
pie showData
    title Traffic by device
    "Mobile" : 58
    "Desktop" : 34
    "Tablet" : 8
```

`cw.py build --chart pie --target mermaid --data traffic.csv --x device --y visits`. Slices draw in input order, so sort the data descending first; `showData` prints values; colours come from the theme only.

A slug that is neither a chart nor a target:

$ python scripts/cw.py show piechart
no chart or target 'piechart'
$ echo $?
0
$ python scripts/cw.py --strict show piechart
no chart or target 'piechart'
$ echo $?
1

list

--family F keeps charts whose main or secondary family is F. --target T keeps charts that T can draw in any way. With no options it lists all 83, one per line:

$ python scripts/cw.py list | wc -l
83

build

Option What it does
--chart SLUG The chart type. Required.
--target T One of the 16 targets on Render targets. Required.
--data FILE The CSV. Required.
--x COL, --y COL The columns for the two axes. Required.
--series COL A column that splits the rows into series.
--y2 COL A second number column: a bullet's target, a range band's upper bound, a dumbbell's second end.
--title T The chart title. The default is <y> by <x>.
--out FILE Write to a file instead of standard output.
--png FILE For matplotlib, pptx, xlsx and docx: the file the generated script will write.
--html Wrap a web spec in a standalone page (vega-lite, plotly, chartjs, echarts, observable-plot).
--agg sum|mean|none How repeated x values within a series combine. The default is sum.
--flag F ... namedSeries (Mermaid 11.16+ series names), showData (Mermaid pie values), dataByUrl (Vega-Lite reads the CSV by its file name instead of holding the values), container (Vega-Lite fills the width of its container instead of 600 pixels).

To standard output:

$ python scripts/cw.py build --chart bar --target quickchart --data regions.csv --x region --y sales
![sales by region](https://quickchart.io/chart?version=4&w=800&h=400&c=%7B%22type%22%3A%22bar%22%2C%22data%22%3A%7B%22labels%22%3A%5B%22North%22%2C%22South%22%2C%22East%22%5D%2C%22datasets%22%3A%5B%7B%22label%22%3A%22sales%22%2C%22data%22%3A%5B200.0%2C225.0%2C130.0%5D%7D%5D%7D%2C%22options%22%3A%7B%22responsive%22%3Atrue%2C%22plugins%22%3A%7B%22title%22%3A%7B%22display%22%3Atrue%2C%22text%22%3A%22sales%20by%20region%22%7D%2C%22legend%22%3A%7B%22display%22%3Afalse%7D%7D%7D%7D)

To a file, then rendered:

$ python scripts/cw.py build --chart grouped-bar --target vega-lite --data sales.csv --x region --y sales --series product --out chart.vl.json
wrote chart.vl.json (885 chars)
$ python scripts/cw.py render --target vega-lite --in chart.vl.json --out chart.svg
wrote chart.svg (9909 bytes)
$ python scripts/cw.py render --target vega-lite --in chart.vl.json --out chart.png
wrote chart.png (92406 bytes)

As a page that loads Vega from a CDN:

$ python scripts/cw.py build --chart grouped-bar --target vega-lite --data sales.csv --x region --y sales --series product --html --out chart.html
wrote chart.html (1357 chars)
$ head -c 300 chart.html
<!doctype html><html><head><meta charset="utf-8"><title>sales by region</title>
<script src="https://cdn.jsdelivr.net/npm/vega@6"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@6"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@7"></script>
<style>body{font-family:s

render

python scripts/cw.py render --target T --in SPEC --out FILE
Target --in --out
vega-lite a spec .svg, .png, .pdf or .html (--scale, default 2, sets the PNG's pixel ratio)
mermaid a .mmd file, or a Markdown file holding a mermaid block .svg or .png
matplotlib, pptx, xlsx, docx the script build wrote the file the script writes (--png at build time)
plotly, chartjs, echarts, observable-plot a spec an .html page
d2, plantuml the text build wrote .svg or .png

A script target:

$ python scripts/cw.py build --chart bar --target matplotlib --data regions.csv --x region --y sales --out chart.py --png chart.png
wrote chart.py (408 chars)
$ python scripts/cw.py render --target matplotlib --in chart.py --out chart.png
wrote chart.png (19416 bytes)

Without the renderer, here on the Python 3.9 run, the script's own error comes back and no file is written:

$ python scripts/cw.py render --target matplotlib --in chart.py --out chart.png
Traceback (most recent call last):
  File "<work>\chart.py", line 1, in <module>
    import matplotlib
ModuleNotFoundError: No module named 'matplotlib'

and for Vega-Lite:

$ python scripts/cw.py render --target vega-lite --in chart.vl.json --out chart.png
vl_convert missing: pip install vl-convert-python

Both exit 0 unless --strict. A format Vega-Lite cannot write:

$ python scripts/cw.py render --target vega-lite --in chart.vl.json --out chart.gif
vega-lite renders svg, png, pdf, html

Authoring commands

These change the knowledge base in place, in the kb/ folder beside the script, whatever folder you run them from. In a Claude Code install that is the plugin's cached copy, which an update replaces, so make such changes in a clone. Afterwards, run validate and index.

note appends a dated line under the file's ## Notes heading, adding the heading if there is none:

$ python scripts/cw.py note pie "fine for two slices when the question is majority"
noted in pie.md: - 2026-10-03: fine for two slices when the question is majority
$ tail -2 kb/charts/pie.md
- 2026-09-18: Sort slices largest first, starting at 12 o'clock.
- 2026-10-03: fine for two slices when the question is majority

tested adds an entry to a target's tested: list (replacing untested) and a dated note:

$ python scripts/cw.py tested d2 --platform Linux "d2 0.7 rendered an SVG of a five-node network"
recorded in d2.md: Linux 2026-10-03: d2 0.7 rendered an SVG of a five-node network; run cw.py index

new-chart SLUG --name N --family F [--shapes S ...] [--force] writes a chart file with TODOs to fill in. The family must be one of the 13 listed on How charts are picked and built. It refuses a slug that exists unless --force is given, and validate --strict fails until the TODOs are gone. Paths print with the platform's separator; this run was on Windows:

$ python scripts/cw.py new-chart horizon --name "Horizon chart" --family change-over-time --shapes time,q*n
<work>\kb\charts\horizon.md exists (use --force)
$ python scripts/cw.py new-chart spiral --name "Spiral plot" --family change-over-time --shapes time,q
wrote <work>\kb\charts\spiral.md; fill the TODOs, then cw.py validate && cw.py index
$ python scripts/cw.py --strict validate
1 problem(s):
  - spiral.md: contains TODO
$ echo $?
1
$ python scripts/cw.py index
indexed 84 charts, 16 targets -> kb/index.json, kb/INDEX.md

new-target SLUG --name N --kind markdown|web|image|office|terminal [--force] writes a target file. Every chart file then needs a support line for it, and the new file needs a tested: line, which the stub leaves out:

$ python scripts/cw.py new-target svgsketch --name "Hand-drawn SVG" --kind image
wrote <work>\kb\targets\svgsketch.md
$ python scripts/cw.py validate | head -3
84 problem(s):
  - adjacency-matrix.md: no support entry for target 'svgsketch'
  - alluvial.md: no support entry for target 'svgsketch'
$ python scripts/cw.py validate | tail -1
  - svgsketch.md: missing frontmatter 'tested'

index and validate

$ python scripts/cw.py --strict validate
ok: 83 charts, 16 targets valid
$ echo $?
0

index rewrites kb/INDEX.md and kb/index.json, including the date in the index's header, so running it changes those files even when nothing else changed. Never edit either file by hand.

doctor and targets

doctor is on Getting started and targets on Render targets.

Messages and exit codes

Code When
0 Success, and also any problem the command reports, unless --strict.
1 With --strict: a problem, such as a missing file or column, an unknown slug or target, a failed render, or validate findings.
2 An argument error from argparse: no command, an unknown command, a missing required option, a bad choice. Always, with or without --strict.

Common messages, as printed:

$ python scripts/cw.py build --chart line --target mermaid --data nothere.csv --x date --y price
note: [Errno 2] No such file or directory: 'nothere.csv'
$ echo $?
0
$ python scripts/cw.py build --chart line --target mermaid --data prices.csv --x day --y price
column 'day' not in ['date', 'price']
$ echo $?
0
$ python scripts/cw.py --strict build --chart line --target mermaid --data prices.csv --x day --y price
column 'day' not in ['date', 'price']
$ echo $?
1
$ python scripts/cw.py build --chart line --target svg --data prices.csv --x date --y price
unknown target 'svg' (mermaid, vega-lite, plotly, chartjs, matplotlib, terminal, echarts, pptx, xlsx, quickchart, plantuml, d2, observable-plot, gsheets, docx)
$ python scripts/cw.py build --chart heatmap --target mermaid --data prices.csv --x date --y price
note: mermaid has no recipe for 'heatmap'; use an image target (cw.py show heatmap --section build)
$ python scripts/cw.py build --chart linechart --target mermaid --data prices.csv --x date --y price
note: mermaid has no recipe for 'linechart'; use an image target (cw.py show linechart --section build)
$ python scripts/cw.py build --chart line --target mermaid --data prices.csv --x date --y price --html
--html applies to vega-lite, plotly, chartjs, echarts, observable-plot

build does not check the chart slug against the knowledge base, so a misspelt slug (linechart) gets the same message as a real chart the target has no builder for. cw.py list shows the slugs.

Where each message goes

Everything goes to standard output, problems included, except two things: the note about combined repeated x values from build goes to standard error, and so do argparse's usage and error lines.

$ python scripts/cw.py build --chart bar --target terminal --data sales.csv --x region --y sales 2>/dev/null
sales by region
North  ███████████████████████████    200
South  ██████████████████████████████ 225
East   █████████████████              130

Output is written as UTF-8 whatever the console's code page, so the block characters print on a Windows console.

Clone this wiki locally