Skip to content

Commit 3c5c904

Browse files
author
SentienceDEV
committed
update models with modal detection
1 parent 355e72d commit 3c5c904

File tree

4 files changed

+104
-14
lines changed

4 files changed

+104
-14
lines changed

sentience/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ class GridInfo(BaseModel):
144144
)
145145
is_dominant: bool = False # Whether this grid is the dominant group (main content area)
146146

147+
# Z-index and modal detection fields (from gateway/sentience-core)
148+
z_index: int = 0 # Z-index of this grid (max among elements in this grid)
149+
z_index_max: int = 0 # Global max z-index across ALL grids (for comparison)
150+
blocks_interaction: bool = False # Whether this grid blocks interaction with content behind it
151+
viewport_coverage: float = 0.0 # Ratio of grid area to viewport area (0.0-1.0)
152+
147153

148154
class Snapshot(BaseModel):
149155
"""Snapshot response from extension"""
@@ -161,6 +167,9 @@ class Snapshot(BaseModel):
161167
dominant_group_key: str | None = None # The most common group_key (main content group)
162168
# Phase 2: Runtime stability/debug info (confidence/reasons/metrics)
163169
diagnostics: SnapshotDiagnostics | None = None
170+
# Modal detection fields (from gateway)
171+
modal_detected: bool | None = None # True if a modal/overlay grid was detected
172+
modal_grids: list[GridInfo] | None = None # Array of GridInfo for detected modal grids
164173

165174
def save(self, filepath: str) -> None:
166175
"""Save snapshot as JSON file"""

sentience/runtime_agent.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,19 @@ async def run_step(
9292
snap = await self._snapshot_with_ramp(step=step)
9393

9494
if await self._should_short_circuit_to_vision(step=step, snap=snap):
95-
ok = await self._vision_executor_attempt(
96-
task_goal=task_goal, step=step, snap=snap
97-
)
95+
ok = await self._vision_executor_attempt(task_goal=task_goal, step=step, snap=snap)
9896
return ok
9997

10098
# 1) Structured executor attempt.
101-
action = self._propose_structured_action(
102-
task_goal=task_goal, step=step, snap=snap
103-
)
99+
action = self._propose_structured_action(task_goal=task_goal, step=step, snap=snap)
104100
await self._execute_action(action=action, snap=snap)
105101
ok = await self._apply_verifications(step=step)
106102
if ok:
107103
return True
108104

109105
# 2) Optional vision executor fallback (bounded).
110106
if step.vision_executor_enabled and step.max_vision_executor_attempts > 0:
111-
ok = await self._vision_executor_attempt(
112-
task_goal=task_goal, step=step, snap=snap
113-
)
107+
ok = await self._vision_executor_attempt(task_goal=task_goal, step=step, snap=snap)
114108
return ok
115109

116110
return False

sentience/trace_event_builder.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,7 @@ def build_step_end_event(
155155
"exec": exec_data,
156156
"post": {
157157
"url": post_url,
158-
**(
159-
{"snapshot_digest": post_snapshot_digest}
160-
if post_snapshot_digest
161-
else {}
162-
),
158+
**({"snapshot_digest": post_snapshot_digest} if post_snapshot_digest else {}),
163159
},
164160
"verify": final_verify_data,
165161
}

tests/test_grid_bounds.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,94 @@ def test_sorted_by_grid_id(self):
348348
assert result[0].grid_id == 0
349349
assert result[1].grid_id == 1
350350
assert result[2].grid_id == 2
351+
352+
353+
class TestGridInfoModalFields:
354+
"""Tests for GridInfo z-index and modal detection fields"""
355+
356+
def test_grid_info_default_values(self):
357+
"""Test that GridInfo has correct default values for new fields"""
358+
grid_info = GridInfo(
359+
grid_id=0,
360+
bbox=BBox(x=0, y=0, width=100, height=100),
361+
row_count=1,
362+
col_count=1,
363+
item_count=1,
364+
)
365+
# New optional fields should have defaults
366+
assert grid_info.z_index == 0
367+
assert grid_info.z_index_max == 0
368+
assert grid_info.blocks_interaction is False
369+
assert grid_info.viewport_coverage == 0.0
370+
371+
def test_grid_info_with_modal_fields(self):
372+
"""Test creating GridInfo with modal detection fields"""
373+
grid_info = GridInfo(
374+
grid_id=1,
375+
bbox=BBox(x=100, y=100, width=500, height=400),
376+
row_count=2,
377+
col_count=3,
378+
item_count=6,
379+
confidence=0.95,
380+
z_index=1000,
381+
z_index_max=1000,
382+
blocks_interaction=True,
383+
viewport_coverage=0.25,
384+
)
385+
assert grid_info.z_index == 1000
386+
assert grid_info.z_index_max == 1000
387+
assert grid_info.blocks_interaction is True
388+
assert grid_info.viewport_coverage == 0.25
389+
390+
391+
class TestSnapshotModalFields:
392+
"""Tests for Snapshot modal detection fields"""
393+
394+
def test_snapshot_without_modal(self):
395+
"""Test snapshot with no modal detected"""
396+
snapshot = Snapshot(
397+
status="success",
398+
url="https://example.com",
399+
elements=[],
400+
)
401+
# modal_detected and modal_grids should be None by default
402+
assert snapshot.modal_detected is None
403+
assert snapshot.modal_grids is None
404+
405+
def test_snapshot_with_modal_detected(self):
406+
"""Test snapshot with modal detected"""
407+
modal_grid = GridInfo(
408+
grid_id=1,
409+
bbox=BBox(x=200, y=150, width=600, height=400),
410+
row_count=1,
411+
col_count=2,
412+
item_count=5,
413+
z_index=1000,
414+
z_index_max=1000,
415+
blocks_interaction=True,
416+
viewport_coverage=0.20,
417+
)
418+
snapshot = Snapshot(
419+
status="success",
420+
url="https://example.com",
421+
elements=[],
422+
modal_detected=True,
423+
modal_grids=[modal_grid],
424+
)
425+
assert snapshot.modal_detected is True
426+
assert snapshot.modal_grids is not None
427+
assert len(snapshot.modal_grids) == 1
428+
assert snapshot.modal_grids[0].z_index == 1000
429+
assert snapshot.modal_grids[0].blocks_interaction is True
430+
431+
def test_snapshot_modal_false(self):
432+
"""Test snapshot with modal_detected explicitly False"""
433+
snapshot = Snapshot(
434+
status="success",
435+
url="https://example.com",
436+
elements=[],
437+
modal_detected=False,
438+
modal_grids=None,
439+
)
440+
assert snapshot.modal_detected is False
441+
assert snapshot.modal_grids is None

0 commit comments

Comments
 (0)