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.

Desktop Debug: Dial log follows the per-device log folders (#2017)

0xken15603b4c51a746
diff --git a/desktop/lib/logging/dial_log_tail.dart b/desktop/lib/logging/dial_log_tail.dart
index 7fc6b7c27..5aa038a23 100644
--- a/desktop/lib/logging/dial_log_tail.dart
+++ b/desktop/lib/logging/dial_log_tail.dart
@@ -6,19 +6,30 @@ import 'app_log.dart';
import 'log_file.dart';
import 'log_stream.dart';
-/// Base name of the dial's per-day file under `~/.harness/logs`, written by the
+/// Base name of the dial's per-day files under `~/.harness/logs`, written by the
/// CLI daemon (`cli/src/cable/dialLog.ts`), never by this app.
const String kDialLogBase = 'dial';
-/// Follows `dial-YYYYMMDD.log` into the in-memory [LogStream], so the dial is
-/// a source in Settings ▸ Debug beside the app's own.
+/// Prefix of one device's log folder under `~/.harness/logs`: the daemon
+/// writes each dial and Pro to `usb-<id>/dial-YYYYMMDD.log`
+/// (`cli/src/cable/cableFleet.ts` `logFolder`).
+const String kDialDeviceFolderPrefix = 'usb-';
+
+/// Follows the dial logs into the in-memory [LogStream], so the dials are a
+/// source in Settings ▸ Debug beside the app's own.
///
/// The other sources are *mirrors* — the app writes the file and the ring at
-/// once. This one cannot be: the daemon writes the dial's file, and the app
-/// only reads it. So it tails: every second it reads whatever bytes were
-/// appended since last time, one entry per line, category `dial`. On first
-/// start it takes only the last [_catchUpBytes] of today's file, enough for
-/// the recent context without replaying a whole day into a 500-entry ring.
+/// once. This one cannot be: the daemon writes the dial's files, and the app
+/// only reads them. So it tails: every second it reads whatever bytes were
+/// appended since last time, one entry per line, category `dial`.
+///
+/// Each plugged-in device has its own folder, `usb-<id>/dial-YYYYMMDD.log`,
+/// and its lines are tagged `[<id>]` so two dials stay apart (the Debug
+/// search finds one by its id). A folder is followed while it has a file for
+/// today, at most [maxDevices] of them; one that appears later is picked up on
+/// the next poll, and one that goes, or has no file for the new day, is
+/// dropped. A daemon older than the per-device folders wrote one top-level
+/// `dial-YYYYMMDD.log`, still read, untagged.
///
/// Levels come from the line itself: the firmware's `W (ticks)` / `E (ticks)`
/// prefixes, and a `[daemon]` line is the daemon speaking. The file is the
@@ -29,25 +40,27 @@ class DialLogTail {
this.stream, {
DateTime Function()? clock,
this.interval = const Duration(seconds: 1),
+ this.maxDevices = 16,
}) : _clock = clock ?? DateTime.now;
final Directory directory;
final LogStream stream;
final Duration interval;
- final DateTime Function() _clock;
- static const int _catchUpBytes = 16 * 1024;
+ /// How many device folders are tailed at once. Folders past it are said
+ /// once in the stream rather than silently left out.
+ final int maxDevices;
+
+ final DateTime Function() _clock;
Timer? _timer;
- String? _day;
- int _offset = 0;
- String _partial = '';
- // Set when the catch-up window opened mid-line: the first "line" read is a
- // fragment and is dropped rather than shown as a half sentence.
- bool _dropFirst = false;
+ Future<void>? _polling;
+ late final _DayFileTail _topLevel = _DayFileTail(directory, null, stream);
+ final Map<String, _DayFileTail> _devices = {};
+ bool _saidOverCap = false;
- File get currentFile =>
- File('${directory.path}/${dailyLogName(kDialLogBase, _clock())}');
+ /// The device ids whose folders are followed now, sorted.
+ List<String> get devices => _devices.keys.toList()..sort();
void start() {
_timer ??= Timer.periodic(interval, (_) => unawaited(poll()));
@@ -60,14 +73,85 @@ class DialLogTail {
}
/// One read of whatever is new. Public so a test can drive it without a
- /// timer; safe to call when nothing changed.
- Future<void> poll() async {
+ /// timer; safe to call when nothing changed. A call made while one is still
+ /// reading joins it, so the timer never reads the same bytes twice.
+ Future<void> poll() =>
+ _polling ??= _pollOnce().whenComplete(() => _polling = null);
+
+ Future<void> _pollOnce() async {
+ final name = dailyLogName(kDialLogBase, _clock());
+ await _topLevel.poll(name);
+ final present = await _deviceIdsWithFile(name);
+ _devices.removeWhere((id, _) => !present.contains(id));
+ final waiting = present.where((id) => !_devices.containsKey(id)).toList()
+ ..sort();
+ for (final id in waiting) {
+ if (_devices.length >= maxDevices) break;
+ _devices[id] = _DayFileTail(
+ Directory('${directory.path}/$kDialDeviceFolderPrefix$id'),
+ id,
+ stream,
+ );
+ }
+ final left = present.length - _devices.length;
+ if (left > 0 && !_saidOverCap) {
+ stream.add(
+ AppLogLevel.warn,
+ 'dial',
+ '$left more dial log${left == 1 ? '' : 's'} not followed '
+ '(limit $maxDevices)',
+ );
+ }
+ _saidOverCap = left > 0;
+ for (final id in devices) {
+ await _devices[id]!.poll(name);
+ }
+ }
+
+ /// Ids of the `usb-<id>` folders holding a [name] file; empty when the logs
+ /// folder cannot be read.
+ Future<Set<String>> _deviceIdsWithFile(String name) async {
+ final ids = <String>{};
+ try {
+ await for (final entity in directory.list()) {
+ if (entity is! Directory) continue;
+ final folder = entity.uri.pathSegments.lastWhere((s) => s.isNotEmpty);
+ if (!folder.startsWith(kDialDeviceFolderPrefix)) continue;
+ if (!await File('${entity.path}/$name').exists()) continue;
+ ids.add(folder.substring(kDialDeviceFolderPrefix.length));
+ }
+ } on Object {
+ // No logs folder yet, or one being removed: nothing to follow.
+ }
+ return ids;
+ }
+}
+
+/// Follows one folder's day file: on a new day (or the first poll) it starts
+/// from the last [_catchUpBytes], enough for the recent context without
+/// replaying a whole day into a 500-entry ring.
+class _DayFileTail {
+ _DayFileTail(this.folder, this.device, this.stream);
+
+ final Directory folder;
+
+ /// The `[id]` each line is tagged with; null for the untagged top-level file.
+ final String? device;
+ final LogStream stream;
+
+ static const int _catchUpBytes = 16 * 1024;
+
+ String? _day;
+ int _offset = 0;
+ String _partial = '';
+ // Set when the catch-up window opened mid-line: the first "line" read is a
+ // fragment and is dropped rather than shown as a half sentence.
+ bool _dropFirst = false;
+
+ Future<void> poll(String day) async {
try {
- final now = _clock();
- final day = dailyLogName(kDialLogBase, now);
- final file = currentFile;
+ final file = File('${folder.path}/$day');
if (day != _day) {
- // A new day (or the first poll): start from the tail, not the top.
_day = day;
_partial = '';
_offset = 0;
@@ -110,7 +194,12 @@ class DialLogTail {
}
if (line.isEmpty) continue;
final parsed = parseDialLine(line);
- stream.add(parsed.level, 'dial', parsed.message);
+ final tag = device;
+ stream.add(
+ parsed.level,
+ 'dial',
+ tag == null ? parsed.message : '[$tag] ${parsed.message}',
+ );
}
}
}
diff --git a/desktop/lib/settings/sections/debug_paths_card.dart b/desktop/lib/settings/sections/debug_paths_card.dart
index adc03077f..2a93e1abd 100644
--- a/desktop/lib/settings/sections/debug_paths_card.dart
+++ b/desktop/lib/settings/sections/debug_paths_card.dart
@@ -2,6 +2,7 @@ import 'package:harness/shared/theme/app_icons.dart';
import 'package:flutter/material.dart';
import '../../core/harness_cli_runner.dart';
+import '../../logging/dial_log_tail.dart';
import '../../logging/log_file.dart';
import '../../shared/theme/app_theme.dart';
import '../../shared/widgets/app_icon_button.dart';
@@ -105,10 +106,13 @@ class _DebugPathsCardState extends State<DebugPathsCard> {
'(${environment.harnessSource.name})',
),
_PathRow(label: 'logs', value: environment.logsDirectory),
- // The daemon's file, not this app's — see logging/dial_log_tail.dart.
+ // The daemon's files, one folder per device, not this app's —
+ // see logging/dial_log_tail.dart.
_PathRow(
label: 'dial',
- value: '${environment.logsDirectory}/dial-YYYYMMDD.log',
+ value:
+ '${environment.logsDirectory}/'
+ '$kDialDeviceFolderPrefix<device>/dial-YYYYMMDD.log',
),
],
);
diff --git a/desktop/test/debug_section_test.dart b/desktop/test/debug_section_test.dart
index 9e3069d40..138ef31c0 100644
--- a/desktop/test/debug_section_test.dart
+++ b/desktop/test/debug_section_test.dart
@@ -62,6 +62,14 @@ void main() {
expect(find.text('2 entries'), findsOneWidget);
});
+ testWidgets('Paths names the per-device dial log folders', (tester) async {
+ await pumpDebug(tester, LogStream());
+ expect(
+ find.text('/tmp/logs/usb-<device>/dial-YYYYMMDD.log'),
+ findsOneWidget,
+ );
+ });
+
testWidgets('the Failed lens keeps the failures and the warnings', (
tester,
) async {
diff --git a/desktop/test/dial_log_tail_test.dart b/desktop/test/dial_log_tail_test.dart
index f9906d4ee..ea69ffbf0 100644
--- a/desktop/test/dial_log_tail_test.dart
+++ b/desktop/test/dial_log_tail_test.dart
@@ -81,6 +81,156 @@ void main() {
},
);
+ group('per-device folders', () {
+ late Directory dir;
+ final now = DateTime(2026, 10, 28, 10);
+ final today = dailyLogName(kDialLogBase, now);
+
+ setUp(() {
+ dir = Directory.systemTemp.createTempSync('dial-tail-');
+ addTearDown(() => dir.deleteSync(recursive: true));
+ });
+
+ File deviceFile(String folder, [String? name]) {
+ final file = File('${dir.path}/$folder/${name ?? today}');
+ file.parent.createSync(recursive: true);
+ return file;
+ }
+
+ test(
+ 'each device folder reaches the stream tagged with its device',
+ () async {
+ deviceFile(
+ 'usb-AA-BB',
+ ).writeAsStringSync('2026-10-28T03:00:00.000Z I (1) ui: face: agent\n');
+ deviceFile('usb-CC-DD')
+ .writeAsStringSync('2026-10-28T03:00:01.000Z E (2) cable: lost\n');
+ final stream = LogStream();
+ await DialLogTail(dir, stream, clock: () => now).poll();
+ expect(stream.entries.map((e) => e.message).toSet(), {
+ '[AA-BB] I (1) ui: face: agent',
+ '[CC-DD] E (2) cable: lost',
+ });
+ expect(stream.entries.every((e) => e.category == 'dial'), isTrue);
+ final lost = stream.entries.firstWhere(
+ (e) => e.message.startsWith('[CC-DD]'),
+ );
+ expect(lost.level, AppLogLevel.error);
+ },
+ );
+
+ test('a device folder that appears after start is followed on the next '
+ 'poll', () async {
+ deviceFile('usb-AA-BB')
+ .writeAsStringSync('2026-10-28T03:00:00.000Z I (1) ui: one\n');
+ final stream = LogStream();
+ final tail = DialLogTail(dir, stream, clock: () => now);
+ await tail.poll();
+ deviceFile('usb-EE-FF')
+ .writeAsStringSync('2026-10-28T03:00:02.000Z I (3) ui: plugged\n');
+ await tail.poll();
+ expect(stream.entries.first.message, '[EE-FF] I (3) ui: plugged');
+ expect(tail.devices, ['AA-BB', 'EE-FF']);
+ });
+
+ test('a top-level day file from an older daemon is still read', () async {
+ File('${dir.path}/$today')
+ .writeAsStringSync('2026-10-28T03:00:00.000Z [daemon] old layout\n');
+ deviceFile('usb-AA-BB')
+ .writeAsStringSync('2026-10-28T03:00:01.000Z I (1) ui: new layout\n');
+ final stream = LogStream();
+ await DialLogTail(dir, stream, clock: () => now).poll();
+ expect(stream.entries.map((e) => e.message).toSet(), {
+ '[daemon] old layout',
+ '[AA-BB] I (1) ui: new layout',
+ });
+ });
+
+ test('a folder that goes away is no longer followed', () async {
+ final file = deviceFile('usb-AA-BB')
+ ..writeAsStringSync('2026-10-28T03:00:00.000Z I (1) ui: one\n');
+ final stream = LogStream();
+ final tail = DialLogTail(dir, stream, clock: () => now);
+ await tail.poll();
+ expect(tail.devices, ['AA-BB']);
+ file.parent.deleteSync(recursive: true);
+ await tail.poll();
+ expect(tail.devices, isEmpty);
+ expect(stream.entries.length, 1);
+ });
+
+ test('a folder without a file for today is not followed', () async {
+ deviceFile(
+ 'usb-AA-BB',
+ 'dial-20261027.log',
+ ).writeAsStringSync('2026-10-27T03:00:00.000Z I (1) ui: yesterday\n');
+ final stream = LogStream();
+ final tail = DialLogTail(dir, stream, clock: () => now);
+ await tail.poll();
+ expect(tail.devices, isEmpty);
+ expect(stream.entries, isEmpty);
+ });
+
+ test('the day rolling over moves each device to its new file', () async {
+ var clock = now;
+ deviceFile('usb-AA-BB')
+ .writeAsStringSync('2026-10-28T23:59:59.000Z I (1) ui: late\n');
+ final stream = LogStream();
+ final tail = DialLogTail(dir, stream, clock: () => clock);
+ await tail.poll();
+ clock = DateTime(2026, 10, 29, 0, 0, 1);
+ deviceFile(
+ 'usb-AA-BB',
+ dailyLogName(kDialLogBase, clock),
+ ).writeAsStringSync('2026-10-29T00:00:00.500Z I (2) ui: early\n');
+ await tail.poll();
+ expect(stream.entries.map((e) => e.message).toList(), [
+ '[AA-BB] I (2) ui: early',
+ '[AA-BB] I (1) ui: late',
+ ]);
+ });
+
+ test(
+ 'past the cap, extra devices are not tailed and that is said once',
+ () async {
+ for (final id in ['AA', 'BB', 'CC']) {
+ deviceFile('usb-$id')
+ .writeAsStringSync('2026-10-28T03:00:00.000Z I (1) ui: $id\n');
+ }
+ final stream = LogStream();
+ final tail = DialLogTail(dir, stream, clock: () => now, maxDevices: 2);
+ await tail.poll();
+ await tail.poll();
+ expect(tail.devices, ['AA', 'BB']);
+ final messages = stream.entries.map((e) => e.message).toList();
+ expect(messages.where((m) => m.contains('[CC]')), isEmpty);
+ expect(
+ messages.where((m) => m == '1 more dial log not followed (limit 2)'),
+ hasLength(1),
+ );
+ },
+ );
+ });
+
+ test('a poll started while one is running reads nothing twice', () async {
+ final dir = Directory.systemTemp.createTempSync('dial-tail-');
+ addTearDown(() => dir.deleteSync(recursive: true));
+ final now = DateTime(2026, 10, 28, 10);
+ final today = dailyLogName(kDialLogBase, now);
+ for (final folder in ['usb-AA', 'usb-BB']) {
+ final file = File('${dir.path}/$folder/$today');
+ file.parent.createSync();
+ file.writeAsStringSync('2026-10-28T03:00:00.000Z I (1) ui: $folder\n');
+ }
+ final stream = LogStream();
+ final tail = DialLogTail(dir, stream, clock: () => now);
+ await Future.wait([tail.poll(), tail.poll()]);
+ expect(stream.entries.map((e) => e.message).toList()..sort(), [
+ '[AA] I (1) ui: usb-AA',
+ '[BB] I (1) ui: usb-BB',
+ ]);
+ });
+
test('parseLogExport reads the CLI answer', () {
final ok = parseLogExport(
'{"path":"/x/harness-logs.zip","included":["a"],"bytes":1}',