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.

1.8 KB
Raw Blame
import 'core/connected_semantics.dart';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'app_shell.dart';
import 'auth/auth_session.dart';
import 'core/config.dart';
import 'core/desktop_window.dart';
import 'screens/swarm_screen.dart';
import 'state/app_state.dart';

/// Normal interactive macOS app wired to a disposable local test stack.
///
/// This entrypoint fails closed unless every value is supplied explicitly by
/// `scripts/start-terminal-local-manual.sh`. It is not used by release builds.
Future<void> main() async {
  HarnessWidgetsBinding();
  const enabled = bool.fromEnvironment('LOCAL_TERMINAL_MANUAL');
  const apiBaseUrl = String.fromEnvironment('LOCAL_MANUAL_API_BASE_URL');
  const apiKey = String.fromEnvironment('LOCAL_MANUAL_API_KEY');
  const machineId = String.fromEnvironment('LOCAL_MANUAL_MACHINE_ID');
  const machineName = String.fromEnvironment(
    'LOCAL_MANUAL_MACHINE_NAME',
    defaultValue: 'local-terminal-manual',
  );

  if (!enabled ||
      !apiBaseUrl.startsWith('http://127.0.0.1:') ||
      !RegExp(r'^[a-f0-9]{64}$').hasMatch(apiKey) ||
      !RegExp(r'^[a-f0-9]{32}$').hasMatch(machineId)) {
    throw StateError(
      'Local manual mode requires its guarded loopback fixture configuration',
    );
  }

  final notifier = AppNotifier(
    config: const AppConfig(apiBaseUrl: apiBaseUrl),
    authSession: AuthSession(),
    localManualFixture: const LocalManualFixture(
      apiBaseUrl: apiBaseUrl,
      apiKey: apiKey,
      machineId: machineId,
      machineName: machineName,
    ),
  );
  notifier.bootstrap();
  await configureDesktopWindow();
  runApp(
    ProviderScope(
      overrides: [appStateProvider.overrideWithValue(notifier)],
      child: HarnessApp(
        authenticatedScreen: (app) => SwarmScreen(notifier: app),
      ),
    ),
  );
}