# GATE 3 PRE-ANSWERED — DO NOT ASK AGAIN

Spec folder: `.opencode/specs/system-spec-kit/026-graph-and-context-optimization/014-local-embeddings-setup-a/022-local-llm-legacy-remediation`
Choice: A) Use existing spec folder

PROCEED DIRECTLY. Never ask Gate 3. Non-interactive --approval-policy=never.

---

# Batch 7 — Runtime config mirrors + .env.example + .gemini launcher + config.jsonc

## CANONICAL POST-014 SHIP STATE (binding, per user Q1=A / Q2=yes)

The runtime cascade is: VOYAGE_API_KEY -> OPENAI_API_KEY -> llama-cpp (when GGUF runtime installed) -> hf-local.
- Voyage default model: `voyage-4` (1024 dims)
- OpenAI default model: `text-embedding-3-small` (1536 dims)
- llama-cpp default GGUF model: `unsloth/embeddinggemma-300m-GGUF` (768 dims, q8) — auto-selected when node-llama-cpp installed AND the GGUF file exists
- hf-local default: `onnx-community/embeddinggemma-300m-ONNX` (768 dims, q8) — ultimate fallback
- DB filenames are profile-keyed via `shared/embeddings/profile.ts:resolveActiveProfileDbPath`. The llama-cpp profile DB name is `context-index__llama-cpp__unsloth-embeddinggemma-300m-gguf__768__q8.sqlite`. The hf-local fallback DB is `context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite`.

llama-cpp is NOT "explicit opt-in" — it's auto-selected when its runtime is installed.

## ALLOWED WRITE PATHS (touch ONLY these)

1. `.opencode/skills/system-spec-kit/.env.example`
2. `.opencode/skills/system-spec-kit/config/config.jsonc`
3. `.gemini/scripts/spec-kit-memory.sh`
4. `.codex/config.toml`

## BANNED OPERATIONS

- NO rm, mv, sed -i, rmdir, git ops, branch changes
- NO writes outside ALLOWED WRITE PATHS
- DO NOT touch `.claude/mcp.json`, `.gemini/settings.json`, `.mcp.json`, `opencode.json`, factory.ts, profile.ts, llama-cpp-availability.ts, providers/*, or 021/022/023 packets

## REQUIREMENTS

### (A) `.env.example`

A.1 Provider list comment `(auto | voyage | openai | hf-local)` -> `(auto | voyage | openai | llama-cpp | hf-local)`
A.2 `Default: auto (detects from API keys, falls back to hf-local)` -> `Default: auto — VOYAGE_API_KEY → OPENAI_API_KEY → llama-cpp (when GGUF runtime installed) → hf-local fallback`
A.3 `HuggingFace local model (default when no API keys set)` -> `HuggingFace local model (final fallback when no API keys AND no llama-cpp runtime)`
A.4 Commented `EMBEDDINGS_MODEL=nomic-ai/nomic-embed-text-v1.5` -> `EMBEDDINGS_MODEL=onnx-community/embeddinggemma-300m-ONNX` (keep `#` prefix)
A.5 `Choose a provider (or use default hf-local)` -> `Set EMBEDDINGS_PROVIDER explicitly (otherwise auto-cascade picks VOYAGE → OPENAI → llama-cpp → hf-local)`

### (B) `config/config.jsonc`

Line containing `"databasePath": ".opencode/skills/system-spec-kit/mcp_server/dist/database/context-index.sqlite"`:
Replace literal `context-index.sqlite` with `context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite` (preserve `dist/database/` path prefix and trailing comma). If a comment near the field exists, update it to say `(profile-derived; resolveActiveProfileDbPath returns the active provider's DB filename)`.

### (C) `.gemini/scripts/spec-kit-memory.sh`

C.1 Provider doc comment `auto | voyage | openai | hf-local` -> `auto | voyage | openai | llama-cpp | hf-local`
C.2 `DEFAULT_DB_PATH="..../mcp_server/database/context-index.sqlite"` -> use `context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite`
C.3 `HF_LOCAL_DB_PATH="...context-index__hf-local__nomic-ai_nomic-embed-text-v1.5__768.sqlite"` -> use `context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite`
C.4 Comment `# Fall back to HF-local database when no API keys are available` -> `# Fall back to hf-local DB only when no API keys AND no llama-cpp runtime; llama-cpp profile DB takes precedence when its GGUF model is installed`
C.5 In any `case` arm mapping `auto|hf-local)` to the hf-local DB: separate them. `auto)` should delegate (do not pin a DB); `hf-local)` keeps hf-local DB. Add `llama-cpp)` arm pointing at `context-index__llama-cpp__unsloth-embeddinggemma-300m-gguf__768__q8.sqlite` if missing.
C.6 Other lines mentioning generic `context-index.sqlite` or `nomic-embed-text-v1.5` — update consistently.

### (D) `.codex/config.toml`

Lines around 16-17 contain something like:
`# e.g., context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite`
`# for the Setup A default since 014/012`

Replace those comment lines to describe llama-cpp-when-installed as the default profile and clarify hf-local is the final fallback. Suggested wording:
- `# e.g., context-index__llama-cpp__unsloth-embeddinggemma-300m-gguf__768__q8.sqlite (when GGUF runtime installed) or context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite (final fallback)`
- `# resolved automatically by the active embedding profile (provider+model+dim+dtype)`

## ACCEPTANCE

After your edits:
- `grep -E 'default.*hf-local|nomic-ai/nomic-embed-text-v1.5' .opencode/skills/system-spec-kit/.env.example` returns 0
- `grep -E 'context-index\.sqlite\b' .gemini/scripts/spec-kit-memory.sh` returns 0 (only profile-keyed filenames remain)
- `grep -E 'context-index\.sqlite' .opencode/skills/system-spec-kit/config/config.jsonc` returns 0

## REPORT

```
BATCH 7 REPORT
File: <path> — <N edits> — <one-line summary>
...
Scope violations: <none | list>
Blocked writes: <none | list>
Total edits: <N>
```

No commits. No git. Stop after the report.
