Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions apps/computer/local-daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1093,21 +1093,27 @@ Agent reads the window again first. Windows Operations get `WindowsToolGuide`.

Linux controls the signed-in user's X11 desktop. The driver `local_linux.py` is
embedded in the Go binary; it reads windows through AT-SPI and sends input with
`xdotool`. The host needs `python3-pyatspi`, `xdotool`, ImageMagick, `xclip` and a
user systemd manager. The Daemon must run as the desktop user and inherit
`xdotool`. The host needs `python3-pyatspi`, `xdotool`, ImageMagick and `xclip`;
a reachable user systemd manager is used when available, with detached session
fallback otherwise. The Daemon must run as the desktop user and inherit
`DISPLAY`, `XAUTHORITY`, `DBUS_SESSION_BUS_ADDRESS` and `XDG_SESSION_TYPE`. With a
missing dependency or under Wayland, `check_permissions` explains why; browser and
file tools still work.

`open_application` and `open_url` start the program through `systemd-run --user`
with `KillMode=process`, so it outlives the tool call. `xdg-open` hands a URL to
`gio`, which exits as soon as it started the browser; the default control-group
mode would kill the browser with it. `open_url` then waits up to 8 seconds for
the active window or its title to change, and fails when neither does. After
any input, a page that is still loading is read again until it loads, for at
most 8 seconds; the result marks `loading` when it has not. A desktop with no
active window, as right after a GNOME login, still launches: any window that
appears counts as opened.
`open_application` and `open_url` launch the program in its own session inside a
transient user scope (`systemd-run --user --scope` under `app.slice`) when
`org.freedesktop.systemd1` is reachable on the user session bus, or directly
detached otherwise, so launched apps outlive the tool call and Snap apps can
create their own tracking scope without `.service` cgroup rejections. The driver
observes startup briefly and surfaces immediate non-zero exits (with stderr from
the user journal stream, or an unlinked temporary file fallback) as confirmed
errors without waiting 8 seconds or blocking the action record. Otherwise
`open_url` waits up to 8 seconds for the active window or its title to change,
failing with any post-exit launch stderr when neither does. After any input, a
page that is still loading is read again until it loads, for at most 8 seconds;
the result marks `loading` when it has not. A desktop with no active window, as
right after a GNOME login, still launches: any window that appears counts as
opened.

`type_text` pastes the text. A terminal emulator gets it on both the clipboard
and the primary selection and receives `shift+Insert`, which every common
Expand Down
49 changes: 37 additions & 12 deletions apps/computer/local-daemon/internal/linger/localtools/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ func (op *operation) linuxComputerCall(ctx context.Context, name string, args js
report := map[string]any{}
if err = op.perform(lease, action); err == nil {
output, state = observe(lease, shot, action.opens(), window, report)
if action.command == "open" && report["window_opened"] == false {
delete(report, "window_opened")
err = errURLNotOpened
if action.opens() && report["window_opened"] == false {
err = launchFailure(lease, action, report)
}
} else if !errors.Is(err, errOutcomeUnknown) {
state = readWindowState(lease)
Expand Down Expand Up @@ -232,10 +231,12 @@ func (op *operation) runActions(ctx context.Context, args json.RawMessage) (json
stopped = fmt.Sprintf("waiting after step %d failed (%v); observe before continuing", done, waitErr)
break
}
if !opened && action.command == "open" {
done--
err = errURLNotOpened
break
if !opened && action.opens() {
if launchErr := launchFailure(lease, action, nil); launchErr != nil {
done--
err = launchErr
break
}
}
current, activeErr := lease.Action("active-window")
if activeErr != nil {
Expand Down Expand Up @@ -277,11 +278,12 @@ func (op *operation) runActions(ctx context.Context, args json.RawMessage) (json
} else if done > 0 && !errors.Is(err, errOutcomeUnknown) {
launched := err == nil && done == len(actions) && actions[done-1].opens()
output, state = observe(lease, shot, launched, mark, report)
if launched && actions[done-1].command == "open" && report["window_opened"] == false {
delete(report, "window_opened")
done--
report["completed_steps"] = done
err = errURLNotOpened
if launched && report["window_opened"] == false {
if launchErr := launchFailure(lease, actions[done-1], report); launchErr != nil {
done--
report["completed_steps"] = done
err = launchErr
}
}
} else if !errors.Is(err, errOutcomeUnknown) {
state = readWindowState(lease)
Expand Down Expand Up @@ -581,6 +583,29 @@ var (
// ran, so the input is known, but no window or title changed.
var errURLNotOpened = errors.New("the URL did not open: no window or tab title changed within 8 s; observe before trying again")

// launchFailure inspects any post-launch error recorded by the driver when a
// launch did not produce a window or title change within launchWait.
func launchFailure(lease *localLinuxLease, action desktopAction, report map[string]any) error {
raw, _ := lease.Action("launch-error", action.command)
detail := string(bytes.TrimSpace(raw))
if action.command == "open" {
if report != nil {
delete(report, "window_opened")
}
if detail != "" {
return fmt.Errorf("%w: %s", errURLNotOpened, detail)
}
return errURLNotOpened
}
if detail != "" {
if report != nil {
delete(report, "window_opened")
}
return errors.New(detail)
}
return nil
}

// opens reports an action that should bring up a window or tab, so its
// result waits for one instead of a fixed pause.
func (a desktopAction) opens() bool { return a.command == "run" || a.command == "open" }
Expand Down
Loading