Phase 3: Patch library — SQLite storage, tools, and tests#6
Merged
Conversation
Add PatchLibrary with SQLite storage for saving, loading, recalling, listing, and deleting named synth patches. Recall sends all saved CC values back to hardware to restore a sound. New files: - patchwork/patch_library.py: PatchLibrary class, Patch dataclass - patchwork/tools/patches.py: save/load/recall/list/delete patch tools - tests/test_patch_library.py: 13 tests for database operations - tests/test_patch_tools.py: 18 tests for tool functions - data/.gitkeep: track data directory for runtime DB Modified: - patchwork/deps.py: add patches field to PatchworkDeps - patchwork/agent.py: register patch tools, update system prompt - patchwork/cli.py: initialize and close PatchLibrary - tests/test_midi_control_tools.py: update helper for new deps field - .gitignore: ignore data/*.db instead of entire data/
- save_patch: validate CC values against value_range before saving - save_patch: reject cross-synth overwrites (same name, different synth) - recall_patch: skip out-of-range values with warning (matches send_patch) - recall_patch: fix MIDI-not-connected message to match midi_control.py - load_patch: show updated_at instead of created_at - cli.py: use PatchLibrary context manager, fix except syntax - Add tests: value-range validation, cross-synth rejection, empty settings, same-synth overwrite, recall out-of-range skip, operations after close
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a SQLite-backed patch library so users can save, list, load, recall, and delete named patches. A "recall" sends all saved CC values back to the hardware synth, restoring the sound. This completes the core save/recall workflow described in the master plan.
How
patchwork/patch_library.py: NewPatchLibraryclass wrapping SQLite withPatchdataclass. Supports upsert semantics (same-synth re-save overwrites, cross-synth overwrite rejected), case-insensitive synth filtering, JSON settings roundtrip, context manager protocol, and WAL journal mode. Schema matches the master plan.patchwork/tools/patches.py: Five agent tools (save_patch,load_patch,recall_patch,list_patches,delete_patch) following the same patterns as the MIDI control tools —RunContext[PatchworkDeps], string returns, descriptive error messages.save_patchnormalizes parameter keys to canonical form before storage and validates CC values againstvalue_range(parity withsend_cc/send_patch).recall_patchcomposes the DB and MIDI layers to restore patches to hardware, skipping out-of-range values with warnings.patchwork/deps.py: Addedpatches: PatchLibraryfield toPatchworkDeps.patchwork/agent.py: Registered all 5 patch tools and updated system prompt with tool descriptions and usage instructions.patchwork/cli.py: UsesPatchLibrarycontext manager for safe cleanup, fixedexceptsyntax bug.data/.gitkeep+.gitignoreupdate: Tracksdata/directory but ignores*.dbfiles.Follow-up Issues
{synth}/{name}) to allow the same patch name across different synths. Requires DB migration (Alembic).Recommended Review Order
patchwork/patch_library.py— core data layerpatchwork/tools/patches.py— agent tool layer, validation, cross-synth guardpatchwork/deps.py— small change, new fieldpatchwork/agent.py— tool registration and prompt updatespatchwork/cli.py— context manager wiring, except syntax fixtests/test_patch_library.py— 14 data layer teststests/test_patch_tools.py— 24 tool layer teststests/test_midi_control_tools.py— minimal update for new deps field