Skip to content

feat(v0.2.4): persistent design store (closes #2)

Choose a tag to compare

@JLay2026 JLay2026 released this 10 Jun 03:24
First v0.3.0 Theme 1 (author ergonomics) item.

Designs are saved to disk under {workspace}/designs/ as {name}.py
(source) + {name}.json (metadata: timestamps, description, geometry
snapshot). Survive container restart; models are still in-memory only.

Two-file persistence (source + sidecar) instead of single JSON so the
source is human-readable on disk (cat workspace/designs/bracket.py)
and git-friendly if the workspace is ever versioned. Sidecar is
bookkeeping that can be regenerated from defaults if missing or corrupt.

API surface:

REST (5 new endpoints):
  POST   /design/save           — save (also executes for geometry snapshot)
  GET    /design/list           — list all (cheap, uses snapshots)
  GET    /design/{name}         — load source + metadata, no execution
  DELETE /design/{name}         — remove .py + .json
  POST   /design/{name}/load    — load + execute as model

MCP (4 new tools):
  partsmith_save_design(name, code, description="")
  partsmith_load_design(name)
  partsmith_list_designs()
  partsmith_delete_design(name)

Design notes:
- save() always tries to execute the code so geometry can be snapshotted
  for list() efficiency. If execution fails the save still succeeds —
  source is the source of truth.
- save() also registers the result as an in-memory model so the design
  is immediately available for render/measure/export without a separate
  partsmith_create_model call. Matches likely workflow.
- Same NAME_PATTERN validation as models. Path-traversal defense via
  resolved-path-relative-to check (belt+braces on top of regex).
- Thread-safety: not safe for concurrent writes to the same name.
  partsmith is single-tenant single-process by design (single uvicorn
  worker), so this is acceptable.

Files:
- src/design_store.py — NEW (~180 LOC, full module with docstrings)
- src/server.py — adds 5 REST endpoints, instantiates store, passes to build_mcp
- src/mcp_transport.py — accepts store kwarg, adds 4 MCP tools
- src/__init__.py — version 0.2.4
- pyproject.toml — version 0.2.4
- CHANGELOG.md — v0.2.4 entry with design notes

Validation:
- py_compile clean on all .py files
- ruff check (E,F,I,W) clean

Resolves #2.