Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

9.8 KB
Raw Blame
// The release's app, engine, manifests and fonts are compressed once at build time
// (scripts/precompress.mjs): each one's .br, else .gz, copy goes to a browser that takes it.
// The Content-Type Next sends for the file itself, so every encoding of it says the same.
const PRECOMPRESSED_TYPES = {
  js: 'application/javascript; charset=UTF-8',
  mjs: 'application/javascript; charset=UTF-8',
  wasm: 'application/wasm',
  json: 'application/json; charset=UTF-8',
  ttf: 'font/ttf',
  otf: 'font/otf',
  svg: 'image/svg+xml',
  html: 'text/html; charset=UTF-8',
}
const ENCODINGS = [
  { name: 'br', suffix: 'br' },
  { name: 'gzip', suffix: 'gz' },
]
// An Accept-Encoding that takes [name]: listed, and not at q=0 (scripts/precompress.mjs).
const accepts = (acceptsEncoding, name) => [{ type: 'header', key: 'accept-encoding', value: acceptsEncoding(name) }]
const releaseFile = (ext) => `/harness-web/releases/:path*/:file.${ext}`

async function precompression() {
  const { PRECOMPRESSED, acceptsEncoding } = await import('./scripts/precompress.mjs')
  const missing = PRECOMPRESSED.filter((ext) => !PRECOMPRESSED_TYPES[ext])
  if (missing.length) throw new Error(`No Content-Type for pre-compressed .${missing.join(', .')}`)
  return { precompressed: PRECOMPRESSED, acceptsEncoding }
}

module.exports = {
  // Self-contained build (.next/standalone: server.js + pruned node_modules) for a lean
  // production container — the runtime image copies this instead of installing deps.
  output: 'standalone',
  // The shell-script routes read their scripts from disk instead of importing them, so nothing traces
  // those files automatically — list them explicitly or a standalone build serves a 500. The KEY is
  // the route path: rename a route and this entry must move with it.
  outputFileTracingIncludes: {
    // '/cli/install.sh' and '/desktop/install.sh' moved to the CDN (see redirects() below) — nothing
    // left here to trace for either.
    '/flash-circle.sh': ['./src/app/flash-circle.sh/flash-circle.sh'],
    '/flash-circle.ps1': ['./src/app/flash-circle.ps1/flash-circle.ps1'],
    '/hub/[id]': ['./public/open-harnesses/**/*'],
    '/hub/[id]/fork': ['./public/open-harnesses/**/*'],
    '/hub/[id]/download': ['./public/open-harnesses/**/*'],
    '/hub/[id]/snapshot': ['./public/open-harnesses/**/*'],
  },
  turbopack: {},
  // Local dev is reached through the local-harness.autonomous.ai hostname (proxied to :3000) — allow it
  // to load /_next/* dev assets cross-origin (Next warns now, will hard-block in a future major).
  allowedDevOrigins: ['local-harness.autonomous.ai', 'local-ac.autonomous.ai', 'localhost', '127.0.0.1'],
  // Domain migration: every legacy web host 308-redirects to the current canonical one, preserving
  // the path. `ac` was the original name and `fleet` the intermediate one — both now land on
  // `harness`. Only WEB domains are redirected — the legacy API hosts stay functional for field
  // devices/adapters that still hardcode them until they OTA/self-update.
  async redirects() {
    return [
      ...['ac.autonomous.ai', 'fleet.autonomous.ai'].map((host) => ({
        source: '/:path*',
        has: [{ type: 'host', value: host }],
        destination: 'https://harness.autonomous.ai/:path*',
        permanent: true,
      })),
      // The front door is the web app again (owner, 2026-10-26; from 2026-10-13 it was the Hub and the
      // app lived at /web). Old /web links land on it, query and all; temporary, so no browser keeps it.
      { source: '/web', destination: '/', permanent: false },
      { source: '/install', destination: '/download', permanent: true },
      { source: '/explore', destination: '/hub', permanent: true },
      { source: '/explore/:id', destination: '/hub/:id', permanent: true },
      { source: '/explore/:id/fork', destination: '/hub/:id/fork', permanent: true },
      // The public CLI command uses this short URL; the script stays on the CDN.
      { source: '/install.sh', destination: 'https://cdn.autonomous.ai/harness/cli/install.sh', permanent: true },
      // Both installer scripts moved to the CDN-fronted public bucket (make upload-cli-install-sh /
      // make upload-desktop-install-sh in the repo root) — these keep `curl -fsSL
      // https://harness.autonomous.ai/{cli,desktop}/install.sh | bash` working for anyone with the old
      // URL (`-fsSL` already follows redirects).
      { source: '/cli/install.sh', destination: 'https://cdn.autonomous.ai/harness/cli/install.sh', permanent: true },
      { source: '/desktop/install.sh', destination: 'https://cdn.autonomous.ai/harness/desktop/install.sh', permanent: true },
    ]
  },
  // Image optimization for mobile
  images: {
    formats: ['image/avif', 'image/webp'],
    deviceSizes: [640, 750, 828, 1080, 1200],
    imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
    minimumCacheTTL: 60,
  },
  // Compression
  compress: true,
  // Performance optimizations
  poweredByHeader: false,
  // The workspace is the Flutter app; this host also serves the public /hub community,
  // install and download pages, and installer redirects. Flutter's base
  // href places its assets under /harness-web/ without changing the visible URL.
  async rewrites() {
    const { precompressed, acceptsEncoding } = await precompression()
    return {
      beforeFiles: [
        // The browser's first accepted encoding wins; one that takes neither gets the file as is.
        ...ENCODINGS.flatMap(({ name, suffix }) => precompressed.map((ext) => ({
          source: releaseFile(ext),
          has: accepts(acceptsEncoding, name),
          destination: `/harness-web/releases/:path*/:file.${ext}.${suffix}`,
        }))),
        // Older desktop builds consume snapshots without following redirects.
        { source: '/explore/:id/snapshot', destination: '/hub/:id/snapshot' },
        { source: '/explore/:id/download', destination: '/hub/:id/download' },
        { source: '/', destination: '/harness-web/index.html' },
        { source: '/s/:id', destination: '/harness-web/index.html' },
        { source: '/auth/callback', destination: '/harness-web/index.html' },
        // Local website previews use the SSO service's native loopback callback.
        { source: '/callback', destination: '/harness-web/index.html' },
        { source: '/harness-web', destination: '/harness-web/index.html' },
        // Plain HTML/CSS; served as a file without a React or Flutter runtime.
        { source: '/os', destination: '/os/index.html' },
        // Harness for agents: one plain HTML file (no script, inline style) for agents that fetch it.
        { source: '/agents', destination: '/agents/index.html' },
      ],
    }
  },
  async headers() {
    const { precompressed, acceptsEncoding } = await precompression()
    return [
      {
        source: '/:path*',
        headers: [
          { key: 'Referrer-Policy', value: 'origin' },
        ],
      },
      {
        source: '/os/:path*',
        headers: [
          { key: 'Cache-Control', value: 'public, max-age=0, must-revalidate' },
          { key: 'X-Content-Type-Options', value: 'nosniff' },
        ],
      },
      ...['/os', '/os/index.html'].map((source) => ({
        source,
        // Keep the standalone page intact: CDN analytics must not inject JavaScript.
        headers: [{ key: 'Cache-Control', value: 'no-store, no-transform' }],
      })),
      ...['/agents', '/agents/index.html', '/llms.txt'].map((source) => ({
        source,
        // Read by agents as written: no CDN script injection or rewriting, and no stale copy after a deploy.
        headers: [
          { key: 'Cache-Control', value: 'no-store, no-transform' },
          { key: 'X-Content-Type-Options', value: 'nosniff' },
        ],
      })),
      {
        // The MCP registry domain-auth file: served exactly as written, never cached or rewritten.
        source: '/.well-known/mcp-registry-auth',
        headers: [
          { key: 'Cache-Control', value: 'no-store, no-transform' },
          { key: 'X-Content-Type-Options', value: 'nosniff' },
        ],
      },
      {
        source: '/os/latest',
        // Cache the GitHub lookup on the server, never the release redirect in a browser or CDN.
        headers: [{ key: 'Cache-Control', value: 'no-store, max-age=0' }],
      },
      {
        source: '/harness-web/:path*',
        headers: [
          // Legacy paths stay available for existing tabs. New entries use the
          // archive-specific namespace below, since edge caches can lengthen
          // this revalidation policy.
          { key: 'Cache-Control', value: 'public, max-age=0, must-revalidate' },
          { key: 'Referrer-Policy', value: 'no-referrer' },
          { key: 'X-Content-Type-Options', value: 'nosniff' },
        ],
      },
      {
        source: '/harness-web/releases/:path*',
        headers: [
          { key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
        ],
      },
      ...precompressed.map((ext) => ({
        source: releaseFile(ext),
        headers: [{ key: 'Vary', value: 'Accept-Encoding' }],
      })),
      // After the rewrite above the file sent is its .br or .gz copy: say what it holds and how.
      // In the rewrites' order reversed, so a browser taking both gets brotli's last, which wins.
      ...[...ENCODINGS].reverse().flatMap(({ name }) => precompressed.map((ext) => ({
        source: releaseFile(ext),
        has: accepts(acceptsEncoding, name),
        headers: [
          { key: 'Content-Encoding', value: name },
          { key: 'Content-Type', value: PRECOMPRESSED_TYPES[ext] },
        ],
      }))),
      ...['/', '/s/:id', '/auth/callback', '/callback', '/harness-web', '/harness-web/index.html', '/harness-web/release.json'].map((source) => ({
        source,
        headers: [
          { key: 'Cache-Control', value: 'no-store' },
          { key: 'Referrer-Policy', value: 'no-referrer' },
          { key: 'X-Content-Type-Options', value: 'nosniff' },
        ],
      })),
    ]
  },
}