@octavus/agent 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,6 +47,7 @@ The working directory you launch in is the agent's workspace (override with `--w
47
47
  - `--backup-model <provider/model-id>` - backup model for this run only.
48
48
  - `--capability <slug>=<on|off>` - toggle one capability for this run (repeatable).
49
49
  - `--config <file>` - JSON run config for scripted sweeps (see below).
50
+ - `--benchmark-tools` - enable the opt-in benchmark tools (e.g. `ask_human`) for this run (see below).
50
51
  - `--json` - print one machine-readable JSON result to stdout.
51
52
  - `--force` - allow running with the workspace at `$HOME` or `/`.
52
53
  - `--verbose` - print diagnostics to stderr.
@@ -87,6 +88,12 @@ Precedence: explicit flags > `--config` file > the agent's dashboard defaults. A
87
88
 
88
89
  `--json` prints exactly one JSON object to stdout - `{ "threadId", "sessionId", "status", "threadUrl" }` - with all human/progress output routed to stderr, so a benchmark harness can capture and correlate a run without scraping text. The exit code signals completed (`0`), failed (`1`), or stopped from the dashboard (`4`). Read the full transcript and a per-run cost/usage summary from `GET /api/v1/workforce/agents/{agentId}/threads/{threadId}` with the same agent key.
89
90
 
91
+ ### Benchmark tools
92
+
93
+ `--benchmark-tools` provides an extra, opt-in set of tools for benchmark harnesses that need a capability the agent's normal toolset lacks. It is off by default and never present on a normal run, so it changes nothing unless you pass it.
94
+
95
+ Today it adds one tool, `benchmark__ask_human`, which lets the agent ask the operator driving the run for an input only they can provide (a withheld form field, a business rule, the location of a source file) and receive the answer inline: the call blocks until the harness answers, then returns the answer as the tool result and the run continues. The agent runs inside the machine you control, so the harness answers by reading `benchmark-ask.json` and writing `benchmark-answer.json` in the run's workdir - an internal transport the agent never sees. Enable it only when your harness is set up to answer; otherwise the tool waits briefly and then tells the agent to proceed on its own.
96
+
90
97
  ### Environments
91
98
 
92
99
  `--env <name>` (or `OCTAVUS_ENV`, default `production`) selects an environment. Each keeps its own credentials and browser profile under `~/.octavus/<env>/`, so you can configure and run more than one side by side without them clobbering each other:
@@ -483,9 +483,54 @@ def enumerate_elements(pid=None):
483
483
  # Screenshot capture
484
484
  # ---------------------------------------------------------------------------
485
485
 
486
+ def _screenshot_tool_cmds(output_path):
487
+ """Full-display capture commands tried in order. scrot is the primary (present
488
+ on our images); the rest are fallbacks so a missing or broken scrot degrades
489
+ gracefully instead of blinding the loop. Each writes ``output_path`` directly."""
490
+ return (
491
+ ["scrot", "-o", output_path],
492
+ ["maim", output_path],
493
+ ["import", "-window", "root", output_path],
494
+ ["gnome-screenshot", "-f", output_path],
495
+ )
496
+
497
+
498
+ def _pillow_x11_grab(output_path):
499
+ """Last-resort capture via Pillow's native X11 grab (no external tool). Returns
500
+ True on a non-empty PNG, else False."""
501
+ try:
502
+ from PIL import ImageGrab
503
+
504
+ image = ImageGrab.grab(xdisplay=os.environ.get("DISPLAY") or ":0")
505
+ image.save(output_path, "PNG")
506
+ return os.path.exists(output_path) and os.path.getsize(output_path) > 0
507
+ except Exception:
508
+ return False
509
+
510
+
486
511
  def capture_screenshot(output_path):
487
- """Take a screenshot using scrot (X11)."""
488
- _run(["scrot", "-o", output_path])
512
+ """Take a full-display screenshot (X11).
513
+
514
+ Prefers scrot; falls back to other common capture tools, then Pillow's native
515
+ X11 grab, so a missing or failing scrot (e.g. it was never installed, or crashed
516
+ with a libpng write error on a full disk) degrades gracefully instead of aborting
517
+ the run with "Required command not found: scrot".
518
+ """
519
+ for cmd in _screenshot_tool_cmds(output_path):
520
+ if shutil.which(cmd[0]) is None:
521
+ continue
522
+ try:
523
+ subprocess.run(cmd, capture_output=True, text=True, timeout=20, check=True)
524
+ except (subprocess.CalledProcessError, subprocess.TimeoutExpired, OSError):
525
+ continue
526
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
527
+ return
528
+ if _pillow_x11_grab(output_path):
529
+ return
530
+ exit_with_error(
531
+ "Screenshot failed: no working capture tool. Install one of scrot, maim, "
532
+ "imagemagick (import), or gnome-screenshot."
533
+ )
489
534
 
490
535
 
491
536
  def crop_screenshot(screenshot_path, region):
@@ -853,11 +898,25 @@ def _resolve_from_desktop_files(name):
853
898
  return binaries, desktop_ids
854
899
 
855
900
 
901
+ # WM_CLASS regex fragments for apps whose window title does not match the app name
902
+ # the agent asks to activate - notably Chrome `--app=<url>` windows, whose title is
903
+ # the page's, not "chrome". "chrome" matches the "google-chrome" class; "chromium"
904
+ # is listed explicitly since it does not contain "chrome".
905
+ _WINDOW_CLASS_ALIASES = {
906
+ "chrome": ["chrome", "chromium"],
907
+ "google chrome": ["chrome", "chromium"],
908
+ "google-chrome": ["chrome", "chromium"],
909
+ "chromium": ["chromium", "chrome"],
910
+ "browser": ["chrome", "chromium", "firefox"],
911
+ "firefox": ["firefox"],
912
+ }
913
+
914
+
856
915
  def activate_app(name):
857
- def find_windows(query):
916
+ def find_windows(flag, query):
858
917
  try:
859
918
  r = subprocess.run(
860
- ["xdotool", "search", "--name", query],
919
+ ["xdotool", "search", flag, query],
861
920
  capture_output=True, text=True, timeout=5,
862
921
  )
863
922
  return [wid for wid in r.stdout.strip().split("\n") if wid]
@@ -865,8 +924,14 @@ def activate_app(name):
865
924
  return []
866
925
 
867
926
  def activate_existing_window():
868
- for query in (name, name.lower()):
869
- wids = find_windows(query)
927
+ # Match an already-open window by title (--name) and by window class
928
+ # (--class). A Chrome `--app=<url>` window carries the page title, not the
929
+ # app name, so a title-only search misses it; the class aliases below focus
930
+ # the running browser window instead of launching a second, duplicate one.
931
+ attempts = [("--name", name), ("--name", name.lower())]
932
+ attempts += [("--class", cls) for cls in _WINDOW_CLASS_ALIASES.get(name.lower(), [])]
933
+ for flag, query in attempts:
934
+ wids = find_windows(flag, query)
870
935
  if wids:
871
936
  # No --sync: `windowactivate --sync` blocks until the WM confirms
872
937
  # activation, which never arrives for a borderless/maximized