Every JavaScript developer gets bitten by .sort() exactly once.
This is a walkthrough of Ask AI in JSLab, our JavaScript and TypeScript scratchpad for macOS, running against a model on your own Mac with Ollama. No API key, no account, and with Ollama at its standard local address, your code never leaves the machine. We'll go from setup to the first fix you review as an inline diff.
What you need
- JSLab on an Apple Silicon Mac (macOS 14 or later).
- Ollama, a separate, free program that runs models locally.
1. Install Ollama and pull a model
Install Ollama with its Mac app from Ollama's site, or with Homebrew:
brew install ollama
ollama serve
Then pull the model JSLab uses for Ollama by default:
ollama pull qwen2.5:7b-instruct
ollama list
Ollama listens on http://localhost:11434, which is exactly where JSLab looks. If you'd rather use another model you've pulled, that works too; you'll pick it in the next step.
2. Point JSLab at Ollama
Open Settings → AI and set Provider to Ollama (Local). It needs no key.
Leave Ollama Model blank to use the default (qwen2.5:7b-instruct in this version), or open the field: it lists the models you've installed. Refresh fetches the list again.
If Ollama runs on another machine, put its address in Ollama Base URL. Otherwise leave it blank.
3. Write something slightly wrong
Open a tab and paste this:
const scores = [10, 9, 2, 1, 100];
const top3 = scores.sort().reverse().slice(0, 3);
console.log(top3);
JSLab runs it a moment after you stop typing, and the output panel shows the result beside line 3:
[ 9, 2, 100 ]
That's not the top three. .sort() with no compare function sorts the values as strings, so 100 lands between 10 and 2. It also sorts scores in place, so the original array is changed too.
4. Ask
Open AI Chat with ⌃⌘I (or Tools → AI Chat…). The header shows the provider and model. Each tab keeps its own conversation.
You don't paste your code. JSLab sends the tab's code with every message, plus the most recent run's output when Send Recent Output is on (it is by default). So you can just ask:
Why isn't top3 [100, 10, 9]? Fix it without changing scores.
Or skip typing: right-click the [ 9, 2, 100 ] row in the output and choose Explain Result. JSLab opens AI Chat and asks why that line produces that result.
The wording of the reply depends on the model. The fix it should land on looks like this:
const scores = [10, 9, 2, 1, 100];
const top3 = [...scores].sort((a, b) => b - a).slice(0, 3);
console.log(top3);
5. Review it as a diff
Every finished code block in a reply has four buttons: Copy, Insert at Cursor, Replace Editor and Preview Changes.
Click Preview Changes. The diff shows up inline, in your editor: the old line is marked as removed and the new one appears in place. Nothing changes until you decide:
- Apply accepts one change and leaves the rest on screen.
- Apply all accepts every change and closes the preview.
- Discard closes the preview and leaves your code as it was.
Apply it, and the output reruns:
[ 100, 10, 9 ]
Accepted changes land as minimal edits, so ⌘Z takes them back if you change your mind.
If something goes wrong
The panel says what failed and offers Retry. The two you're most likely to see with Ollama:
-
Couldn't reach the provider. Ollama isn't running. Start it (
ollama serve, or open the app). -
The provider has no such model. The name in Ollama Model isn't one you've pulled. Check
ollama list.
Prefer a hosted model?
Ask AI also works with OpenAI, Anthropic and Google Gemini, with your own API key. Get a key from the provider, paste it into its field under API Keys in Settings → AI, and click Save. The key is stored in your macOS Keychain, never in a settings file, and requests go straight from your Mac to the provider.
JSLab doesn't include AI credits of its own: it's Ollama on your Mac, or your own key with the provider you choose.
What gets sent, exactly
Each message carries JSLab's instructions to the assistant, your tab's code (up to 100 KB), the latest output (up to 20 KB, if Send Recent Output is on), the conversation so far, and your message. Nothing else from your Mac. With Ollama on localhost, none of it leaves the machine.
The full reference, including proposed file changes for tabs with a working directory, is in the docs: Ask AI.
Top comments (0)