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(desktop): warn before installing a package Harness has not reviewed (#93)

bubu-dudu59ce00535b5f
diff --git a/desktop/lib/core/dsh_catalog.dart b/desktop/lib/core/dsh_catalog.dart
index f21db927a..bd32ab682 100644
--- a/desktop/lib/core/dsh_catalog.dart
+++ b/desktop/lib/core/dsh_catalog.dart
@@ -88,6 +88,7 @@ class DshEntry {
this.installedCommit,
this.availableCommit,
this.updateAvailable = false,
+ this.unverified = false,
});
/// `owner/name` — the install directory on the machine and the wire id.
@@ -149,6 +150,15 @@ class DshEntry {
final bool updateAvailable;
bool get hasUpdate => installed && !linked && updateAvailable;
+ /// The machine says Harness has NOT reviewed this package (`verified: false`
+ /// in `dsh_list`): a community entry whose code lives in someone else's
+ /// repository. Installing or updating it runs that code's setup script as
+ /// the person, so it is never done without their say-so. The daemon decides
+ /// it — an entry cannot mark itself verified (cli `parseStoreCatalog`). An
+ /// older daemon that sends no `verified` at all offered built-ins only, so
+ /// only an explicit false counts.
+ final bool unverified;
+
static DshEntry? fromJson(Object? raw) {
if (raw is! Map) return null;
final id = raw['id'];
@@ -190,6 +200,7 @@ class DshEntry {
installedCommit: _commit(raw['installedCommit']),
availableCommit: _commit(raw['availableCommit']),
updateAvailable: raw['updateAvailable'] == true,
+ unverified: raw['verified'] == false,
name: name is String && name.trim().isNotEmpty
? name.trim().substring(0, name.trim().length.clamp(0, 40))
: id.substring(id.indexOf('/') + 1),
diff --git a/desktop/lib/core/harness_catalog.dart b/desktop/lib/core/harness_catalog.dart
index 4b075cabe..f9cf5a3b7 100644
--- a/desktop/lib/core/harness_catalog.dart
+++ b/desktop/lib/core/harness_catalog.dart
@@ -89,6 +89,7 @@ DshEntry _currentEntry(String id, List<DshEntry> entries) {
installedCommit: installation.installedCommit,
availableCommit: installation.availableCommit,
updateAvailable: installation.updateAvailable,
+ unverified: installation.unverified || metadata.unverified,
viewer: installation.installed ? installation.viewer : metadata.viewer,
viewerUse: installation.installed
? installation.viewerUse
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 3fb15f83e..20ab5589b 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -6864,19 +6864,46 @@ class AppNotifier extends ChangeNotifier {
/// socket is back. Consumed by [_onMachineConnected].
final Set<String> _dshProbeOnReconnect = {};
- Future<String?> installDsh(String machineId, String id) =>
- _installOrUpdateDsh(machineId, id, update: false);
+ /// [trustUnverified] is the person's answer to the Store's warning about a
+ /// package Harness has not reviewed ([DshEntry.unverified]). Without it such
+ /// a package is refused here, so a way into an install that has no warning
+ /// of its own — New Harness, a future caller — cannot run a stranger's setup
+ /// script unannounced.
+ Future<String?> installDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) => _installOrUpdateDsh(
+ machineId,
+ id,
+ update: false,
+ trustUnverified: trustUnverified,
+ );
- Future<String?> updateDsh(String machineId, String id) =>
- _installOrUpdateDsh(machineId, id, update: true);
+ Future<String?> updateDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) => _installOrUpdateDsh(
+ machineId,
+ id,
+ update: true,
+ trustUnverified: trustUnverified,
+ );
Future<String?> _installOrUpdateDsh(
String machineId,
String id, {
required bool update,
+ required bool trustUnverified,
}) async {
final machine = machineStates[machineId];
if (machine == null) return 'Machine not found';
+ final entry = machine.dsh[id];
+ if (entry != null && entry.unverified && !trustUnverified) {
+ return '${entry.name} is not reviewed by Harness. Open it in the Store '
+ 'to check its source before you ${update ? 'update' : 'install'} it.';
+ }
final machineName = machine.machine.displayName;
final action = update ? 'Update' : 'Install';
final verb = update ? 'update' : 'install';
diff --git a/desktop/lib/store/store_screen.dart b/desktop/lib/store/store_screen.dart
index 7d1af3999..02ad930a7 100644
--- a/desktop/lib/store/store_screen.dart
+++ b/desktop/lib/store/store_screen.dart
@@ -988,11 +988,15 @@ class _ProductPageState extends State<_ProductPage> {
// An engine is installed by the daemon on the way to the first harness
// that needs it (`installIfMissing` on create), so Get is Open.
if (widget.entry.isEngine) return _open(machineId);
- if (!_busy.add(machineId)) return;
+ if (_busy.contains(machineId)) return;
+ final trusted = _unverified(local);
+ if (trusted && !await _confirmUnverified(local, update: false)) return;
+ if (!mounted || !_busy.add(machineId)) return;
setState(() {});
final failure = await widget.notifier.installDsh(
machineId,
_operationId(local, widget.entry.id),
+ trustUnverified: trusted,
);
_busy.remove(machineId);
if (mounted) setState(() {});
@@ -1015,19 +1019,55 @@ class _ProductPageState extends State<_ProductPage> {
if (local == null ||
local.machine.machineId != machineId ||
_machineHarness(local, widget.entry.id)?.hasUpdate != true ||
- !_busy.add(machineId)) {
+ _busy.contains(machineId)) {
return;
}
+ final trusted = _unverified(local);
+ if (trusted && !await _confirmUnverified(local, update: true)) return;
+ if (!mounted || !_busy.add(machineId)) return;
setState(() {});
final failure = await widget.notifier.updateDsh(
machineId,
_operationId(local, widget.entry.id),
+ trustUnverified: trusted,
);
_busy.remove(machineId);
if (mounted) setState(() {});
if (failure != null) _say(_failureSentence(local, failure));
}
+ /// Harness has not reviewed this package ([DshEntry.unverified]), on the
+ /// machine's word or the page's.
+ bool _unverified(MachineState local) =>
+ widget.entry.unverified ||
+ _machineHarness(local, widget.entry.id)?.unverified == true;
+
+ /// Asks before a package Harness has not reviewed is installed or updated:
+ /// both run its setup script as the person, and Update fetches whatever its
+ /// repository holds now. True only when they confirm.
+ Future<bool> _confirmUnverified(
+ MachineState local, {
+ required bool update,
+ }) async {
+ final source =
+ _machineHarness(local, widget.entry.id)?.repo ??
+ widget.entry.repo ??
+ 'its own repository';
+ final ok = await showAppDialog<bool>(
+ context: context,
+ builder: (context) => _ConfirmCard(
+ title: 'Harness has not reviewed ${widget.entry.name}',
+ detail:
+ 'Its code comes from $source, not from Harness. '
+ '${update ? 'Updating fetches its latest code and runs its setup script again' : 'Installing runs its setup script'} '
+ 'on ${local.machine.displayName} as you, with access to your files '
+ 'and credentials. Continue only if you trust its author.',
+ action: update ? 'Update anyway' : 'Install anyway',
+ ),
+ );
+ return ok == true && mounted;
+ }
+
Future<void> _remove(String machineId, String machineName) async {
final local = widget.notifier.localMachineState;
final installation = _machineHarness(local, widget.entry.id);
diff --git a/desktop/test/dsh_catalog_test.dart b/desktop/test/dsh_catalog_test.dart
index 847ab7127..b4a6e41f7 100644
--- a/desktop/test/dsh_catalog_test.dart
+++ b/desktop/test/dsh_catalog_test.dart
@@ -318,6 +318,56 @@ void main() {
},
);
+ test('only an explicit verified:false marks a package unverified', () {
+ expect(DshEntry.fromJson(_circuit)!.unverified, isFalse);
+ expect(
+ DshEntry.fromJson({..._circuit, 'verified': true})!.unverified,
+ isFalse,
+ );
+ expect(
+ DshEntry.fromJson({..._circuit, 'verified': false})!.unverified,
+ isTrue,
+ );
+ });
+
+ test(
+ 'an unreviewed package is not installed or updated until the person trusts it',
+ () async {
+ const community = {
+ 'id': 'someone/thing',
+ 'name': 'Thing',
+ 'engine': 'claude',
+ 'installed': false,
+ 'verified': false,
+ };
+ final connection = _Connection()
+ ..answer = (type, _) => Future.value(
+ type == 'dsh_list'
+ ? {
+ 'dsh': [
+ {...community, 'installed': true},
+ ],
+ }
+ : {'ok': true},
+ );
+ final app = createApp(connectionForTest: (_) => connection);
+ addTearDown(app.dispose);
+ app.stateOf('m')!.dsh.replace([DshEntry.fromJson(community)!]);
+
+ final refused = await app.installDsh('m', 'someone/thing');
+ expect(refused, contains('not reviewed by Harness'));
+ expect(await app.updateDsh('m', 'someone/thing'), isNotNull);
+ expect(connection.calls, isEmpty);
+ expect(app.stateOf('m')!.dsh.runs['someone/thing'], isNull);
+
+ expect(
+ await app.installDsh('m', 'someone/thing', trustUnverified: true),
+ isNull,
+ );
+ expect(connection.calls.first.$1, 'dsh_install');
+ },
+ );
+
test('a refused install says so and stays retryable', () async {
final connection = _Connection()
..answer = (type, _) => Future.error(
diff --git a/desktop/test/new_agent_dsh_test.dart b/desktop/test/new_agent_dsh_test.dart
index 0841f3aac..1c94ca70e 100644
--- a/desktop/test/new_agent_dsh_test.dart
+++ b/desktop/test/new_agent_dsh_test.dart
@@ -78,7 +78,11 @@ class _Notifier extends AppNotifier {
}) async => {'profiles': <dynamic>[]};
@override
- Future<String?> installDsh(String machineId, String id) {
+ Future<String?> installDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) {
installs.add(id);
final machine = machineStates[machineId]!;
machine.dsh.applyInstall(DshInstallProgress(id: id, phase: 'setup'));
diff --git a/desktop/test/new_agent_rows_and_task_test.dart b/desktop/test/new_agent_rows_and_task_test.dart
index 416781704..f38d721cb 100644
--- a/desktop/test/new_agent_rows_and_task_test.dart
+++ b/desktop/test/new_agent_rows_and_task_test.dart
@@ -109,7 +109,11 @@ class _App extends AppNotifier {
}) async => {'profiles': <dynamic>[]};
@override
- Future<String?> installDsh(String machineId, String id) =>
+ Future<String?> installDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) =>
pendingInstall?.future ?? Future.value(null);
@override
diff --git a/desktop/test/new_harness_install_pane_test.dart b/desktop/test/new_harness_install_pane_test.dart
index 7080404cd..20fbde866 100644
--- a/desktop/test/new_harness_install_pane_test.dart
+++ b/desktop/test/new_harness_install_pane_test.dart
@@ -89,7 +89,11 @@ class _Notifier extends AppNotifier {
/// The machine's side of an install: a fresh run, then whatever the test
/// narrates through [narrate], then [pendingInstall]'s answer.
@override
- Future<String?> installDsh(String machineId, String id) async {
+ Future<String?> installDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) async {
installs.add(id);
final machine = machineStates[machineId]!;
machine.dsh.runs.remove(id);
diff --git a/desktop/test/store_page_test.dart b/desktop/test/store_page_test.dart
index 501579d5e..513b24db1 100644
--- a/desktop/test/store_page_test.dart
+++ b/desktop/test/store_page_test.dart
@@ -85,11 +85,19 @@ class _Notifier extends AppNotifier {
}
@override
- Future<String?> installDsh(String machineId, String id) async {
+ Future<String?> installDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) async {
installs.add((machineId, id));
+ trusted.add(trustUnverified);
return installGate?.future;
}
+ /// `trustUnverified` of each install/update, in order.
+ final trusted = <bool>[];
+
@override
Future<String?> removeDsh(String machineId, String id) async {
removals.add((machineId, id));
@@ -97,8 +105,13 @@ class _Notifier extends AppNotifier {
}
@override
- Future<String?> updateDsh(String machineId, String id) async {
+ Future<String?> updateDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) async {
updates.add((machineId, id));
+ trusted.add(trustUnverified);
return updateGate?.future;
}
@@ -471,6 +484,61 @@ void main() {
},
);
+ testWidgets(
+ 'Get on a package Harness has not reviewed warns first, and only a yes installs it',
+ (tester) async {
+ const thing = DshEntry(
+ id: 'someone/thing',
+ name: 'Thing',
+ engine: 'claude',
+ category: 'Documents',
+ repo: 'https://github.com/someone/thing',
+ unverified: true,
+ );
+ final (app, _) = await _open(
+ tester,
+ initialHarness: thing.id,
+ seed: (app) => app.machine(
+ 'machine-1',
+ name: 'studio-mac',
+ local: true,
+ dsh: const [thing, _typst],
+ engines: const [
+ EngineAvailability(engine: 'claude', installed: true),
+ ],
+ ),
+ );
+ await tester.tap(_key('store-primary-action'));
+ await tester.pumpAndSettle();
+ expect(find.text('Harness has not reviewed Thing'), findsOneWidget);
+ expect(
+ find.textContaining('https://github.com/someone/thing'),
+ findsOneWidget,
+ );
+ await tester.tap(find.widgetWithText(TextButton, 'Cancel'));
+ await tester.pumpAndSettle();
+ expect(app.installs, isEmpty);
+
+ await tester.tap(_key('store-primary-action'));
+ await tester.pumpAndSettle();
+ await tester.tap(_key('store-confirm'));
+ await tester.pumpAndSettle();
+ expect(app.installs, [('machine-1', 'someone/thing')]);
+ expect(app.trusted, [true]);
+ },
+ );
+
+ testWidgets('a reviewed package installs without a warning', (
+ tester,
+ ) async {
+ final (app, _) = await _open(tester, initialHarness: _typst.id);
+ await tester.tap(_key('store-primary-action'));
+ await tester.pumpAndSettle();
+ expect(find.textContaining('has not reviewed'), findsNothing);
+ expect(app.installs, [('machine-1', 'autonomous/typst')]);
+ expect(app.trusted, [false]);
+ });
+
testWidgets('an install that ends after the page is gone says nothing', (
tester,
) async {
diff --git a/desktop/test/store_screen_test.dart b/desktop/test/store_screen_test.dart
index 12fa90d14..1a8e61c75 100644
--- a/desktop/test/store_screen_test.dart
+++ b/desktop/test/store_screen_test.dart
@@ -80,13 +80,21 @@ class _Notifier extends AppNotifier {
}
@override
- Future<String?> installDsh(String machineId, String id) async {
+ Future<String?> installDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) async {
installs.add((machineId, id));
return null;
}
@override
- Future<String?> updateDsh(String machineId, String id) async {
+ Future<String?> updateDsh(
+ String machineId,
+ String id, {
+ bool trustUnverified = false,
+ }) async {
updates.add((machineId, id));
return null;
}
diff --git a/desktop/test/support/model_manager.dart b/desktop/test/support/model_manager.dart
index 46d4722fc..ed33e139b 100644
--- a/desktop/test/support/model_manager.dart
+++ b/desktop/test/support/model_manager.dart
@@ -217,7 +217,11 @@ class ModelManagerTestApp extends AppNotifier {
}
@override
- Future<String?> installDsh(String machineId, String harness) async {
+ Future<String?> installDsh(
+ String machineId,
+ String harness, {
+ bool trustUnverified = false,
+ }) async {
installs++;
if (installError != null) return installError;
installed = true;