Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
aa9a2ea
feat(engine): expose task-scoped usage recorder
senamakel Oct 20, 2026
0611c2a
feat(engine): export browser-only task runner
senamakel Oct 20, 2026
6665f12
Merge remote-tracking branch 'origin/epic-202-u4-models' into epic-20…
senamakel Oct 20, 2026
1f8df05
feat(tinycomputer-browser): add host action gate
senamakel Oct 20, 2026
21616b2
Merge remote-tracking branch 'origin/epic-202-u2-gate' into epic-202-…
senamakel Oct 20, 2026
c491537
feat(engine): add browser-only task runner
senamakel Oct 20, 2026
f3b8b53
test(engine): verify browser-only task flow and refusal recovery
senamakel Oct 20, 2026
786dea6
docs(engine): document in-process browser task runtime
senamakel Oct 20, 2026
2e0afd5
feat(engine): accept host model routes and tally usage
senamakel Oct 20, 2026
07fdc99
chore(tinycomputer): refresh audited dependencies
senamakel Oct 20, 2026
10623ae
Merge branch 'epic-202-u1-runtime' of https://github.com/tinyhumansai…
senamakel Oct 20, 2026
270da13
chore(deps): pin merged TinyInference usage support
senamakel Oct 20, 2026
9f979b4
fix(tinycomputer-browser): tighten action gate context
senamakel Oct 20, 2026
af86833
Merge remote-tracking branch 'origin/epic-202-u2-gate' into epic-202-…
senamakel Oct 20, 2026
614b8a3
Merge remote-tracking branch 'origin/epic-202-u2-gate' into epic-202-…
senamakel Oct 20, 2026
222e2c5
test(engine): cover BrowserRunner and usage wire contract
senamakel Oct 20, 2026
38f63f1
feat(engine): add SecretHost handle API
senamakel Oct 20, 2026
db16676
Merge remote-tracking branch 'origin/epic-202-u1-runtime' into epic-2…
senamakel Oct 20, 2026
70636b1
Merge commit '222e2c526ae736182b1f3912190f06608e4c5e5e' into epic-202…
senamakel Oct 20, 2026
3b0aaf4
fix(tests): use is_ok_and for runner gate context
senamakel Oct 20, 2026
1e68b88
test(engine): update flow run constructor
senamakel Oct 20, 2026
5ad0f6e
Merge remote-tracking branch 'origin/epic-202-u1-runtime' into epic-2…
senamakel Oct 20, 2026
52dfe40
Merge remote-tracking branch 'origin/epic-202-u3-secret-host' into ep…
senamakel Oct 20, 2026
5f96b3b
Merge remote-tracking branch 'origin/epic-202-u1-runtime' into epic-2…
senamakel Oct 20, 2026
45508b9
Merge remote-tracking branch 'origin/epic-202-u1-runtime' into epic-2…
senamakel Oct 20, 2026
91b4b6b
feat(engine): type host-held secret facts
senamakel Oct 20, 2026
c6549ea
Merge remote-tracking branch 'origin/epic-202-u3-secret-host' into ep…
senamakel Oct 20, 2026
d93e258
feat(engine): add host secret redaction hook
senamakel Oct 20, 2026
4135761
fix(engine): include warmups and retries in usage
senamakel Oct 20, 2026
12cee01
feat(bus): version host secret handles
senamakel Oct 20, 2026
32cf63f
feat(engine): add host secret redaction hook
senamakel Oct 20, 2026
7a0e2a2
Merge remote-tracking branch 'origin/epic-202-u3-secret-host' into ep…
senamakel Oct 20, 2026
5e127b0
feat(engine): persist resumable paused tasks
senamakel Oct 20, 2026
ecea6c3
Merge remote-tracking branch 'origin/epic-202-u4-models' into epic-20…
senamakel Oct 20, 2026
8d39f86
test(engine): include host handles in Describe schema
senamakel Oct 20, 2026
1946ffa
Merge remote-tracking branch 'origin/epic-202-u3-secret-host' into ep…
senamakel Oct 20, 2026
bf02639
test(engine): cover paused task id safety
senamakel Oct 20, 2026
3708ff6
docs(examples): backtick TinyBus in runner example
senamakel Oct 20, 2026
28d5621
Merge remote-tracking branch 'origin/epic-202-u1-runtime' into epic-2…
senamakel Oct 20, 2026
bc0f8ea
Merge pull request #121 from tinyhumansai/epic-202-u2-gate
senamakel Oct 20, 2026
9d447bf
fix(engine): redact host secrets across task outputs
senamakel Oct 20, 2026
eb4ee88
Merge pull request #123 from tinyhumansai/epic-202-u4-models
senamakel Oct 20, 2026
02a2cda
Merge pull request #124 from tinyhumansai/epic-202-u5-persistence
senamakel Oct 20, 2026
ac779fe
Merge remote-tracking branch 'origin/epic-202-u4-models' into epic-20…
senamakel Oct 20, 2026
5b840bd
test: pin contract 2.21 and gate test mutex
senamakel Oct 20, 2026
3563c5f
Merge pull request #122 from tinyhumansai/epic-202-u1-runtime
senamakel Oct 20, 2026
412f314
test(bus): pin host handle contract version
senamakel Oct 20, 2026
deba725
merge: integrate latest tinycomputer epic base
senamakel Oct 20, 2026
9679362
Merge remote-tracking branch 'origin/epic/202-tinycomputer' into epic…
senamakel Oct 20, 2026
93e4e6d
test(engine): cover secret host debug redaction
senamakel Oct 20, 2026
8bac63b
Merge pull request #125 from tinyhumansai/epic-202-u3-secret-host
senamakel Oct 20, 2026
debf17f
chore(tinycomputer): pin audited agent-browser dependencies
senamakel Oct 20, 2026
bf00176
Merge pull request #126 from tinyhumansai/epic-202-u2-gate
senamakel Oct 20, 2026
228bdc2
Merge remote-tracking branch 'origin/epic/202-tinycomputer' into epic…
senamakel Oct 20, 2026
4f972d2
Merge pull request #127 from tinyhumansai/epic-202-u4-models
senamakel Oct 20, 2026
c9fe051
chore: pin TinyInference 0.4.2
senamakel Oct 20, 2026
8abe5ce
Merge pull request #128 from tinyhumansai/epic-202-inference-version
senamakel Oct 20, 2026
1566d39
fix(browser): gate page observations
senamakel Oct 20, 2026
ff856d6
Merge pull request #129 from tinyhumansai/epic-202-observation-gate
senamakel Oct 20, 2026
6b781fe
fix(browser): await confirmed session closes
senamakel Oct 20, 2026
d9eb61a
Merge pull request #130 from tinyhumansai/epic-202-h3-driver
senamakel Oct 20, 2026
ddd6a6e
fix(browser): refuse operations after failed close
senamakel Oct 20, 2026
136790a
Merge pull request #131 from tinyhumansai/epic-202-h3-driver
senamakel Oct 20, 2026
c2d3e73
feat(engine): accept host handles on task continuation
senamakel Oct 21, 2026
4753117
fix(engine): await cancelled task cleanup
senamakel Oct 21, 2026
97305a0
feat(engine): expose task browser session id
senamakel Oct 21, 2026
eeef0ee
Merge pull request #132 from tinyhumansai/epic-202-h3-driver
senamakel Oct 21, 2026
d910c6f
Merge branch 'epic/202-tinycomputer' of github.com:tinyhumansai/tinyc…
senamakel Oct 21, 2026
f74f2fa
Merge pull request #133 from tinyhumansai/h3d-continuation-handles
senamakel Oct 21, 2026
697b42f
feat(engine): add host-authorized payment continuation
senamakel Oct 21, 2026
bac42cc
Merge pull request #134 from tinyhumansai/epic-202-tinycomputer-h3c-p…
senamakel Oct 21, 2026
5994bfb
fix(engine): reuse payment task session on continuation
senamakel Oct 21, 2026
67bff3e
Merge pull request #135 from tinyhumansai/epic-202-tinycomputer-payme…
senamakel Oct 21, 2026
9d7354b
feat(tinycomputer-engine): add bounded host recovery hook
senamakel Oct 21, 2026
e5166b9
Merge pull request #136 from tinyhumansai/epic-202-h3f-fallback
senamakel Oct 21, 2026
9cc868f
feat(engine): continue paid at-shop receipt inspection
senamakel Oct 21, 2026
03a0bc9
Merge epic payment with paid receipt continuation
senamakel Oct 21, 2026
7d8b270
Merge pull request #137 from tinyhumansai/epic-202-tinycomputer-paid-…
senamakel Oct 21, 2026
a263213
feat(tinycomputer-engine): recover tasks when planning fails
senamakel Oct 21, 2026
ec7ad0c
Merge pull request #138 from tinyhumansai/epic-202-h3f-fallback
senamakel Oct 21, 2026
592321f
fix: bind action context to retained session
senamakel Oct 21, 2026
7b4de92
fix: keep retained session identity authoritative
senamakel Oct 21, 2026
2e0e16d
Merge pull request #139 from tinyhumansai/epic-202-tinycomputer-scope…
senamakel Oct 21, 2026
b81831e
feat(browser): observe successful actions
senamakel Oct 21, 2026
b73c5a0
feat(engine): hand completed prefixes to planner
senamakel Oct 21, 2026
4276b5a
Merge remote-tracking branch 'origin/epic/202-tinycomputer' into epic…
senamakel Oct 21, 2026
24a7690
feat: add safe recipe prefix handoff and action observer
senamakel Oct 21, 2026
3d2a921
Merge pull request #140 from tinyhumansai/epic-202-h4-recipe-observer
senamakel Oct 21, 2026
1f2735e
feat(browser): expose fresh target uniqueness to host gates
senamakel Oct 21, 2026
569dde9
Merge remote-tracking branch 'origin/epic/202-tinycomputer' into epic…
senamakel Oct 21, 2026
6eb4a86
Merge pull request #141 from tinyhumansai/epic-202-h4-recipe-observer
senamakel Oct 21, 2026
1222e4f
fix(tinycomputer-engine): redact private form observations
senamakel Oct 21, 2026
42dc90b
Merge remote-tracking branch 'origin/epic/202-tinycomputer' into epic…
senamakel Oct 21, 2026
96a03a7
fix(tinycomputer-engine): fail closed on redaction collisions
senamakel Oct 21, 2026
9ddf6d9
fix(tinycomputer-engine): drop secret bounds metadata
senamakel Oct 21, 2026
9cfc89f
fix(tinycomputer-browser): mask private tree descendants
senamakel Oct 21, 2026
1083deb
fix(tinycomputer-browser): omit private field descendants
senamakel Oct 21, 2026
c309368
fix(tinycomputer-browser): mask Sight field root values
senamakel Oct 21, 2026
acf4264
Merge pull request #142 from tinyhumansai/epic-202-h5-canary
senamakel Oct 21, 2026
fcb0167
fix(browser): tag trusted surface observations
senamakel Oct 21, 2026
32f2124
fix(tinycomputer-browser): mask private cover observations
senamakel Oct 21, 2026
22ba27d
Merge remote-tracking branch 'origin/epic-202-h4-stability-observatio…
senamakel Oct 21, 2026
236ec77
chore(tinycomputer-browser): fix strict test lints
senamakel Oct 21, 2026
99d1685
fix(tinycomputer-browser): filter private control aggregates
senamakel Oct 21, 2026
cb3a419
Merge pull request #143 from tinyhumansai/epic-202-h5-cover
senamakel Oct 21, 2026
97d5a9e
feat(engine): reserve host calls in task budgets
senamakel Oct 21, 2026
1877b01
fix(browser): resolve sight targets from fresh snapshots
senamakel Oct 21, 2026
9992b77
fix(browser): reject stale shadow snapshot refs
senamakel Oct 21, 2026
ea838d1
Merge pull request #145 from tinyhumansai/epic-202-h4-stability-obser…
senamakel Oct 21, 2026
318531e
Merge remote-tracking branch 'origin/epic/202-tinycomputer' into epic…
senamakel Oct 21, 2026
4ee80f8
fix(engine): close retained host budget scopes
senamakel Oct 21, 2026
7ed60fa
Merge pull request #144 from tinyhumansai/epic-202-h3f-fallback
senamakel Oct 21, 2026
0c1da39
chore: sync TinyInference and browser pins
senamakel Oct 21, 2026
db833bb
Merge pull request #146 from tinyhumansai/epic-202-198-ti-pin
senamakel Oct 21, 2026
c7ca161
chore: pin latest TinyInference usage fixes
senamakel Oct 21, 2026
bfc73c3
Merge pull request #147 from tinyhumansai/epic-202-198-ti-pin
senamakel Oct 21, 2026
4902204
fix(engine): keep stable Clippy clean with checked task ids
senamakel Oct 21, 2026
4a41dcb
test: align shipped contract version assertion
senamakel Oct 21, 2026
b2de346
Merge pull request #149 from tinyhumansai/epic-202-148-clippy
senamakel Oct 21, 2026
bfe4613
fix: make persistence tests portable and cover defaults
senamakel Oct 21, 2026
dcb712d
docs: document contract versions 2.23 and 2.24
senamakel Oct 21, 2026
e148790
fix: preserve task context and handoff origins
senamakel Oct 21, 2026
e70bef3
test: assert task identity in browser observations
senamakel Oct 21, 2026
22f8ec6
fix: recheck missing inputs before restoring a pause
senamakel Oct 21, 2026
3b39065
test: move inline tests to sibling modules
senamakel Oct 21, 2026
c79852e
test: cover default secret authorization refusal
senamakel Oct 21, 2026
16d5052
fix(task): enforce model-call budgets on payment continuation
senamakel Oct 21, 2026
06f3449
refactor(task): split payment budget lookup into two steps
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
466 changes: 357 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

243 changes: 243 additions & 0 deletions crates/tinycomputer-browser/src/action_gate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
//! Host policy for actions sent to a browser page.

use std::sync::Arc;

use serde_json::Value;
use tinycomputer_bus::browser::{Action, ElementRef, Target};

/// Per-task facts supplied by the host when it creates a browser surface.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ActionContext {
/// The task that is driving the page, when there is one.
pub task_id: Option<String>,
/// The retained browser session driving this request, when it is open.
pub session_id: Option<String>,
/// Whether payment handling is in play for the task.
pub payment_in_play: bool,
}

/// A target resolved as far as the latest accessibility snapshot allows.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ActionTarget {
/// The element's accessibility role, when known.
pub role: Option<String>,
/// The element's accessible name, when known.
pub name: Option<String>,
/// The snapshot ref used to identify the element, when known.
pub reference: Option<String>,
/// Whether exactly one element in the latest snapshot has this role and
/// accessible name. Locators without a snapshot ref are never unique.
pub unique: bool,
}

/// Page content an engine caller is about to receive.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ObservationKind {
/// The page's accessibility tree and controls.
Snapshot,
/// The page's extracted text, Markdown, or HTML.
ReadPage,
/// A screenshot of the page.
Screenshot,
/// A fixed browser-surface page-stability watcher. This exposes only
/// whether the page changed, not its content.
PageStability,
/// A fixed-purpose hit-test used by the browser surface before it decides
/// whether a target's pointer action is covered.
TargetCheck,
}

/// Information a trusted host may inspect before the browser acts or returns
/// page content.
///
/// `payload` contains the requested action and its value, including typed
/// text. It is intentionally omitted from `Debug`; implementations must treat
/// it as confidential and must not log or persist it.
pub struct ActionRequest {
/// The typed or raw browser action, including values sent to the page.
pub payload: Value,
/// The resolved semantic target, if the request names one.
pub target: Option<ActionTarget>,
/// The page's actual current URL immediately before the request.
/// The actual address the browser reported immediately before the request,
/// or `None` when the page is between documents and has no readable URL.
/// A host that makes page-specific decisions should refuse an unknown URL.
pub current_url: Option<String>,
/// The requested destination for a navigation, when applicable.
pub destination_url: Option<String>,
/// Whether this request observes page content rather than acting on it.
pub observation: Option<ObservationKind>,
/// Host-supplied task context.
pub context: ActionContext,
}

impl ActionRequest {
pub(crate) fn typed(
action: &Action,
current_url: Option<String>,
destination_url: Option<String>,
context: &ActionContext,
refs: &[ElementRef],
) -> Self {
let payload = serde_json::to_value(action).unwrap_or(Value::Null);
let target = action_target(action, refs);
Self {
payload,
target,
current_url,
destination_url,
observation: None,
context: context.clone(),
}
}

pub(crate) fn raw(
payload: Value,
current_url: Option<String>,
destination_url: Option<String>,
context: &ActionContext,
refs: &[ElementRef],
) -> Self {
let target = payload
.get("selector")
.and_then(Value::as_str)
.and_then(|selector| selector.strip_prefix('@'))
.and_then(|reference| resolve_reference(reference, refs));
Self {
payload,
target,
current_url,
destination_url,
observation: None,
context: context.clone(),
}
}

pub(crate) fn observation(
kind: ObservationKind,
current_url: Option<String>,
context: &ActionContext,
) -> Self {
Self {
payload: serde_json::json!({ "action": "observe" }),
target: None,
current_url,
destination_url: None,
observation: Some(kind),
context: context.clone(),
}
}
}

impl std::fmt::Debug for ActionRequest {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("ActionRequest")
.field(
"action",
&self.payload.get("action").and_then(Value::as_str),
)
.field("target", &self.target)
.field("current_url", &self.current_url)
.field("destination_url", &self.destination_url)
.field("observation", &self.observation)
.field("context", &self.context)
.finish_non_exhaustive()
}
}

/// The host's decision for one action.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionVerdict {
/// Let the browser perform the request.
Allow,
/// Refuse it before any page interaction occurs.
Refuse {
/// A short explanation safe to show in task reports. Do not include
/// the request value in this message.
reason: String,
},
}

/// A synchronous host policy consulted before every typed or raw action and
/// before a snapshot, page read, or screenshot can expose content.
pub trait ActionGate: Send + Sync {
/// Decide whether this request may reach the page.
fn check(&self, request: &ActionRequest) -> ActionVerdict;
}

/// A gate that leaves browser behavior unchanged.
#[derive(Debug, Default)]
pub struct AllowAllActions;

impl ActionGate for AllowAllActions {
fn check(&self, _request: &ActionRequest) -> ActionVerdict {
ActionVerdict::Allow
}
}

pub(crate) fn default_gate() -> Arc<dyn ActionGate> {
Arc::new(AllowAllActions)
}

fn action_target(action: &Action, refs: &[ElementRef]) -> Option<ActionTarget> {
let target = match action {
Action::Click { target, .. }
| Action::DoubleClick { target }
| Action::Hover { target }
| Action::Focus { target }
| Action::Fill { target, .. }
| Action::Select { target, .. }
| Action::Check { target, .. }
| Action::GetText { target }
| Action::GetAttribute { target, .. }
| Action::IsVisible { target } => Some(target),
Action::Type { target, .. }
| Action::Press { target, .. }
| Action::Scroll { target, .. }
| Action::WaitFor { target, .. } => target.as_ref(),
Action::Back | Action::Forward | Action::Reload => None,
}?;
target_from_target(target, refs)
}

fn target_from_target(target: &Target, refs: &[ElementRef]) -> Option<ActionTarget> {
match target {
Target::Ref { value } => resolve_reference(value, refs),
Target::Selector { .. } => None,
Target::Locator { value } if value.by == tinycomputer_bus::browser::LocateBy::Role => {
Some(ActionTarget {
role: Some(value.value.clone()),
name: value.name.clone(),
reference: None,
unique: false,
})
}
Target::Locator { value } => Some(ActionTarget {
role: None,
name: Some(value.value.clone()),
reference: None,
unique: false,
}),
}
}

fn resolve_reference(value: &str, refs: &[ElementRef]) -> Option<ActionTarget> {
let reference = value.strip_prefix('@').unwrap_or(value);
refs.iter()
.find(|item| item.id == reference)
.map(|item| ActionTarget {
role: Some(item.role.clone()),
name: Some(item.name.clone()),
reference: Some(item.id.clone()),
unique: refs
.iter()
.filter(|candidate| candidate.role == item.role && candidate.name == item.name)
.count()
== 1,
})
}

#[cfg(test)]
#[path = "action_gate_tests.rs"]
mod tests;
82 changes: 82 additions & 0 deletions crates/tinycomputer-browser/src/action_gate_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//! Tests for tests behavior.

use serde_json::json;
use tinycomputer_bus::browser::{Action, ElementRef, Target};

use super::{ActionContext, ActionRequest, action_target, resolve_reference};

fn refs() -> Vec<ElementRef> {
vec![ElementRef {
id: "e1".to_owned(),
role: "button".to_owned(),
name: "Place order".to_owned(),
}]
}

#[test]
fn only_explicit_snapshot_refs_resolve_to_snapshot_metadata() {
let refs = refs();
assert_eq!(
resolve_reference("@e1", &refs).map(|target| target.unique),
Some(true)
);
assert_eq!(
resolve_reference("e1", &refs).map(|target| target.unique),
Some(true)
);
assert!(
action_target(
&Action::Click {
target: Target::selector("e1"),
new_tab: false,
},
&refs,
)
.is_none()
);
}

#[test]
fn duplicate_snapshot_targets_are_not_reported_as_unique() {
let mut refs = refs();
refs.push(ElementRef {
id: "e2".to_owned(),
role: "button".to_owned(),
name: "Place order".to_owned(),
});
assert_eq!(
resolve_reference("e1", &refs).map(|target| target.unique),
Some(false)
);
assert_eq!(
resolve_reference("e2", &refs).map(|target| target.unique),
Some(false)
);
}

#[test]
fn raw_css_selectors_do_not_alias_snapshot_refs() {
let refs = refs();
let css = ActionRequest::raw(
json!({"action": "click", "selector": "e1"}),
Some("https://shop.test/".to_owned()),
None,
&ActionContext::default(),
&refs,
);
let reference = ActionRequest::raw(
json!({"action": "click", "selector": "@e1"}),
Some("https://shop.test/".to_owned()),
None,
&ActionContext::default(),
&refs,
);
assert!(css.target.is_none());
assert_eq!(
reference
.target
.as_ref()
.and_then(|target| target.name.as_deref()),
Some("Place order")
);
}
23 changes: 23 additions & 0 deletions crates/tinycomputer-browser/src/error/error_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ fn a_lost_connection_tells_the_host_to_open_a_new_session() {
);
}

#[test]
fn a_host_refusal_is_a_non_retryable_policy_denial() {
let error = Error::ActionRefused {
reason: "host did not allow the action".to_owned(),
};
let envelope = error.envelope();

assert_eq!(error.wire_name(), errors::BLOCKED_BY_POLICY);
assert_eq!(envelope.code, "POLICY_DENIED");
assert_eq!(
envelope.disposition.delivery,
DeliveryDisposition::NotDelivered
);
assert_eq!(
envelope.message,
"action refused by host: host did not allow the action"
);
}

#[test]
fn stale_ref_tells_the_caller_to_snapshot_again() {
let error = Error::StaleRef {
Expand Down Expand Up @@ -110,6 +129,9 @@ fn every_variant() -> Vec<Error> {
Error::BlockedByPolicy {
url: "https://evil.test/".to_string(),
},
Error::ActionRefused {
reason: "blocked by the trusted host".to_owned(),
},
Error::LeftRefusedPage {
url: "https://evil.test/".to_string(),
},
Expand Down Expand Up @@ -218,6 +240,7 @@ fn only_failures_decided_before_the_page_claim_nothing_was_delivered() {
| Error::NoSuchOutput { .. }
| Error::StaleRef { .. }
| Error::BlockedByPolicy { .. }
| Error::ActionRefused { .. }
)
};
for error in every_variant() {
Expand Down
Loading
Loading