Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(local-llm): run llama.cpp ngram spec types without a drafter GGUF

Adam Eivy4eb6ccb5dc3f
diff --git a/client/src/components/settings/LocalLlmTab.jsx b/client/src/components/settings/LocalLlmTab.jsx
index 252d2dec0a..961e2ae6a1 100644
--- a/client/src/components/settings/LocalLlmTab.jsx
+++ b/client/src/components/settings/LocalLlmTab.jsx
@@ -810,6 +810,19 @@ export function LocalLlmTab() {
const baseWeightMissing = missingWeight('model');
const draftWeightMissing = missingWeight('draftModel');
const llamaStartBlocked = llamaModelMissing || baseWeightMissing || draftWeightMissing;
+ // Rendered from the server's list (status payload) so the card never carries a
+ // second copy of the llama.cpp vocabulary.
+ const specTypeSuggestions = llamaStatus?.specTypes || [];
+ // MIRROR of `isDraftSpecType` / `parseSpecTypes` in
+ // server/lib/specDecodePresets.js. The launcher drops drafter-based types when
+ // no drafter is configured; say so here rather than letting the server quietly
+ // rewrite the launch line the user thought they were starting.
+ const draftlessSpecTypes = (llamaForm.draftModel || '').trim()
+ ? []
+ : String(llamaForm.specType || '').split(',').map((t) => t.trim()).filter((t) => t.startsWith('draft-'));
+ const draftlessSpecNotice = draftlessSpecTypes.length > 0
+ ? `${draftlessSpecTypes.join(', ')} will be skipped until a Drafter Model is set.`
+ : '';
const llamaStartBlockedReason = llamaModelMissing
? 'Enter a Target Base Model path to enable Start'
: baseWeightMissing
@@ -1090,7 +1103,7 @@ export function LocalLlmTab() {
</div>
<p className="text-xs text-gray-400 leading-relaxed">
- Speculative decoding pairs a small drafter with your target model for 2–3× faster generation at identical output. You can launch and manage a local <code className="text-gray-300">llama-server</code> from PortOS and connect using the <strong className="text-white">OpenCode llama TUI</strong> provider. <strong className="text-white">DSpark</strong> (<code className="text-gray-300">draft-dspark</code>) works on a stock <code className="text-gray-300">brew install llama.cpp</code>; the DFlash 2 presets need a from-source build of an unmerged llama.cpp branch.
+ Speculative decoding pairs a small drafter with your target model for 2–3× faster generation at identical output. You can launch and manage a local <code className="text-gray-300">llama-server</code> from PortOS and connect using the <strong className="text-white">OpenCode llama TUI</strong> provider. <strong className="text-white">DSpark</strong> (<code className="text-gray-300">draft-dspark</code>) works on a stock <code className="text-gray-300">brew install llama.cpp</code>; the DFlash 2 presets need a from-source build of an unmerged llama.cpp branch. No drafter GGUF to hand? The <code className="text-gray-300">ngram-*</code> spec types under Advanced options draft from the context window alone.
</p>
{llamaStatus?.running ? (
@@ -1102,7 +1115,7 @@ export function LocalLlmTab() {
<p><span className="text-gray-500">Base Model:</span> <code className="text-gray-300">{llamaStatus.config.model}</code></p>
)}
{llamaStatus.config?.draftModel && (
- <p><span className="text-gray-500">Drafter:</span> <code className="text-port-accent">{llamaStatus.config.draftModel}</code> ({llamaStatus.config.specType || 'draft-dflash'})</p>
+ <p><span className="text-gray-500">Drafter:</span> <code className="text-port-accent">{llamaStatus.config.draftModel}</code></p>
)}
{llamaStatus.config && (
<p>
@@ -1111,6 +1124,16 @@ export function LocalLlmTab() {
{' '}— Providers must send this name. Change it under Advanced options before starting.
</p>
)}
+ {/* Split out from the Drafter line: an `ngram-*` launch runs
+ speculative decoding with no drafter at all, so hanging the
+ spec type off that line hid it exactly when it was the only
+ thing configured. */}
+ <p>
+ <span className="text-gray-500">Spec Type:</span>{' '}
+ {llamaStatus.config?.specType
+ ? <code className="text-port-accent">{llamaStatus.config.specType}</code>
+ : <span className="text-gray-500">none — speculative decoding off</span>}
+ </p>
</div>
{llamaStatus.managed ? (
<button
@@ -1229,16 +1252,31 @@ export function LocalLlmTab() {
className="w-full bg-port-card border border-port-border rounded px-2 py-1 text-xs text-white"
/>
</div>
- <div>
+ <div className="col-span-2 sm:col-span-4">
<label htmlFor="llama-spec-type" className="text-[11px] text-gray-400 block mb-1">Spec Type</label>
<input
id="llama-spec-type"
aria-label="Spec Type"
type="text"
+ list="llama-spec-type-options"
value={llamaForm.specType}
onChange={(e) => setLlamaField('specType', e.target.value)}
className="w-full bg-port-card border border-port-border rounded px-2 py-1 text-xs text-white"
/>
+ <datalist id="llama-spec-type-options">
+ {specTypeSuggestions.map((entry) => (
+ <option key={entry.id} value={entry.id}>{entry.note}</option>
+ ))}
+ </datalist>
+ <p className="text-[11px] text-gray-500 mt-1">
+ Comma-separate to run several at once, e.g. <code className="text-gray-400">draft-dflash,ngram-map-k</code>.
+ Only <code className="text-gray-400">draft-*</code> types need a drafter GGUF — the{' '}
+ <code className="text-gray-400">ngram-*</code> ones speculate from the tokens already in context, so they run
+ with the Drafter field empty.
+ </p>
+ {draftlessSpecNotice && (
+ <p className="text-[11px] text-port-warning mt-1">{draftlessSpecNotice}</p>
+ )}
</div>
<div>
<label htmlFor="llama-alias" className="text-[11px] text-gray-400 block mb-1">Model id (alias)</label>
@@ -1261,7 +1299,7 @@ export function LocalLlmTab() {
className="text-[11px] text-gray-500 hover:text-gray-300 flex items-center gap-1"
>
{showLlamaAdvanced ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
- {showLlamaAdvanced ? 'Hide options' : 'Advanced options (port, ctx, GPU layers, model id)'}
+ {showLlamaAdvanced ? 'Hide options' : 'Advanced options (port, ctx, GPU layers, model id, spec type)'}
</button>
<div className="flex items-center gap-2">
{llamaStartBlocked && (
diff --git a/docs/features/dflash2.md b/docs/features/dflash2.md
index 0c9c3ee29a..42170c1269 100644
--- a/docs/features/dflash2.md
+++ b/docs/features/dflash2.md
@@ -85,6 +85,37 @@ llama-server \
--n-gpu-layers 99
```
+### 2b. Drafter-free speculation (n-gram spec types)
+
+`--spec-type` is a **comma-separated list**, and only its `draft-*` entries need a
+drafter GGUF. The `ngram-*` implementations draft by pattern-matching the tokens
+already in the context window — no second model, no extra VRAM — which makes them
+worth having even when you have no drafter for your target:
+
+| Spec type | Needs a drafter? | What it drafts from |
+| --- | --- | --- |
+| `draft-dspark` / `draft-dflash` / `draft-simple` / `draft-mtp` | yes | a second model |
+| `ngram-map-k` / `ngram-map-k4v` | no | repeated n-grams in the live context |
+| `ngram-simple` / `ngram-mod` / `ngram-cache` | no | n-gram lookup over token history |
+
+Mixing the two families in one server is supported and is the usual reason to
+comma-separate — the drafter handles novel text while the n-gram map catches the
+long verbatim repeats an agent produces (re-emitted file contents, diffs, JSON):
+
+```bash
+llama-server \
+ -m models/Qwen3.8-27B-Q4_K_M.gguf \
+ --model-draft models/Qwen3.8-27B-DSpark-BF16.gguf \
+ --spec-type draft-dspark,ngram-map-k \
+ --port 5568 --host 127.0.0.1 --alias dflash
+```
+
+In PortOS, set this in **Settings → Local LLMs → Speculative Decoding →
+Advanced options → Spec Type** (the picker suggests the types above). Leaving the
+**Drafter Model** field empty is a supported configuration: PortOS drops the
+`draft-*` entries from the launch line — logging which ones — and starts with the
+`ngram-*` half. Vocabulary reference: llama.cpp `docs/speculative.md`.
+
### 3. Use in PortOS
1. Navigate to **AI Providers** (`/ai`) or **Settings → Local LLMs**.
2. Verify **OpenCode llama TUI** is enabled.
diff --git a/server/lib/README.md b/server/lib/README.md
index f865a199f2..c72a0735e7 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -309,7 +309,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `huggingfaceModel.js` | HuggingFace base-model (image/video) classifier for the self-service "add a model" flow (#2124): inspect repo siblings + card → decide the loadable runtime/runner, STRICTLY refuse GGUF-only / wan / hunyuan / unclassifiable repos (so a bad add can't wedge the picker), build the `media-models.json` entry (`source:'user'`), + a `searchHuggingfaceModels` Hub-search helper. Pure. |
| `localLlmCatalog.js` | Curated cross-backend (Ollama↔LM Studio) local-LLM catalog + install-id mapping for the migrate flow. Pure. |
| `localLlmDisk.js` | Pure on-disk reasoning for the migrate "copy GGUF locally instead of re-downloading" fast-path (Ollama manifest/blob parsing, LM Studio path layout, MLX/projector/shard detection) plus the Hugging Face registry addressing used to finish an abandoned Ollama pull. |
-| `specDecodePresets.js` | Curated llama-server speculative-decoding presets (target + drafter GGUF paths, `--spec-type`, and the Hugging Face repo/quant each file comes from) plus `findSpecDecodePreset` / `specDecodeSource` / `hfSearchUrl`. Server-owned so the launcher card can offer a Download button per file. Pure. |
+| `specDecodePresets.js` | Curated llama-server speculative-decoding presets (target + drafter GGUF paths, `--spec-type`, and the Hugging Face repo/quant each file comes from) plus `findSpecDecodePreset` / `specDecodeSource` / `hfSearchUrl`. Also owns the `--spec-type` vocabulary: `SPEC_TYPE_SUGGESTIONS` (published to the launcher card), `parseSpecTypes` (the flag is a comma-separated list) and `isDraftSpecType` (the `draft-` prefix is what needs a drafter GGUF — every `ngram-*` type runs without one). Server-owned so the launcher card can offer a Download button per file. Pure. |
| `ollamaContext.js` | Ollama runtime context-window reasoning. `resolveOllamaContextLength(provider, env)` → the window PortOS should hold the daemon at (`provider.numCtx`, then `OLLAMA_CONTEXT_LENGTH`, then `null` = leave Ollama's VRAM-based auto-pick alone); `withOllamaContextEnv(env, n)` builds the `ollama serve` child env; `parseOllamaContextOverflow(text)` recognizes the `exceed_context_size_error` rejection and pulls `{ promptTokens, contextLength }` out of either the JSON body or the human message; `describeOllamaContextOverflow` / `describeOllamaContextTooSmall` render the actionable one-liners; `isSameOllamaDaemon(providerBase, managedBase)` compares host+port so a provider pointed at a *remote* Ollama never triggers a local-daemon reload; `OLLAMA_AGENT_MIN_CONTEXT` is the window below which an agent harness is warned. Pure — the daemon side lives in `services/ollamaManager.js` (`ensureContextWindow`), the pre-spawn enforcement in `services/ollamaAgentContext.js`. |
| `localModelHeuristics.js` | Capability heuristics for untyped local (Ollama/LM Studio) models. `isEmbeddingModel`/`isGenerationModel` (so a generation/fallback run never picks an embedding model like `nomic-embed-text`); `isVisionModel(model)` (string id or model card — prefers explicit `type:'vlm'`/`capabilities:['vision']` metadata, falls back to id regex; used by the LoRA captioner); `recommendEditorialModel(models, { measured })` ranks installed models for editorial review/editing, dropping any a fresh measurement proved cannot run here. Pure. Mirror `isEmbeddingModel`/`isVisionModel` in `client/src/utils/providers.js`. |
| `localModelAssessment.js` | Scoring for MEASURED local-model assessments (recorded by `services/localModelAssessments.js`): `classifyFitVerdict` (`fits`/`does-not-fit`/`incompatible`/`unknown`), `summarizePerformance` (mean/peak chars-per-second, TTFT, max working context, cross-context degradation), `scoreAssessment` + `scoreForIntent` + `rankByIntent` for the balanced/smartest/fastest/lightweight pickers, `explainAssessment`, `compareEnvironments`/`describeStaleness` (is a stored reading still valid for THIS machine?), and `measuredFitVerdict`/`reconcileFit` (fold a measurement into the catalog's size-estimate fit badge, keeping the disagreement). Pure. `null` strictly means NOT MEASURED — never 0, never "failed". |
diff --git a/server/lib/mediaValidation.js b/server/lib/mediaValidation.js
index 8e815f7221..3e0b91f0bf 100644
--- a/server/lib/mediaValidation.js
+++ b/server/lib/mediaValidation.js
@@ -165,7 +165,14 @@ export const localLlmOllamaServiceSchema = z.object({ action: z.enum(['start', '
export const localLlmLlamaServerStartSchema = z.object({
model: z.string().trim().min(1).max(500),
draftModel: z.string().trim().max(500).optional().nullable(),
- specType: z.string().trim().max(100).optional().default('draft-dflash'),
+ // A comma-separated list of llama.cpp `--spec-type` implementations
+ // (`ngram-map-k`, `draft-dflash,ngram-map-k`). Free vocabulary on purpose —
+ // fork builds ship their own — but shaped, since it lands in the launch argv.
+ // Empty is allowed and means "no speculative decoding".
+ specType: z.string().trim().max(100).regex(
+ /^$|^[A-Za-z0-9._-]+(?:\s*,\s*[A-Za-z0-9._-]+)*$/,
+ 'specType must be a comma-separated list of llama.cpp spec-type names',
+ ).optional().default('draft-dflash'),
port: z.coerce.number().int().min(1).max(65535).optional().default(PORTS.LLAMA_SERVER),
host: z.string().trim().max(100).optional().default('127.0.0.1'),
ctxSize: z.coerce.number().int().min(512).max(1048576).optional().default(32768),
diff --git a/server/lib/specDecodePresets.js b/server/lib/specDecodePresets.js
index 27b0b4f834..9b6e4c3e2b 100644
--- a/server/lib/specDecodePresets.js
+++ b/server/lib/specDecodePresets.js
@@ -98,6 +98,54 @@ export const SPEC_DECODE_PRESETS = Object.freeze([
},
]);
+/**
+ * `--spec-type` implementations worth suggesting in the launcher, each with the
+ * one-line note the picker shows. Surfaced on the llama-server status payload so
+ * the client renders this list rather than keeping a copy that can rot.
+ *
+ * Deliberately a SUGGESTION list, not a vocabulary: `draft-dflash` /
+ * `draft-dspark` exist only in particular builds (see the note above the
+ * presets), and a from-source llama.cpp can carry implementations that never
+ * land upstream. The field therefore stays free text — what PortOS actually
+ * reasons about is the `draft-` prefix, which is what decides whether a drafter
+ * GGUF is required. Reference: llama.cpp `docs/speculative.md`.
+ */
+export const SPEC_TYPE_SUGGESTIONS = Object.freeze([
+ { id: 'none', note: 'Speculative decoding off' },
+ { id: 'draft-dspark', note: 'DSpark drafter — needs a drafter GGUF' },
+ { id: 'draft-dflash', note: 'DFlash drafter — needs a drafter GGUF' },
+ { id: 'draft-simple', note: 'Any smaller model as drafter — needs a drafter GGUF' },
+ { id: 'draft-mtp', note: 'Multi-token-prediction drafter — needs a drafter GGUF' },
+ { id: 'ngram-map-k', note: 'Drafts from repeated n-grams already in context — no drafter' },
+ { id: 'ngram-map-k4v', note: '4-token-key n-gram map — no drafter' },
+ { id: 'ngram-simple', note: 'Longest-match n-gram lookup — no drafter' },
+ { id: 'ngram-mod', note: 'Modulo-hashed n-gram lookup — no drafter' },
+ { id: 'ngram-cache', note: 'Persistent n-gram cache — no drafter' },
+]);
+
+/**
+ * Split a `--spec-type` field into its implementations. llama.cpp accepts a
+ * comma-separated list and runs them together — mixing a drafter-based entry
+ * with a drafter-free one (`draft-dflash,ngram-map-k`) is the documented way to
+ * cover both patterns in one server.
+ * @param {string|null|undefined} value
+ * @returns {string[]}
+ */
+export const parseSpecTypes = (value) =>
+ String(value ?? '').split(',').map((type) => type.trim()).filter(Boolean);
+
+/**
+ * Whether one implementation needs a `--model-draft` GGUF.
+ *
+ * The `draft-` prefix is llama.cpp's own naming split: `draft-*` speculates with
+ * a second model, every `ngram-*` speculates by pattern-matching the tokens
+ * already in the context window and needs no weights at all. Keyed on the prefix
+ * rather than a fixed list so a fork's new drafter type is classified correctly
+ * without a PortOS release.
+ * @param {string} type
+ */
+export const isDraftSpecType = (type) => String(type).startsWith('draft-');
+
// The preset the launcher mounts on, and the roles a download request may name.
export const DEFAULT_SPEC_PRESET_ID = 'qwen3.8-27b-dspark';
export const SPEC_MODEL_ROLES = Object.freeze(['model', 'draftModel']);
diff --git a/server/routes/localLlm.js b/server/routes/localLlm.js
index 159a86aceb..b5515bfb9a 100644
--- a/server/routes/localLlm.js
+++ b/server/routes/localLlm.js
@@ -31,6 +31,7 @@ import {
} from '../lib/validation.js'
import { getLlamaServerStatus, startLlamaServer, stopLlamaServer, installLlamaServer } from '../services/llamaServerManager.js'
import { getSpecDecodePresetStatus, downloadSpecDecodeModel } from '../services/specDecodeModels.js'
+import { SPEC_TYPE_SUGGESTIONS } from '../lib/specDecodePresets.js'
import { resetProviderReadinessCache } from '../services/providerReadiness.js'
import { getCatalog, searchCatalog, isBackend } from '../lib/localLlmCatalog.js'
import { isAppleSilicon } from '../lib/platform.js'
@@ -473,7 +474,9 @@ router.post('/assessments/delete', asyncHandler(async (req, res) => {
// Start to discover a missing file. Disk-only: no Hugging Face call here.
router.get('/llama-server/status', asyncHandler(async (_req, res) => {
const [status, presets] = await Promise.all([getLlamaServerStatus(), getSpecDecodePresetStatus()])
- res.json({ ...status, presets })
+ // Spec-type suggestions ride along for the same reason the presets do: the
+ // card renders the server's list instead of keeping a copy that can rot.
+ res.json({ ...status, presets, specTypes: SPEC_TYPE_SUGGESTIONS })
}))
// POST /api/local-llm/llama-server/download-model — fetch one preset's GGUF from
diff --git a/server/routes/localLlm.test.js b/server/routes/localLlm.test.js
index 6ee2460403..7ebb04b731 100644
--- a/server/routes/localLlm.test.js
+++ b/server/routes/localLlm.test.js
@@ -511,13 +511,23 @@ describe('llama-server routes', () => {
it('GET /api/local-llm/llama-server/status returns status with the weight presets', async () => {
const res = await request(makeApp()).get('/api/local-llm/llama-server/status');
expect(res.status).toBe(200);
- expect(res.body).toEqual({
+ expect(res.body).toMatchObject({
installed: true,
running: false,
presets: [{ id: 'test-preset', label: 'Test', specType: 'draft-dspark', model: null, draftModel: null }],
});
});
+ it('GET /api/local-llm/llama-server/status publishes the drafter-free spec types', async () => {
+ // The card renders the picker from this list, so a launch with no drafter
+ // GGUF (`ngram-map-k`) has to be reachable without the user knowing the
+ // llama.cpp vocabulary by heart.
+ const res = await request(makeApp()).get('/api/local-llm/llama-server/status');
+ expect(res.body.specTypes.map((entry) => entry.id)).toEqual(
+ expect.arrayContaining(['ngram-map-k', 'draft-dflash', 'none']),
+ );
+ });
+
it('POST /api/local-llm/llama-server/download-model fetches one preset GGUF', async () => {
const { downloadSpecDecodeModel } = await import('../services/specDecodeModels.js');
const res = await request(makeApp())
diff --git a/server/services/llamaServerManager.js b/server/services/llamaServerManager.js
index 9917803e39..51ed3e56f5 100644
--- a/server/services/llamaServerManager.js
+++ b/server/services/llamaServerManager.js
@@ -12,6 +12,7 @@ import { commandExists } from '../lib/commandExists.js';
import { findCommandOnPath, safeChildProcessEnv, safeChildProcessOptions } from '../lib/processEnv.js';
import { expandHome, sleep } from '../lib/fileUtils.js';
import { resolveSpecModelPath } from './specDecodeModels.js';
+import { parseSpecTypes, isDraftSpecType } from '../lib/specDecodePresets.js';
import { probeOpenAiModels } from '../lib/openAiModelsProbe.js';
import { isPortInUse } from '../lib/platform.js';
import { PORTS } from '../lib/ports.js';
@@ -86,7 +87,9 @@ function parseConfigFromArgs(args) {
if (!model) return null;
const draftModel = getArg('--model-draft') || getArg('--spec-draft-model') || getArg('-md');
- const specType = getArg('--spec-type') || 'draft-dflash';
+ // Absent means the process is running WITHOUT speculative decoding — don't
+ // invent a type the launch line never carried.
+ const specType = getArg('--spec-type');
const port = getArg('--port') ? Number(getArg('--port')) : PORTS.LLAMA_SERVER;
const host = getArg('--host') || '127.0.0.1';
const ctxSize = getArg('--ctx-size') ? Number(getArg('--ctx-size')) : 32768;
@@ -214,11 +217,23 @@ export async function startLlamaServer(options = {}) {
: null;
if (draftPath) await assertModelFileExists('The drafter model', draftPath);
+ // `--spec-type` is a comma-separated LIST, and only its `draft-*` entries want
+ // a drafter GGUF — every `ngram-*` implementation speculates off the tokens
+ // already in the context window. Emitting the flag only alongside a drafter
+ // therefore threw away perfectly valid drafter-free launches
+ // (`--spec-type ngram-map-k`) and silently ignored the ngram half of a mixed
+ // one (`draft-dflash,ngram-map-k`). Drop just the drafter-based entries when
+ // no drafter is set — that keeps the card's documented "clear the field to run
+ // without it" working — and pass everything else through.
+ const requestedSpecTypes = parseSpecTypes(specType);
+ const effectiveSpecTypes = draftPath
+ ? requestedSpecTypes
+ : requestedSpecTypes.filter((type) => !isDraftSpecType(type));
+ const droppedSpecTypes = requestedSpecTypes.filter((type) => !effectiveSpecTypes.includes(type));
+
const args = ['-m', expandHome(model.trim())];
- if (draftPath) {
- args.push('--model-draft', expandHome(draftPath));
- if (specType) args.push('--spec-type', specType.trim());
- }
+ if (draftPath) args.push('--model-draft', expandHome(draftPath));
+ if (effectiveSpecTypes.length > 0) args.push('--spec-type', effectiveSpecTypes.join(','));
if (port) args.push('--port', String(port));
if (host) args.push('--host', host);
if (ctxSize) args.push('--ctx-size', String(ctxSize));
@@ -227,12 +242,18 @@ export async function startLlamaServer(options = {}) {
lastExitError = null;
recentLogs = [];
+ if (droppedSpecTypes.length > 0) {
+ appendLog(`Ignoring spec-type ${droppedSpecTypes.join(',')} — no drafter model is set`);
+ console.log(`🦙 llama-server dropping drafter-based spec types ${droppedSpecTypes.join(',')} (no --model-draft configured)`);
+ }
appendLog(`Starting: llama-server ${args.join(' ')}`);
currentConfig = {
model,
draftModel: draftModel || null,
- specType,
+ // The types actually on the launch line, so the status card reports what is
+ // running rather than what was asked for.
+ specType: effectiveSpecTypes.join(','),
port,
host,
ctxSize,
diff --git a/server/services/llamaServerManager.test.js b/server/services/llamaServerManager.test.js
index 2f9b87605c..936659f02a 100644
--- a/server/services/llamaServerManager.test.js
+++ b/server/services/llamaServerManager.test.js
@@ -184,6 +184,49 @@ describe('llamaServerManager', () => {
expect(status.pid).toBe(12345);
});
+ it('starts an ngram spec type with no drafter model at all', async () => {
+ // `ngram-*` implementations draft from the tokens already in context, so a
+ // drafter GGUF is not just optional — there is nothing to download.
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');
+
+ await startLlamaServer({ model: modelPath, specType: 'ngram-map-k' });
+
+ const startCall = execPm2Calls.find((c) => c[0] === 'start');
+ expect(startCall).not.toContain('--model-draft');
+ expect(startCall.slice(startCall.indexOf('--spec-type'), startCall.indexOf('--spec-type') + 2))
+ .toEqual(['--spec-type', 'ngram-map-k']);
+ });
+
+ it('passes a combined drafter + ngram spec type through as one comma-separated flag', async () => {
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');
+
+ await startLlamaServer({ model: modelPath, draftModel: draftPath, specType: 'draft-dflash, ngram-map-k' });
+
+ const startCall = execPm2Calls.find((c) => c[0] === 'start');
+ expect(startCall[startCall.indexOf('--spec-type') + 1]).toBe('draft-dflash,ngram-map-k');
+ });
+
+ it('drops only the drafter-based half of a combined spec type when no drafter is set', async () => {
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');
+
+ await startLlamaServer({ model: modelPath, specType: 'draft-dflash,ngram-map-k' });
+
+ const startCall = execPm2Calls.find((c) => c[0] === 'start');
+ expect(startCall[startCall.indexOf('--spec-type') + 1]).toBe('ngram-map-k');
+ const status = await getLlamaServerStatus();
+ // The card reports what is running, not what was asked for.
+ expect(status.config.specType).toBe('ngram-map-k');
+ });
+
+ it('omits --spec-type entirely when the only requested type needs an absent drafter', async () => {
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');
+
+ await startLlamaServer({ model: modelPath, specType: 'draft-dspark' });
+
+ const startCall = execPm2Calls.find((c) => c[0] === 'start');
+ expect(startCall).not.toContain('--spec-type');
+ });
+
it('uses PortOS\'s extension port when no port is supplied', async () => {
vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');