# Everything is a command you can script

Every action in Voltecx is a named command: `circuit.addComponent`, `simulation.run`, `analysis.acSweep`, `design.auto`. The menus, the command palette (Cmd+K), the command line, Python and AI assistants all call the same list of more than 170 commands. A new feature cannot ship without being reachable from all of them.

## The command line

`powercraft-cli` runs the engine without a window.

```sh
# Open the buck example, simulate it with the fast solver, measure after 3 ms
powercraft-cli run \
  --cmd file.openExample --params '{"name":"buck"}' \
  --cmd simulation.run   --params '{"solver":"fast"}' \
  --cmd scope.measure    --params '{"signals":["v(out)","i(L1)"],"t0":"3m"}' \
  --out buck.voltecx
```

Each command prints one line of JSON. `powercraft-cli commands` lists them all. `powercraft-cli convert` converts between formats, and `powercraft-cli sim` runs a saved circuit and checks numbers against limits, with an exit code your build system can read:

```sh
powercraft-cli sim pol.voltecx --tend 5m \
  --expect 'mean(v(out), 4m, 5m) in 3.2..3.4' \
  --expect 'pp(v(out), 4m, 5m) < 0.05'
```

That makes a converter design something you can test in continuous integration, like code.

Lab data goes in the same way. With a folder allowed, a scope export is named by its path, with no escaping:

```sh
powercraft-cli run --in pol.voltecx --root lab \
  --cmd simulation.run \
  --cmd file.importMeasurement --params '{"path":"scope.csv","map":{"v(out)":"CH1"}}'
```

*In the next release.* With `--root DIR`, a file opened with `--in` from that folder is saved back by `--cmd file.save`, and a command that needs a simulation first (a BOM, the scope's measurements, the stresses) says so in its error instead of stopping the chain without a reason.

## Python and Jupyter

The `powercraft` Python package runs any command by its id and returns waveforms as NumPy arrays, or a pandas DataFrame.

```python
import powercraft

s = powercraft.Session()
s.execute("file.openExample", {"name": "buck"})
s.run(solver="fast")
w = s.waveforms(["v(out)", "i(L1)"])
print(w["v(out)"].max())
```

## Scripts, batches and background jobs

- **Tools › Scripting** runs a text file of commands as one undo step, with `for` loops, `if`/`else`, `set` for arithmetic and `break`. A script that sweeps the switching frequency can stop at the first point whose ripple meets the target. Every script ends: at most 10,000 steps and 10 minutes by default, checked before and while it runs. [Example and limits](https://voltecx-web.nguyenvanqui291.workers.dev/docs/manual/13-tools-menu/#scripting).
- **Tools › Parameter Sweep** runs many cases.
- Long work runs as a background job with progress and cancel (`job.start`, `job.status`, `job.cancel`).

## Servers for agents and tools

- `powercraft-cli serve` speaks JSON-lines over stdio.
- Every command has a JSON Schema.
- The desktop app opens a token-protected local channel with `--control`, so a test or an assistant can drive the running window and take screenshots.

File access is limited to the folders you allow. Without them, nothing outside reads or writes a file.

## Files that diff

A `.voltecx` file is plain JSON that keeps numbers bit for bit, written the same way every time: saving an unchanged circuit changes no byte, and changing one value changes one line. Put it in version control and a diff shows what changed. `file.diff` compares two versions of a circuit, two runs of the Run History, or a file with the circuit you have open, including LTspice, SPICE and imported files from other simulators.

**File › Compare With File** draws the two schematics side by side, with added parts green, removed parts red and changed ones amber, and every change listed before and after. In a terminal, `powercraft-cli diff a.voltecx b.voltecx` prints a line per change, and it works as git's diff driver, so `git diff` and `git difftool` show circuit changes instead of JSON lines:

```sh
git config diff.voltecx.command 'powercraft-cli diff'
printf '*.voltecx diff=voltecx\n' >> .gitattributes
```

See the [AI assistant](https://voltecx-web.nguyenvanqui291.workers.dev/features/ai-assistant) for the assistant inside the app.
