Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ rusqlite = { version = "=0.31.0", features = ["bundled", "hooks"] }
tungstenite = { version = "=0.21.0", default-features = false, features = ["handshake"] }
# Keep the transitive URL parser compatible with the project's Rust 1.75 MSRV.
# Newer url 2.5.x releases pull in edition-2024 IDNA crates.
url = "=2.4.1"
url = { version = "=2.4.1", features = ["serde"] }
# Ratatui's compatible range otherwise resolves to a release requiring Rust 1.85.
unicode-segmentation = "=1.12.0"
vt100 = "=0.15.2"
Expand Down
25 changes: 24 additions & 1 deletion docs/work-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,30 @@ command globally. No BetterAgentView companion app or Hammerspoon is needed.
This example uses **F8** (Fn+F8 on keyboards whose top row controls media).
Choose another binding if you already use it. Press it while a browser or another
app has focus: BetterAgentView switches in the background without typing into that app.
Press it again to switch back. It doesn't hide the other app or its windows.
Press it again to switch back. It leaves other apps and unmanaged browser tabs alone.

If your dashboard uses a custom `XDG_STATE_HOME`, set the same value in the
shortcut's shell command so both use the same saved mode.

## Private HTML artifacts on macOS

An OpenCode shell wrapper can pass local HTML or SVG artifact paths to

betteragentview open-artifact -- /path/to/artifact.html

Use the existing session environment, including `OPENCODE_SESSION_ID`. The command
looks up the originating project, not the artifact's output folder. If the
command prints `work`, continue with the usual open behavior. If it prints
`private`, BetterAgentView handled the open. If it fails, report the error rather
than opening the file in an unmanaged tab. Add `--background` before `--` to avoid
explicitly activating Chrome.

Private artifacts open in their own Chrome windows. Work-only closes only the
tabs BetterAgentView created, and restores them from disk when you return to All
Sessions. An artifact requested during Work-only opens when you switch back. The
page reloads; live page state is not preserved.

macOS may ask for permission to automate Google Chrome. Tabs opened outside the
wrapper, moved to other windows, navigated away, or restored by Chrome after a
restart are not tracked. Existing tabs at the same URL are untouched. This is
a screen presentation feature, not a way to hide browser history or erase files.
30 changes: 30 additions & 0 deletions src/adapters/opencode_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ use rusqlite::{Connection, OpenFlags, OptionalExtension};
use crate::perf;
use crate::process::{CommandOutput, CommandRequest, CommandRunner};

/// Use the originating session's directory, not shell cwd or artifact location.
#[cfg(target_os = "macos")]
pub(crate) fn artifact_session_directory(program: &str, id: &str) -> Result<PathBuf> {
let runner = DirectDbRunner::new(Arc::new(crate::process::ProcessRunner), program.to_owned());
let path = runner
.path()
.ok_or_else(|| anyhow!("OpenCode database not found"))?;
let db = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_ONLY)?;
db.busy_timeout(Duration::from_secs(1))?;
for (table, query) in [
("session_v2", "SELECT directory FROM session_v2 WHERE id=?1"),
("session", "SELECT directory FROM session WHERE id=?1"),
] {
let exists: bool = db.query_row(
"SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name=?1)",
[table],
|row| row.get(0),
)?;
if exists {
if let Some(directory) = db
.query_row(query, [id], |row| row.get::<_, String>(0))
.optional()?
{
return Ok(PathBuf::from(directory));
}
}
}
bail!("originating OpenCode session was not found")
}

pub(super) struct DirectDbRunner {
inner: Arc<dyn CommandRunner>,
program: String,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub mod order;
pub mod paused;
pub mod perf_log;
pub mod pi_supervisor;
#[cfg(target_os = "macos")]
pub mod private_artifacts;
pub mod proc_info;
pub mod process;
pub mod queue;
Expand Down
29 changes: 29 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ enum Commands {
#[arg(value_enum)]
mode: ScopeMode,
},
/// Route a local OpenCode HTML or SVG artifact from a shell open wrapper.
#[cfg(target_os = "macos")]
OpenArtifact {
#[arg(long)]
background: bool,
path: PathBuf,
},
/// Private mobile history sync and queued replies. Disabled until explicitly paired.
Bridge {
#[arg(long, value_name = "PATH")]
Expand Down Expand Up @@ -654,6 +661,16 @@ fn main() -> Result<()> {
match command {
Commands::View { mode } => {
let store = agentview::work_view::WorkViewStore::load_default()?;
#[cfg(target_os = "macos")]
let enabled = agentview::private_artifacts::set_mode(
&store,
match mode {
ScopeMode::Toggle => None,
ScopeMode::Work => Some(true),
ScopeMode::All => Some(false),
},
)?;
#[cfg(not(target_os = "macos"))]
let enabled = match mode {
ScopeMode::Toggle => store.toggle()?,
ScopeMode::Work => {
Expand All @@ -667,6 +684,18 @@ fn main() -> Result<()> {
};
println!("{}", if enabled { "Work only" } else { "All sessions" });
}
#[cfg(target_os = "macos")]
Commands::OpenArtifact { background, path } => {
let session = std::env::var("OPENCODE_SESSION_ID")
.context("open-artifact needs the originating OPENCODE_SESSION_ID")?;
let handled = agentview::private_artifacts::open(
&cli.opencode_bin,
&session,
path,
!background,
)?;
println!("{}", if handled { "private" } else { "work" });
}
Commands::Bridge { state_dir, command } => {
let dir = state_dir
.clone()
Expand Down
67 changes: 67 additions & 0 deletions src/private_artifacts.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use framework "AppKit"
use scripting additions

on launchIdentity()
set instances to current application's NSRunningApplication's runningApplicationsWithBundleIdentifier:"com.google.Chrome"
if (instances's |count|() as integer) is 0 then return ""
if (instances's |count|() as integer) is not 1 then error "More than one Chrome instance is running"
set browserApp to instances's firstObject()
return (browserApp's processIdentifier() as text) & ":" & ((browserApp's launchDate()'s timeIntervalSince1970()) as text)
end launchIdentity

on run argv
set operation to item 1 of argv
set epoch to my launchIdentity()
if operation is "create" then
if epoch is "" then
tell application id "com.google.Chrome" to launch
set epoch to my launchIdentity()
if epoch is "" then error "Chrome did not start"
end if
tell application id "com.google.Chrome"
set ownedWindow to make new window
return epoch & " " & (id of ownedWindow) & " " & (id of active tab of ownedWindow)
end tell
end if
if epoch is "" or epoch is not (item 2 of argv) then return "gone"
set windowKey to item 3 of argv
set tabKey to item 4 of argv
set expectedURL to item 5 of argv
set bringForward to (item 6 of argv) is "yes"
tell application id "com.google.Chrome"
try
set ownedWindow to window id windowKey
if (mode of ownedWindow) is not "normal" then return "gone"
set ownedTab to tab id tabKey of ownedWindow
set actualURL to URL of ownedTab
on error messageText number errorCode
if errorCode is -1728 or errorCode is -1719 then return "gone"
error messageText number errorCode
end try
if epoch is not (my launchIdentity()) then return "gone"
set isEmptyTab to (actualURL is "chrome://newtab/" or actualURL is "about:blank" or actualURL is "")
considering case
set sameURL to actualURL is expectedURL
end considering
if operation is "navigate" or operation is "reload" then
if operation is "reload" and sameURL then
reload ownedTab
else if operation is "navigate" and isEmptyTab then
set URL of ownedTab to expectedURL
else
return "gone"
end if
if bringForward then
if (count of tabs of ownedWindow) is 1 then set index of ownedWindow to 1
activate
end if
else if operation is "close" then
if not sameURL then return "gone"
close ownedTab
if exists (tab id tabKey of window id windowKey) then error "Chrome did not close the private tab"
else
error "Unknown artifact operation"
end if
return "ok"
end tell
end run
Loading
Loading