feat(ffi-wasi): convert to JSON-RPC 2.0 protocol#352
Merged
Conversation
Replace CLI-style stdin/stdout interface with JSON-RPC 2.0: - Add jsonrpc module with request/response handling and router - Implement JSON-RPC methods: - ledger.load, ledger.loadFile, ledger.validate - query.execute - entry.clamp, entry.filter, entry.create, entry.createBatch - format.source, format.entry, format.entries - util.version, util.types, util.isEncrypted, util.getAccountType - Implement proper clamp logic with: - Balance sheet account summarization - Income/expense closing to Equity:Earnings:Previous - Price tracking for entries before date range - Add OpenRPC specification (openrpc.json) - Add README with API documentation This enables language-agnostic integration via JSON-RPC over stdin/stdout. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 task
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-02-14)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the rustledger-ffi-wasi WASI module from a CLI-style stdin/stdout command interface to a JSON-RPC 2.0 protocol, adding a router-based method dispatch layer plus an OpenRPC spec and README for client integration.
Changes:
- Replaced CLI command parsing in
main.rswith JSON-RPC request processing (jsonrpc::process_stdin). - Added JSON-RPC request/response/error types and a method router implementing ledger/query/format/entry/util methods.
- Added OpenRPC spec (
openrpc.json) and crate-level README documenting the JSON-RPC API.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-ffi-wasi/src/main.rs | Switch entrypoint to JSON-RPC stdin processing and update module docs. |
| crates/rustledger-ffi-wasi/src/jsonrpc/mod.rs | Implement stdin request parsing, routing, and response output. |
| crates/rustledger-ffi-wasi/src/jsonrpc/request.rs | Define JSON-RPC request + params structs and batch parsing. |
| crates/rustledger-ffi-wasi/src/jsonrpc/response.rs | Define JSON-RPC response and per-method result payloads. |
| crates/rustledger-ffi-wasi/src/jsonrpc/error.rs | Define JSON-RPC error codes and error object structure. |
| crates/rustledger-ffi-wasi/src/jsonrpc/router.rs | Implement JSON-RPC method dispatch and handlers for all exposed methods. |
| crates/rustledger-ffi-wasi/src/commands/clamp.rs | Refactor clamp/filter logic into reusable functions for JSON-RPC methods. |
| crates/rustledger-ffi-wasi/src/commands/query.rs | Refactor query execution into a pure function returning QueryOutput. |
| crates/rustledger-ffi-wasi/src/commands/load.rs | Keep LoadFullOutput type for ledger.loadFile response. |
| crates/rustledger-ffi-wasi/src/commands/util.rs | Retain util types (TypesOutput, MissingSentinel) used by router. |
| crates/rustledger-ffi-wasi/src/commands/mod.rs | Narrow commands module to types/helpers used by JSON-RPC. |
| crates/rustledger-ffi-wasi/src/types/input.rs | Add Debug derives for JSON-RPC param deserialization debugging. |
| crates/rustledger-ffi-wasi/src/types/output.rs | Remove legacy CLI output types no longer used (e.g., VersionOutput). |
| crates/rustledger-ffi-wasi/src/types/mod.rs | Stop re-exporting removed legacy output types. |
| crates/rustledger-ffi-wasi/openrpc.json | Add OpenRPC definition for the JSON-RPC surface area. |
| crates/rustledger-ffi-wasi/README.md | Add usage and method documentation for the new JSON-RPC API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
🧪 CI InsightsHere's what we observed from your CI run for 4cf86a7. 🟢 All jobs passed!But CI Insights is watching 👀 |
Fixes from Copilot code review:
- Fix booking_methods list: remove REDUCE, add STRICT_WITH_SIZE
- Fix format.entries: use concat() instead of join("\n") to avoid extra newlines
- Fix clamp sort stability: add deterministic tiebreakers (type priority, hash)
- Fix batch parsing: parse each element individually per JSON-RPC 2.0 spec
- Fix OpenRPC columns schema: use ColumnInfo objects instead of strings
- Fix cost parsing: fall back to Position::simple for invalid costs
- Fix price tracking: use >= for same-day prices (last wins)
- Fix filter_entries: drop invalid dates consistently with clamp_entries
- Fix OpenRPC TypesOutput: add missing MissingSentinel field
- Fix clippy warnings: const fn, collapsible if, format strings, semicolons
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Per JSON-RPC 2.0 spec, invalid elements in a batch should return individual error responses rather than failing the entire batch. Changes: - Add BatchElement enum to represent valid/invalid request elements - Parse batch elements individually, preserving IDs for error responses - Mark entry.clamp date params as required in OpenRPC spec - Add 12 unit tests for clamp/filter functionality - Add integration tests for batch error handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
JSON-RPC Methods
ledger.loadledger.loadFileledger.validatequery.executeentry.clampentry.filterentry.createentry.createBatchformat.sourceformat.entryformat.entriesutil.versionutil.typesutil.isEncryptedutil.getAccountTypeTest plan
🤖 Generated with Claude Code