Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

nanocua: fix the stop key's target, and ask before the whole screen

Rach Pradhan5b0d13d473c8
diff --git a/apps/nanocua/README.md b/apps/nanocua/README.md
index df6c8730..854f2328 100644
--- a/apps/nanocua/README.md
+++ b/apps/nanocua/README.md
@@ -78,7 +78,10 @@ brings the app forward.
pointer, so it's also on a key, **⌃⌥⌘.**, and outside the panel (below).
- **Allow input** is off at launch: agents can look but not click, type or
open apps until you turn it on.
-- **Allow whole screen** is off at launch too: agents stay inside one app.
+- **Allow whole screen** is off at launch too: agents stay inside one app. Its
+ switch asks first, on the same card as requests from outside: the click that
+ brings this window forward also presses what's under it, and this switch hands
+ over the real pointer.
- nanocua's own window is off limits: agents don't see it in trees and can't
click, type or set values in it, so an agent can't press its own Resume.
- **Activity** lists every call: the tool, its arguments, how long it took,
diff --git a/apps/nanocua/src/app.zig b/apps/nanocua/src/app.zig
index 1bef9d94..25f75c65 100644
--- a/apps/nanocua/src/app.zig
+++ b/apps/nanocua/src/app.zig
@@ -133,6 +133,10 @@ pub const App = struct {
/// Turning it off always does.
pub fn fromPanel(a: *App, want: control.Want, on: bool) void {
if (on and !a.clickIsReal()) return;
+ // nanoui's windows act on the click that brings them forward, so a click
+ // meant only to focus this window can land here. This switch takes over
+ // the real pointer, so it gets the card, and a second, deliberate click.
+ if (on and want == .whole_screen) return a.askHere(want);
switch (want) {
.input => a.setInput(on),
.whole_screen => a.setWholeScreen(on),
@@ -140,6 +144,15 @@ pub const App = struct {
}
}
+ /// The user asking from this window: nobody's waiting, and a Deny of someone
+ /// else's question doesn't hold them back.
+ fn askHere(a: *App, want: control.Want) void {
+ a.settleRequest();
+ a.gate.quiet_until = 0;
+ _ = a.gate.ask(want, "this window", 0, "", a.hub.clock());
+ a.redraw();
+ }
+
fn clickIsReal(a: *App) bool {
const real = if (a.real_pointer) |f| f() else true;
if (!real) a.ignored_until = a.hub.clock() + 5;
@@ -281,7 +294,7 @@ pub const App = struct {
fn finishRequest(a: *App, r: control.Request, outcome: []const u8) void {
if (!a.hidden) if (a.window) |w| if (a.raise) |f| f(w, false);
- a.reply(r.conn, r.id(), outcome);
+ if (r.conn != 0) a.reply(r.conn, r.id(), outcome);
a.redraw();
}
diff --git a/apps/nanocua/src/control.zig b/apps/nanocua/src/control.zig
index fbe90ea4..b67dfa00 100644
--- a/apps/nanocua/src/control.zig
+++ b/apps/nanocua/src/control.zig
@@ -36,6 +36,7 @@ pub const quiet_after_deny: f64 = 15;
pub const Request = struct {
want: Want,
at: f64,
+ /// 0: nobody's waiting, the user asked in the panel (connections start at 1).
conn: u64,
from_buf: [32]u8 = undefined,
from_len: u8 = 0,
diff --git a/apps/nanocua/src/ctl.zig b/apps/nanocua/src/ctl.zig
index bed0b092..fefaf45a 100644
--- a/apps/nanocua/src/ctl.zig
+++ b/apps/nanocua/src/ctl.zig
@@ -79,6 +79,10 @@ pub fn describe(a: std.mem.Allocator, s: control.Status) ![]const u8 {
"Just denied: try again in a few seconds."
else if (std.mem.eql(u8, o, "unreachable"))
"Couldn't reach nanocua: open nanocua.app."
+ else if (std.mem.eql(u8, o, "already_on"))
+ "It's already on: there's nothing to answer."
+ else if (std.mem.eql(u8, o, "already_allowed"))
+ "macOS already allows it."
else if (std.mem.eql(u8, o, "opened"))
"macOS's prompt or its settings should be open: turn nanocua on there."
else
@@ -193,4 +197,5 @@ test "what a person reads" {
try std.testing.expect(std.mem.indexOf(u8, on, "Accessibility allowed, Screen Recording not allowed") != null);
try std.testing.expect(std.mem.endsWith(u8, on, "Waiting in nanocua's window: resume\n"));
try std.testing.expect(std.mem.indexOf(u8, try describe(a, .{ .stopped = true }), "nanocua: stopped") != null);
+ try std.testing.expect(std.mem.startsWith(u8, try describe(a, .{ .outcome = "already_on" }), "It's already on"));
}
diff --git a/apps/nanocua/src/mac/hotkey.zig b/apps/nanocua/src/mac/hotkey.zig
index 371c9932..3295455c 100644
--- a/apps/nanocua/src/mac/hotkey.zig
+++ b/apps/nanocua/src/mac/hotkey.zig
@@ -7,7 +7,7 @@ const std = @import("std");
const EventTypeSpec = extern struct { class: u32, kind: u32 };
const HotKeyID = extern struct { signature: u32, id: u32 };
const Handler = *const fn (next: ?*anyopaque, event: ?*anyopaque, user: ?*anyopaque) callconv(.c) i32;
-extern "c" fn GetApplicationEventTarget() *anyopaque;
+extern "c" fn GetEventDispatcherTarget() *anyopaque;
extern "c" fn InstallEventHandler(target: *anyopaque, handler: Handler, n: usize, list: [*]const EventTypeSpec, user: ?*anyopaque, out: ?*?*anyopaque) i32;
extern "c" fn RegisterEventHotKey(code: u32, modifiers: u32, id: HotKeyID, target: *anyopaque, options: u32, out: *?*anyopaque) i32;
extern "c" fn UnregisterEventHotKey(ref: *anyopaque) i32;
@@ -28,7 +28,7 @@ pub const HotKey = struct {
/// Registers the key; `hk` must stay where it is.
pub fn register(hk: *HotKey) bool {
- const target = GetApplicationEventTarget();
+ const target = GetEventDispatcherTarget();
const spec = [_]EventTypeSpec{.{ .class = keyboard_class, .kind = hot_key_pressed }};
if (InstallEventHandler(target, pressed, 1, &spec, hk, null) != 0) return false;
return RegisterEventHotKey(period, cmd | option | control, .{ .signature = 0x6e637561, .id = 1 }, target, 0, &hk.ref) == 0;
diff --git a/apps/nanocua/src/tests_app.zig b/apps/nanocua/src/tests_app.zig
index c9313fa5..0aaaeab3 100644
--- a/apps/nanocua/src/tests_app.zig
+++ b/apps/nanocua/src/tests_app.zig
@@ -87,6 +87,11 @@ test "the panel: stop and resume, input, the log, copying the command" {
try std.testing.expectEqual(@as(usize, 2), rec.calls);
try t.clickText("Allow whole screen: your pointer and keyboard, pictures of everything");
t.settle(0.5);
+ try std.testing.expect(!a.hub.policy.allow_whole_screen);
+ a.gate.request.?.at -= 1;
+ t.frame();
+ try t.clickText("Allow");
+ t.settle(0.5);
try std.testing.expect(a.hub.policy.allow_whole_screen);
try std.testing.expect(t.hasText("Whole screen"));
call(&a, 31, "screenshot", "{\"whole_screen\":true}");
@@ -135,10 +140,20 @@ test "the switches stay as the user left them: calls and redraws don't flip them
t.settle(0.5);
try std.testing.expect(!a.hub.policy.allow_whole_screen);
- // One click, one flip; off stays off through calls, redraws and the pointer.
+ // A click on the switch only asks: it may have been meant to focus the
+ // window. Allow turns it on, and nobody's waiting to be told.
try t.clickText(whole);
t.settle(0.5);
+ try std.testing.expect(!a.hub.policy.allow_whole_screen);
+ try std.testing.expect(t.hasText("A request from this window"));
+ a.gate.request.?.at -= 1;
+ t.frame();
+ try t.clickText("Allow");
+ t.settle(0.5);
try std.testing.expect(a.hub.policy.allow_whole_screen);
+ try std.testing.expect(!t.hasText("A request from this window"));
+
+ // Off takes one click; off stays off through calls, redraws and the pointer.
try t.clickText(whole);
t.settle(0.5);
try std.testing.expect(!a.hub.policy.allow_whole_screen);
diff --git a/docs/adr/0314-nanocua-is-grafts-computer-use.md b/docs/adr/0314-nanocua-is-grafts-computer-use.md
index 3402e6ef..dd41c5ef 100644
--- a/docs/adr/0314-nanocua-is-grafts-computer-use.md
+++ b/docs/adr/0314-nanocua-is-grafts-computer-use.md
@@ -58,7 +58,9 @@ and a Deny refuses new ones for 15s. nanocua checks that a click came from
hardware, not a program, and only for turning things on: Stop works however it's
clicked. Switch Control and Voice Control post their own clicks, so they can't
turn things on. nanoui's `--nanoui-*` flags are refused outside debug builds,
-since they drive the same window.
+since they drive the same window. The panel's own whole-screen switch asks on the
+same card, because nanoui's windows act on the click that brings them forward, and
+a click meant only to focus the window could otherwise hand over the real pointer.
A process running as the user can still attack this in ways nanocua can't see,
such as editing what the app loads. The check closes the easy route, not every one.