refactor: add type-safe persisted signals for KV store #7355
+328
−51
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
Add type-safe
kv.signal()helper and migrate UI settings to use persisted signals, eliminating repetitive boilerplate and adding type safety.Key Improvements
✅ Fixed unused
kv.signal()helper - Now returns proper SolidJS signal tuple✅ Added comprehensive
KVSchemainterface - Type safety for all 12 persisted settings✅ Eliminated repetitive toggle boilerplate - 5+ lines of boilerplate removed per toggle
✅ Maintained backward compatibility - Existing
kv.get()/kv.set()calls still work✅ Added comprehensive test suite - 11 tests covering persistence, type safety, and signal logic
Changes Made
packages/opencode/src/cli/cmd/tui/context/kv.tsx)KVSchemainterface with JSDoc documentation for all persisted settings:sidebar: "show" | "hide" | "auto"thinking_visibility: booleantimestamps: "show" | "hide"tool_details_visibility: booleanassistant_metadata_visibility: booleanscrollbar_visible: booleananimations_enabled: booleanterminal_title_enabled: booleantips_hidden: booleandismissed_getting_started: booleanopenrouter_warning: booleantheme_mode: "dark" | "light"theme: stringkv.signal()implementation to return proper SolidJS signal tuple with automatic persistenceget()/set()methodspackages/opencode/src/cli/cmd/tui/routes/session/index.tsx)Before: Manual
createSignal(kv.get(...))pattern with repetitive toggle handlersAfter: Clean
kv.signal(...)calls with simplified 3-line toggle handlersMigrated Signals:
sidebar- 3-state toggle (auto/show/hide)showThinking- Boolean visibility toggleshowTimestamps- String toggle ("show"/"hide") with boolean conversionshowDetails- Boolean visibility toggleshowAssistantMetadata- Boolean visibility toggleshowScrollbar- Boolean visibility toggleanimationsEnabled- Boolean visibility togglepackages/opencode/src/cli/cmd/tui/app.tsx)terminalTitleEnabledto usekv.signal()test/cli/tui/kv-integration.test.ts- 5 teststest/cli/tui/kv-signal-logic.test.ts- 6 testsImpact Assessment
📊 Code Quality Improvements
🛡️ Behavior Preservation
kv.get()/kv.set()calls continue to workkv.jsonfile structure unchanged⚡ Performance
Testing Performed
✅ Automated Testing
✅ Manual Testing
kv.signal()logic testsMigration Path for Future
Phase 1 (This PR) ✅
KVSchemawith JSDoc documentationkv.signal()implementationkv.signal()Phase 2 (Optional Follow-up)
kv.get()calls in UI components (inline usage)kv.jsonformatsTechnical Details
Type Safety Benefits
// Before (any types):
const [showThinking, setShowThinking] = createSignal(kv.get("thinking_visibility", true))
setShowThinking((prev) => {
const next = !prev
kv.set("thinking_visibility", next) // Could be any value
return next
})
// After (fully typed):
const [showThinking, setShowThinking] = kv.signal("thinking_visibility", true)
setShowThinking((prev) => !prev) // Automatically persisted, type-safe
Simplified Toggle Pattern
Before (7 lines):
onSelect: (dialog) => {
setShowThinking((prev) => {
const next = !prev
kv.set("thinking_visibility", next)
return next
})
dialog.clear()
},
After (3 lines):
onSelect: (dialog) => {
setShowThinking((prev) => !prev)
dialog.clear()
},
Breaking Changes
None - This is a pure additive improvement with full backward compatibility.
Files Changed
Checklist for Reviewers