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.

17.8 KB
Raw Blame
import 'package:harness/shared/theme/app_icons.dart';
import 'package:flutter/material.dart';
import 'package:harness/terminal/terminal_text.dart';

import '../core/dsh_catalog.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/skeleton.dart';
import '../state/essential_harness_controller.dart';
import 'store_collections.dart';
import 'store_editorial.dart';
import 'store_exploration.dart';
import 'store_explore_widgets.dart';
import 'store_featured_art.dart';
import 'store_host.dart';
import 'store_listing.dart';
import 'store_models.dart';

/// Three editorial features invite exploration before the icon collections. The catalog itself
/// uses the same recognizable icons and rows as categories and search.
class StoreDiscover extends StatelessWidget {
  const StoreDiscover({
    super.key,
    required this.entries,
    required this.loaded,
    required this.ratingFor,
    required this.onOpen,
    required this.onCategory,
    required this.onAll,
    required this.onEngines,
    this.essentialLabel,
    this.onEssential,
  });

  final List<DshEntry> entries;
  final bool loaded;
  final StoreRating Function(DshEntry) ratingFor;
  final ValueChanged<String> onOpen;
  final ValueChanged<String> onCategory;
  final VoidCallback onAll;
  final VoidCallback onEngines;

  /// The Store's Essentials are created or opened in one click, never through New Harness: the
  /// button's word ("Create" or "Open") and what it does. Absent, the section is not shown.
  final String Function(String id)? essentialLabel;
  final ValueChanged<String>? onEssential;

  @override
  Widget build(BuildContext context) {
    grid.AppTheme.watch(context);
    final byId = {for (final entry in entries) entry.id: entry};
    // Editorial stories share an art direction and open actual catalog entries.
    final features = [
      ?(byId['codex'] ?? byId['claude']),
      ?byId['autonomous/blender'],
      ?byId['autonomous/autonomous-circuit'],
    ];
    final engines = [
      for (final id in ['claude', 'codex', 'cursor']) ?byId[id],
    ];
    final essentials = [
      if (essentialLabel != null && onEssential != null)
        for (final essential in storeEssentials) ?byId[essential.id],
    ];
    final crafts = entries
        .where((entry) => !entry.isEngine && !entry.isViewerPackage)
        .toList();
    const picks = [
      'autonomous/text-to-cad',
      'autonomous/strudel',
      'autonomous/marimo',
      'autonomous/remotion',
      'autonomous/roundtable',
      'autonomous/marp',
    ];
    crafts.sort((a, b) {
      final ai = picks.indexOf(a.id), bi = picks.indexOf(b.id);
      final rank = (ai < 0 ? 999 : ai).compareTo(bi < 0 ? 999 : bi);
      return rank == 0 ? a.name.compareTo(b.name) : rank;
    });
    final recent = storeRecentlyUpdated(crafts).take(6).toList();
    final topRated = storeTopRated(entries, ratingFor).take(6).toList();
    final categories = [
      for (final name in [...storeCategoryDomains.keys, 'Other'])
        // Essentials have their own section above; they are not a discipline.
        if (name != 'Coding' &&
            name != 'Essentials' &&
            crafts.any((entry) => storeCategoryFor(entry) == name))
          name,
    ];
    return LayoutBuilder(
      builder: (context, box) {
        final padding = box.maxWidth < 680 ? 20.0 : 36.0;
        return SingleChildScrollView(
          key: const PageStorageKey('store-discover-scroll'),
          padding: EdgeInsets.fromLTRB(padding, 32, padding, 40),
          child: Center(
            child: ConstrainedBox(
              constraints: const BoxConstraints(maxWidth: 1440),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Text(
                    'Follow your curiosity.',
                    key: const ValueKey('store-curiosity-hero'),
                    style: grid.AppType.heading(
                      height: 1.15,
                      color: grid.AppPalette.textPrimary,
                    ),
                  ),
                  if (features.isNotEmpty) ...[
                    const SizedBox(height: 24),
                    LayoutBuilder(
                      builder: (context, constraints) {
                        final scale = grid.appTextScaleOf(context);
                        final wide =
                            constraints.maxWidth >= 980 &&
                            scale <= 1.25 &&
                            features.length == 3;
                        final width = wide
                            ? (constraints.maxWidth - 40) / 3
                            : (constraints.maxWidth * .86).clamp(280.0, 520.0);
                        final cards = [
                          for (final entry in features)
                            SizedBox(
                              width: width,
                              child: _FeaturedStory(
                                entry: entry,
                                onTap: () => onOpen(entry.id),
                              ),
                            ),
                        ];
                        return SingleChildScrollView(
                          key: const PageStorageKey('store-featured-scroll'),
                          scrollDirection: Axis.horizontal,
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              for (var i = 0; i < cards.length; i++) ...[
                                if (i > 0) const SizedBox(width: 20),
                                cards[i],
                              ],
                            ],
                          ),
                        );
                      },
                    ),
                  ],
                  if (essentials.isNotEmpty) ...[
                    const SizedBox(height: 28),
                    const StoreExploreHeading(
                      title: 'Essentials',
                      subtitle: 'Made by Harness. Free to run on OpenCode; switch to any agent from the pane.',
                    ),
                    const SizedBox(height: 8),
                    StoreListing(
                      key: const ValueKey('store-essentials-collection'),
                      rowKeyPrefix: 'store-essential',
                      entries: essentials,
                      ratingFor: ratingFor,
                      onOpen: onOpen,
                      actionFor: (entry) => _EssentialButton(
                        key: ValueKey('store-essential-action:${entry.id}'),
                        label: essentialLabel!(entry.id),
                        onPressed: () => onEssential!(entry.id),
                      ),
                    ),
                  ],
                  if (engines.isNotEmpty) ...[
                    const SizedBox(height: 24),
                    StoreExploreHeading(
                      title: 'Start with code.',
                      action: 'All coding agents',
                      onAction: onEngines,
                    ),
                    const SizedBox(height: 6),
                    StoreListing(
                      entries: engines,
                      ratingFor: ratingFor,
                      onOpen: onOpen,
                    ),
                  ],
                  if (recent.isNotEmpty) ...[
                    const SizedBox(height: 28),
                    const StoreExploreHeading(
                      title: 'New & updated',
                      subtitle:
                          'The latest additions and updates in this release.',
                    ),
                    const SizedBox(height: 8),
                    StoreListing(
                      key: const ValueKey('store-recent-collection'),
                      rowKeyPrefix: 'store-recent',
                      entries: recent,
                      ratingFor: ratingFor,
                      onOpen: onOpen,
                    ),
                  ],
                  if (topRated.length >= 2) ...[
                    const SizedBox(height: 28),
                    const StoreExploreHeading(
                      title: 'Top rated',
                      subtitle: 'Rated by the people building with them.',
                    ),
                    const SizedBox(height: 8),
                    StoreListing(
                      key: const ValueKey('store-top-rated-collection'),
                      rowKeyPrefix: 'store-top-rated',
                      showRanks: true,
                      entries: topRated,
                      ratingFor: ratingFor,
                      onOpen: onOpen,
                    ),
                  ],
                  if (crafts.isNotEmpty) ...[
                    const SizedBox(height: 32),
                    StoreExploreHeading(
                      title: 'A little beyond your comfort zone.',
                      subtitle: 'Pick a tool. Try a small idea. See where it takes you.',
                      action: 'Browse all',
                      onAction: onAll,
                    ),
                    const SizedBox(height: 8),
                    StoreListing(
                      entries: crafts.take(6).toList(),
                      ratingFor: ratingFor,
                      onOpen: onOpen,
                    ),
                    const SizedBox(height: 32),
                    const StoreExploreHeading(
                      title: 'Build across disciplines.',
                    ),
                    const SizedBox(height: 16),
                    LayoutBuilder(
                      builder: (context, constraints) {
                        final scale = grid.appTextScaleOf(context);
                        final columns = (constraints.maxWidth / (320 * scale))
                            .floor()
                            .clamp(1, 3);
                        final width =
                            (constraints.maxWidth - (columns - 1) * 16) /
                            columns;
                        return Wrap(
                          spacing: 16,
                          runSpacing: 16,
                          children: [
                            for (final name in categories)
                              SizedBox(
                                width: width,
                                child: _DisciplineLink(
                                  key: ValueKey('store-category:$name'),
                                  name: name,
                                  entries: crafts
                                      .where(
                                        (entry) =>
                                            storeCategoryFor(entry) == name,
                                      )
                                      .toList(),
                                  onTap: () => onCategory(name),
                                ),
                              ),
                          ],
                        );
                      },
                    ),
                    const SizedBox(height: 32),
                    Text(
                      'For polymaths in the making.',
                      style: grid.AppType.heading(
                        color: grid.AppPalette.textPrimary,
                      ),
                    ),
                    const SizedBox(height: 6),
                    Text(
                      'Learn the next craft through the things you build.',
                      style: grid.AppType.body(
                        height: 1.5,
                        color: grid.AppPalette.textSecondary,
                      ),
                    ),
                  ] else if (storeRunsNoHarness(context)) ...[
                    // A browser runs no harness: no computer will answer.
                    const SizedBox(height: 32),
                    Text(
                      'Open the Harness app on a computer to see more harnesses.',
                      style: grid.AppType.body(
                        height: 1.5,
                        color: grid.AppPalette.textSecondary,
                      ),
                    ),
                  ] else if (!loaded) ...[
                    const SizedBox(height: 32),
                    const SkeletonBlock(
                      child: Skeleton(height: 160, radius: 16),
                    ),
                  ] else ...[
                    const SizedBox(height: 32),
                    Text(
                      'Start with a coding agent. More disciplines will appear here as harnesses become available.',
                      style: grid.AppType.body(
                        height: 1.5,
                        color: grid.AppPalette.textSecondary,
                      ),
                    ),
                  ],
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}

class _FeaturedStory extends StatelessWidget {
  const _FeaturedStory({required this.entry, required this.onTap});
  final DshEntry entry;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    TerminalFontScope.watch(context);
    final category = entry.isEngine
        ? 'Coding'
        : entry.id == 'autonomous/blender'
        ? 'Design'
        : 'Engineering';
    final headline = switch (category) {
      'Coding' => 'Build what comes next.',
      'Design' => 'Give your ideas shape.',
      _ => 'Build something real.',
    };
    final scale = grid.appTextScaleOf(context);
    return StoreExploreCard(
      key: ValueKey('store-feature:${entry.id}'),
      color: storeDiscipline(category).color,
      onTap: onTap,
      semanticLabel: 'Explore ${entry.name}',
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Padding(
            padding: const EdgeInsets.all(18),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  category,
                  style: grid.AppType.caption(
                    fontWeight: grid.AppFont.medium,
                    color: grid.AppPalette.accentOnSurface,
                  ),
                ),
                const SizedBox(height: 8),
                SizedBox(
                  height: 50 * scale,
                  child: Text(
                    headline,
                    style: grid.AppType.title(
                      height: 1.15,
                      color: grid.AppPalette.textPrimary,
                    ),
                  ),
                ),
                Row(
                  children: [
                    StoreAppIcon(entry: entry, size: 24),
                    const SizedBox(width: 8),
                    Expanded(
                      child: Text(
                        'Explore ${entry.name}',
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: grid.AppType.label(
                          color: grid.AppPalette.textSecondary,
                        ),
                      ),
                    ),
                    Icon(
                      AppIcons.arrowRight,
                      size: 16,
                      color: grid.AppPalette.textSecondary,
                    ),
                  ],
                ),
              ],
            ),
          ),
          AspectRatio(
            aspectRatio: 2,
            child: StoreFeaturedArt(
              key: ValueKey('store-feature-art:${entry.id}'),
              category: category,
              entry: entry,
            ),
          ),
        ],
      ),
    );
  }
}

class _DisciplineLink extends StatelessWidget {
  const _DisciplineLink({
    super.key,
    required this.name,
    required this.entries,
    required this.onTap,
  });
  final String name;
  final List<DshEntry> entries;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    final discipline = storeDiscipline(name);
    final example = discipline.example(entries)!;
    return StoreExploreCard(
      color: discipline.color,
      onTap: onTap,
      semanticLabel: 'Explore $name',
      child: Padding(
        padding: const EdgeInsets.all(18),
        child: Row(
          children: [
            StoreAppIcon(entry: example, size: 48),
            const SizedBox(width: 14),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    name,
                    style: grid.AppType.label(
                      color: grid.AppPalette.textPrimary,
                    ),
                  ),
                  const SizedBox(height: 5),
                  Text(
                    '${entries.length} ${entries.length == 1 ? 'harness' : 'harnesses'}',
                    style: grid.AppType.body(
                      color: grid.AppPalette.textSecondary,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(width: 8),
            Icon(
              AppIcons.chevronRight,
              size: 16,
              color: grid.AppPalette.textSecondary,
            ),
          ],
        ),
      ),
    );
  }
}

/// The Essentials row's one-click button, the size of a row's title.
class _EssentialButton extends StatelessWidget {
  const _EssentialButton({
    super.key,
    required this.label,
    required this.onPressed,
  });
  final String label;
  final VoidCallback onPressed;

  @override
  Widget build(BuildContext context) {
    return FilledButton(
      onPressed: onPressed,
      style: FilledButton.styleFrom(
        backgroundColor: grid.AppSurface.selectedFill,
        foregroundColor: grid.AppPalette.textPrimary,
        minimumSize: const Size(72, 30),
        padding: const EdgeInsets.symmetric(horizontal: 16),
        textStyle: grid.AppType.label(fontWeight: grid.AppFont.semibold),
        shape: const StadiumBorder(),
      ),
      child: Text(label),
    );
  }
}