Metadata-Version: 2.5
Name: agentslicer
Version: 0.2.0
Summary: Let AI agents slice with OrcaSlicer, see the result, and run a Bambu Lab printer over LAN, via MCP
Project-URL: Repository, https://github.com/jasoncronje/agentslicer
Author: Jason Cronje
License-Expression: AGPL-3.0-only
License-File: LICENSE
Keywords: 3d-printing,agent,bambu-lab,mcp,orcaslicer,slicer
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Printing
Requires-Python: >=3.11
Requires-Dist: av>=14
Requires-Dist: matplotlib>=3.9
Requires-Dist: mcp==2.3.0
Requires-Dist: numpy>=2.0
Requires-Dist: paho-mqtt>=2.1
Provides-Extra: calib
Requires-Dist: opencv-python-headless>=4.10; extra == 'calib'
Description-Content-Type: text/markdown

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="brand/social/readme-banner-dark.png">
  <img alt="agentslicer" src="brand/social/readme-banner-light.png">
</picture>

# AgentSlicer

Let an AI agent slice with OrcaSlicer, look at the result, and run a Bambu Lab printer over LAN (tested on a P2S), through MCP.

AgentSlicer is built on top of your OrcaSlicer install, not beside it: it uses Orca's own profiles (and your own custom presets from Orca), the printers you connected in Orca, and Orca's CLI. There is nothing to configure.

## Requirements

- [OrcaSlicer](https://github.com/OrcaSlicer/OrcaSlicer/releases) (macOS, Linux or Windows). No display needed: slicing runs through Orca's CLI. Found in the usual install locations, or set `AGENTSLICER_ORCA` to its executable.
- [uv](https://docs.astral.sh/uv/getting-started/installation/).
- For printer control: the printer connected in Orca's Device tab in LAN mode, with Developer Mode on.

## Install

**Claude Code** (MCP server + skill):

```
/plugin marketplace add jasoncronje/agentslicer
/plugin install agentslicer@agentslicer
```

**Any MCP client:** run `uvx agentslicer` as a stdio server, e.g.

```json
{ "mcpServers": { "agentslicer": { "command": "uvx", "args": ["agentslicer"] } } }
```

The workflow and safety rules for agents live in [`skills/agentslicer/SKILL.md`](skills/agentslicer/SKILL.md) (`npx skills add jasoncronje/agentslicer` for other agents); the server also sends a short version as MCP instructions.

**Without MCP:** `uvx --from agentslicer agentslicer-printer status|frame|light|upload|print|pause|resume|stop|clear-error`.

## How it uses Orca

- **Profiles:** read from the preset caches Orca ships and updates (`<vendor>.opc`), so slicing works offline and matches the app exactly.
- **Printers:** read from Orca's config (`OrcaSlicer.conf` → `local_machines`): name, IP, serial and access code of every LAN printer you connected. With several printers, `slice` and every printer tool take `printer` (name or serial); the default is the one selected in Orca. `list_printers(status=true)` shows each one's state, nozzle and loaded filaments, and each printer has its own background monitor.
- **Settings catalogue** (`find_settings`): setting labels, ranges and the tab layout exist only in Orca's source, so three source files are downloaded once per Orca version.
- Everything derived is cached in `~/.cache/agentslicer/` and rebuilt automatically when Orca or its profiles update. `uvx --from agentslicer python -m agentslicer.slicer.sync` shows the status.

## Docker

```sh
docker build -t agentslicer .
docker run -i --rm --network host \
  -v ~/.config/OrcaSlicer:/root/.config/OrcaSlicer:ro \
  -v agentslicer-cache:/root/.cache/agentslicer \
  agentslicer
```

Mount your OrcaSlicer config folder (above: Linux path; macOS `~/Library/Application Support/OrcaSlicer`, Windows `%APPDATA%\\OrcaSlicer`) so the container sees the printers you connected in Orca. The image bundles Orca's Linux build (extracted AppImage, x86_64 or arm64) and runs the MCP server over stdio. The bridge only makes outbound connections to the printer (MQTT, FTPS, RTSPS); `--network host` is the simplest setup on Linux. Printer control from inside Docker is not tested yet.

## Development

```sh
uv run agentslicer              # the MCP server, from this checkout
uv run --with pytest pytest tests  # fast checks: no Orca slice, no printer
uv run python scripts/smoke.py  # printer-free end-to-end check
claude plugin validate .
```

CI runs the smoke test on Linux without a display, in Docker and on Windows. Releases: bump the version in `pyproject.toml` only, commit, and push a `vX.Y.Z` tag. The release workflow publishes to PyPI, waits until the version is installable (PyPI plus uv's 10-minute index cache), and only then points the Claude Code plugin at it on `main`. Don't edit the plugin's version by hand.

## Tools

| Tool | Does |
|---|---|
| `list_profiles` | Orca machine / process / filament profile names, system and your own (`custom`); for filaments also Orca's filament library of other brands (`library`) |
| `find_settings` | All 600+ Orca settings: browse by tab/page, search by name or print problem, full detail (type, range, allowed values, default, profile value; the profiles default as in `slice`) |
| `plate_layout` | Bed size and each part's footprint, plus a tight one-plate packing, to plan a plate. The machine defaults as in `slice` and is named in the result |
| `slice` | Models → `.gcode.3mf`, with setting overrides and plate layout (Orca's arrange, tight one-plate `pack`, or exact `placements`); returns time, weight, filament use, iso and plate previews. A result with several plates reports each plate's time, weight, filaments and parts (`plates_detail`), their `total`, and a plate view per plate (up to 6); the top-level numbers are plate 1's. Machine, process, filament and bed type left out follow your OrcaSlicer setup (selected printer; process, filament and plate last used with it); the `used` block says what was used and whether it came from the caller, Orca or a default. For a project 3MF also `model_wants` (the filaments, printer, nozzle and bed type it was made for) and `model_warnings` where the slice differs; refuses a model that prints in more filaments than it was given |
| `sliced_info` | Estimates for an existing `.gcode.3mf`: per plate (`plates_detail`) and in total; `plate=N` puts that plate's time, weight and filaments at the top level |
| `analyze_print` | Layers, per-feature path/filament, bridge / overhang / support layers, seams |
| `preview` | Toolpath image: `iso` / `top` / `front` / one `layer` (seams marked) / `plate` (whole bed, parts labelled); `highlight` features |
| `plan_ams_mapping` | Which AMS slot each filament prints from (Orca's own matching), with warnings |
| `set_ams_filament` | Set what an AMS slot or the external spool holds (system or custom filament profile + colour), like Orca's slot editor; RFID spools are read-only |
| `list_printers` | Printers connected in Orca; `status=true` adds each one's live state, job, nozzle size and loaded filaments (an offline printer is listed as not reachable) |
| `printer_status` | State, current step, temps, AMS trays, the print error code and each HMS message with its text |
| `camera_frame` | One chamber camera image |
| `chamber_light` | Light on/off |
| `start_print` | Upload + start with automatic AMS mapping. One plate per call (`plate=N`); a multi-plate file is one print job per plate. Refuses unless `user_confirmed=true`, when the file was sliced for another printer model or nozzle size, and when the AMS plan has warnings (pass the plan back as `ams_slots` or set `accept_ams_warnings=true`). Timelapse and the calibrations default to your last choices in Orca's Print dialog; the `used` block names each one and its source |
| `pause_print` / `resume_print` | Pause the running print / continue a paused one. Resume refuses unless `user_confirmed=true`; both refuse when the printer's state doesn't fit |
| `stop_print` / `clear_error` | Cancel a print (cannot be resumed) / dismiss its error |
| `start_monitoring` / `monitor_events` / `stop_monitoring` | Background watcher, one per printer (`printer`): state/step/layer/error events, camera frames every N layers, on pause, fail and finish. Logs are in a folder per printer |
| `check_progress` | Camera frame next to a render of what should be printed by the current layer; the frame alone when the printer is running another job or hasn't reached layer 1 |

## Notes (verified on P2S, Orca 2.5.3)

- Custom presets are read from Orca's active user folder (`user/<preset_folder>` in Orca's data dir, as Orca loads them). Every tool that takes a profile name takes them. For slicing, the CLI resolves their `inherits` against Orca's installed system profiles, so `slice` passes `--datadir` (read only) when one is used. A custom filament that builds on an Orca preset gets that preset's filament id, as in Orca, so on the printer an AMS slot set to "OVERTURE PLA Basic" shows as Generic PLA, with the custom preset's type, colour and temperatures.
- Orca's filament library (`OrcaFilamentLibrary`, about 1,060 filaments of other brands) is listed by `list_profiles` as `library` and taken by `slice` by name. About a third name the printers they are made for; the "@System" ones fit every printer and are found by brand or material, not by printer name. Orca's CLI resolves them from the unpacked library tree as it does Bambu's (`PresetBundle::resolve_preset_config`). Not carried over: Orca's app hides an "@System" filament on a printer that has its own preset of the same name, and `set_ams_filament` doesn't take library names yet. Read from Orca 2.5.3's source and profiles; a slice with one has not been run.
- Your Orca choices are read from `OrcaSlicer.conf` (`agentslicer/slicer/orca_choices.py`): the selected printer from `presets.machine`; the process, slot 1 filament and plate last used with a printer from its `orca_presets` entry (bed type is the `BedType` enum's number, 6 = Supertack); the Print dialog options from the section named after the printer's model code (`N7` for the P2S). The `print` section is not used: Orca fills it with "1" itself and only its multi-printer send page reads it. An Orca choice is skipped, with the reason in `orca_skipped`, when the profile doesn't exist here or its `compatible_printers` doesn't list the machine.
- The Orca CLI resolves profile `inherits` itself when given system profile files from a vendor tree with its manifest (`profiles/BBL.json` in the cache). It leaves `printer_model_id` blank, so `slice` patches it (P2S = N7).
- The printer moves uploaded files to `/cache` after a print; `start_print` uploads every time.
- Print options `auto_bed_leveling`, `extrude_cali_flag`, `nozzle_offset_cali` take 0/1/2 = off/on/auto (Orca `PrintOption::getValueInt`). Wire format reference: `agentslicer/bridge/fixtures/orca-project_file-p2s.json`.
- Nothing Orca-version-specific lives in the repo. `agentslicer/slicer/opc.py` reads Orca's preset caches (`PresetCacheFormat.cpp`'s format) and unpacks them into the JSON tree the CLI resolves `inherits` against; it is rebuilt whenever Orca's caches change. `agentslicer/slicer/catalog.py` parses the installed version's `PrintConfig.cpp`, `Tab.cpp` (and `PublishSettings.cpp` where present), downloaded over HTTPS. A release without a source tag (nightly) only loses `find_settings`. If a newer Orca yields 10% fewer settings than the last version, `find_settings` warns that the parser may need updating.
- Plate layout: Orca's CLI arrange moves what doesn't fit to another plate. `arrange="pack"` and `placements` instead transform the meshes here (`agentslicer/slicer/layout.py`: STL/OBJ/3MF, one part per 3MF object) and slice them with `--arrange 0`, which keeps every object where it is. A 3MF's process settings are kept; its per-object settings and paint are not. Modifiers and support blockers or enforcers are dropped and listed in `layout_warnings`; a 3MF with a negative part is refused, since dropping it would change the shape (use `arrange="orca"` or `"off"`).
- Setting overrides go to the CLI as `--key=value`; a bare `--enable-support 1` makes Orca read `1` as an input file.
- Previews are drawn from the G-code's own `; FEATURE:` / `; CHANGE_LAYER` annotations (`agentslicer/render/`), no GPU needed.
- Verified end to end on the P2S (2026-11-29): Orca slice → monitor → start_print → step, layer, frame and finish events → check_progress mid-print.
- `check_progress` renders through a calibrated model of the P2S chamber camera (`agentslicer/render/cameras/p2s.json`): Kannala-Brandt fisheye, ~117° horizontal FOV, 0.37 px rms over 5 bed heights. Recalibrate: print test/camera_calib_plate.stl, run `uv run python -m agentslicer.render.capture_calib DIR` (moves the bed), then `uv run --extra calib python -m agentslicer.render.calibrate DIR`.
- AMS mapping is a port of Orca's `DevMappingUtil::ams_filament_mapping`: material type must match, then the closest colour by Orca's colour distance (which feeds 0-255 values into a 0-1 formula; kept so picks match Orca's Print dialog), ties to the same filament id. Pass `filament_colors` to `slice` so the file's colours match the loaded spools; Orca's default is orange.
- Step names come from Orca's `get_stage_string`; error texts from Bambu's HMS tables, fetched the way Orca's `HMSQuery` does (only the 3-character model prefix of the serial is sent). An HMS message's 16-digit code is built from its `attr` and `code` as in Orca's `DevHMSItem::get_long_error_code`.

## License

AGPL-3.0, as OrcaSlicer: parts of AgentSlicer are ports of Orca code (preset cache format, AMS mapping, settings definitions).
