Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Sizes in decimal MB on the first-run card and the update check (one helper); the engine bundle of a per-GPU install is removed after an update only when the same engine is complete in the store (size and SHA-256), else kept with one log line
Niko12217063f3adca75
diff --git a/apps/host/server/bundled-engine.mjs b/apps/host/server/bundled-engine.mjsindex 8ae24287d..1260eb942 100644--- a/apps/host/server/bundled-engine.mjs+++ b/apps/host/server/bundled-engine.mjs@@ -234,3 +234,45 @@ export async function installBundledEngine({ bundleDir, components, platform = nreturn { action: 'refused', reason: error?.message ?? String(error) };}}++/**+ * After an update from an installer that carried an engine (a per-GPU build), its `engine-bundle` folder is still in the install folder+ * (about 570 MB) although the engine was copied to the engine store long ago. It is removed only when EVERY package in it exists complete in+ * the store (every file there with the size and SHA-256 its manifest lists); otherwise it stays and one line says why.+ * Returns { removed: bool, reason?: string, packages?: number }; never throws.+ */+export async function removeVerifiedBundle({ bundleDir, components, log = () => {} } = {}) {+ try {+ if (!bundleDir || !components || !existsSync(bundleDir)) return { removed: false, reason: 'no bundle' };+ const packages = [];+ for (const entry of await readdir(bundleDir, { withFileTypes: true })) {+ if (!entry.isDirectory()) continue;+ const folder = join(bundleDir, entry.name);+ const manifest = await readManifest(folder);+ packages.push({ folder, manifest, name: entry.name });+ }+ if (!packages.length) return { removed: false, reason: 'nothing in the bundle' };+ const store = join(components, 'engine');+ const stored = existsSync(store) ? (await readdir(store, { withFileTypes: true })).filter(e => e.isDirectory() && !e.name.startsWith('.')).map(e => join(store, e.name)) : [];+ for (const pkg of packages) {+ if (!pkg.manifest) return keepBundle(log, `${pkg.name} has no readable manifest`);+ let found = false;+ for (const candidate of stored) {+ const theirs = await readManifest(candidate);+ if (!theirs || theirs.version !== pkg.manifest.version || theirs.platform !== pkg.manifest.platform || theirs.backend !== pkg.manifest.backend+ || (theirs.variant ?? '') !== (pkg.manifest.variant ?? '') || (theirs.build_id ?? '') !== (pkg.manifest.build_id ?? '')) continue;+ if (await packageIsWhole(candidate, pkg.manifest, { deep: true })) { found = true; break; }+ }+ if (!found) return keepBundle(log, `${pkg.name} is not (or not completely) in the engine store`);+ }+ for (const pkg of packages) await rm(pkg.folder, { recursive: true, force: true });+ log(`engine bundle: the copy that came with the installer (${packages.map(p => p.name).join(', ')}) was removed; the same engine is complete in the engine store`);+ return { removed: true, packages: packages.length };+ } catch (error) {+ return keepBundle(log, `could not be checked (${error?.message ?? error})`);+ }+}+function keepBundle(log, why) {+ log(`engine bundle: kept in the install folder (${why})`);+ return { removed: false, reason: why };+}diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjsindex 3dfdb3799..d0549df3d 100644--- a/apps/host/server/index.mjs+++ b/apps/host/server/index.mjs@@ -70,7 +70,7 @@ import { createImageModels } from './image-models.mjs';import { createRuntimeModels } from './runtime-models.mjs';import { createNativeControl } from './native-control.mjs';import { nativeUnloadPlan } from './storage-check.mjs';-import { installBundledEngine } from './bundled-engine.mjs';+import { installBundledEngine, removeVerifiedBundle } from './bundled-engine.mjs';import { findControl, createControl, componentsDirectory } from './control-runtime.mjs';import { forbidden as acquisitionForbidden } from './acquisition.mjs';import { randomBytes, timingSafeEqual } from 'node:crypto';@@ -131,6 +131,9 @@ const appUpdater = appUi.updater;const bundledEngine = control && !process.env.STRATA_NO_BUNDLED_ENGINE? installBundledEngine({ bundleDir: process.env.STRATA_ENGINE_BUNDLE_DIR || resolve(HERE, '..', '..', 'engine-bundle'), components: componentsDirectory(), log: line => console.log(line) }): Promise.resolve({ action: 'none' });+const engineBundleDir = process.env.STRATA_ENGINE_BUNDLE_DIR || resolve(HERE, '..', '..', 'engine-bundle');+/* An update from a per-GPU installer leaves its engine-bundle behind; it goes only when the same engine is complete in the store (sizes and hashes). */+bundledEngine.then(result => { if (['installed', 'kept', 'repaired'].includes(result?.action)) return removeVerifiedBundle({ bundleDir: engineBundleDir, components: componentsDirectory(), log: line => console.log(line) }); }, () => {});let bundledEngineSettled = !(control && !process.env.STRATA_NO_BUNDLED_ENGINE);bundledEngine.then(() => { bundledEngineSettled = true; }, () => { bundledEngineSettled = true; });/* A build made for another make of graphics card is not unpacked; Control's answer then carries the plain sentence (with the right download) instead of its own. */diff --git a/apps/host/server/updates.mjs b/apps/host/server/updates.mjsindex e53372583..89dce9fb2 100644--- a/apps/host/server/updates.mjs+++ b/apps/host/server/updates.mjs@@ -59,7 +59,7 @@ export async function checkComponentUpdates({ control, appUpdater = null, appVerconst message = /update server|aren't available|No internet/.test(plain.headline) ? plain.message : `Couldn't check for updates. Try again in a moment.`;return { checkedAt, strata: { installedVersion: appVersion ?? control.version ?? null, status: 'error', message, details: plain.details, canInstall: false }, engine: { installedVersion: null, status: 'error', message, details: plain.details, canInstall: false } };}- const mib = bytes => `${Math.round((bytes ?? 0) / (1 << 20))} MB`;+ const mib = bytes => `${Math.round((bytes ?? 0) / 1_000_000)} MB`; // decimal megabytes, like the Terminal and the release pageconst engine = report.engine ?? {};const installedEngine = engine.installed?.version ?? null;const offered = engine.offered?.version ?? null;diff --git a/apps/host/src/components/EngineFirstRun.tsx b/apps/host/src/components/EngineFirstRun.tsxindex fac6cce43..2992cf846 100644--- a/apps/host/src/components/EngineFirstRun.tsx+++ b/apps/host/src/components/EngineFirstRun.tsx@@ -5,6 +5,7 @@ import { Bar, Btn, Icon } from './ui';import { api } from '../lib/client';import { useDownloadEta } from '../lib/download-eta';import type { NativeJob } from '../lib/native';+import { megabytes } from '../lib/format';/** What the host says about this PC's engine (GET /api/engine/first-run). */export interface FirstRunInfo {@@ -18,8 +19,7 @@ export interface FirstRunInfo {freeBytes?: number;}-const MB = 1024 * 1024;-export const mb = (bytes: number) => Math.max(1, Math.round(bytes / MB));+export const mb = megabytes;/*** Whether this PC still needs its engine. Reads only Control's local answer (no network): the engine is missing and the engine that camediff --git a/apps/host/src/lib/format.ts b/apps/host/src/lib/format.tsindex 3d7c23fcf..f0e6623e6 100644--- a/apps/host/src/lib/format.ts+++ b/apps/host/src/lib/format.ts@@ -128,3 +128,6 @@ export function formatModelName(model: {export function userError(message: string): string {return message.replace(/^\s*Fixture:\s*/i, '').replace(/^./, c => c.toUpperCase());}++/** Decimal megabytes (1 MB = 1,000,000 bytes, at least 1): the same figure as the Terminal and the release page. The only size helper in MB; no binary units. */+export const megabytes = (bytes: number) => Math.max(1, Math.round(bytes / 1_000_000));diff --git a/apps/host/tests/bundled-engine.test.mjs b/apps/host/tests/bundled-engine.test.mjsindex 2bfdec3c3..4ebcee2a4 100644--- a/apps/host/tests/bundled-engine.test.mjs+++ b/apps/host/tests/bundled-engine.test.mjs@@ -5,7 +5,7 @@ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, readdiimport { createHash } from 'node:crypto';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { installBundledEngine, compareVersions, wrongMakeNotice } from '../server/bundled-engine.mjs';+import { installBundledEngine, removeVerifiedBundle, compareVersions, wrongMakeNotice } from '../server/bundled-engine.mjs';// the make of card is read from this computer unless a test names it; the existing tests are written for an NVIDIA PCprocess.env.STRATA_ENGINE_BACKEND = 'cuda';@@ -185,3 +185,47 @@ test('Windows: the display adapters decide the make, and a leftover nvidia-smi dassert.equal(windowsDisplayVendors({ platform: 'linux', run: () => { throw new Error('must not run'); } }).size, 0);assert.equal(windowsDisplayVendors({ platform: 'win32', run: () => { throw new Error('no registry'); } }).size, 0);});++test('after an update, the engine bundle of the old install folder is removed only when the same engine is complete in the store', async () => {+ const t = setup();+ try {+ const name = makePackage(t.bundle, '0.1.48');+ writeFileSync(join(t.bundle, '.gitignore'), 'ignore-all');+ const lines = [];+ // 1. nothing in the store yet: kept, and one line says why+ let r = await removeVerifiedBundle({ bundleDir: t.bundle, components: t.components, log: l => lines.push(l) });+ assert.equal(r.removed, false);+ assert.equal(lines.length, 1);+ assert.match(lines[0], /kept in the install folder.*not \(or not completely\) in the engine store/);+ assert.ok(existsSync(join(t.bundle, name)));+ // 2. the engine is copied (the app's own first start does this)+ assert.equal((await installBundledEngine({ bundleDir: t.bundle, components: t.components })).action, 'installed');+ // 3. a store file with the right size and the wrong content: kept (the hash is checked, not only the size)+ const target = join(t.engine, name, 'strata.exe');+ const good = readFileSync(target);+ writeFileSync(target, Buffer.alloc(good.length, 'x'));+ lines.length = 0;+ r = await removeVerifiedBundle({ bundleDir: t.bundle, components: t.components, log: l => lines.push(l) });+ assert.equal(r.removed, false);+ assert.equal(lines.length, 1, 'exactly one line');+ assert.ok(existsSync(join(t.bundle, name)));+ // 4. a store file with the wrong size: kept+ writeFileSync(target, Buffer.concat([good, Buffer.from('extra')]));+ assert.equal((await removeVerifiedBundle({ bundleDir: t.bundle, components: t.components })).removed, false);+ // 5. the store copy is whole: the bundle goes, its .gitignore stays, and the store is untouched+ writeFileSync(target, good);+ lines.length = 0;+ r = await removeVerifiedBundle({ bundleDir: t.bundle, components: t.components, log: l => lines.push(l) });+ assert.equal(r.removed, true);+ assert.equal(existsSync(join(t.bundle, name)), false);+ assert.ok(existsSync(join(t.bundle, '.gitignore')));+ assert.equal(readFileSync(target, 'utf8'), 'engine-0.1.48');+ assert.match(lines.at(-1), /was removed; the same engine is complete in the engine store/);+ // 6. nothing left to do+ assert.equal((await removeVerifiedBundle({ bundleDir: t.bundle, components: t.components })).removed, false);+ // 7. a different version in the store does not count+ const other = makePackage(t.bundle, '0.1.49');+ assert.equal((await removeVerifiedBundle({ bundleDir: t.bundle, components: t.components })).removed, false);+ assert.ok(existsSync(join(t.bundle, other)));+ } finally { t.cleanup(); }+});diff --git a/apps/host/tests/component-updates.test.mjs b/apps/host/tests/component-updates.test.mjsindex d9ec73f95..13a336b68 100644--- a/apps/host/tests/component-updates.test.mjs+++ b/apps/host/tests/component-updates.test.mjs@@ -121,7 +121,7 @@ test('the Settings check says so, in plain words, when the own update check of t});test('the Settings update check maps the feed to the existing result shape', async () => {- const report = overrides => ({ ok: true, feed: { sequence: 3 }, engine: { installed: { version: '0.1.45' }, offered: { version: '0.1.46' }, status: 'available', download_bytes: 505 * (1 << 20) }, control: { installed: '0.1.45', offered: '0.1.45', status: 'current' }, app: { status: 'not-in-feed' }, ...overrides });+ const report = overrides => ({ ok: true, feed: { sequence: 3 }, engine: { installed: { version: '0.1.45' }, offered: { version: '0.1.46' }, status: 'available', download_bytes: 505_000_000 }, control: { installed: '0.1.45', offered: '0.1.45', status: 'current' }, app: { status: 'not-in-feed' }, ...overrides });const make = value => ({ version: '0.1.45', async updateCheck() { if (value instanceof Error) throw value; return value; } });let result = await checkComponentUpdates({ control: make(report()), appVersion: '0.1.0' });assert.equal(result.engine.status, 'available');@@ -130,7 +130,7 @@ test('the Settings update check maps the feed to the existing result shape', asyassert.doesNotMatch(result.engine.message, /0\.1\.4|sha|exit/i);assert.equal(result.engine.canInstall, true);assert.equal(result.strata.status, 'current');- result = await checkComponentUpdates({ control: make(report({ engine: { installed: null, offered: { version: '0.1.46' }, status: 'install', download_bytes: 505 * (1 << 20) } })) });+ result = await checkComponentUpdates({ control: make(report({ engine: { installed: null, offered: { version: '0.1.46' }, status: 'install', download_bytes: 505_000_000 } })) });assert.equal(result.engine.status, 'available');assert.match(result.engine.message, /needs an engine to run models\. Press Update engine/);result = await checkComponentUpdates({ control: make(report({ engine: { installed: { version: '0.1.46' }, offered: { version: '0.1.46' }, status: 'current' } })) });diff --git a/apps/host/tests/size-label.test.mjs b/apps/host/tests/size-label.test.mjsnew file mode 100644index 000000000..adbcfa834--- /dev/null+++ b/apps/host/tests/size-label.test.mjs@@ -0,0 +1,15 @@+/** The first-run card and the update check show decimal megabytes, the same figure as the Terminal and the release page. */+import test from 'node:test';+import assert from 'node:assert/strict';+import { build } from 'esbuild';+import { fileURLToPath } from 'node:url';++const out = await build({ entryPoints: [fileURLToPath(new URL('../src/lib/format.ts', import.meta.url))], bundle: true, format: 'esm', platform: 'node', write: false, logLevel: 'silent' });+const { megabytes } = await import(`data:text/javascript;base64,${Buffer.from(out.outputFiles[0].text).toString('base64')}`);++test('engine sizes are decimal megabytes: 606,513,890 bytes is 607 MB, not 578', () => {+ assert.equal(megabytes(606513890), 607);+ assert.equal(megabytes(581299508), 581);+ assert.equal(megabytes(1), 1);+ assert.equal(megabytes(0), 1);+});