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 'package:flutter/foundation.dart';

import 'app_log.dart';
import 'cli_log.dart';
import 'debug_surface.dart';
import 'dial_log_tail.dart';
import 'log_file.dart';
import 'log_stream.dart';
import 'log_stream_sinks.dart';

/// Base names of the two per-day files under `~/.harness/logs`.
const String kAppLogBase = 'app';
const String kCliLogBase = 'cli';

/// Point [appLog] and [cliLog] at real files under `~/.harness/logs`, and — in
/// a build that has the Debug screen — at the in-memory [logStream] as well.
///
/// Called once from `main()`. Nothing else calls it, which is what keeps the
/// suite honest: both sinks default to their no-op, so `flutter test` cannot
/// write into a real Harness home no matter which code path it exercises.
///
/// Deliberately not `async`: the first lines this app writes are the ones about
/// starting up, and awaiting a directory probe here would lose them.
void installFileLogs() {
  if (kIsWeb) {
    appLog = StreamAppLog(logStream);
    cliLog = StreamCliLog(logStream);
    return;
  }
  final directory = DailyLogFile.defaultDirectory;
  final file = FileAppLog(
    DailyLogFile(directory, kAppLogBase),
    bufferDebug: true,
  );
  final cli = FileCliLog(DailyLogFile(directory, kCliLogBase));
  if (!kDebugSurfaceEnabled) {
    appLog = file;
    cliLog = cli;
    return;
  }
  // The file first in both fan-outs: if the mirror ever throws, the record
  // has already reached the file sink (routine debug entries may be buffered).
  appLog = FanoutAppLog([file, StreamAppLog(logStream)]);
  cliLog = FanoutCliLog([cli, StreamCliLog(logStream)]);
  // The dial's log is the daemon's to write; this app only reads it. Tailed
  // into the same ring so Settings ▸ Debug has a Dial lens.
  DialLogTail(directory, logStream).start();
}