Skip to content

feat(suggestions): Implement typing suggestion feature for inline autocomplete - #759

Merged
haiphucnguyen merged 6 commits into
mainfrom
feature/ai-suggestion
Oct 11, 2026
Merged

haiphucnguyen merged 6 commits into
mainfrom
feature/ai-suggestion

Conversation

@haiphucnguyen

Copy link
Copy Markdown
Collaborator

Summary

  • Introduces learned phrase suggestions for inline autocomplete during chat.
  • Suggestions are based on generalized typing habits, never storing raw message content.
  • The system refreshes habits using messages across all past chat sessions.
  • Adds dedicated settings UI for managing and resetting learned suggestions.
  • Updates database schema and core services to handle persistent suggestion storage.

Related Issue(s)

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

…ocomplete

- Introduces learned phrase suggestions for inline autocomplete during chat.
- Suggestions are based on generalized typing habits, never storing raw message content.
- The system refreshes habits using messages across all past chat sessions.
- Adds dedicated settings UI for managing and resetting learned suggestions.
- Updates database schema and core services to handle persistent suggestion storage.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 00:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Default cloud transmission, reset races, stale completions, refresh gating, and empty license notices must be addressed.

8 open findings
What changed in this PR

Adds learned inline autocomplete to desktop chat using session history and AI-derived phrase habits.

Changes:

  • Adds suggestion services, persistence, refresh gating, and schema migration.
  • Integrates ghost-text completion and suggestion controls into the desktop UI.
  • Adds localized settings and native-image metadata.
File Description
THIRD-PARTY-NOTICES.txt Regenerates dependency notices.
SchemaMigrationEquivalenceTest.kt Includes the suggestions table.
migrations/​63.sqm Creates suggestion storage.
UserPhraseSuggestions.sq Defines suggestion queries.
ChatMessages.sq Adds global message queries.
UserMessageAddedEvent.kt Introduces refresh-triggering event.
DatabaseManager.kt Registers the new repository and adapter.
AppConfig.kt Adds suggestion configuration.
SuggestionService.kt Defines the suggestion interface.
PhraseHabitRefreshService.kt Extracts and refreshes learned habits.
PersistedPhraseSuggestionService.kt Serves cached learned phrases.
HistoryBackedSuggestionService.kt Suggests from session history.
CompositeSuggestionService.kt Combines suggestion sources.
UserPhraseSuggestionRepository.kt Implements persistence and eviction.
ChatMessageRepository.kt Emits events and exposes refresh queries.
AdvancedSettingsSection.kt Adds controls and reset behavior.
Main.kt Starts background extraction.
DesktopModule.kt Registers suggestion dependencies.
messages.properties Adds English strings.
messages_zh_TW.properties Adds Traditional Chinese strings.
messages_zh_CN.properties Adds Simplified Chinese strings.
messages_vi_VN.properties Adds Vietnamese strings.
messages_pt_BR.properties Adds Portuguese strings.
messages_ko_KR.properties Adds Korean strings.
messages_ja_JP.properties Adds Japanese strings.
messages_fr.properties Adds French strings.
messages_es.properties Adds Spanish strings.
messages_de.properties Adds German strings.
ChatInputField.kt Renders and accepts ghost text.
reachability-metadata.json Updates native-image metadata.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread THIRD-PARTY-NOTICES.txt Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Comment on lines +232 to +233
val wordCount = phrase.trim().split(Regex("\\s+")).size
if (wordCount < MIN_SUSPICIOUS_WORDS) return false
var inlineSuggestion by remember { mutableStateOf<String?>(null) }
LaunchedEffect(inputText.text, inputText.selection, sessionId) {
val text = inputText.text
val cursorAtEnd = inputText.selection.start == text.length
Comment on lines +832 to +848
if (enabled) {
Row(
horizontalArrangement = Arrangement.spacedBy(Spacing.small),
verticalAlignment = Alignment.CenterVertically,
) {
dangerButton(onClick = { showConfirmDialog = true }) {
Text(stringResource("settings.suggestions.reset"))
}

AnimatedVisibility(visible = showResetSuccess, enter = fadeIn(), exit = fadeOut()) {
Text(
text = stringResource("settings.suggestions.reset.success"),
style = AppTextStyles.caption,
)
}
}
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Privacy fail-safes, raw-content filtering, native metadata, and capacity enforcement contain unresolved defects.

9 open findings
1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Opt-out failure can leave privacy setting unsaved

desktop/​src/​main/​kotlin/​io/​askimo/​desktop/​settings/​AdvancedSettingsSection.kt:828

The opt-out is not durably fail-safe. AppConfig.updateField updates its cache before writing and throws on a write failure, so this handler can leave the switch looking disabled for the current process while the saved value remains enabled; after restart, message excerpts can be sent again. This privacy control needs to persist atomically (or roll back/fail closed), and the UI must surface a save failure rather than letting it escape the event handler.

🧠 Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +57 to +58
.filterIsInstance<UserMessageAddedEvent>()
.collect { onUserMessageAdded(it.content) }

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Consent persistence, raw-content filtering, native metadata, and eviction correctness issues remain unresolved.

5 open findings
2 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity New variant can be immediately selected for eviction

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​repository/​UserPhraseSuggestionRepository.kt:130

The new variant participates in its own eviction selection. If the wall clock moves backward (the case explicitly handled for category eviction below), every existing variant can have a later updatedAt, causing the just-inserted variant to be immediately deleted and the new phrase silently discarded. Exclude newId from eviction candidates as is done for new categories.

Medium severity Checkpoint read errors incorrectly trigger paid provider calls

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​service/​PhraseHabitRefreshService.kt:183

A checkpoint read failure is treated exactly like “no checkpoint,” so a transient database error bypasses both persisted refresh gates and triggers another paid provider call. Fail closed on repository errors and reserve null for the successful no-checkpoint result.

🧠 Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved persistence, privacy, cache invalidation, eviction, and native-image metadata defects affect correctness and user data handling.

5 open findings
1 resolved since last review
Previously missed (3)

In code that hasn't changed since last review

Medium severity Exclude the newly inserted variant from eviction

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​repository/​UserPhraseSuggestionRepository.kt:130

The newly inserted variant participates in its own eviction. If existing rows have equal/future timestamps (clock rollback—the category path below explicitly handles this), minBy can immediately delete newId, so a full category cannot learn new variants until the clock catches up. Evict only from the variants that existed before this insertion.

Medium severity Allow autocomplete matching when sessionId is null

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​service/​HistoryBackedSuggestionService.kt:65

A new-chat ChatView has a null sessionId, so this gate disables the always-on local history autocomplete precisely while the user drafts the first message. The service does not otherwise scope by session, so null should not prevent matching.

Medium severity Invalidate cached profiles after refresh failures

shared-jvm/​src/​main/​kotlin/​io/​askimo/​core/​chat/​service/​PersistedPhraseSuggestionService.kt:63

On a refresh failure for an already cached profile, leaving cachedProfileId unchanged prevents the documented retry: subsequent suggest calls see the same profile ID and never call refreshCache again. This can leave newly merged rows unavailable indefinitely and can continue serving deleted rows after a reset that reports success. Invalidate the cache on failure so the next call retries and cannot serve stale data.

🧠 Review effort: Balanced

@haiphucnguyen
haiphucnguyen merged commit 7d49120 into main Oct 11, 2026
12 of 13 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/ai-suggestion branch October 11, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants