refactor: add type-safe command interface to appInvoke#13
Merged
Conversation
Type safety issue: appInvoke used unsafe string cmd and any args, allowing
typos, wrong argument types, and incorrect return types to pass type checking.
Changes:
- Add AppInvokeCommands interface defining all commands with typed args and results
- Update appInvoke signature to use conditional types for type-safe invocation
- Remove all generic type parameters from appInvoke call sites (33 locations)
- Add 'savedAt' field to list_agent_sessions result type to match actual schema
- Update internal implementation to use typed cmdArgs instead of loose 'args'
Benefits:
- Command names are now autocompleted and typo-checked at compile time
- Argument structure is validated for each command
- Return types are inferred automatically, no manual type annotations needed
- Eliminates entire class of runtime errors from incorrect API usage
Example before:
const result = await appInvoke<any>('list_sessions', { prefix: 'typo' });
// No error, but crashes at runtime
Example after:
const result = await appInvoke('list_agent_sessions', { prefix: 'test' });
// Type error if command name or args are wrong, result type is inferred
Test results:
- ✅ 186 Rust unit tests pass
- ✅ TypeScript type check passes
ee47619 to
0b9bfa4
Compare
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
Fixes type safety issue where
appInvokeused unsafestringcmd andanyargs, allowing typos, wrong argument types, and incorrect return types to pass type checking.Changes
Type System
AppInvokeCommandsinterface defining all commands with typed args and resultsappInvokesignature to use conditional types for type-safe invocationCode Updates
appInvokecall sites (33 locations across 7 files)savedAtfield tolist_agent_sessionsresult type to match actual schemacmdArgsinstead of looseargsExample
Before (unsafe):
After (type-safe):
Benefits
Test Plan
appInvokecalls now have proper type inferenceBreaking Changes
None for runtime behavior. Type-level only: code that was previously using incorrect command names or arguments will now show TypeScript errors (which is the intended improvement).