Files
waggle-os/scripts/check-workspace-deps.mjs
shumeiko.it 2e1999a3f6 refactor: remove self-learning and the optimizer package (P1.4)
Self-learning is excluded from the community edition (ADR-0004); the
project owner reworks it separately. Cost tracking stays.

- agent: delete behaviour evolution (evolve-schema, iterative GEPA,
  compose-evolution, evolution gates, orchestrator and deploy),
  improvement and correction detection, AgentLearning, the eval-dataset
  builder, optimization-capture and the agent_insights tool. Secret
  detection moves from eval-dataset to secret-patterns. The LLM wiring
  keeps only the Haiku adapter and judge call used by skill audit and
  hygiene, so @ax-llm/ax is now declared by agent instead of server.
- server: delete /api/evolution/*, the evolution and optimizer services,
  GEPA expansion of the first chat message, the prompt_optimization and
  monthly_assessment jobs, the idle-session reviewer and its
  session-reviewer persona, prompt injection of past corrections and
  thumbs-down recorded as correction signals. Existing job rows of the
  removed types are ignored, not deleted.
- core: delete OptimizationLogStore; stop re-exporting the improvement
  signal and evolution run stores.
- web: delete the Evolution screen and the two job types in the
  automation editor.
- delete packages/optimizer.

Also logs UF-027 (self-learning loops read data nothing collects) and
UF-028 (the Settings prompt-shape choice is ignored by chat).
2026-10-20 00:54:58 +02:00

119 lines
4.2 KiB
JavaScript

#!/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/wiki-compiler',
]);
const EXCLUDED_PREFIX = 'packages/hive-mind-';
// Known undeclared imports that a work package removes. Each entry needs a reason.
const PENDING = {};
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.');