Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
87d3463
refactor(task): split controller into focused submodules
senamakel Oct 21, 2026
44acaee
feat(task): add task controller module
senamakel Oct 21, 2026
3ebd5c8
refactor(task): use absolute paths for task module imports
senamakel Oct 21, 2026
607314b
refactor(task): split persistence into a module
senamakel Oct 21, 2026
4e3fdd8
style(task): remove stray blank lines and brace
senamakel Oct 21, 2026
e7e4258
refactor(task): widen persistence visibility for reuse
senamakel Oct 21, 2026
56e25cc
refactor(task): move snapshot type imports into persistence types
senamakel Oct 21, 2026
8363704
chore(task): tidy persistence imports
senamakel Oct 21, 2026
f5ff4f6
refactor(task): narrow persistence type visibility
senamakel Oct 21, 2026
8c6bb63
refactor(task): split task drive module into submodules
senamakel Oct 21, 2026
36fcbd9
docs(task): move run budget doc comment to run module
senamakel Oct 21, 2026
c868a7b
style(task): reformat drive module and relocate finish doc comment
senamakel Oct 21, 2026
c4b755b
refactor(task): widen drive visibility to the task module
senamakel Oct 21, 2026
03e5d09
refactor(task): widen written_names visibility for reuse
senamakel Oct 21, 2026
5a57e17
refactor(browser): split browser runner into a module
senamakel Oct 21, 2026
692fc90
test(browser): move redaction tests module to browser mod
senamakel Oct 21, 2026
b89989e
fix(browser): restrict redaction helpers to module scope
senamakel Oct 21, 2026
f13fa3f
refactor(task): replace glob imports with explicit imports
senamakel Oct 21, 2026
fabb829
refactor(task): replace glob imports with explicit ones
senamakel Oct 21, 2026
a26413d
refactor(task): tidy controller imports
senamakel Oct 21, 2026
8703698
refactor(task): flatten drive and persistence module imports
senamakel Oct 21, 2026
673a694
refactor(task): import shared types from their defining modules
senamakel Oct 21, 2026
267f5f2
refactor(task): split handoff logic into submodules
senamakel Oct 21, 2026
0fd2b95
docs(handoff): document plan_handoff and tidy imports
senamakel Oct 21, 2026
0710522
refactor(handoff): move planning debit into planner module
senamakel Oct 21, 2026
6a2faff
refactor(handoff): widen draft_handoff visibility to the handoff module
senamakel Oct 21, 2026
67260d2
refactor(browser): move secret redacting surface into mod.rs
senamakel Oct 21, 2026
34dd5a6
refactor(browser): update imports for jev operation and surface types
senamakel Oct 21, 2026
eb5aedb
test(browser): cover secret redacting surface delegation
senamakel Oct 21, 2026
a7ba200
test(browser): simplify redaction test browser setup
senamakel Oct 21, 2026
cc8edac
test(browser): expect observe to succeed in redaction test
senamakel Oct 21, 2026
73497b8
test(browser): relax await_change assertion in redaction test
senamakel Oct 21, 2026
5e1f375
test(browser): return result from redaction surface test
senamakel Oct 21, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,105 @@ use tinycomputer_bus::{DesktopError, DesktopResponse, JevOperation, RunFlowReque
use tinycomputer_core::surface::{Candidate, Depth, Screen, Surface};

use super::{CaptureFuture, FlowFuture, FlowRunner, PrepareFuture, TextFuture};

mod redaction;
use crate::SecretHost;
use crate::{JevRuntime, UsageRecorder};
use redaction::{redact_observation_error, redact_response, redact_screen};

/// Keeps known host-held values out of every model-facing screen and browser
/// reply while delegating live reads and actions to the underlying surface.
/// Editable field values are removed structurally by
/// `BrowserSurface::without_form_values`; this layer also scrubs page text,
/// labels, non-form values, and error output using the host's intent-scoped
/// redactor.
#[derive(Clone)]
pub(super) struct SecretRedactingSurface {
pub(super) inner: BrowserSurface,
pub(super) host: Arc<dyn SecretHost>,
pub(super) task_id: String,
}

impl SecretRedactingSurface {
pub(super) fn redact_screen(&self, screen: &mut Screen) {
redact_screen(&*self.host, &self.task_id, screen);
}

pub(super) fn redact_response(&self, response: DesktopResponse) -> DesktopResponse {
redact_response(&*self.host, &self.task_id, response)
}
}

impl Surface for SecretRedactingSurface {
fn observe(
&self,
app: &str,
root: Option<&str>,
depth: Depth,
) -> Result<Screen, Box<DesktopResponse>> {
let mut screen = match self.inner.observe(app, root, depth) {
Ok(screen) => screen,
Err(error) => {
return Err(redact_observation_error(&*self.host, &self.task_id, error));
}
};
self.redact_screen(&mut screen);
Ok(screen)
}

fn execute(
&self,
operation: JevOperation,
target: Option<Candidate>,
text: Option<String>,
) -> DesktopResponse {
self.redact_response(self.inner.execute(operation, target, text))
}

fn authorize_secret_type(&self, target: &Candidate) -> Result<String, String> {
self.inner.authorize_secret_type(target)
}

fn read_value(&self, target: &Candidate) -> Option<String> {
self.inner.read_value(target)
}

fn paste(&self, app: &str, target: &Candidate, text: &str) -> DesktopResponse {
self.redact_response(self.inner.paste(app, target, text))
}

fn press(&self, app: &str, combo: &str) -> DesktopResponse {
self.redact_response(self.inner.press(app, combo))
}

fn launch(&self, app: &str) -> DesktopResponse {
self.redact_response(self.inner.launch(app))
}

fn settle(&self) {
self.inner.settle();
}

fn settle_briefly(&self) {
self.inner.settle_briefly();
}

fn await_change(&self, ms: u64) -> bool {
self.inner.await_change(ms)
}

fn navigate(&self, url: &str) -> DesktopResponse {
self.redact_response(self.inner.navigate(url))
}

fn back(&self, app: &str) -> DesktopResponse {
self.redact_response(self.inner.back(app))
}

fn dismiss_cover(&self, target: &Candidate) -> DesktopResponse {
self.redact_response(self.inner.dismiss_cover(target))
}
}

/// Runs task flows directly on one in-process browser surface per task.
///
Expand Down Expand Up @@ -332,210 +429,6 @@ impl BrowserRunner {
}
}

/// Keeps known host-held values out of every model-facing screen and browser
/// reply while delegating live reads and actions to the underlying surface.
/// Editable field values are removed structurally by
/// `BrowserSurface::without_form_values`; this layer also scrubs page text,
/// labels, non-form values, and error output using the host's intent-scoped
/// redactor.
#[derive(Clone)]
struct SecretRedactingSurface {
inner: BrowserSurface,
host: Arc<dyn SecretHost>,
task_id: String,
}

impl SecretRedactingSurface {
fn redact_screen(&self, screen: &mut Screen) {
redact_screen(&*self.host, &self.task_id, screen);
}

fn redact_response(&self, response: DesktopResponse) -> DesktopResponse {
redact_response(&*self.host, &self.task_id, response)
}
}

impl Surface for SecretRedactingSurface {
fn observe(
&self,
app: &str,
root: Option<&str>,
depth: Depth,
) -> Result<Screen, Box<DesktopResponse>> {
let mut screen = match self.inner.observe(app, root, depth) {
Ok(screen) => screen,
Err(error) => {
return Err(redact_observation_error(&*self.host, &self.task_id, error));
}
};
self.redact_screen(&mut screen);
Ok(screen)
}

fn execute(
&self,
operation: JevOperation,
target: Option<Candidate>,
text: Option<String>,
) -> DesktopResponse {
self.redact_response(self.inner.execute(operation, target, text))
}

fn authorize_secret_type(&self, target: &Candidate) -> Result<String, String> {
self.inner.authorize_secret_type(target)
}

fn read_value(&self, target: &Candidate) -> Option<String> {
self.inner.read_value(target)
}

fn paste(&self, app: &str, target: &Candidate, text: &str) -> DesktopResponse {
self.redact_response(self.inner.paste(app, target, text))
}

fn press(&self, app: &str, combo: &str) -> DesktopResponse {
self.redact_response(self.inner.press(app, combo))
}

fn launch(&self, app: &str) -> DesktopResponse {
self.redact_response(self.inner.launch(app))
}

fn settle(&self) {
self.inner.settle();
}

fn settle_briefly(&self) {
self.inner.settle_briefly();
}

fn await_change(&self, ms: u64) -> bool {
self.inner.await_change(ms)
}

fn navigate(&self, url: &str) -> DesktopResponse {
self.redact_response(self.inner.navigate(url))
}

fn back(&self, app: &str) -> DesktopResponse {
self.redact_response(self.inner.back(app))
}

fn dismiss_cover(&self, target: &Candidate) -> DesktopResponse {
self.redact_response(self.inner.dismiss_cover(target))
}
}

fn redact_observation_error(
host: &dyn SecretHost,
task_id: &str,
response: Box<DesktopResponse>,
) -> Box<DesktopResponse> {
Box::new(redact_response(host, task_id, *response))
}

fn redact_response(
host: &dyn SecretHost,
task_id: &str,
response: DesktopResponse,
) -> DesktopResponse {
let redact = |text: &str| host.redact(task_id, text);
let Ok(mut value) = serde_json::to_value(response) else {
return redaction_failed_response();
};

// These fields can be used to address or replay an operation. Rewriting
// them into a placeholder would make an apparently valid response point
// at a different target, so fail closed on a collision.
if operational_collision(&value, &redact) {
return redaction_failed_response();
}
super::redact_value(&mut value, &redact);
serde_json::from_value(value).unwrap_or_else(|_| redaction_failed_response())
}

fn operational_collision(value: &serde_json::Value, redact: &impl Fn(&str) -> String) -> bool {
match value {
serde_json::Value::Object(fields) => fields.iter().any(|(key, value)| {
let operational = matches!(
key.as_str(),
"command" | "code" | "ref" | "ref_id" | "target" | "action" | "available_actions"
);
(operational && value.as_str().is_some_and(|text| redact(text) != text))
|| operational_collision(value, redact)
}),
serde_json::Value::Array(items) => {
items.iter().any(|item| operational_collision(item, redact))
}
_ => false,
}
}

fn redaction_failed_response() -> DesktopResponse {
DesktopResponse::err(
"redaction",
DesktopError::new(
"REDACTION_FAILED",
"the browser response could not be safely redacted",
),
)
}

fn redact_screen(host: &dyn SecretHost, task_id: &str, screen: &mut Screen) {
fn candidate(host: &dyn SecretHost, task_id: &str, node: &mut Candidate) -> bool {
let redact = |text: &str| host.redact(task_id, text);
let reference = redact(&node.ref_id);
let role = redact(&node.role);
// Refs and actions are executable metadata. If redaction finds a
// collision, omit the candidate instead of manufacturing an invalid
// target that could address a different control.
if reference != node.ref_id || role != node.role {
return false;
}
node.available_actions
.retain(|action| redact(action) == *action);
node.name = node.name.take().map(|text| redact(&text));
node.description = node.description.take().map(|text| redact(&text));
node.states.retain(|state| redact(state) == *state);
for path in &mut node.path {
*path = redact(path);
}
if let Some(value) = &mut node.value {
super::redact_value(value, &redact);
}
if let Some(bounds) = &mut node.bounds {
let original = bounds.clone();
super::redact_value(bounds, &redact);
if *bounds != original {
node.bounds = None;
}
}
node.children
.retain_mut(|child| candidate(host, task_id, child));
true
}
let redact = |text: &str| host.redact(task_id, text);
screen.app = redact(&screen.app);
screen.window = screen.window.take().map(|text| redact(&text));
screen.surface = redact(&screen.surface);
for text in &mut screen.context {
*text = redact(text);
}
screen
.unexplored
.retain(|reference| redact(reference) == *reference);
screen
.candidates
.retain_mut(|node| candidate(host, task_id, node));
screen
.text_nodes
.retain_mut(|node| candidate(host, task_id, node));
}

#[cfg(test)]
#[path = "browser_redaction_tests.rs"]
mod redaction_tests;

async fn tinycomputer_engine_flow(
surface: impl Surface + Sync,
runtime: JevRuntime,
Expand All @@ -546,5 +439,9 @@ async fn tinycomputer_engine_flow(
}

#[cfg(test)]
#[path = "browser_tests.rs"]
#[path = "../browser_redaction_tests.rs"]
mod redaction_tests;

#[cfg(test)]
#[path = "../browser_tests.rs"]
mod browser_tests;
Loading
Loading