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.

10.6 KB
Raw Blame
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';

import '../shared/theme/app_theme.dart' as grid;
import '../theme/app_theme.dart';

class EngineIdentity {
  final String id;
  final String label;
  final Color color;
  final String? asset;

  const EngineIdentity({
    required this.id,
    required this.label,
    required this.color,
    this.asset,
  });
}

const _engines = <String, EngineIdentity>{
  'claude': EngineIdentity(
    id: 'claude',
    label: 'Claude',
    color: Color(0xffcc7c5e),
  ),
  'codex': EngineIdentity(
    id: 'codex',
    label: 'Codex',
    color: Color(0xff64d2ff),
    asset: 'assets/engine-icons/codex.png',
  ),
  'cursor': EngineIdentity(
    id: 'cursor',
    label: 'Cursor',
    color: Color(0xffc6ff72),
    asset: 'assets/engine-icons/cursor.png',
  ),
  'opencode': EngineIdentity(
    id: 'opencode',
    label: 'OpenCode',
    color: Color(0xfff1ecec),
    asset: 'assets/engine-icons/opencode.png',
  ),
  'pi': EngineIdentity(
    id: 'pi',
    label: 'Pi',
    color: Colors.white,
    asset: 'assets/engine-icons/pi.png',
  ),
  'hermes': EngineIdentity(
    id: 'hermes',
    label: 'Hermes',
    color: Color(0xff9b8cff),
    asset: 'assets/engine-icons/hermes.png',
  ),
  'commandcode': EngineIdentity(
    id: 'commandcode',
    label: 'Command Code',
    color: Color(0xfff5f5f5),
    asset: 'assets/engine-icons/commandcode.png',
  ),
  'devin': EngineIdentity(
    id: 'devin',
    label: 'Devin',
    color: Color(0xff8fb8ff),
    asset: 'assets/engine-icons/devin.png',
  ),
  'muse': EngineIdentity(
    id: 'muse',
    label: 'Muse',
    color: Color(0xff0082fb),
    asset: 'assets/engine-icons/muse.png',
  ),
  'amp': EngineIdentity(
    id: 'amp',
    label: 'Amp',
    color: Color(0xfff34e3f),
    asset: 'assets/engine-icons/amp.png',
  ),
  'kilo': EngineIdentity(
    id: 'kilo',
    label: 'Kilo',
    color: Color(0xfff8f676),
    asset: 'assets/engine-icons/kilo.png',
  ),
  'grok': EngineIdentity(
    id: 'grok',
    label: 'Grok',
    color: Colors.white,
    asset: 'assets/engine-icons/grok.png',
  ),
  'copilot': EngineIdentity(
    id: 'copilot',
    label: 'Copilot',
    color: Color(0xff8957e5),
    asset: 'assets/engine-icons/copilot.png',
  ),
  'agy': EngineIdentity(
    id: 'agy',
    label: 'Antigravity',
    color: Color(0xff3287fb),
    asset: 'assets/engine-icons/agy.png',
  ),
};

/// The daemon's engine id for a plain shell, the desktop's `kTerminalEngine`: what New Harness
/// offers after every agent, and what a harness started as one is listed with.
///
/// ⚠️ **Deliberately NOT in [_engines]**, as it is not in the desktop's. [allEngines] is what
/// `engines_probe` asks a machine about, and [isCodeEngine] reads that table: a terminal is neither
/// installable nor absent (every machine has a shell), and it writes no code. New lists it on its
/// own, last; [engineIdentity] still gives it a face, since a harness running one shows a mark.
const String kTerminalEngine = 'terminal';

/// The desktop's `_terminal`: its name, and the pale steel its mark is drawn in on a dark palette.
const EngineIdentity _terminal = EngineIdentity(
  id: kTerminalEngine,
  label: 'Terminal',
  color: Color(0xffa8b0b8),
);

/// The terminal's face, for the one list that offers it: New Harness.
EngineIdentity get terminalIdentity => _terminal;

/// Whether [engine] is the shell rather than an agent.
bool isTerminalEngine(String? engine) => engine == kTerminalEngine;

/// All known engines, in declaration order — for the New Agent engine picker.
List<EngineIdentity> get allEngines => _engines.values.toList(growable: false);

/// Whether [id] names a domain-specific harness rather than an engine — the desktop's
/// `isHarnessId`. The slash is the tell: engine ids are bare words, harness ids are `owner/name`.
bool isHarnessId(String? id) => id != null && id.contains('/');

/// Whether [engine] is a coding engine — the desktop's `category: 'Code'`.
///
/// ⚠️ **Every engine in [_engines] is one**, as every engine in the desktop's own table is (the
/// same fourteen, claude to agy); it is the harnesses that carry other categories, and those are
/// told apart by [isHarnessId]. An engine added here that does not write code has to be excluded
/// by name, or a tab of it would be called `code`.
bool isCodeEngine(String? engine) =>
    _engines.containsKey(engine?.trim().toLowerCase());

/// Harness ids that were renamed, to the id each goes by now — the desktop's `retiredHarnessIds`
/// (`core/harness_catalog.dart`), copied as it stands, so an agent made from an old id is named
/// by its current one on both.
const _retiredHarnessIds = <String, String>{
  'local/ollama': 'autonomous/ollama',
  'local/mlx-lm': 'autonomous/mlx-lm',
  'local/vllm': 'autonomous/vllm',
  'autonomous/copper': 'autonomous/autonomous-circuit',
  'autonomous/circuit': 'autonomous/autonomous-circuit',
  'autonomous/solder': 'autonomous/kicad',
  'autonomous/machines': 'autonomous/machine-monitor',
  'autonomous/toymaker': 'autonomous/autonomous-workshop',
  'autonomous/solid': 'autonomous/autonomous-workshop',
  'autonomous/workshop': 'autonomous/autonomous-workshop',
};

/// [id] as the harness goes by now — see [_retiredHarnessIds].
String canonicalHarnessId(String id) => _retiredHarnessIds[id] ?? id;

EngineIdentity engineIdentity(String? engine, {String? displayName}) {
  final id = engine?.trim().toLowerCase() ?? '';
  final known = _engines[id] ?? (id == kTerminalEngine ? _terminal : null);
  if (known != null) return known;
  final raw = displayName?.trim().isNotEmpty == true
      ? displayName!.trim()
      : id.isEmpty
      ? 'Agent'
      : id;
  final label = raw[0].toUpperCase() + raw.substring(1);
  return EngineIdentity(
    id: id.isEmpty ? 'unknown' : id,
    label: label,
    color: AppColors.mutedStrong,
  );
}

class EngineMark extends StatelessWidget {
  final String? engine;
  final String? displayName;
  final bool enabled;
  final double size;

  const EngineMark({
    super.key,
    required this.engine,
    this.displayName,
    this.enabled = true,
    this.size = 16,
  });

  @override
  Widget build(BuildContext context) {
    final dark = grid.AppTheme.watch(context) == Brightness.dark;
    final identity = engineIdentity(engine, displayName: displayName);
    final mark = identity.asset != null
        ? Image.asset(
            identity.asset!,
            key: ValueKey('engine-icon-${identity.id}'),
            width: size,
            height: size,
            fit: BoxFit.contain,
            filterQuality: FilterQuality.high,
            errorBuilder: (_, _, _) => _InitialMark(
              key: ValueKey('engine-fallback-${identity.id}'),
              identity: identity,
              size: size,
            ),
          )
        : identity.id == 'claude'
        ? CustomPaint(
            key: const ValueKey('engine-icon-claude'),
            size: Size.square(size),
            // The brand clay is 2.5:1 on a light workspace; there the same
            // hue a step deeper (3.1:1+), so the mark still reads as a shape.
            painter: _ClaudeMarkPainter(
              dark ? identity.color : const Color(0xffc2633f),
            ),
          )
        // The desktop's terminal mark: a prompt glyph, not the initial a "T" would read as.
        : identity.id == kTerminalEngine
        ? Icon(
            LucideIcons.terminal400,
            key: const ValueKey('engine-icon-terminal'),
            size: size,
            // The shell's pale steel is 1.8:1 on a light workspace; there it takes the secondary
            // ink, as on the desktop.
            color: dark ? identity.color : AppColors.mutedStrong,
          )
        : _InitialMark(
            key: ValueKey('engine-fallback-${identity.id}'),
            identity: identity,
            size: size,
          );
    // These vendor assets use near-white ink with no ground of their own. They
    // sit bare on a dark palette as they always have; on a light one they get
    // the desktop's dark tile, or their shapes are white on white.
    final needsDarkTile =
        !dark &&
        const {'cursor', 'opencode', 'grok', 'copilot'}.contains(identity.id);
    return Opacity(
      opacity: enabled ? 1 : 0.45,
      child: needsDarkTile
          ? SizedBox.square(
              dimension: size,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  color: const Color(0xff29322f),
                  borderRadius: BorderRadius.circular(size * .2),
                ),
                child: Padding(
                  padding: EdgeInsets.all(size * .08),
                  child: mark,
                ),
              ),
            )
          : mark,
    );
  }
}

class _InitialMark extends StatelessWidget {
  final EngineIdentity identity;
  final double size;

  const _InitialMark({super.key, required this.identity, required this.size});

  @override
  Widget build(BuildContext context) {
    return SizedBox.square(
      dimension: size,
      child: Center(
        child: Text(
          identity.label.characters.first.toUpperCase(),
          // ⚠️ Sized from [size], a FIXED box, not from the type ramp — so it
          // must not take the app's UI scale either. At the top of the range the
          // glyph would grow while its 17px square did not, and the letter would
          // clip out of its own mark.
          textScaler: TextScaler.noScaling,
          style: TextStyle(
            color: identity.color,
            // The app's mono stack, not a literal: `Menlo` names nothing on
            // Linux, so this initial was drawn in the proportional default
            // while every mark beside it was monospaced.
            fontFamily: AppFonts.mono,
            fontFamilyFallback: AppFonts.monoFallback,
            fontSize: size * 0.68,
            height: 1,
            fontWeight: FontWeight.w700,
          ),
        ),
      ),
    );
  }
}

class _ClaudeMarkPainter extends CustomPainter {
  final Color color;
  const _ClaudeMarkPainter(this.color);

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = color
      ..strokeWidth = size.width * 0.098
      ..strokeCap = StrokeCap.round;
    final c = Offset(size.width / 2, size.height / 2);
    final radius = size.width * 0.39;
    for (var i = 0; i < 4; i++) {
      final angle = i * 0.78539816339;
      final dx = radius * math.cos(angle);
      final dy = radius * math.sin(angle);
      canvas.drawLine(c - Offset(dx, dy), c + Offset(dx, dy), paint);
    }
  }

  @override
  bool shouldRepaint(covariant _ClaudeMarkPainter oldDelegate) =>
      oldDelegate.color != color;
}