diff --git a/install.sh b/install.sh index 5109e2a..7bfdce2 100755 --- a/install.sh +++ b/install.sh @@ -341,7 +341,7 @@ main() { # D5 — 3-way idempotent directory branch. if [ -d "$INSTALL_DIR" ] && [ -f "$marker" ]; then say "Already installed at ${INSTALL_DIR}" - info "To update: cd ${INSTALL_DIR} && git pull && npm install && npm run build:packages$( [ "$BUILD_WEB" -eq 1 ] && echo ' && npm run build' )" + info "To update: cd ${INSTALL_DIR} && git pull && ONNXRUNTIME_NODE_INSTALL_CUDA=skip npm install && npm run build:packages$( [ "$BUILD_WEB" -eq 1 ] && echo ' && npm run build' )" info "To run: bash ${INSTALL_DIR}/scripts/waggle-server.sh start --port ${PORT} --data-dir ${DATA_DIR}" info "To reinstall fresh: remove ${marker} (or the whole directory) and re-run." exit 0 @@ -358,7 +358,9 @@ main() { fi say "Installing dependencies (this can take a few minutes)" - ( cd "$INSTALL_DIR" && npm install --no-audit --no-fund ) + # onnxruntime-node would otherwise download CUDA libraries (hundreds of MB) + # on every Linux x64 install, GPU or not; the in-process models run on CPU. + ( cd "$INSTALL_DIR" && ONNXRUNTIME_NODE_INSTALL_CUDA=skip npm install --no-audit --no-fund ) say "Building packages" ( cd "$INSTALL_DIR" && npm run build:packages ) diff --git a/package-lock.json b/package-lock.json index 59d11d3..5843810 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,8 +47,7 @@ "@rollup/rollup-linux-x64-musl": "4.60.4", "@rollup/rollup-win32-x64-msvc": "4.60.4", "@swc/core-win32-x64-msvc": "^1.15.21", - "lightningcss-win32-x64-msvc": "^1.32.0", - "sqlite-vec-windows-x64": "^0.1.9" + "lightningcss-win32-x64-msvc": "^1.32.0" } }, "apps/web": { diff --git a/package.json b/package.json index c3102b3..2b5b990 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,6 @@ "@rollup/rollup-linux-x64-musl": "4.60.4", "@rollup/rollup-win32-x64-msvc": "4.60.4", "@swc/core-win32-x64-msvc": "^1.15.21", - "lightningcss-win32-x64-msvc": "^1.32.0", - "sqlite-vec-windows-x64": "^0.1.9" + "lightningcss-win32-x64-msvc": "^1.32.0" } } diff --git a/packages/agent/package.json b/packages/agent/package.json index 56a89f2..a146e37 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -1,7 +1,7 @@ { "name": "@waggle/agent", "version": "0.1.0", - "description": "Waggle agent \u2014 Orchestrator and Tools", + "description": "Waggle agent — Orchestrator and Tools", "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/cli/package.json b/packages/cli/package.json index 658794c..fde4c96 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@waggle/cli", "version": "0.1.0", - "description": "Waggle CLI \u2014 interactive AI agent with persistent memory", + "description": "Waggle CLI — interactive AI agent with persistent memory", "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/server/src/local/managed-ollama-runtime.ts b/packages/server/src/local/managed-ollama-runtime.ts index 18becac..a988c1a 100644 --- a/packages/server/src/local/managed-ollama-runtime.ts +++ b/packages/server/src/local/managed-ollama-runtime.ts @@ -21,6 +21,7 @@ import path from 'node:path'; import { Readable, Transform } from 'node:stream'; import { pipeline } from 'node:stream/promises'; import { promisify } from 'node:util'; +import zlib from 'node:zlib'; import { createLogger } from './logger.js'; const execFileAsync = promisify(execFile); @@ -196,6 +197,26 @@ export const OLLAMA_RUNTIME_ARTIFACTS: ReadonlyArray = [ sizeBytes: 145_356_966, executableName: 'ollama', }, + { + version: OLLAMA_ROLLBACK_VERSION, + platform: 'linux', + arch: 'x64', + filename: 'ollama-linux-amd64.tar.zst', + url: `${ollamaReleaseRoot(OLLAMA_ROLLBACK_VERSION)}/ollama-linux-amd64.tar.zst`, + sha256: '56362d7609dfa9e35aaebb7c9cab25605d8f0528ec3d5d585dc83d6642002bab', + sizeBytes: 1_436_128_693, + executableName: 'ollama', + }, + { + version: OLLAMA_ROLLBACK_VERSION, + platform: 'linux', + arch: 'arm64', + filename: 'ollama-linux-arm64.tar.zst', + url: `${ollamaReleaseRoot(OLLAMA_ROLLBACK_VERSION)}/ollama-linux-arm64.tar.zst`, + sha256: '2c1fbc47a5351c74f5400d7e4b1104bb470291af5d2f425c37c151487a477ad6', + sizeBytes: 1_556_234_636, + executableName: 'ollama', + }, { version: OLLAMA_TARGET_VERSION, platform: 'win32', @@ -236,6 +257,26 @@ export const OLLAMA_RUNTIME_ARTIFACTS: ReadonlyArray = [ sizeBytes: 145_790_989, executableName: 'ollama', }, + { + version: OLLAMA_TARGET_VERSION, + platform: 'linux', + arch: 'x64', + filename: 'ollama-linux-amd64.tar.zst', + url: `${ollamaReleaseRoot(OLLAMA_TARGET_VERSION)}/ollama-linux-amd64.tar.zst`, + sha256: '2597d74fbe654ef6a37db56f771cf37d4a85c6bde4018127874e3927d3113800', + sizeBytes: 1_421_853_873, + executableName: 'ollama', + }, + { + version: OLLAMA_TARGET_VERSION, + platform: 'linux', + arch: 'arm64', + filename: 'ollama-linux-arm64.tar.zst', + url: `${ollamaReleaseRoot(OLLAMA_TARGET_VERSION)}/ollama-linux-arm64.tar.zst`, + sha256: '61af0def977ffc9e76cc961f9505d621805653c63f444796de2f77b4eaaa7047', + sizeBytes: 1_542_500_407, + executableName: 'ollama', + } ]; interface InstallMetadata { @@ -425,6 +466,10 @@ async function defaultExtract( destination: string, artifact: OllamaRuntimeArtifact, ): Promise { + if (artifact.filename.endsWith('.tar.zst')) { + await extractTarZst(archivePath, destination); + return; + } const executable = artifact.platform === 'win32' ? 'tar.exe' : 'tar'; await execFileAsync(executable, ['-xf', archivePath, '-C', destination], { windowsHide: true, @@ -432,6 +477,26 @@ async function defaultExtract( }); } +/** + * Linux releases are zstd-compressed tarballs. Node 22 decompresses zstd itself + * and the system tar only unpacks; on older Node, tar needs zstd support. + */ +export async function extractTarZst(archivePath: string, destination: string): Promise { + const createZstdDecompress = (zlib as { createZstdDecompress?: () => Transform }).createZstdDecompress; + if (!createZstdDecompress) { + await execFileAsync('tar', ['--zstd', '-xf', archivePath, '-C', destination], { timeout: 10 * 60_000 }); + return; + } + const tar = spawn('tar', ['-xf', '-', '-C', destination], { stdio: ['pipe', 'ignore', 'pipe'] }); + let stderr = ''; + tar.stderr?.on('data', (chunk: Buffer) => { stderr += chunk.toString(); }); + const exited = new Promise((resolve, reject) => { + tar.once('error', reject); + tar.once('close', (code) => (code === 0 ? resolve() : reject(new Error(`tar exited with ${code}: ${stderr.trim()}`)))); + }); + await Promise.all([pipeline(createReadStream(archivePath), createZstdDecompress(), tar.stdin!), exited]); +} + function inside(root: string, candidate: string): boolean { const relative = path.relative(path.resolve(root), path.resolve(candidate)); return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative)); diff --git a/packages/server/tests/local/managed-ollama-linux.test.ts b/packages/server/tests/local/managed-ollama-linux.test.ts new file mode 100644 index 0000000..4626b14 --- /dev/null +++ b/packages/server/tests/local/managed-ollama-linux.test.ts @@ -0,0 +1,62 @@ +import { execFileSync } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import zlib from 'node:zlib'; +import { afterEach, describe, expect, it } from 'vitest'; +import { + extractTarZst, + OLLAMA_RUNTIME_ARTIFACTS, + resolveOllamaRuntimeArtifact, +} from '../../src/local/managed-ollama-runtime.js'; + +const dirs: string[] = []; +function tempDir(): string { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-ollama-linux-')); + dirs.push(dir); + return dir; +} + +afterEach(() => { + for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true }); +}); + +describe('managed Ollama on Linux', () => { + it('has a pinned artifact for x64 and arm64', () => { + for (const arch of ['x64', 'arm64']) { + const artifact = resolveOllamaRuntimeArtifact('linux', arch); + expect(artifact).toMatchObject({ + platform: 'linux', + arch, + executableName: 'ollama', + url: expect.stringMatching(/^https:\/\/github\.com\/ollama\/ollama\/releases\/download\/v[\d.]+\/ollama-linux-(amd64|arm64)\.tar\.zst$/), + sha256: expect.stringMatching(/^[0-9a-f]{64}$/), + }); + } + expect(resolveOllamaRuntimeArtifact('linux', 'ia32')).toBeNull(); + }); + + it('keeps one rollback artifact per Linux architecture', () => { + const linux = OLLAMA_RUNTIME_ARTIFACTS.filter((entry) => entry.platform === 'linux'); + expect(new Set(linux.map((entry) => `${entry.version}/${entry.arch}`)).size).toBe(linux.length); + expect(linux).toHaveLength(4); + }); + + it.skipIf(process.platform === 'win32' || !('createZstdCompress' in zlib))( + 'unpacks a zstd-compressed tarball', + async () => { + const source = tempDir(); + fs.mkdirSync(path.join(source, 'bin')); + fs.writeFileSync(path.join(source, 'bin', 'ollama'), '#!/bin/sh\necho ok\n'); + const tarball = path.join(tempDir(), 'runtime.tar'); + execFileSync('tar', ['-cf', tarball, '-C', source, 'bin']); + const compress = (zlib as unknown as { zstdCompressSync: (input: Buffer) => Buffer }).zstdCompressSync; + const archive = `${tarball}.zst`; + fs.writeFileSync(archive, compress(fs.readFileSync(tarball))); + + const destination = tempDir(); + await extractTarZst(archive, destination); + expect(fs.readFileSync(path.join(destination, 'bin', 'ollama'), 'utf8')).toContain('echo ok'); + }, + ); +});