Skip to content

feat(init): graceful Ollama first-run in coco init#1264

Merged
gfargo merged 1 commit into
mainfrom
feat/ollama-first-run-init
Jun 14, 2026
Merged

feat(init): graceful Ollama first-run in coco init#1264
gfargo merged 1 commit into
mainfrom
feat/ollama-first-run-init

Conversation

@gfargo

@gfargo gfargo commented Jun 14, 2026

Copy link
Copy Markdown
Owner

First slice of the 0.73 Ollama onboarding polish (freeze-allowed). Since Ollama is the default provider in the picker, this is most new users' first impression of the "local AI commits" path the launch leads with.

Problem

The Ollama branch of coco init shelled out:

ollama list | awk '{print $1}' | awk '{if(NR>1)print}'
  • Non-portable — no awk on Windows.
  • Crashes if Ollama isn't installed (execPromise rejects with a raw "command not found").
  • On no models, prints a vague message and hard-exits, discarding every prior init answer (scope, commitlint).
  • No "daemon not running" guidance.

Change

New lib/langchain/utils/ollamaStatus.ts:

  • getOllamaStatus(endpoint?) — probes the HTTP API (/api/tags) for reachability and pulled models in one cross-platform call; a PATH probe only distinguishes "not installed" from "not running" for the copy.
  • pullOllamaModel(model)ollama pull with live progress.
  • OllamaNotReadyError — typed signal.

coco init now guides each first-run state instead of crashing:

  • not installed → install link (ollama.com/download / brew install ollama)
  • installed but not runningollama serve
  • up but no models → recommends + optionally pulls llama3.1:8b (~4.7 GB, the cost-tier commit default), prompted — never automatic

When Ollama can't be used and the user doesn't fix it inline, the handler catches OllamaNotReadyError and re-offers the provider picker — prior answers are preserved (no more session loss).

Tests

  • ollamaStatus.test.ts — reachable / not-running / not-installed / non-OK / endpoint normalization (7 cases).
  • init.test.ts — new test: not-ready → re-prompt → completes with another provider.

Validation

eslint (0 errors), tsc --noEmit clean, jest init + ollamaStatus suites green (7/7 each). Full rollup build deferred to CI (nested-worktree PATH quirk locally).

Follow-ups (rest of the 0.73 Ollama polish)

  • coco doctor: Ollama daemon liveness + configured-model-pulled check
  • Actionable runtime error on commit when daemon down / model missing
  • Fix handleMissingApiKey Ollama copy (OLLAMA_API_KEY is misleading for local)

The Ollama branch of `coco init` shelled out `ollama list | awk …` and
hard-exited on any hiccup — non-portable (no awk on Windows), and a raw
crash if Ollama wasn't installed/running, discarding every prior answer.
Since Ollama is the default provider, this was most new users' first
impression of the "local AI commits" path.

Replace it with a cross-platform probe + guided recovery:

- New `lib/langchain/utils/ollamaStatus.ts`: `getOllamaStatus()` queries the
  HTTP API (`/api/tags`) for reachability + pulled models in one call, with a
  PATH probe only to tell "not installed" from "not running"; plus
  `pullOllamaModel()` (live progress) and a typed `OllamaNotReadyError`.
- `init` now guides each first-run state: not installed → install link;
  installed but down → `ollama serve`; up but no models → recommend and
  optionally pull `llama3.1:8b`.
- When Ollama can't be used and the user doesn't fix it inline, the handler
  catches `OllamaNotReadyError` and re-offers the provider picker instead of
  aborting — prior answers (scope, commitlint) are preserved.

Tests: unit coverage for getOllamaStatus across reachable / not-running /
not-installed / non-OK, and a handler test for the re-prompt path.
@gfargo gfargo merged commit 4573438 into main Jun 14, 2026
16 checks passed
@gfargo gfargo deleted the feat/ollama-first-run-init branch June 14, 2026 15:36
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.

1 participant