Skip to content

AI Suggestion Core #29

Description

@Omoshirokunai

What

Implement the non-blocking suggestion generation system in the service worker.

Core Components

1. Suggestion Queue (src/lib/ai/suggestion-queue.js)

  • Debounces keystroke events at 500ms (user perceives as instant)
  • Routes suggestions through fast brain (instant) then slow brain (async)
  • Stores results in chrome.storage.local.suggestions
  • Fires SUGGESTIONS_READY message to UI

2. Ollama Client (src/lib/ai/ollama-client.js)

  • Async HTTP client to http://localhost:11434/api/generate
  • 2000ms timeout and then fast fallback to second brain
  • Provides: sentence completion, paraphrase
  • Handles connection failures silently
  • No blocking on the calling thread

3. second brain (src/lib/ai/heuristic-brain.js)

  • Returns suggestions in <5ms
  • Provides:
    • Word completion predictions (no AI)
    • Synonym detection (word frequency lookup)
    • Grammar error detection (regex)
    • Pattern detection (e.g., "According to...")
  • Gracefully handles empty/short input

Acceptance Criteria

  • SuggestionQueue queues with 500ms debounce
  • HeuristicBrain.suggest() returns in <5ms, no async calls
  • OllamaClient.suggest() has 2000ms timeout
  • Suggestions stored in chrome.storage.local.suggestions
  • Service worker integration: LOG_EVENT 'edit' triggers enqueue (no await)
  • GET_SUGGESTIONS message handler returns stored suggestions
  • No typing lag observed (content script unaffected)

Metadata

Metadata

Labels

CoreFoundation extension functionalitypath-aOllama / local AI path

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions