From d2b6506f8b6dd2b0b2172fc8352777ed51f2fea2 Mon Sep 17 00:00:00 2001 From: "shumeiko.it" Date: Thu, 15 Oct 2026 19:31:50 +0200 Subject: [PATCH] build: declare workspace dependencies and check them in CI (P0.2) Packages relied on npm hoisting for imports they never declared, so a package installed on its own fails (UF-024). - server: + @waggle/marketplace, @waggle/sdk, @waggle/weaver, zod (MIT), @anthropic-ai/sdk (MIT), @ax-llm/ax (Apache-2.0); - @waggle/hive-mind-shim-core and stripe (unused) - agent: + pdf-parse (Apache-2.0); playwright-core (Apache-2.0) as an optional peer, since it is loaded only when available - worker: + @waggle/waggle-dance; web: + @waggle/shared - launcher: + @waggle/server as a dev dependency (bundled by tsup); - stripe; cli: - @waggle/weaver (unused); root: - stripe scripts/check-workspace-deps.mjs (npm run check:deps) compares the imports in each community-edition package's src/ with its manifest and runs in CI. Two imports wait for P1.4 (optimizer, evolution wiring). --- .github/workflows/ci.yml | 3 + AGENTS.md | 4 +- apps/web/package.json | 1 + docs/oss/upstream-fixes.md | 10 +++ package-lock.json | 23 ++++-- package.json | 2 +- packages/agent/package.json | 9 +++ packages/cli/package.json | 1 - packages/launcher/package.json | 2 +- packages/server/package.json | 8 +- packages/worker/package.json | 1 + scripts/check-workspace-deps.mjs | 126 +++++++++++++++++++++++++++++++ 12 files changed, 179 insertions(+), 11 deletions(-) create mode 100644 scripts/check-workspace-deps.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa57ffb..eb7d1ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,9 @@ jobs: - name: Lint (root flat config) run: npm run lint + - name: Workspace dependency declarations + run: npm run check:deps + - name: Tauri TS typecheck (app/scripts) run: npx tsc -p app/tsconfig.json diff --git a/AGENTS.md b/AGENTS.md index 03b379a..af1fed3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -155,7 +155,9 @@ npx tsc --noEmit --project packages/server/tsconfig.json # the sidecar runs vi npx tsc --noEmit --project app/tsconfig.json npm run test # root Vitest: packages, tests/, scripts/ (excludes apps/**) (cd apps/web && npx vitest run) # web UI tests use their own config -npm run lint +npm run lint # root config; ignores apps/web +(cd apps/web && npx eslint .) # web config; 49 errors pre-exist (docs/oss/baseline.md) +npm run check:deps # every imported package is declared in its package.json ``` - Playwright e2e reuses any server already listening on :3333 and its data directory. For an diff --git a/apps/web/package.json b/apps/web/package.json index b1dc2ed..e5f2faf 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -47,6 +47,7 @@ "@tauri-apps/api": "^2.10.1", "@tauri-apps/plugin-dialog": "^2.7.0", "@types/qrcode": "^1.5.6", + "@waggle/shared": "*", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.1.1", diff --git a/docs/oss/upstream-fixes.md b/docs/oss/upstream-fixes.md index 907ea96..f584736 100644 --- a/docs/oss/upstream-fixes.md +++ b/docs/oss/upstream-fixes.md @@ -52,6 +52,7 @@ Baseline: commit `b20b138` of `git.os-dev.tech/oleg.m/waggle-os`. | UF-021 | Settings visual-regression baseline is ignored by git | Fixed | Tests, git | | UF-022 | Unit tests write into the developer's real `~/.waggle` | Fixed | Tests | | UF-023 | Four unit-test files fail on macOS | Open | Tests, macOS | +| UF-024 | Workspace packages import packages they do not declare | Fixed | Build, packaging | ## Entries @@ -234,3 +235,12 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14. - Cause: the runtime fixtures appear to assume the Windows archive layout, and the path checks do not account for `/var` being a symlink to `/private/var` on macOS. The OpenClaw timeout is not investigated yet. - What we did: nothing yet. The failures are recorded as known in `docs/oss/baseline.md`. - Recommendation: make the runtime fixtures platform-aware, compare resolved paths (`fs.realpathSync`) in path assertions, and run the unit suite on macOS and Linux in CI. + +### UF-024. Workspace packages import packages they do not declare +- Status: Fixed +- Found: 2026-10-15 +- Where: `package.json` of `packages/server`, `packages/agent`, `packages/launcher`, `packages/worker`, `packages/cli` and `apps/web` +- Symptom: inside the monorepo everything works because npm hoists all dependencies to the root `node_modules`, but a package installed on its own fails to resolve imports. `server` imports `@waggle/marketplace`, `@waggle/sdk`, `@waggle/weaver`, `zod`, `@anthropic-ai/sdk` and `@ax-llm/ax` without declaring them; `agent` imports `pdf-parse` and `playwright-core`; `worker` imports `@waggle/waggle-dance`; `launcher` imports `@waggle/server`; `apps/web` imports `@waggle/shared`. `server` declares `@waggle/hive-mind-shim-core` and `cli` declares `@waggle/weaver` without using them. +- Cause: no check compares imports with declared dependencies. +- What we did: declared the missing dependencies (`playwright-core` as an optional peer, because `agent` loads it only when available; `@waggle/server` as a dev dependency of `launcher`, because its build bundles `@waggle/*`), removed the unused ones, and added `scripts/check-workspace-deps.mjs` (`npm run check:deps`) to CI. +- Recommendation: apply the same declarations in the main project and run the check in CI. diff --git a/package-lock.json b/package-lock.json index 2baf12c..185f994 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,6 @@ "@tauri-apps/plugin-shell": "^2.3.5", "@vitejs/plugin-react": "5.1.1", "sharp": "0.35.3", - "stripe": "^21.0.1", "tailwind-merge": "^3.5.0" }, "devDependencies": { @@ -89,6 +88,7 @@ "@tauri-apps/api": "^2.10.1", "@tauri-apps/plugin-dialog": "^2.7.0", "@types/qrcode": "^1.5.6", + "@waggle/shared": "*", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.1.1", @@ -23953,12 +23953,21 @@ "exceljs": "^4.4.0", "glob": "^13.0.6", "jszip": "^3.10.1", + "pdf-parse": "^2.4.5", "pdfmake": "^0.3.7", "undici": "^6.27.0" }, "devDependencies": { "@types/pdfmake": "^0.3.2", "pptxgenjs": "file:../../vendor/pptxgenjs" + }, + "peerDependencies": { + "playwright-core": "^1.60.0" + }, + "peerDependenciesMeta": { + "playwright-core": { + "optional": true + } } }, "packages/agent/node_modules/pptxgenjs": { @@ -23973,7 +23982,6 @@ "@anthropic-ai/sdk": "^0.78.0", "@waggle/agent": "*", "@waggle/core": "*", - "@waggle/weaver": "*", "chalk": "^5.4.1" }, "bin": { @@ -24549,7 +24557,6 @@ "pdf-parse": "^2.4.5", "postgres": "^3.4.0", "sqlite-vec": "^0.1.7-alpha.2", - "stripe": "^21.0.1", "undici": "^6.27.0", "ws": "^8.21.0", "zod": "^3.24.0" @@ -24558,6 +24565,7 @@ "waggle": "dist/cli.js" }, "devDependencies": { + "@waggle/server": "*", "tsup": "^8.5.1", "tsx": "^4.21.0" }, @@ -24884,15 +24892,19 @@ "name": "@waggle/server", "version": "0.1.0", "dependencies": { + "@anthropic-ai/sdk": "^0.78.0", + "@ax-llm/ax": "^19.0.12", "@clerk/fastify": "^3.1.3", "@fastify/cors": "^10.0.0", "@fastify/static": "^10.1.2", "@fastify/websocket": "^11.0.0", "@waggle/agent": "*", "@waggle/core": "*", - "@waggle/hive-mind-shim-core": "*", + "@waggle/marketplace": "*", + "@waggle/sdk": "*", "@waggle/shared": "*", "@waggle/waggle-dance": "*", + "@waggle/weaver": "*", "@waggle/wiki-compiler": "*", "@whiskeysockets/baileys": "^7.0.0-rc13", "adm-zip": "^0.6.0", @@ -24908,7 +24920,7 @@ "mammoth": "^1.11.0", "pdf-parse": "^2.4.5", "postgres": "^3.4.0", - "stripe": "^21.0.1" + "zod": "^3.24.0" }, "devDependencies": { "@types/archiver": "^7.0.0", @@ -24959,6 +24971,7 @@ "@waggle/agent": "*", "@waggle/core": "*", "@waggle/shared": "*", + "@waggle/waggle-dance": "*", "bullmq": "^5.0.0", "drizzle-orm": "^0.45.2", "ioredis": "^5.4.0", diff --git a/package.json b/package.json index 1c7f039..996685d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dev:www": "npm run dev -w apps/www", "build:www": "npm run build -w apps/www", "lint": "eslint .", + "check:deps": "node scripts/check-workspace-deps.mjs", "lint:no-invalid-snapshots": "node scripts/check-no-invalid-snapshots.mjs", "ux:contrast": "node scripts/ux-gates/contrast-tokens.mjs", "ux:color-guard": "node scripts/ux-gates/text-color-guard.mjs", @@ -103,7 +104,6 @@ "@tauri-apps/plugin-shell": "^2.3.5", "@vitejs/plugin-react": "5.1.1", "sharp": "0.35.3", - "stripe": "^21.0.1", "tailwind-merge": "^3.5.0" }, "//optionalDependencies": "Platform-specific native binaries — optional so npm SKIPS them on os/cpu mismatch (Linux/macOS CI) instead of failing install with EBADPLATFORM. See docs/audits/2026-06-01-full-repo-verification-sweep.md.", diff --git a/packages/agent/package.json b/packages/agent/package.json index cd24616..14068c1 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -31,9 +31,18 @@ "exceljs": "^4.4.0", "glob": "^13.0.6", "jszip": "^3.10.1", + "pdf-parse": "^2.4.5", "pdfmake": "^0.3.7", "undici": "^6.27.0" }, + "peerDependencies": { + "playwright-core": "^1.60.0" + }, + "peerDependenciesMeta": { + "playwright-core": { + "optional": true + } + }, "license": "MIT", "devDependencies": { "@types/pdfmake": "^0.3.2", diff --git a/packages/cli/package.json b/packages/cli/package.json index 82e5a09..cb5f049 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -51,7 +51,6 @@ "dependencies": { "@waggle/core": "*", "@waggle/agent": "*", - "@waggle/weaver": "*", "@anthropic-ai/sdk": "^0.78.0", "chalk": "^5.4.1" }, diff --git a/packages/launcher/package.json b/packages/launcher/package.json index 62cde61..5d647de 100644 --- a/packages/launcher/package.json +++ b/packages/launcher/package.json @@ -56,12 +56,12 @@ "pdf-parse": "^2.4.5", "postgres": "^3.4.0", "sqlite-vec": "^0.1.7-alpha.2", - "stripe": "^21.0.1", "undici": "^6.27.0", "ws": "^8.21.0", "zod": "^3.24.0" }, "devDependencies": { + "@waggle/server": "*", "tsup": "^8.5.1", "tsx": "^4.21.0" } diff --git a/packages/server/package.json b/packages/server/package.json index 16a9cf7..7c48973 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -17,15 +17,19 @@ "start:local": "tsx src/local/start.ts" }, "dependencies": { + "@anthropic-ai/sdk": "^0.78.0", + "@ax-llm/ax": "^19.0.12", "@clerk/fastify": "^3.1.3", "@fastify/cors": "^10.0.0", "@fastify/static": "^10.1.2", "@fastify/websocket": "^11.0.0", "@waggle/agent": "*", "@waggle/core": "*", - "@waggle/hive-mind-shim-core": "*", + "@waggle/marketplace": "*", + "@waggle/sdk": "*", "@waggle/shared": "*", "@waggle/waggle-dance": "*", + "@waggle/weaver": "*", "@waggle/wiki-compiler": "*", "@whiskeysockets/baileys": "^7.0.0-rc13", "adm-zip": "^0.6.0", @@ -41,7 +45,7 @@ "mammoth": "^1.11.0", "pdf-parse": "^2.4.5", "postgres": "^3.4.0", - "stripe": "^21.0.1" + "zod": "^3.24.0" }, "devDependencies": { "@types/archiver": "^7.0.0", diff --git a/packages/worker/package.json b/packages/worker/package.json index fe2914c..112e0d1 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -20,6 +20,7 @@ "@waggle/shared": "*", "@waggle/core": "*", "@waggle/agent": "*", + "@waggle/waggle-dance": "*", "bullmq": "^5.0.0", "drizzle-orm": "^0.45.2", "ioredis": "^5.4.0", diff --git a/scripts/check-workspace-deps.mjs b/scripts/check-workspace-deps.mjs new file mode 100644 index 0000000..f1bf9c0 --- /dev/null +++ b/scripts/check-workspace-deps.mjs @@ -0,0 +1,126 @@ +#!/usr/bin/env node +/** + * Fails when a workspace package imports a package it does not declare. + * + * npm hoists every dependency to the root node_modules, so an undeclared + * import still works inside the monorepo and only breaks once the package is + * installed on its own. This check reads the runtime sources (`src/`) of each + * community-edition package and compares the bare import specifiers with the + * package's dependencies, devDependencies, peerDependencies and + * optionalDependencies. + * + * Usage: node scripts/check-workspace-deps.mjs + */ +import fs from 'node:fs'; +import path from 'node:path'; +import { builtinModules } from 'node:module'; + +const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..'); + +// Packages leaving the community edition are not checked (AGENTS.md, section 2). +const EXCLUDED = new Set([ + 'apps/www', + 'packages/admin-web', + 'packages/memory-mcp', + 'packages/optimizer', + 'packages/wiki-compiler', +]); +const EXCLUDED_PREFIX = 'packages/hive-mind-'; + +// Known undeclared imports that a work package removes. Each entry needs a reason. +const PENDING = { + 'packages/agent': { + '@ax-llm/ax': 'evolution-llm-wiring.ts is removed in P1.4 (ADR-0004)', + }, + 'packages/server': { + '@waggle/optimizer': 'optimizer-service.ts is removed in P1.4 (ADR-0004)', + }, +}; + +const SOURCE_EXT = /\.(?:[cm]?[jt]sx?)$/; +// Valid npm package names, so specifier-like text inside strings is ignored. +const PACKAGE_NAME = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i; +const BUILTINS = new Set(builtinModules); + +function workspaceDirs() { + const dirs = []; + for (const parent of ['apps', 'packages']) { + for (const name of fs.readdirSync(path.join(ROOT, parent))) { + const rel = `${parent}/${name}`; + if (EXCLUDED.has(rel) || rel.startsWith(EXCLUDED_PREFIX)) continue; + if (fs.existsSync(path.join(ROOT, rel, 'package.json'))) dirs.push(rel); + } + } + return dirs.sort(); +} + +function sourceFiles(dir) { + const out = []; + const walk = (d) => { + for (const entry of fs.readdirSync(d, { withFileTypes: true })) { + if (entry.name === 'node_modules' || entry.name === 'dist') continue; + const full = path.join(d, entry.name); + if (entry.isDirectory()) walk(full); + else if (SOURCE_EXT.test(entry.name) && !/\.(?:test|spec)\./.test(entry.name)) out.push(full); + } + }; + if (fs.existsSync(dir)) walk(dir); + return out; +} + +function stripComments(code) { + return code + .replace(/\/\*[\s\S]*?\*\//g, '') + .replace(/(^|[^:'"`\\])\/\/.*$/gm, '$1'); +} + +const SPECIFIER_PATTERNS = [ + /\bfrom\s*['"]([^'"\n]+)['"]/g, + /\bimport\s*['"]([^'"\n]+)['"]/g, + /\bimport\s*\(\s*['"]([^'"\n]+)['"]\s*\)/g, + /\brequire\s*\(\s*['"]([^'"\n]+)['"]\s*\)/g, +]; + +function packageName(specifier) { + if (specifier.startsWith('.') || specifier.startsWith('/')) return null; + if (specifier.startsWith('node:') || specifier.startsWith('@/') || specifier.startsWith('virtual:')) return null; + const parts = specifier.split('/'); + const name = specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]; + if (BUILTINS.has(name) || !PACKAGE_NAME.test(name)) return null; + return name; +} + +let failures = 0; +for (const rel of workspaceDirs()) { + const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, rel, 'package.json'), 'utf8')); + const declared = new Set([ + manifest.name, + ...Object.keys(manifest.dependencies ?? {}), + ...Object.keys(manifest.devDependencies ?? {}), + ...Object.keys(manifest.peerDependencies ?? {}), + ...Object.keys(manifest.optionalDependencies ?? {}), + ]); + const pending = PENDING[rel] ?? {}; + const missing = new Map(); + for (const file of sourceFiles(path.join(ROOT, rel, 'src'))) { + const code = stripComments(fs.readFileSync(file, 'utf8')); + for (const pattern of SPECIFIER_PATTERNS) { + for (const match of code.matchAll(pattern)) { + const name = packageName(match[1]); + if (!name || declared.has(name) || declared.has(`@types/${name}`) || name in pending) continue; + if (!missing.has(name)) missing.set(name, path.relative(ROOT, file)); + } + } + } + if (missing.size > 0) { + failures += missing.size; + console.error(`${rel} (${manifest.name}) imports undeclared packages:`); + for (const [name, file] of missing) console.error(` ${name} (first seen in ${file})`); + } +} + +if (failures > 0) { + console.error(`\n${failures} undeclared import(s). Declare them in the package's package.json.`); + process.exit(1); +} +console.log('All workspace imports are declared.');