build: package the sidecar without the legacy memory runtime (P1.5, P1.3b)
- Stop building and staging the hive-mind CLI, the coding-agent hook packages and the memory MCP server: the hooks, Waggle Room and the memory MCP server are hidden in v1 (ADR-0002) and all of them write to the legacy .mind files. - Drop sqlite-vec: nothing loads a SQLite extension since the legacy memory engine left. bundle-native-deps no longer copies vec0, the resource check no longer probes it, the Tauri shell no longer sets WAGGLE_SQLITE_VEC_PATH and install.sh checks plain SQLite. - Stage bundle roots that npm keeps inside a workspace. mem0ai is not hoisted (it stays in packages/memory-mem0), so staging skipped it silently and the packaged sidecar would fail on the first memory access. Roots that are not installed are now listed in the output. - js-yaml is a runtime dependency of Puppeteer's config loader since the WhatsApp channel moved to whatsapp-web.js (ADR-0005); it leaves the resource-check denylist. chromium-bidi stays unstaged: Puppeteer loads it only for WebDriver BiDi sessions.
This commit is contained in:
@@ -19,14 +19,14 @@ const nativeDir = path.join(root, 'app', 'src-tauri', 'resources', 'native');
|
||||
const platform = process.platform;
|
||||
const arch = process.env.TARGET_ARCH || process.arch;
|
||||
|
||||
// macOS "universal" is not a valid staging target: sqlite-vec and onnxruntime
|
||||
// macOS "universal" is not a valid staging target: better-sqlite3 and onnxruntime
|
||||
// ship per-arch binaries (no darwin/universal path exists), so a universal run
|
||||
// silently falls through to the x64 variant and mis-stages the arm64 half.
|
||||
// Build each arch separately and lipo the app bundle instead.
|
||||
if (arch === 'universal') {
|
||||
console.error(
|
||||
'[bundle-native-deps] FATAL — TARGET_ARCH=universal is not supported.\n'
|
||||
+ ' Native modules (sqlite-vec, onnxruntime-node) are per-arch. Build each\n'
|
||||
+ ' Native modules (better-sqlite3, onnxruntime-node) are per-arch. Build each\n'
|
||||
+ ' arch separately: TARGET_ARCH=arm64 (aarch64-apple-darwin) and\n'
|
||||
+ ' TARGET_ARCH=x64 (x86_64-apple-darwin) — see release.yml\'s macOS matrix\n'
|
||||
+ ' and the app tauri:build:mac:arm64 / :x64 scripts.',
|
||||
@@ -114,16 +114,7 @@ function copyDir(srcDir, destSubDir) {
|
||||
console.log('[bundle-native-deps] better-sqlite3:');
|
||||
copyFile('node_modules/better-sqlite3/build/Release/better_sqlite3.node', 'better_sqlite3.node');
|
||||
|
||||
// 2. sqlite-vec
|
||||
console.log('[bundle-native-deps] sqlite-vec:');
|
||||
const vecOs = platform === 'win32' ? 'windows' : platform === 'darwin' ? 'darwin' : 'linux';
|
||||
const vecExt = platform === 'win32' ? 'dll' : platform === 'darwin' ? 'dylib' : 'so';
|
||||
copyFile(
|
||||
`node_modules/sqlite-vec-${vecOs}-${arch}/vec0.${vecExt}`,
|
||||
`vec0.${vecExt}`,
|
||||
);
|
||||
|
||||
// 3. onnxruntime-node (multiple files — binding + shared libraries)
|
||||
// 2. onnxruntime-node (multiple files — binding + shared libraries)
|
||||
console.log('[bundle-native-deps] onnxruntime-node:');
|
||||
const ortOs = platform === 'win32' ? 'win32' : platform === 'darwin' ? 'darwin' : 'linux';
|
||||
const ortDir = `node_modules/onnxruntime-node/bin/napi-v3/${ortOs}/${arch}`;
|
||||
|
||||
@@ -33,9 +33,8 @@ const targetArch = process.env.TARGET_ARCH || process.arch;
|
||||
const SIDECAR_PROVENANCE_PREFIX = '// Waggle-Sidecar-Provenance: ';
|
||||
const SOURCE_ARTIFACT_PATTERN = /(?:\.map|\.(?:[cm]?ts|tsx)|\.tsbuildinfo)$/i;
|
||||
const FIRST_PARTY_RUNTIME_ENTRY_PATTERN = /^(?:dist|package\.json|licen[cs]e(?:\.(?:md|txt))?|notice(?:\.(?:md|txt))?)$/i;
|
||||
const MANUAL_FIRST_PARTY_RUNTIME_TARGETS = new Map([
|
||||
['@waggle/hive-mind-hooks-openclaw', ['dist/handler.bundle.cjs']],
|
||||
]);
|
||||
// Runtime files of a staged first-party package that its manifest does not name.
|
||||
const MANUAL_FIRST_PARTY_RUNTIME_TARGETS = new Map();
|
||||
const REQUIRED_SHARP_VERSION = '0.35.3';
|
||||
const REQUIRED_BETTER_SQLITE_RANGE = '>=12.6.2 <13';
|
||||
const STAGED_DEPENDENCY_VERSION_ALLOWLISTS = new Map([
|
||||
@@ -43,7 +42,10 @@ const STAGED_DEPENDENCY_VERSION_ALLOWLISTS = new Map([
|
||||
['fast-uri', new Set(['3.1.5'])],
|
||||
['ip-address', new Set(['10.4.0'])],
|
||||
]);
|
||||
const STAGED_DEPENDENCY_DENYLIST = new Set(['js-yaml']);
|
||||
// Packages that must never reach the installer. js-yaml left this list with the
|
||||
// WhatsApp channel (ADR-0005): Puppeteer reads its config through cosmiconfig,
|
||||
// which parses YAML with it at runtime.
|
||||
const STAGED_DEPENDENCY_DENYLIST = new Set();
|
||||
|
||||
const missing = [];
|
||||
const unsafe = [];
|
||||
@@ -717,7 +719,6 @@ const nativeEntries = fs.existsSync(nativeDir)
|
||||
: [];
|
||||
const requiredWindowsNativeFiles = [
|
||||
'better_sqlite3.node',
|
||||
'vec0.dll',
|
||||
'onnxruntime/onnxruntime_binding.node',
|
||||
];
|
||||
if (process.platform === 'win32') {
|
||||
@@ -731,7 +732,6 @@ if (process.platform === 'win32') {
|
||||
} else if (process.platform === 'darwin') {
|
||||
const requiredMacNativeFiles = [
|
||||
'better_sqlite3.node',
|
||||
'vec0.dylib',
|
||||
'onnxruntime/onnxruntime_binding.node',
|
||||
];
|
||||
for (const entry of requiredMacNativeFiles) {
|
||||
@@ -772,10 +772,6 @@ const stagedSharpWindowsBinding = path.join(
|
||||
'lib',
|
||||
`sharp-win32-x64-${REQUIRED_SHARP_VERSION}.node`,
|
||||
);
|
||||
const vecExtension = path.join(
|
||||
nativeDir,
|
||||
`vec0.${process.platform === 'win32' ? 'dll' : process.platform === 'darwin' ? 'dylib' : 'so'}`,
|
||||
);
|
||||
if (!fs.existsSync(path.join(stagedBetterSqlite, 'package.json'))) {
|
||||
missing.push('resources/node_modules/* (run: node scripts/stage-sidecar-deps.mjs)');
|
||||
}
|
||||
@@ -902,20 +898,16 @@ if (
|
||||
fs.existsSync(nodePath)
|
||||
&& fs.existsSync(path.join(stagedBetterSqlite, 'package.json'))
|
||||
&& fs.existsSync(path.join(stagedOnnxRuntime, 'package.json'))
|
||||
&& fs.existsSync(vecExtension)
|
||||
) {
|
||||
try {
|
||||
const probe = [
|
||||
'const Database = require(process.argv[1]);',
|
||||
'if (process.arch !== process.argv[2]) throw new Error(`architecture ${process.arch}`);',
|
||||
'const database = new Database(\':memory:\');',
|
||||
'database.loadExtension(process.argv[3]);',
|
||||
'const row = database.prepare(\'SELECT 1 AS ok\').get();',
|
||||
'const vec = database.prepare(\'SELECT vec_version() AS version\').get();',
|
||||
'database.close();',
|
||||
'if (row.ok !== 1) throw new Error(\'SQLite query failed\');',
|
||||
'if (typeof vec.version !== \'string\' || vec.version.length === 0) throw new Error(\'sqlite-vec query failed\');',
|
||||
'const onnx = require(process.argv[4]);',
|
||||
'const onnx = require(process.argv[3]);',
|
||||
'if (typeof onnx.InferenceSession !== \'function\') throw new Error(\'ONNX binding failed\');',
|
||||
].join('');
|
||||
execFileSync(nodePath, [
|
||||
@@ -923,7 +915,6 @@ if (
|
||||
probe,
|
||||
stagedBetterSqlite,
|
||||
targetArch,
|
||||
vecExtension,
|
||||
stagedOnnxRuntime,
|
||||
], {
|
||||
cwd: resourcesDir,
|
||||
@@ -932,32 +923,12 @@ if (
|
||||
});
|
||||
} catch {
|
||||
missing.push(
|
||||
`resources native runtime probe failed for better-sqlite3, sqlite-vec, or onnxruntime-node `
|
||||
`resources native runtime probe failed for better-sqlite3 or onnxruntime-node `
|
||||
+ `using bundled ${nodeBinary} for ${targetArch}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// External agents and hook management run directly from this staged payload;
|
||||
// none of these packages are available from npm in a packaged installation.
|
||||
const hookRuntimeEntries = [
|
||||
'@waggle/hive-mind-cli/dist/index.js',
|
||||
'@waggle/hive-mind-hooks-claude-code/dist/bin/claude-code-hooks-cli.js',
|
||||
'@waggle/hive-mind-hooks-claude-desktop/dist/bin/claude-desktop-hooks.js',
|
||||
'@waggle/hive-mind-hooks-codex/dist/bin/codex-hooks.js',
|
||||
'@waggle/hive-mind-hooks-codex-desktop/dist/bin/codex-desktop-hooks.js',
|
||||
'@waggle/hive-mind-hooks-cursor/dist/bin/cursor-hooks.js',
|
||||
'@waggle/hive-mind-hooks-hermes/dist/bin/hermes-hooks.js',
|
||||
'@waggle/hive-mind-hooks-openclaw/dist/bin/openclaw-hooks.js',
|
||||
'@waggle/hive-mind-hooks-openclaw/dist/handler.bundle.cjs',
|
||||
'waggle-memory-mcp/dist/index.js',
|
||||
];
|
||||
for (const entry of hookRuntimeEntries) {
|
||||
if (!fs.existsSync(path.join(stagedDepsDir, ...entry.split('/')))) {
|
||||
missing.push(`resources/node_modules/${entry} (run: node scripts/stage-sidecar-deps.mjs)`);
|
||||
}
|
||||
}
|
||||
|
||||
if (missing.length > 0 || unsafe.length > 0) {
|
||||
console.error('[check-sidecar-resources] FATAL — sidecar resources are not release-safe:');
|
||||
for (const m of missing) console.error(` - ${m}`);
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { builtinModules } from 'node:module';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
@@ -40,18 +39,6 @@ const resourcesDir = path.join(root, 'app', 'src-tauri', 'resources');
|
||||
const metaFile = path.join(os.tmpdir(), 'waggle-sidecar-meta.json');
|
||||
const stageDir = path.join(resourcesDir, 'node_modules');
|
||||
const bundledNpmRuntimeDir = path.join(stageDir, 'waggle-node-runtime');
|
||||
const hookRuntimeBuild = path.join(root, 'scripts', 'build-hook-runtime.mjs');
|
||||
const HOOK_RUNTIME_ROOTS = new Set([
|
||||
'@waggle/hive-mind-cli',
|
||||
'@waggle/hive-mind-hooks-claude-code',
|
||||
'@waggle/hive-mind-hooks-claude-desktop',
|
||||
'@waggle/hive-mind-hooks-codex',
|
||||
'@waggle/hive-mind-hooks-codex-desktop',
|
||||
'@waggle/hive-mind-hooks-cursor',
|
||||
'@waggle/hive-mind-hooks-hermes',
|
||||
'@waggle/hive-mind-hooks-openclaw',
|
||||
'waggle-memory-mcp',
|
||||
]);
|
||||
// These are loaded through computed require() calls, so esbuild's metafile
|
||||
// cannot discover them even though installed desktop features require them.
|
||||
const DYNAMIC_RUNTIME_ROOTS = new Set(['adm-zip']);
|
||||
@@ -109,9 +96,8 @@ const RUNTIME_PRUNED_DIR_NAMES = new Set([
|
||||
]);
|
||||
const SOURCE_ARTIFACT_PATTERN = /(?:\.map|\.(?:[cm]?ts|tsx)|\.tsbuildinfo)$/i;
|
||||
const WORKSPACE_RUNTIME_ENTRY_PATTERN = /^(?:dist|package\.json|licen[cs]e(?:\.(?:md|txt))?|notice(?:\.(?:md|txt))?)$/i;
|
||||
const MANUAL_WORKSPACE_RUNTIME_TARGETS = new Map([
|
||||
['@waggle/hive-mind-hooks-openclaw', ['dist/handler.bundle.cjs']],
|
||||
]);
|
||||
// Runtime files of a staged workspace package that its manifest does not name.
|
||||
const MANUAL_WORKSPACE_RUNTIME_TARGETS = new Map();
|
||||
const WINDOWS_1252_EXTRA_CODEPOINTS = new Set([
|
||||
0x20ac, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030,
|
||||
0x0160, 0x2039, 0x0152, 0x017d, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022,
|
||||
@@ -168,6 +154,26 @@ function resolvePkgDir(name, fromDir) {
|
||||
}
|
||||
}
|
||||
|
||||
const WORKSPACE_DIRS = ['packages', 'apps'].flatMap((base) => {
|
||||
const dir = path.join(root, base);
|
||||
return fs.existsSync(dir) ? fs.readdirSync(dir).map((name) => path.join(dir, name)) : [];
|
||||
});
|
||||
|
||||
/**
|
||||
* Resolve a bundle root. npm keeps a package inside the workspace that depends
|
||||
* on it when it cannot hoist it (mem0ai stays in packages/memory-mem0), so look
|
||||
* in the workspaces when the repo root does not have it.
|
||||
*/
|
||||
function resolveRootPkgDir(name) {
|
||||
const fromRoot = resolvePkgDir(name, root);
|
||||
if (fromRoot) return fromRoot;
|
||||
for (const workspaceDir of WORKSPACE_DIRS) {
|
||||
const candidate = path.join(workspaceDir, 'node_modules', name);
|
||||
if (fs.existsSync(path.join(candidate, 'package.json'))) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
let copiedPackages = 0;
|
||||
let prunedRuntimeDirs = 0;
|
||||
let prunedRuntimeFiles = 0;
|
||||
@@ -243,16 +249,18 @@ function readManifest(pkgDir) {
|
||||
*/
|
||||
function stageClosure(rootNames) {
|
||||
const processedDirs = new Set();
|
||||
const queue = [...rootNames].map((name) => ({ name, fromDir: root }));
|
||||
const queue = [...rootNames].map((name) => ({ name, fromDir: null }));
|
||||
const absentRoots = [];
|
||||
|
||||
while (queue.length > 0) {
|
||||
const { name, fromDir } = queue.shift();
|
||||
if (SKIP.has(name)) continue;
|
||||
|
||||
const pkgDir = resolvePkgDir(name, fromDir);
|
||||
const pkgDir = fromDir === null ? resolveRootPkgDir(name) : resolvePkgDir(name, fromDir);
|
||||
if (!pkgDir) {
|
||||
// Optional/absent (e.g. bufferutil, utf-8-validate, pg): the bundle
|
||||
// guards these or never reaches them — nothing to stage.
|
||||
if (fromDir === null) absentRoots.push(name);
|
||||
continue;
|
||||
}
|
||||
const pkgKey = fs.realpathSync.native(pkgDir);
|
||||
@@ -267,6 +275,9 @@ function stageClosure(rootNames) {
|
||||
queue.push({ name: dep, fromDir: pkgDir });
|
||||
}
|
||||
}
|
||||
if (absentRoots.length) {
|
||||
console.log(`[stage-sidecar-deps] not installed, not staged: ${absentRoots.sort().join(', ')}`);
|
||||
}
|
||||
return processedDirs;
|
||||
}
|
||||
|
||||
@@ -622,11 +633,6 @@ function preserveBundledNpmRuntime() {
|
||||
// ── main ───────────────────────────────────────────────────────────
|
||||
console.log(`[stage-sidecar-deps] Platform: ${platform}-${arch}`);
|
||||
|
||||
// These workspace packages are loaded by hook installers/external agents, not
|
||||
// by the sidecar bundle itself, so the esbuild metafile cannot discover them.
|
||||
// Build them explicitly before copying their production dependency closure.
|
||||
execFileSync(process.execPath, [hookRuntimeBuild], { cwd: root, stdio: 'inherit' });
|
||||
|
||||
// Fresh stage dir each run so a removed dep never lingers in a stale bundle.
|
||||
const preservedNpmRuntime = preserveBundledNpmRuntime();
|
||||
try {
|
||||
@@ -643,7 +649,6 @@ try {
|
||||
const externals = readExternalPackages();
|
||||
const runtimeRoots = new Set([
|
||||
...externals,
|
||||
...HOOK_RUNTIME_ROOTS,
|
||||
...DYNAMIC_RUNTIME_ROOTS,
|
||||
]);
|
||||
const staged = [...runtimeRoots].filter((n) => !SKIP.has(n)).sort();
|
||||
|
||||
Reference in New Issue
Block a user