👾 Open Computer Use – Open-Source Alternative to Codex Computer Use
Swift accessibilityai-agentai-agentsclaude-codecodexcodex-computer-usecomputer-usecomputer-use-agentcross-platformcuadesktop-automationgemini-cligui-automationmacosmcpmodel-context-protocolopen-computer-useopen-computer-use-mcpopenai-codexopencode
Preserve images in compact accessibility rows
Leo96441d0f8829
diff --git a/docs/histories/2026-05/20260507-1825-polish-accessibility-formatting.md b/docs/histories/2026-05/20260507-1825-polish-accessibility-formatting.mdindex 6f5d8ce..bdfd017 100644--- a/docs/histories/2026-05/20260507-1825-polish-accessibility-formatting.md+++ b/docs/histories/2026-05/20260507-1825-polish-accessibility-formatting.md@@ -15,13 +15,16 @@- Matched the official window button help/action format by rendering `Help:` without a leading comma and adding the comma before `Secondary Actions` when prior metadata exists.- Special-cased `AXZoomWindow` to render as `zoom the window`, matching the official full-screen button output.- Restored short text-summary wrapper nodes to `container` instead of `text`, which better matches official Electron rows where compact text usually lives under a container parent.+- When a compact text-summary container also has image descendants, rendered the summary as a child `text` row and preserved up to four image descendants. This moves Lark message rows closer to the official `container -> text + image` shape without expanding long menu/body content.### Verification- `OPEN_COMPUTER_USE_DISABLE_APP_AGENT_PROXY=1 swift run OpenComputerUse call get_app_state --args '{"app":"com.electron.lark"}'`- Confirmed `full screen button Help: this button also has an action to zoom the window, Secondary Actions: zoom the window`.- - Confirmed short Lark message summaries render as `container ...`.+ - Confirmed short Lark message summaries render as `container` parent rows.+ - Confirmed message rows with avatars/images render as `container -> text + image`.- Confirmed `text entry area`, `SideEdgeView`, and focused `HTML 内容 messenger-chat, URL: ...` are still present.- Confirmed no `Scroll To Visible` or `selectable` noise in the sampled tree.+- Added `testAccessibilityRendererRendersSummariesWithImagesAsChildren` to cover the summary/image split decision.### Files Modified- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift`diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swiftindex 5b0fa0c..a26935f 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift@@ -393,6 +393,11 @@ private struct TreeRenderer {role: role,childElements: childElements)+ let summaryImageChildren = genericTextSummary == nil ? [] : summaryImageDescendants(of: root)+ let rendersSummaryAsChildren = shouldRenderGenericTextSummaryAsChildren(+ genericTextSummary,+ summaryImageCount: summaryImageChildren.count+ )let title = preferredDisplayTitle(for: root,role: role,@@ -443,7 +448,8 @@ private struct TreeRenderer {let traitsSegment = traits.isEmpty ? "" : " (\(traits.joined(separator: ", ")))"let titleSegment = title.map { " \($0)" } ?? ""- let rowSummarySegment = (inlineRowSummary ?? genericTextSummary).map { " \($0)" } ?? ""+ let rowSummary = inlineRowSummary ?? (rendersSummaryAsChildren ? nil : genericTextSummary)+ let rowSummarySegment = rowSummary.map { " \($0)" } ?? ""let labelSegment = label != nil && label != title ? " Description: \(label!)" : ""let helpSegment = {guard let help else {@@ -498,6 +504,14 @@ private struct TreeRenderer {return}+ if rendersSummaryAsChildren, let genericTextSummary {+ renderSyntheticText(genericTextSummary, representedBy: root, depth: depth + 1)+ for image in summaryImageChildren {+ render(image, depth: depth + 1, ancestors: nextAncestors)+ }+ return+ }+if hidesChildren {return}@@ -507,6 +521,25 @@ private struct TreeRenderer {}}+ private mutating func renderSyntheticText(_ text: String, representedBy element: AXUIElement, depth: Int) {+ guard shouldContinueRendering(nextIndex: nextIndex, depth: depth) else {+ return+ }++ let index = nextIndex+ nextIndex += 1+ lines.append("\(String(repeating: "\t", count: depth + 1))\(index) text \(text)")++ records[index] = ElementRecord(+ index: index,+ identifier: nil,+ element: element,+ localFrame: resolveLocalFrame(of: element, windowBounds: context.windowBounds),+ rawActions: [],+ prettyActions: []+ )+ }+private func opaqueIdentifier(for element: AXUIElement) -> String {String(CFHash(element))}@@ -1006,6 +1039,40 @@ private func summarizedGenericText(return joined.isEmpty ? nil : joined}+private func summaryImageDescendants(of element: AXUIElement, depth: Int = 0) -> [AXUIElement] {+ guard depth < 4 else {+ return []+ }++ let children = copyArray(element, attribute: kAXChildrenAttribute) ?? []+ var images: [AXUIElement] = []++ for child in children {+ let role = stringValue(of: child, attribute: kAXRoleAttribute) ?? ""+ if role == kAXImageRole as String {+ if !images.contains(where: { CFEqual($0, child) }) {+ images.append(child)+ }+ } else {+ for image in summaryImageDescendants(of: child, depth: depth + 1) {+ if !images.contains(where: { CFEqual($0, image) }) {+ images.append(image)+ }+ }+ }++ if images.count >= 4 {+ return Array(images.prefix(4))+ }+ }++ return images+}++func shouldRenderGenericTextSummaryAsChildren(_ genericTextSummary: String?, summaryImageCount: Int) -> Bool {+ genericTextSummary != nil && summaryImageCount > 0+}+func shouldMergeTextOnlySiblings(_ texts: [String]) -> Bool {if texts.contains("日期") && texts.contains("时间") {return falsediff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex 3eef160..135d72f 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -608,6 +608,12 @@ final class OpenComputerUseKitTests: XCTestCase {]))}+ func testAccessibilityRendererRendersSummariesWithImagesAsChildren() {+ XCTAssertTrue(shouldRenderGenericTextSummaryAsChildren("AgentSphere 17:18 好的,谢谢", summaryImageCount: 1))+ XCTAssertFalse(shouldRenderGenericTextSummaryAsChildren("AgentSphere 17:18 好的,谢谢", summaryImageCount: 0))+ XCTAssertFalse(shouldRenderGenericTextSummaryAsChildren(nil, summaryImageCount: 1))+ }+func testAccessibilityRendererFiltersScrollToVisibleNoise() {XCTAssertEqual(meaningfulActions(