# GATE 3 PRE-ANSWERED — Spec folder: `.opencode/specs/system-spec-kit/026-graph-and-context-optimization/014-local-embeddings-setup-a/022-local-llm-legacy-remediation` — A) existing. PROCEED. Non-interactive --approval-policy=never. No clarifying questions.

---

# Batch 8 — Doctor command assets (post-014/Q1=A alignment)

## SHIP STATE (binding)

Cascade: VOYAGE_API_KEY -> OPENAI_API_KEY -> llama-cpp (when GGUF runtime installed) -> hf-local.
- llama-cpp profile DB: `context-index__llama-cpp__unsloth-embeddinggemma-300m-gguf__768__q8.sqlite`
- hf-local profile DB: `context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite`
- Voyage profile DB: `context-index__voyage__voyage-4__1024.sqlite` (only when VOYAGE_API_KEY set)
- OpenAI profile DB: `context-index__openai__text-embedding-3-small__1536.sqlite` (only when OPENAI_API_KEY set)
- Active profile resolution: `shared/embeddings/profile.ts:resolveActiveProfileDbPath`

## ALLOWED WRITE PATHS

1. `.opencode/commands/doctor/_routes.yaml`
2. `.opencode/commands/doctor/assets/doctor_memory.yaml`
3. `.opencode/commands/doctor/scripts/mcp-doctor.sh`

## BANNED OPERATIONS

- NO rm/mv/sed -i/git/branch
- NO writes outside ALLOWED WRITE PATHS
- NO touching factory.ts, profile.ts, llama-cpp-availability.ts, providers/*, 021/022/023 packets

## REQUIREMENTS

### (A) `.opencode/commands/doctor/_routes.yaml`

Around line 29 there's a route boundary mentioning `mcp_server/database/context-index.sqlite + context-index__voyage__voyage-4__1024.sqlite` as the memory route's `mutation_targets` or boundary. Read the file first.

Replace any LITERAL `context-index.sqlite` (without profile suffix) with a description of the active provider-keyed profile DB. Voyage 1024 reference: keep as one example among many, OR generalize to "any provider-keyed profile DB matching `context-index__*.sqlite`".

Recommended replacement pattern for boundary/mutation_target literals: use a glob `mcp_server/database/context-index__*.sqlite` instead of pinned filenames. If the YAML structure requires a list, list all 4 canonical profile filenames (hf-local, llama-cpp, voyage, openai) instead of just one.

### (B) `.opencode/commands/doctor/assets/doctor_memory.yaml`

Line ~22: `Memory doctor workflows treat context-index.sqlite and the voyage vector DB as ...` — rewrite around active provider-keyed profile DBs (mention llama-cpp + hf-local + voyage + openai profiles).

Line ~64: `- "mcp_server/database/context-index.sqlite"  # primary memory FTS/metadata DB` — change to either the active-profile-derived path OR list all 4 canonical profile filenames as the allowed target set, OR use a glob.

Line ~145: `- "Bash: stat -f '%m %z' database/context-index.sqlite (mtime + size)"` — change to stat the active profile DB. Acceptable rewrite: `database/context-index__*.sqlite` (glob expanded by Bash to the actual present files).

Apply the same logic to any OTHER lines in this file that reference the legacy singleton filename or hardcoded voyage-1024 filename.

### (C) `.opencode/commands/doctor/scripts/mcp-doctor.sh`

Around line 200: `local db_file="$db_dir/context-index.sqlite"` — change to resolve the active profile DB. Since this is a shell script, simplest:

```bash
# Active embedding profile DB (derived in TS at runtime); shell-side, glob for present profile files.
local db_file
db_file=$(ls -t "$db_dir"/context-index__*.sqlite 2>/dev/null | head -1)
if [[ -z "$db_file" ]]; then
  # Fallback: hf-local default profile (covers fresh-install case before any provider DB exists)
  db_file="$db_dir/context-index__hf-local__onnx-community_embeddinggemma-300m-onnx__768__q8.sqlite"
fi
```

Adjust the surrounding code to handle the fallback case if needed. Look for OTHER places in the same script that use `db_file` (or the singleton path) and confirm they still work after the change.

## ACCEPTANCE

After edits:
- `grep -E '"context-index\.sqlite"' .opencode/commands/doctor/_routes.yaml .opencode/commands/doctor/assets/doctor_memory.yaml` returns 0
- `grep -E 'context-index\.sqlite[^_]' .opencode/commands/doctor/scripts/mcp-doctor.sh` returns 0
- `bash -n .opencode/commands/doctor/scripts/mcp-doctor.sh` returns 0 (syntax check)

## REPORT

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

No commits. No git. Stop after the report.
