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.

fix(web): keep dart:ffi out of the browser build

Dev jacob14c8526407a5
diff --git a/desktop/lib/core/mac_responsibility_probe_native.dart b/desktop/lib/core/mac_responsibility_probe_native.dart
new file mode 100644
index 000000000..f3a2a1912
--- /dev/null
+++ b/desktop/lib/core/mac_responsibility_probe_native.dart
@@ -0,0 +1,59 @@
+import 'dart:ffi';
+import 'dart:io' show Platform;
+
+import 'package:ffi/ffi.dart';
+
+import 'process_responsibility.dart' show ResponsibilityProbe;
+
+/// libSystem's answers. `responsibility_get_pid_responsible_for_pid` is private API, so every lookup
+/// degrades to null — which the verdict below reads as "cannot tell", never as "restart".
+class MacResponsibilityProbe implements ResponsibilityProbe {
+ MacResponsibilityProbe();
+
+ static const _maxPath = 4096;
+
+ late final int Function(int)? _responsible = _lookup(
+ () => DynamicLibrary.process()
+ .lookupFunction<Int32 Function(Int32), int Function(int)>(
+ 'responsibility_get_pid_responsible_for_pid',
+ ),
+ );
+
+ late final int Function(int, Pointer<Uint8>, int)? _pidPath = _lookup(
+ () =>
+ DynamicLibrary.process().lookupFunction<
+ Int32 Function(Int32, Pointer<Uint8>, Uint32),
+ int Function(int, Pointer<Uint8>, int)
+ >('proc_pidpath'),
+ );
+
+ static T? _lookup<T>(T Function() find) {
+ if (!Platform.isMacOS) return null;
+ try {
+ return find();
+ } on ArgumentError {
+ return null;
+ }
+ }
+
+ @override
+ int? responsiblePid(int pid) {
+ final responsible = _responsible?.call(pid);
+ return responsible == null || responsible <= 0 ? null : responsible;
+ }
+
+ @override
+ String? executablePath(int pid) {
+ final pidPath = _pidPath;
+ if (pidPath == null) return null;
+ final buffer = calloc<Uint8>(_maxPath);
+ try {
+ final length = pidPath(pid, buffer, _maxPath);
+ return length <= 0
+ ? null
+ : buffer.cast<Utf8>().toDartString(length: length);
+ } finally {
+ calloc.free(buffer);
+ }
+ }
+}
diff --git a/desktop/lib/core/mac_responsibility_probe_web.dart b/desktop/lib/core/mac_responsibility_probe_web.dart
new file mode 100644
index 000000000..2f0e485ed
--- /dev/null
+++ b/desktop/lib/core/mac_responsibility_probe_web.dart
@@ -0,0 +1,13 @@
+import 'process_responsibility.dart' show ResponsibilityProbe;
+
+/// A browser has no processes to ask about: every lookup is "cannot tell",
+/// which keeps the daemon.
+class MacResponsibilityProbe implements ResponsibilityProbe {
+ MacResponsibilityProbe();
+
+ @override
+ int? responsiblePid(int pid) => null;
+
+ @override
+ String? executablePath(int pid) => null;
+}
diff --git a/desktop/lib/core/process_responsibility.dart b/desktop/lib/core/process_responsibility.dart
index fc6219fbf..332a45356 100644
--- a/desktop/lib/core/process_responsibility.dart
+++ b/desktop/lib/core/process_responsibility.dart
@@ -1,7 +1,6 @@
-import 'dart:ffi';
-import 'dart:io' show Platform;
-
-import 'package:ffi/ffi.dart';
+// The libSystem probe needs dart:ffi, which a browser build cannot compile.
+export 'mac_responsibility_probe_native.dart'
+ if (dart.library.js_interop) 'mac_responsibility_probe_web.dart';
/// Who macOS holds responsible for a process — the identity its Local Network permission is judged by.
///
@@ -18,59 +17,6 @@ abstract interface class ResponsibilityProbe {
String? executablePath(int pid);
}
-/// libSystem's answers. `responsibility_get_pid_responsible_for_pid` is private API, so every lookup
-/// degrades to null — which the verdict below reads as "cannot tell", never as "restart".
-class MacResponsibilityProbe implements ResponsibilityProbe {
- MacResponsibilityProbe();
-
- static const _maxPath = 4096;
-
- late final int Function(int)? _responsible = _lookup(
- () => DynamicLibrary.process()
- .lookupFunction<Int32 Function(Int32), int Function(int)>(
- 'responsibility_get_pid_responsible_for_pid',
- ),
- );
-
- late final int Function(int, Pointer<Uint8>, int)? _pidPath = _lookup(
- () =>
- DynamicLibrary.process().lookupFunction<
- Int32 Function(Int32, Pointer<Uint8>, Uint32),
- int Function(int, Pointer<Uint8>, int)
- >('proc_pidpath'),
- );
-
- static T? _lookup<T>(T Function() find) {
- if (!Platform.isMacOS) return null;
- try {
- return find();
- } on ArgumentError {
- return null;
- }
- }
-
- @override
- int? responsiblePid(int pid) {
- final responsible = _responsible?.call(pid);
- return responsible == null || responsible <= 0 ? null : responsible;
- }
-
- @override
- String? executablePath(int pid) {
- final pidPath = _pidPath;
- if (pidPath == null) return null;
- final buffer = calloc<Uint8>(_maxPath);
- try {
- final length = pidPath(pid, buffer, _maxPath);
- return length <= 0
- ? null
- : buffer.cast<Utf8>().toDartString(length: length);
- } finally {
- calloc.free(buffer);
- }
- }
-}
-
enum DaemonOwnerAction {
keep,
restart,