Agent review pass.

This commit is contained in:
hjozwiak committed 2026-11-24 11:12:17 -05:00
1 parent e9b2e9508b
commit 64ee749a8e
105 files changed
+2098 -320

No files matched your search

+7
View File
@@ -381,6 +381,13 @@ func (adapter *Adapter) markProviderHung(busName string, at time.Time) {
if adapter.hungBuses == nil {
adapter.hungBuses = make(map[string]time.Time)
}
// Sweep expired entries on every mark so the map only ever holds buses
// hung within one cooldown window instead of growing without bound.
for bus, since := range adapter.hungBuses {
if at.Sub(since) > providerHungCooldown {
delete(adapter.hungBuses, bus)
}
}
adapter.hungBuses[busName] = at
}
+1 -1
View File
@@ -422,7 +422,7 @@ func (adapter *Adapter) readNativeDocumentCaret(ctx context.Context, position Ob
case DocumentCaretWord:
granularity = C.AtspiTextGranularity(C.ATSPI_TEXT_GRANULARITY_WORD)
}
rangeText := C.atspi_text_get_string_at_offset(text, C.gint(offset), granularity, &nativeErr)
rangeText := C.cthulhu_text_get_string_at_offset(text, C.gint(offset), granularity, &nativeErr)
if nativeErr != nil {
err := adapter.documentObjectError(position.ID(), nativeError("read document text", nativeErr))
C.g_error_free(nativeErr)
+6
View File
@@ -412,6 +412,12 @@ func cthulhuAtspiTreeCaptureCallback(userData unsafe.Pointer) {
request := <-adapter.treeRequests
captureDiagnosticsFrom(request.ctx).beginStage("callback-setup", request.reviewFocus, "")
adapter.applySecureReset()
// A deferred selection waits on a DEFAULT_IDLE source, which repeated
// G_PRIORITY_HIGH captures can overtake indefinitely. Flush it here so
// the selection that preceded this capture is presented first. The
// foreground tick needs no flush: it is a short 50ms timeout at default
// priority, so the idle source still runs between ticks.
C.cthulhu_flush_selection(adapter.callbackData)
if request.ctx.Err() != nil {
request.result <- treeCaptureResult{err: request.ctx.Err()}
return
+10 -4
View File
@@ -80,7 +80,12 @@ func (tree *AccessibleTree) DocumentLineAtOffset(ctx context.Context, reference
if node.Hidden {
continue
}
contributed := false
// Presentation indexes SourceContexts by content index, so every
// emitted range needs its own entry even when one node contributes
// several ranges to the same visual row. Fetch the owner's ancestry
// once per node, but append it once per range.
var ancestry []Snapshot
fetched := false
for _, textRange := range node.Text.Ranges {
if !boundsAreOnSameLine(caretRange.Bounds, textRange.Bounds) {
continue
@@ -88,11 +93,12 @@ func (tree *AccessibleTree) DocumentLineAtOffset(ctx context.Context, reference
if textRange.Text == "" {
continue
}
if !contributed {
if !fetched {
owner, _ := tree.DocumentContext(node.Reference)
line.SourceContexts = append(line.SourceContexts, owner.Ancestors)
contributed = true
ancestry = owner.Ancestors
fetched = true
}
line.SourceContexts = append(line.SourceContexts, ancestry)
line.Contents = append(line.Contents, DocumentContent{
Reference: node.Reference,
Snapshot: node.Snapshot,
+11 -3
View File
@@ -184,9 +184,17 @@ func TestDocumentLineAssemblesSameVisualRow(t *testing.T) {
}
nodes[index].Text = text
}
lineNode(3, "/heading", "heading", "Before", Rectangle{X: 0, Y: 100, Width: 50, Height: 20}, true)
lineNode(3, "/heading", "heading", "Before more", Rectangle{X: 0, Y: 100, Width: 100, Height: 20}, true)
lineNode(5, "/link", "link", "link text", Rectangle{X: 100, Y: 100, Width: 80, Height: 20}, true)
lineNode(6, "/other", "paragraph", "Other row", Rectangle{X: 0, Y: 200, Width: 80, Height: 20}, false)
// The heading contributes a second range to the same visual row. Each
// emitted range needs its own SourceContexts entry, or presentation
// (which indexes contexts by content index) attributes the link's
// ancestry to this fragment and runs past the end for the last one.
nodes[3].Text.Ranges = []TextRange{
{Start: 0, End: 6, Text: "Before", Bounds: Rectangle{X: 0, Y: 100, Width: 50, Height: 20}},
{Start: 7, End: 11, Text: "more", Bounds: Rectangle{X: 50, Y: 100, Width: 50, Height: 20}},
}
tree, err := NewAccessibleTree(testID("/root"), nodes)
if err != nil {
t.Fatal(err)
@@ -203,7 +211,7 @@ func TestDocumentLineAssemblesSameVisualRow(t *testing.T) {
for _, content := range line.Contents {
contents = append(contents, content.Text)
}
if !reflect.DeepEqual(contents, []string{"Before", "link text"}) {
if !reflect.DeepEqual(contents, []string{"Before", "more", "link text"}) {
t.Fatalf("line contents = %q", contents)
}
if line.Document.ID() != testID("/doc") {
@@ -219,7 +227,7 @@ func TestDocumentLineAssemblesSameVisualRow(t *testing.T) {
}
// The first fragment is outside the caret object's ancestry. Keep its
// original ancestry even though line.Context belongs to the caret.
if line.SourceContexts[0][1].ID() != testID("/doc") || line.SourceContexts[1][1].ID() != testID("/inner") {
if line.SourceContexts[0][1].ID() != testID("/doc") || line.SourceContexts[2][1].ID() != testID("/inner") {
t.Fatal("neighbor ancestry was replaced by caret ancestry")
}
}