Skip to content

feat(ai): device-aware Ollama recommendation + one-click pull#198

Merged
qnbs merged 5 commits into
mainfrom
feat/ollama-device-pull
Jun 21, 2026
Merged

feat(ai): device-aware Ollama recommendation + one-click pull#198
qnbs merged 5 commits into
mainfrom
feat/ollama-device-pull

Conversation

@qnbs

@qnbs qnbs commented Jun 21, 2026

Copy link
Copy Markdown
Owner

User description

Summary

PR E of the Critical & Immediate hardening sequence. Turns the static Ollama model hint into a "recommended for your device" chip with a real one-click install, plus battery-aware sizing.

Changes

  • pullOllamaModel(name, {baseUrl, signal, onProgress}) (services/ollamaService.ts) — POST /api/pull, streams NDJSON progress (status + byte fraction). Surfaces Ollama's in-band {error} lines as thrown errors, propagates AbortError unchanged for cancel, and reports unreachable-server / non-200 distinctly.
  • getOllamaModelForDevice(report) (services/ai/modelRecommendations.ts) — curated tiered catalog (high-end qwen2.5:7b / mid-range llama3.2:3b / low-end llama3.2:1b) driven by the profiler's deviceClass. Steps down one tier on low battery (battery/perf hardening) and flags the downgrade.
  • OllamaDevicePull (components/settings/) — recommendation chip (reuses PR B's Badge) + Pull button with live progress bar, cancel, error+retry, and "use this model"; wired into the Ollama provider block in AiSections.
  • i18n: 10 ollamaPull.* keys (5 core translated; Beta/RTL EN-fallback) + bundles.
  • Tests: pullOllamaModel (progress/abort/inline-error/non-200/empty-name — 8), getOllamaModelForDevice (tier + battery downgrade — 6), OllamaDevicePull (render/pull-success/error-retry/abort/battery — 5).
  • Tauri CSP already allows localhost:11434 / 127.0.0.1:11434 — no change needed.

Verification

  • check-suppressions (52) · lint · typecheck (exit 0) · i18n:check (17 locales / 2776 keys) green.
  • 41 new/updated tests pass; AiSections existing tests unaffected (default provider gemini).

🤖 Generated with Claude Code


CodeAnt-AI Description

Show a device-based Ollama recommendation and let users install it in one step

What Changed

  • The Ollama settings area now shows a model recommended for the current device, with a clear size hint and a note when a smaller model is chosen to save battery.
  • Users can pull the recommended model directly from settings, watch download progress, cancel the pull, retry on failure, and apply the installed model right away.
  • Ollama pulls now report reachability problems, server errors, and Ollama’s own error messages as clear failures instead of stopping silently.

Impact

✅ Faster model setup
✅ Fewer failed Ollama installs
✅ Clearer device-fit recommendations

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

PR E of the 1.24.0 hardening sequence. Turns the static Ollama hint into a
"recommended for your device" chip with a real one-click install, plus
battery-aware model sizing.

- services/ollamaService.ts: pullOllamaModel(name, {baseUrl, signal, onProgress})
  — POST /api/pull, streams NDJSON progress (status + byte fraction), surfaces
  Ollama's in-band {error} lines as thrown errors, propagates AbortError unchanged
  for cancel, and reports unreachable-server / non-200 distinctly.
- services/ai/modelRecommendations.ts: getOllamaModelForDevice(report) — curated
  tiered catalog (high-end qwen2.5:7b / mid-range llama3.2:3b / low-end llama3.2:1b)
  driven by the profiler's deviceClass; steps down one tier on low battery
  (battery/perf hardening) and flags the downgrade.
- components/settings/OllamaDevicePull.tsx: recommendation chip (reuses the PR B
  Badge) + Pull button with live progress bar, cancel, error+retry, and
  "use this model"; wired into the Ollama provider block in AiSections.
- i18n: 10 ollamaPull.* keys (5 core translated, Beta/RTL EN-fallback) + bundles.
- Tests: pullOllamaModel (progress/abort/error/non-200/empty-name, 8),
  getOllamaModelForDevice (tier + battery downgrade, 6), OllamaDevicePull (5).
- Tauri CSP already allows localhost:11434 — no change needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldscript-studio Ready Ready Preview, Comment Jun 21, 2026 1:34pm

@codeant-ai codeant-ai Bot added the size:XL This PR changes 500-999 lines, ignoring generated files label Jun 21, 2026
Comment thread locales/el/settings.json Outdated
Comment thread components/settings/AiSections.tsx
Comment thread services/ollamaService.ts Outdated
…eta locales

CodeAnt wave-1 on PR E:
- ollamaService.pullOllamaModel: wrap the read loop in try/finally and cancel the
  reader in finally, so an inline {error} throw (or any parse error) can't leave the
  HTTP body streaming in the background (resource leak).
- AiSections "use this model": recommended tags aren't in the known-options list, so
  applying one takes the custom-model path — sync setCustomModelInput so the selector
  isn't left showing a stale custom value.
- i18n: replace the English-fallback ollamaPull.* values with proper translations
  across all 12 Beta/RTL locales (el/ja/pt/zh/fi/sv/hu/is/eu/ar/he/fa) + bundles.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@qnbs

qnbs commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

@CodeAnt-AI review

@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added size:XL This PR changes 500-999 lines, ignoring generated files and removed size:XL This PR changes 500-999 lines, ignoring generated files labels Jun 21, 2026
@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Sequence Diagram

This PR adds a settings panel flow that selects an Ollama model based on the user's device profile, lets the user pull it from their local Ollama server with live progress, and then apply it as the active AI model in one click.

sequenceDiagram
    participant User
    participant SettingsUI
    participant ModelRecommender
    participant OllamaService
    participant OllamaServer
    participant SettingsStore

    User->>SettingsUI: Open advanced AI settings with Ollama provider
    SettingsUI->>ModelRecommender: Request device-aware Ollama model
    ModelRecommender-->>SettingsUI: Recommended model, tier and battery note

    User->>SettingsUI: Click Pull model
    SettingsUI->>OllamaService: Start pullOllamaModel with base URL and callbacks
    OllamaService->>OllamaServer: Call pull API and stream progress
    OllamaServer-->>OllamaService: Status events and final success
    OllamaService-->>SettingsUI: Progress updates and installed state

    User->>SettingsUI: Click Use this model
    SettingsUI->>SettingsStore: Save selected Ollama model for provider
Loading

Generated by CodeAnt AI

Comment thread tests/unit/settings/OllamaDevicePull.test.tsx Outdated
CodeAnt wave-2: the abort test asserted queryByRole('alert') === null immediately
after the click, which is trivially true before the async pull settles (false
positive). Use a deferred pull promise to first confirm the in-flight state (Cancel
button visible), then reject with AbortError and wait (findBy) for the idle Pull
button to return with no alert — a real post-abort transition.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@qnbs

qnbs commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

@CodeAnt-AI review

@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added size:XL This PR changes 500-999 lines, ignoring generated files and removed size:XL This PR changes 500-999 lines, ignoring generated files labels Jun 21, 2026
@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Sequence Diagram

This PR adds a device- and battery-aware Ollama model recommendation in the settings UI and wires it to a one-click pull flow that streams progress from the local Ollama server and applies the model as the active selection.

sequenceDiagram
    participant User
    participant SettingsUI
    participant DeviceProfiler
    participant RecommendationService
    participant OllamaServer

    User->>SettingsUI: Open advanced AI settings with Ollama provider
    SettingsUI->>DeviceProfiler: getHealthReport
    DeviceProfiler-->>RecommendationService: Device report
    RecommendationService-->>SettingsUI: Recommended model and tier (battery-aware)
    
    User->>SettingsUI: Click pull recommended model
    SettingsUI->>OllamaServer: POST pull model and stream progress
    OllamaServer-->>SettingsUI: NDJSON status and progress until success
    
    User->>SettingsUI: Click use this model
    SettingsUI->>SettingsUI: Set active Ollama model to recommended tag
Loading

Generated by CodeAnt AI

Comment thread tests/unit/settings/OllamaDevicePull.test.tsx Outdated
…test

CodeAnt wave-3: the abort test manually rejected the mocked pull instead of clicking
Cancel, so broken cancel wiring (onClick not aborting the controller) could slip
through. The mock now observes the AbortSignal and rejects only when it fires; the
test clicks the real Cancel button (onClick → abortRef.abort() → signal) and waits
for the idle Pull button to return — broken wiring would hang in the pulling state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@qnbs

qnbs commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

@CodeAnt-AI review

@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added size:XL This PR changes 500-999 lines, ignoring generated files and removed size:XL This PR changes 500-999 lines, ignoring generated files labels Jun 21, 2026
@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Sequence Diagram

This PR adds a settings flow that profiles the device, selects a battery-aware Ollama model, and lets the user pull and activate that model with streamed progress, cancel, and retry handling.

sequenceDiagram
    participant User
    participant SettingsUI
    participant DeviceProfiler
    participant RecommendationService
    participant OllamaAPI
    participant SettingsStore

    SettingsUI->>DeviceProfiler: Request device health
    DeviceProfiler-->>SettingsUI: Device report
    SettingsUI->>RecommendationService: Get Ollama model for device
    RecommendationService-->>SettingsUI: Recommended model and tier
    User->>SettingsUI: Click pull recommended model
    SettingsUI->>OllamaAPI: Pull model with progress stream
    OllamaAPI-->>SettingsUI: Progress updates and final status

    alt Pull success
        SettingsUI->>SettingsStore: Save recommended Ollama model as active
        SettingsStore-->>User: Model installed and ready to use
    else Pull error
        SettingsUI-->>User: Show error and retry option
    end
Loading

Generated by CodeAnt AI

Comment thread components/settings/OllamaDevicePull.tsx Outdated
CodeAnt wave-4 (race): startPull had no in-flight guard and its finally cleared
abortRef unconditionally, so a late-resolving stale pull could null a newer pull's
controller and break Cancel. Add an early `if (abortRef.current) return;` guard and
only clear the ref in finally when it still points to this controller.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@qnbs

qnbs commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

@CodeAnt-AI review

@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added size:XL This PR changes 500-999 lines, ignoring generated files and removed size:XL This PR changes 500-999 lines, ignoring generated files labels Jun 21, 2026
@codeant-ai

codeant-ai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Sequence Diagram

This diagram shows how the settings UI profiles the device to pick a recommended Ollama model, streams a one-click pull from the local Ollama server with progress, and then applies the pulled model as the active AI setting.

sequenceDiagram
    participant User
    participant SettingsUI
    participant DeviceAdvisor
    participant OllamaServer
    participant SettingsStore

    SettingsUI->>DeviceAdvisor: Get recommended Ollama model for device
    DeviceAdvisor-->>SettingsUI: Recommended model and tier (battery-aware)

    User->>SettingsUI: Click Pull model
    SettingsUI->>OllamaServer: Request pull for recommended model (streamed)
    OllamaServer-->>SettingsUI: Progress updates and final success
    SettingsUI-->>User: Show pull progress and installed state

    User->>SettingsUI: Click Use this model
    SettingsUI->>SettingsStore: Save selected Ollama model as active setting
Loading

Generated by CodeAnt AI

@qnbs
qnbs merged commit 3c7d571 into main Jun 21, 2026
18 checks passed
@qnbs
qnbs deleted the feat/ollama-device-pull branch June 21, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant