👾 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
Align Feishu state wrappers
Leo2fa8bf97878f
diff --git a/docs/histories/2026-05/20260508-1022-align-feishu-state-wrappers.md b/docs/histories/2026-05/20260508-1022-align-feishu-state-wrappers.mdnew file mode 100644index 0000000..d4566a1--- /dev/null+++ b/docs/histories/2026-05/20260508-1022-align-feishu-state-wrappers.md@@ -0,0 +1,27 @@+# Align Feishu state wrappers++## User request++用户重启 Codex 后要求继续对比 `open-computer-use` 与官方 `computer-use`,确认新版 Dev app 在 Feishu / Electron state rendering 上的差异。++## Changes++- 对齐官方 `computer-use` 的 Electron state tree:单子节点、无自有语义、仅带 `settable/string` trait 的 generic wrapper 现在会被压平。+- WebArea 下不再仅因为处在浅层就保留单子节点 generic container,减少 Feishu 页面顶部和正文区的冗余层级。+- 文本合并规则新增独立时间范围保护,避免把日程标题、倒计时和 `HH:mm - HH:mm` 时间段合成一整句。+- 文本摘要允许 AXLink 参与合并,让内容列表项能更接近官方的单行摘要形状。+- 补充单元测试覆盖 wrapper elision 和时间范围合并边界。++## Validation++- `swift test`+- `./scripts/build-open-computer-use-app.sh debug`+- 直连新构建 Dev app 抽样 `get_app_state`,确认 Feishu 顶层 `ClientView` 前的空 wrapper 已压平,日程时间范围不再被合并。+- `./scripts/run-tool-smoke-tests.sh`+- `./scripts/check-docs.sh`+- `git diff --check`++## Affected files++- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swiftindex b06f7a2..50c5a2c 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift@@ -1206,6 +1206,17 @@ func shouldElideNode(return false}+ if childCount == 1,+ title == nil,+ label == nil,+ value == nil,+ identifier == nil,+ actions.isEmpty,+ traitsAreNonDescriptiveWrapperTraits(traits)+ {+ return true+ }+return title == nil&& label == nil&& value == nil@@ -1215,11 +1226,15 @@ func shouldElideNode(}func shouldPreserveWebAreaGenericContainer(childCount: Int, webAreaDepth: Int?) -> Bool {- guard childCount > 0, let webAreaDepth else {+ guard childCount > 0, webAreaDepth != nil else {return false}- return childCount > 1 || webAreaDepth <= 4+ return childCount > 1+}++private func traitsAreNonDescriptiveWrapperTraits(_ traits: [String]) -> Bool {+ traits.isEmpty || traits == ["settable", "string"]}private func shouldSuppressChildren(@@ -1319,6 +1334,10 @@ func shouldMergeTextOnlySiblings(_ texts: [String]) -> Bool {return false}+ if texts.contains(where: isStandaloneTimeRangeText(_:)) {+ return false+ }+let totalLength = texts.reduce(0) { $0 + $1.count }return texts.count <= 8 && totalLength <= 220}@@ -1327,6 +1346,10 @@ private func isSiblingCounterText(_ text: String) -> Bool {text.range(of: #"^\d+\s*/\s*\d+$"#, options: .regularExpression) != nil}+private func isStandaloneTimeRangeText(_ text: String) -> Bool {+ text.range(of: #"^\d{1,2}:\d{2}\s*-\s*\d{1,2}:\d{2}$"#, options: .regularExpression) != nil+}+private func isPlainGenericTextContainer(_ element: AXUIElement, children: [AXUIElement], depth: Int = 0) -> Bool {for child in children {let childRole = stringValue(of: child, attribute: kAXRoleAttribute) ?? ""@@ -1335,6 +1358,10 @@ private func isPlainGenericTextContainer(_ element: AXUIElement, children: [AXUIcontinue}+ if childRole == "AXLink", summaryTextForLink(child) != nil {+ continue+ }+if childRole == kAXGroupRole as String || childRole == kAXUnknownRole as String {guard depth < 3 else {return false@@ -1539,6 +1566,10 @@ private func descendantTextsForSummary(of element: AXUIElement, depth: Int = 0)}let role = stringValue(of: element, attribute: kAXRoleAttribute) ?? ""+ if role == "AXLink", let linkText = summaryTextForLink(element) {+ return [linkText]+ }+if role == kAXStaticTextRole as String || role == kAXTextFieldRole as String {if let value = sanitizedValue(of: element), !value.isEmpty {return [value]@@ -1554,6 +1585,26 @@ private func descendantTextsForSummary(of element: AXUIElement, depth: Int = 0).flatMap { descendantTextsForSummary(of: $0, depth: depth + 1) }}+private func summaryTextForLink(_ element: AXUIElement) -> String? {+ guard let url = urlValue(of: element, attribute: kAXURLAttribute), !url.isEmpty else {+ return nil+ }++ let childText = (copyArray(element, attribute: kAXChildrenAttribute) ?? [])+ .flatMap { descendantTextsForSummary(of: $0) }+ .joined(separator: " ")+ let sanitized = sanitizeText(childText)+ guard !sanitized.isEmpty else {+ return nil+ }++ if sanitized == url {+ return url+ }++ return "[\(markdownEscapedLinkText(sanitized))](\(url))"+}+private func visibleRows(in rows: [AXUIElement], parent: AXUIElement) -> [AXUIElement] {guard let parentFrame = resolveLocalFrame(of: parent, windowBounds: nil) else {return Array(rows.prefix(20))diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex 209ccdf..1413b3d 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -636,6 +636,17 @@ final class OpenComputerUseKitTests: XCTestCase {childCount: 3,webAreaDepth: 4))+ XCTAssertTrue(shouldElideNode(+ role: kAXGroupRole as String,+ title: nil,+ label: nil,+ value: nil,+ identifier: nil,+ traits: [],+ actions: [],+ childCount: 1,+ webAreaDepth: 4+ ))XCTAssertTrue(shouldElideNode(role: kAXGroupRole as String,title: nil,@@ -669,11 +680,32 @@ final class OpenComputerUseKitTests: XCTestCase {childCount: 1,webAreaDepth: 8))+ XCTAssertTrue(shouldElideNode(+ role: kAXGroupRole as String,+ title: nil,+ label: nil,+ value: nil,+ identifier: nil,+ traits: ["settable", "string"],+ actions: [],+ childCount: 1+ ))+ XCTAssertFalse(shouldElideNode(+ role: kAXGroupRole as String,+ title: nil,+ label: nil,+ value: nil,+ identifier: nil,+ traits: ["settable", "string"],+ actions: [],+ childCount: 0+ ))}func testAccessibilityRendererOnlyMergesShortTextOnlySiblingRuns() {XCTAssertTrue(shouldMergeTextOnlySiblings(["AgentSphere", "17:18", "好的,谢谢"]))XCTAssertFalse(shouldMergeTextOnlySiblings(["日期", "时间", "2026年5月7日", "晚餐", "18:00-20:00"]))+ XCTAssertFalse(shouldMergeTextOnlySiblings(["as-next 10min 站会", "12 分钟后", "10:30 - 10:45"]))XCTAssertFalse(shouldMergeTextOnlySiblings(["📌 3层简卡轻食","自助餐",