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
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ in the same turn; on the CLI only a later identical call may consume an
approved record. The trusted CLI or the desktop
approvals window can decide a record; the window shows a request only when core
reproduces its digest, and approval needs a single-use review token.
When a desktop turn starts waiting, Rust shows the approvals window: it comes
to the front only when OMGCode owns the foreground window, and otherwise its
taskbar button flashes without taking focus from another application
([ADR-0105](docs/adr/0105-show-the-approvals-window-when-a-turn-starts-waiting.md)).
`workspace_run_command` then
invokes the trusted runner, and `workspace_edit_file` then calls the
checkpointed apply with the size and digest of a live trusted read
Expand Down
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,63 @@ Changes are recorded here before a release version is assigned.

### Changed

- Version 0.69.0 makes the read-write container grant say what it does
(ADR-0104). In the desktop `settings` window, **Grant a folder** with read
and write no longer opens a folder dialog: core accepts that access only on
the workspace's own directory, so Rust uses the recorded one, and core
still checks that the directory there is the recorded directory. The
button reads **Grant the workspace folder…**, the access options read
**Read and execute a folder you choose** and **Read and write the
workspace's own folder**, and a hint under the selects says what each
does. A read-execute grant still opens the dialog. The grant, revoke, and
toolchain-discovery confirmations, the folder dialog's title, and the
group's help now say that the access goes to the workspace's AppContainer,
the Windows sandbox its commands run in, and that registering a folder
gives it none; the read-write confirmation names the folder once instead
of as both the workspace and the folder. A run refused for a missing grant
now says the workspace's sandbox has no read-write grant on the workspace
folder, and where to grant it. The command's request is unchanged and
carries no path. An operator had read the old confirmation as giving a
folder access to itself. No test applies a real grant, and the native
dialogs were not driven by automation.

- Version 0.69.0 also shows the desktop approvals window as soon as a chat
turn starts waiting for an approval (ADR-0105), instead of only counting
it in the `main` window. Core's `ApprovalWaitSlot` can carry a `WaitObserver`
that the turn calls on its own thread, with no lock held, each time it
publishes the call it waits on; the observer receives nothing and decides
nothing. `DesktopService::set_approval_wait_observer` holds one, each turn
copies it when it starts, the turn table keeps only an
`ApprovalWaitSlot::reader` without it, and `DesktopService::shutdown`
drops it. The shell registers an observer at startup that posts one
closure to the event loop, which checks the foreground and acts in the
same callback. When OMGCode owns the foreground window, read on Windows
with `GetForegroundWindow` and `GetWindowThreadProcessId` in a new
`omgcode-platform` function (`foreground::this_process_owns_foreground`),
the approvals window is unminimized, shown, and activated with
`SetForegroundWindow` alone (`foreground::activate_if_foreground_owner`),
never tao's `set_focus`. Otherwise, or if Windows refuses, it is shown
and its taskbar button flashes, and the foreground is not taken, because
on Windows that sends the other application a simulated key press. No
command, event, or capability is added, and the approvals window still
never focuses **Approve**, decides on no key, and arms **Approve** one
second after a review renders. The approvals window also lists again
when it gains focus, so a request that brought it forward appears without
waiting up to 3 seconds for the next poll; a new request still never
replaces the one under review. An approval recorded by a CLI turn still
shows only in the count. The `settings` and `approvals` show commands now share one helper
and behave as before; the operator saw the settings window open in front
every time in their latest testing, and no cause of an earlier, occasional
open behind `main` was found. `omgcode-desktop` now depends on the
workspace crate `omgcode-platform`. Tests cover the observer and its
reader, a real desktop turn telling it once while still waiting for a
decision, shutdown dropping it with and without a finished turn, the
activation refusing a handle that is not this process's window, and the
focus refresh keeping the review; which window ends
up in front, the taskbar flash, and whether WebView2 delivers the focus
event were not driven by automation. The approvals tests now dispose a
window before starting another in the same test.

- Version 0.61.0 restyles the desktop windows in the OMG Software
outlined-toggle palette (ADR-0095). The theme uses neutral greys around
charcoal `#151515`, switch orange `#ff761f` as the accent, and charcoal
Expand Down
11 changes: 6 additions & 5 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 @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/omgcode-core", "crates/omgcode-cli", "crates/omgcode-platform", "crates/omgcode-app", "crates/omgcode-desktop"]

[workspace.package]
version = "0.68.0"
version = "0.69.0"
edition = "2024"
rust-version = "1.99.1"
license = "Apache-2.0"
Expand Down
16 changes: 15 additions & 1 deletion crates/omgcode-app/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@
//! | `reviews` | outstanding single-use approval review tokens |
//! | `events` | the one chat event subscriber and the running turns' previews |
//! | `pending_cache` | an atomic copy of the last pending-approval count read |
//! | `approval_wait_observer` | the shell's one approval-wait observer (ADR-0105) |
//! | `session_choices` | the read-modify-write of `session-connections.json` (ADR-0071) |
//!
//! **Lock order** when two are ever needed: `turns`, then `index`, then
//! `reviews`. The code takes one at a time. The `events` lock is never held
//! together with the `turns` lock (where both are needed, `turns` is taken and
//! released first) and never while `index` or `reviews` is taken. It is held
//! while a subscriber sink runs, so a sink must not block or call the service
//! (see [`ChatEventSink`]). No service lock and no open
//! (see [`ChatEventSink`]). The `approval_wait_observer` lock is held only to
//! clone or replace the observer, with no other lock, and never while the
//! observer runs. No service lock and no open
//! control store is held across provider I/O, a chat turn, a journal
//! inspection, a thread join, or a sleep. The one deliberate exception is the
//! `index` lock during a refresh: a refresh needs `&mut SessionIndex`, so it
Expand Down Expand Up @@ -320,6 +323,16 @@ struct Inner {
/// The last pending-approval count read, served when the settings store is
/// busy. Advisory only; it authorizes nothing.
pending_cache: AtomicU64,
/// Called on a turn's thread each time the turn starts waiting for an
/// approval decision, so the shell can show its approvals window
/// (ADR-0105). It decides nothing. Each turn copies the observer when it
/// starts. Owners: this field and the threads of turns started while it
/// was set; the turn table keeps only a reader of each slot, without the
/// observer, because it keeps finished slots. A shell observer may own a
/// handle that reaches this service, which is a cycle;
/// [`DesktopService::shutdown`] clears the field to end it, and a turn
/// that outlives shutdown keeps its copy until its thread ends.
approval_wait_observer: Mutex<Option<omgcode_core::turn::WaitObserver>>,
/// Set while one settings change waits for the operator or applies, so
/// a second change is refused rather than opening a second dialog.
settings_change: AtomicBool,
Expand Down Expand Up @@ -391,6 +404,7 @@ impl DesktopService {
reviews: Mutex::new(ReviewTokens::default()),
events: Mutex::new(EventHub::default()),
pending_cache: AtomicU64::new(0),
approval_wait_observer: Mutex::new(None),
settings_change: AtomicBool::new(false),
settings_scope: Mutex::new(None),
session_choices: Mutex::new(()),
Expand Down
58 changes: 53 additions & 5 deletions crates/omgcode-app/src/desktop/chat.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Chat commands: defaults, model list, send, status, cancel, and shutdown.

use std::sync::PoisonError;
use std::time::Duration;

use omgcode_core::session_index::IndexedState;
use uuid::Uuid;

use omgcode_core::skills::{MAX_SELECTED_SKILLS, SkillName};
use omgcode_core::turn::ApprovalWaitSlot;
use omgcode_core::turn::{ApprovalWaitSlot, WaitObserver};

use super::ChatEventSink;
use super::error::DesktopError;
Expand Down Expand Up @@ -281,7 +282,14 @@ impl DesktopService {
let clients = ChatClients::for_connection(&settings, &connection)
.map_err(|error| DesktopError::from_app(&error))?;
let token = connection.token;
let approval_wait = ApprovalWaitSlot::new();
let approval_wait = match inner.current_approval_wait_observer()? {
Some(observer) => ApprovalWaitSlot::new().with_observer(observer),
None => ApprovalWaitSlot::new(),
};
// The table keeps finished slots, so it holds a reader: only the turn
// thread's copy keeps the observer, which shutdown must be able to
// release (ADR-0105).
let awaited = approval_wait.reader();
let job = TurnJob {
session_id,
path,
Expand All @@ -290,7 +298,7 @@ impl DesktopService {
token,
clients,
skills,
approval_wait: approval_wait.clone(),
approval_wait,
};

// Reserve the slot and start the thread under one lock hold, so two
Expand All @@ -307,7 +315,7 @@ impl DesktopService {
return Err(DesktopError::too_many_turns());
}
let handle = spawn_turn(inner, job)?;
turns.insert_running(session_id, handle, approval_wait);
turns.insert_running(session_id, handle, awaited);
drop(turns);
Ok(status_of(
session_id,
Expand Down Expand Up @@ -376,6 +384,25 @@ impl DesktopService {
Ok(())
}

/// Register the one approval-wait observer, replacing any earlier one
/// (ADR-0105). Turns started afterwards call it on their own thread each
/// time they start waiting for an approval decision; a turn already
/// running keeps the observer it started with. The observer must return
/// promptly, must not panic, and must not call this service. It is told
/// only that a wait began and can approve nothing.
///
/// # Errors
///
/// `internal` when the service state is unavailable.
pub fn set_approval_wait_observer(&self, observer: WaitObserver) -> Result<(), DesktopError> {
*self
.inner
.approval_wait_observer
.lock()
.map_err(|_| DesktopError::poisoned())? = Some(observer);
Ok(())
}

/// Request cancellation of every running turn and wait up to `grace` for
/// the turn threads to finish, polling for completion.
///
Expand All @@ -388,7 +415,16 @@ impl DesktopService {
/// close later with the interrupt command. After shutdown, `chat_send` is
/// refused.
pub fn shutdown(&self, grace: Duration) -> ShutdownReport {
self.inner.shutdown_turns(grace)
let report = self.inner.shutdown_turns(grace);
// No turn starts after shutdown, so the observer is no longer needed.
// Dropping it ends the cycle a shell observer may form with this
// service. A poisoned lock is recovered: the value is a whole `Option`.
self.inner
.approval_wait_observer
.lock()
.unwrap_or_else(PoisonError::into_inner)
.take();
report
}

fn read_status(&self, session_id: Uuid) -> Result<ChatStatus, DesktopError> {
Expand Down Expand Up @@ -478,3 +514,15 @@ fn status_of(session_id: Uuid, state: Option<&SlotState>) -> ChatStatus {
error,
}
}

impl Inner {
/// A copy of the registered approval-wait observer, if any (ADR-0105).
/// The lock is held only to clone it.
fn current_approval_wait_observer(&self) -> Result<Option<WaitObserver>, DesktopError> {
Ok(self
.approval_wait_observer
.lock()
.map_err(|_| DesktopError::poisoned())?
.clone())
}
}
12 changes: 10 additions & 2 deletions crates/omgcode-app/src/desktop/settings_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ pub enum FolderPurpose {
ToolchainRoot,
/// A `PATH` entry of a toolchain profile, inside one of its roots.
ToolchainPathEntry,
/// A folder to grant to a workspace's container.
/// A folder to grant read and execute to a workspace's container. A
/// read-write grant opens no dialog (ADR-0104).
ContainerGrant,
}

Expand All @@ -97,7 +98,9 @@ impl FolderPurpose {
Self::Skill => "Choose a skill folder",
Self::ToolchainRoot => "Choose a read-only root for the toolchain profile",
Self::ToolchainPathEntry => "Choose a PATH entry inside a root of the profile",
Self::ContainerGrant => "Choose a folder to grant to the workspace's container",
// The access goes to the workspace's AppContainer, not to the
// operator or the folder (ADR-0104).
Self::ContainerGrant => "Choose a folder the workspace's sandbox may read and execute",
}
}
}
Expand Down Expand Up @@ -1534,5 +1537,10 @@ mod tests {
FolderPurpose::PackageCache.title(),
"Choose a package cache folder"
);
// The grant dialog names who receives the access (ADR-0104).
assert_eq!(
FolderPurpose::ContainerGrant.title(),
"Choose a folder the workspace's sandbox may read and execute"
);
}
}
2 changes: 1 addition & 1 deletion crates/omgcode-app/src/desktop/settings_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ fn grants_confirmation(
Confirmation {
title: "Grant toolchain folders to a workspace",
message: format!(
"Give the workspace\n{workspace}\nread and execute access to these folders?\n{}\n\nThis changes each folder's access-control list on disk for that workspace's AppContainer, and each grant stays until you revoke it. Runs in the workspace can then read and execute everything beneath them.{skipped}",
"Let the commands OMGCode runs for the workspace\n{workspace}\nread and execute these folders and everything beneath them?\n{}\n\nThis adds the workspace's AppContainer, the Windows sandbox its commands run in, to each folder's access-control list on disk, and each grant stays until you revoke it.{skipped}",
list(folders)
),
}
Expand Down
Loading