Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

2.8 KB
Raw Blame
#!/usr/bin/env node

import { cp, mkdir, rm } from 'node:fs/promises';
import { spawnSync } from 'node:child_process';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { stageInternalRuntimeBundles } from '../../../../scripts/stage-internal-runtime-bundles.mjs';

const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const repoRoot = resolve(packageDir, '..', '..', '..');
const pluginsDir = join(packageDir, 'plugins');

// `dist` is intentionally ignored by Git, so publishing without a build can
// create a tarball whose declared entry point does not exist. Build the only
// emitted project reference CLI needs (`@claude-flow/swarm`) and then CLI.
// Do not use `tsc --build`: it recursively rebuilds unrelated optional
// workspace packages whose development-only dependencies are not required to
// package this CLI.
const compiler = join(packageDir, 'node_modules', 'typescript', 'bin', 'tsc');
for (const buildDir of [resolve(packageDir, '..', 'swarm'), packageDir]) {
  const build = spawnSync(process.execPath, [compiler], {
    cwd: buildDir,
    stdio: 'inherit',
  });
  if (build.error) throw build.error;
  if (build.status !== 0) {
    throw new Error(`TypeScript release build failed for ${buildDir} with exit code ${build.status ?? 'unknown'}`);
  }
}

await stageInternalRuntimeBundles(packageDir);

await cp(join(repoRoot, 'README.md'), join(packageDir, 'README.md'));
await rm(pluginsDir, { recursive: true, force: true });
await mkdir(pluginsDir, { recursive: true });
await cp(
  join(repoRoot, 'plugins', 'ruflo-metaharness'),
  join(pluginsDir, 'ruflo-metaharness'),
  { recursive: true },
);

// ADR-489: `ruflo tui` loads one bundled file from the CLI's own install
// (plugins/ruflo-console/dist/tui.mjs, see src/commands/tui.ts). Build it from
// the plugin's source with the repo's esbuild and stage only that file, so the
// registry install runs the console and the tarball carries no console source.
const tuiBundle = join(pluginsDir, 'ruflo-console', 'dist', 'tui.mjs');
const tuiBuild = spawnSync(
  process.execPath,
  [join(repoRoot, 'plugins', 'ruflo-console', 'scripts', 'build-tui.mjs'), '--outfile', tuiBundle],
  { cwd: repoRoot, stdio: 'inherit' },
);
if (tuiBuild.error) throw tuiBuild.error;
if (tuiBuild.status !== 0) {
  throw new Error(`build-tui.mjs failed with exit code ${tuiBuild.status ?? 'unknown'}`);
}

for (const script of [
  'generate-catalog-manifest.mjs',
  'sign-helpers.mjs',
  'verify-helpers.mjs',
]) {
  const result = spawnSync(process.execPath, [join(packageDir, 'scripts', script)], {
    cwd: packageDir,
    stdio: 'inherit',
  });
  if (result.error) throw result.error;
  if (result.status !== 0) {
    throw new Error(`${script} failed with exit code ${result.status ?? 'unknown'}`);
  }
}