👾 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
feat(snapshot): 添加可配置 tree 预算参数
tisfeng653e83e07541
diff --git a/apps/OpenComputerUse/Sources/OpenComputerUse/MacOSAppAgentProxy.swift b/apps/OpenComputerUse/Sources/OpenComputerUse/MacOSAppAgentProxy.swiftindex d51fa22..4d9fc75 100644--- a/apps/OpenComputerUse/Sources/OpenComputerUse/MacOSAppAgentProxy.swift+++ b/apps/OpenComputerUse/Sources/OpenComputerUse/MacOSAppAgentProxy.swift@@ -384,9 +384,9 @@ private final class AppAgentConnection: @unchecked Sendable {let service = ComputerUseService()return CLIProxyResponse(stdout: (service.listApps().primaryText ?? "") + "\n", stderr: "", exitCode: EXIT_SUCCESS)- case let .snapshot(app, showFullText):+ case let .snapshot(app, showFullText, treeLimits):let service = ComputerUseService()- let text = try service.getAppState(app: app, showFullText: showFullText).primaryText ?? ""+ let text = try service.getAppState(app: app, showFullText: showFullText, treeLimits: treeLimits).primaryText ?? ""return CLIProxyResponse(stdout: text + "\n", stderr: "", exitCode: EXIT_SUCCESS)case let .call(invocation):diff --git a/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift b/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swiftindex cef6d82..f5a14f0 100644--- a/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift+++ b/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift@@ -57,9 +57,9 @@ enum OpenComputerUseMain {case .listApps:let service = ComputerUseService()print(service.listApps().primaryText ?? "")- case let .snapshot(app, showFullText):+ case let .snapshot(app, showFullText, treeLimits):let service = ComputerUseService()- print(try service.getAppState(app: app, showFullText: showFullText).primaryText ?? "")+ print(try service.getAppState(app: app, showFullText: showFullText, treeLimits: treeLimits).primaryText ?? "")case let .call(invocation):if VisualCursorSupport.isEnabled {_ = NSApplication.shared.setActivationPolicy(.accessory)diff --git a/apps/OpenComputerUseLinux/main.go b/apps/OpenComputerUseLinux/main.goindex ec75d85..ace0e67 100644--- a/apps/OpenComputerUseLinux/main.go+++ b/apps/OpenComputerUseLinux/main.go@@ -152,6 +152,8 @@ type linuxRequest struct {Value string `json:"value,omitempty"`WindowBounds *frame `json:"windowBounds,omitempty"`ShowFullText bool `json:"show_full_text,omitempty"`+ MaxTreeNodes int `json:"max_tree_nodes,omitempty"`+ MaxTreeDepth int `json:"max_tree_depth,omitempty"`}type linuxResponse struct {@@ -174,7 +176,15 @@ func (s *service) callTool(name string, args map[string]any) toolCallResult {case "list_apps":return s.listApps()case "get_app_state":- return s.getAppState(requiredString(args, "app"), optionalBool(args, "show_full_text"))+ maxTreeNodes, err := optionalPositiveInt(args, "max_tree_nodes")+ if err != nil {+ return textResult(err.Error(), true)+ }+ maxTreeDepth, err := optionalPositiveInt(args, "max_tree_depth")+ if err != nil {+ return textResult(err.Error(), true)+ }+ return s.getAppState(requiredString(args, "app"), optionalBool(args, "show_full_text"), maxTreeNodes, maxTreeDepth)case "click":return s.click(requiredString(args, "app"),@@ -230,11 +240,18 @@ func (s *service) listApps() toolCallResult {return textResult(response.Text, false)}-func (s *service) getAppState(app string, showFullText bool) toolCallResult {+func (s *service) getAppState(app string, showFullText bool, maxTreeNodes, maxTreeDepth *int) toolCallResult {if app == "" {return textResult("Missing required argument: app", true)}- snapshot, result := s.refreshSnapshot(app, linuxRequest{Tool: "get_app_state", App: app, ShowFullText: showFullText})+ request := linuxRequest{Tool: "get_app_state", App: app, ShowFullText: showFullText}+ if maxTreeNodes != nil {+ request.MaxTreeNodes = *maxTreeNodes+ }+ if maxTreeDepth != nil {+ request.MaxTreeDepth = *maxTreeDepth+ }+ snapshot, result := s.refreshSnapshot(app, request)if result.IsError {return result}@@ -967,6 +984,58 @@ func optionalBool(args map[string]any, key string) bool {return value}+func optionalPositiveInt(args map[string]any, key string) (*int, error) {+ value, ok := args[key]+ if !ok {+ return nil, nil+ }+ return positiveIntFromValue(value, key)+}++func positiveIntFromValue(value any, key string) (*int, error) {+ switch typed := value.(type) {+ case int:+ return positiveIntFromInt64(int64(typed), key)+ case float64:+ if !isWholeNumber(typed) {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ return positiveIntFromFloat64(typed, key)+ case json.Number:+ integer, err := typed.Int64()+ if err != nil {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ return positiveIntFromInt64(integer, key)+ default:+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+}++func positiveIntFromFloat64(value float64, key string) (*int, error) {+ if !isWholeNumber(value) || value <= 0 || value > float64(maxInt()) {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ integer := int(value)+ return &integer, nil+}++func positiveIntFromInt64(value int64, key string) (*int, error) {+ if value <= 0 || value > int64(maxInt()) {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ integer := int(value)+ return &integer, nil+}++func isWholeNumber(value float64) bool {+ return !math.IsNaN(value) && !math.IsInf(value, 0) && math.Trunc(value) == value+}++func maxInt() int {+ return int(^uint(0) >> 1)+}+func intValue(value *float64, fallback int) int {if value == nil {return fallback@@ -1022,6 +1091,8 @@ func toolDefinitions() []toolDefinition {InputSchema: objectSchema(map[string]any{"app": stringProperty("App name or bundle identifier"),"show_full_text": booleanProperty("Return full accessibility text without the default 500 character truncation. Defaults to false."),+ "max_tree_nodes": positiveIntegerProperty("Maximum accessibility tree nodes to render. Defaults to 1200."),+ "max_tree_depth": positiveIntegerProperty("Maximum accessibility tree depth to render. Defaults to 64."),}, []string{"app"}),},{@@ -1124,6 +1195,10 @@ func integerProperty(description string) map[string]any {return map[string]any{"type": "integer", "description": description}}+func positiveIntegerProperty(description string) map[string]any {+ return map[string]any{"type": "integer", "minimum": 1, "description": description}+}+func main() {if err := runCLI(os.Args[1:], os.Stdout); err != nil {fmt.Fprintln(os.Stderr, err)@@ -1161,14 +1236,21 @@ func runCLI(args []string, stdout io.Writer) error {fmt.Fprintln(stdout, result.Content[0].Text)return nilcase "snapshot":- app, showFullText, err := parseSnapshotArgs(args[1:])+ app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs(args[1:])if err != nil {return err}- result := newService().callTool("get_app_state", map[string]any{+ toolArgs := map[string]any{"app": app,"show_full_text": showFullText,- })+ }+ if maxTreeNodes != nil {+ toolArgs["max_tree_nodes"] = *maxTreeNodes+ }+ if maxTreeDepth != nil {+ toolArgs["max_tree_depth"] = *maxTreeDepth+ }+ result := newService().callTool("get_app_state", toolArgs)if result.IsError {return errors.New(result.Content[0].Text)}@@ -1193,27 +1275,58 @@ func runCLI(args []string, stdout io.Writer) error {}}-func parseSnapshotArgs(args []string) (string, bool, error) {+func parseSnapshotArgs(args []string) (string, bool, *int, *int, error) {var app stringshowFullText := false- for _, arg := range args {+ var maxTreeNodes *int+ var maxTreeDepth *int+ for index := 0; index < len(args); index++ {+ arg := args[index]switch arg {case "--show-full-text":showFullText = true+ case "--max-tree-nodes":+ index+++ if index >= len(args) {+ return "", false, nil, nil, errors.New("--max-tree-nodes requires a positive integer value")+ }+ value, err := parsePositiveIntegerOption(args[index], "--max-tree-nodes")+ if err != nil {+ return "", false, nil, nil, err+ }+ maxTreeNodes = &value+ case "--max-tree-depth":+ index+++ if index >= len(args) {+ return "", false, nil, nil, errors.New("--max-tree-depth requires a positive integer value")+ }+ value, err := parsePositiveIntegerOption(args[index], "--max-tree-depth")+ if err != nil {+ return "", false, nil, nil, err+ }+ maxTreeDepth = &valuedefault:if strings.HasPrefix(arg, "-") {- return "", false, fmt.Errorf("unknown snapshot option: %s", arg)+ return "", false, nil, nil, fmt.Errorf("unknown snapshot option: %s", arg)}if app != "" {- return "", false, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")+ return "", false, nil, nil, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")}app = arg}}if app == "" {- return "", false, errors.New("snapshot requires an app name, process name, window title, or pid")+ return "", false, nil, nil, errors.New("snapshot requires an app name, process name, window title, or pid")+ }+ return app, showFullText, maxTreeNodes, maxTreeDepth, nil+}++func parsePositiveIntegerOption(value, option string) (int, error) {+ integer, err := strconv.Atoi(value)+ if err != nil || integer <= 0 {+ return 0, fmt.Errorf("%s must be a positive integer", option)}- return app, showFullText, nil+ return integer, nil}func runCallCommand(args []string, svc *service) (any, bool, error) {@@ -1446,7 +1559,7 @@ func helpText(command string) string {case "call":return "Usage:\n open-computer-use call <tool> [--args '<json-object>']\n open-computer-use call --calls '<json-array>'\n\nThe JSON array form keeps all calls in one process so element_index state can be reused.\n"case "snapshot":- return "Usage:\n open-computer-use snapshot [--show-full-text] <app>\n\nPrint the current Linux AT-SPI snapshot for the target app.\n"+ return "Usage:\n open-computer-use snapshot [--show-full-text] [--max-tree-nodes <positive-int>] [--max-tree-depth <positive-int>] <app>\n\nPrint the current Linux AT-SPI snapshot for the target app.\n"default:return `Open Computer Use for Linuxdiff --git a/apps/OpenComputerUseLinux/main_test.go b/apps/OpenComputerUseLinux/main_test.goindex a43f751..c0fe229 100644--- a/apps/OpenComputerUseLinux/main_test.go+++ b/apps/OpenComputerUseLinux/main_test.go@@ -23,6 +23,20 @@ func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {if got := showFullText["type"]; got != "boolean" {t.Fatalf("show_full_text type = %v, want boolean", got)}+ maxTreeNodes := properties["max_tree_nodes"].(map[string]any)+ if got := maxTreeNodes["type"]; got != "integer" {+ t.Fatalf("max_tree_nodes type = %v, want integer", got)+ }+ if got := maxTreeNodes["minimum"]; got != 1 {+ t.Fatalf("max_tree_nodes minimum = %v, want 1", got)+ }+ maxTreeDepth := properties["max_tree_depth"].(map[string]any)+ if got := maxTreeDepth["type"]; got != "integer" {+ t.Fatalf("max_tree_depth type = %v, want integer", got)+ }+ if got := maxTreeDepth["minimum"]; got != 1 {+ t.Fatalf("max_tree_depth minimum = %v, want 1", got)+ }required := tool.InputSchema["required"].([]string)if len(required) != 1 || required[0] != "app" {t.Fatalf("required = %#v, want [app]", required)@@ -30,20 +44,40 @@ func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {}func TestParseSnapshotArgsSupportsShowFullText(t *testing.T) {- app, showFullText, err := parseSnapshotArgs([]string{"--show-full-text", "Text Editor"})+ app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs([]string{"--show-full-text", "Text Editor"})+ if err != nil {+ t.Fatal(err)+ }+ if app != "Text Editor" || !showFullText || maxTreeNodes != nil || maxTreeDepth != nil {+ t.Fatalf("parseSnapshotArgs = (%q, %v, %v, %v), want (Text Editor, true, nil, nil)", app, showFullText, maxTreeNodes, maxTreeDepth)+ }++ app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Text Editor"})if err != nil {t.Fatal(err)}- if app != "Text Editor" || !showFullText {- t.Fatalf("parseSnapshotArgs = (%q, %v), want (Text Editor, true)", app, showFullText)+ if app != "Text Editor" || showFullText || maxTreeNodes != nil || maxTreeDepth != nil {+ t.Fatalf("parseSnapshotArgs default = (%q, %v, %v, %v), want (Text Editor, false, nil, nil)", app, showFullText, maxTreeNodes, maxTreeDepth)}- app, showFullText, err = parseSnapshotArgs([]string{"Text Editor"})+ app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"--max-tree-nodes", "3000", "--max-tree-depth", "96", "Text Editor"})if err != nil {t.Fatal(err)}- if app != "Text Editor" || showFullText {- t.Fatalf("parseSnapshotArgs default = (%q, %v), want (Text Editor, false)", app, showFullText)+ if app != "Text Editor" || showFullText || maxTreeNodes == nil || *maxTreeNodes != 3000 || maxTreeDepth == nil || *maxTreeDepth != 96 {+ t.Fatalf("parseSnapshotArgs custom tree budget = (%q, %v, %v, %v), want (Text Editor, false, 3000, 96)", app, showFullText, maxTreeNodes, maxTreeDepth)+ }+}++func TestParseSnapshotArgsRejectsInvalidTreeBudget(t *testing.T) {+ if _, _, _, _, err := parseSnapshotArgs([]string{"--max-tree-nodes", "0", "Text Editor"}); err == nil || err.Error() != "--max-tree-nodes must be a positive integer" {+ t.Fatalf("invalid max_tree_nodes error = %v", err)+ }+ if _, _, _, _, err := parseSnapshotArgs([]string{"--max-tree-depth", "1.5", "Text Editor"}); err == nil || err.Error() != "--max-tree-depth must be a positive integer" {+ t.Fatalf("invalid max_tree_depth error = %v", err)+ }+ if _, _, _, _, err := parseSnapshotArgs([]string{"--max-tree-nodes"}); err == nil || err.Error() != "--max-tree-nodes requires a positive integer value" {+ t.Fatalf("missing max_tree_nodes error = %v", err)}}@@ -143,6 +177,12 @@ func TestLinuxRuntimeTextLimitSupportsFullTextMode(t *testing.T) {if !strings.Contains(linuxRuntimeScript, "show_full_text=bool(operation.get(\"show_full_text\", False))") {t.Fatal("Linux get_app_state should pass show_full_text into snapshot rendering")}+ if !strings.Contains(linuxRuntimeScript, "max_tree_nodes=positive_int(operation.get(\"max_tree_nodes\"), MAX_ELEMENTS)") {+ t.Fatal("Linux get_app_state should pass max_tree_nodes into snapshot rendering")+ }+ if !strings.Contains(linuxRuntimeScript, "max_tree_depth=positive_int(operation.get(\"max_tree_depth\"), MAX_DEPTH)") {+ t.Fatal("Linux get_app_state should pass max_tree_depth into snapshot rendering")+ }if !strings.Contains(linuxRuntimeScript, "TEXT_CHARACTER_LIMIT + 1") {t.Fatal("Linux default truncation should read one extra character so it can append ellipsis")}diff --git a/apps/OpenComputerUseLinux/runtime.py b/apps/OpenComputerUseLinux/runtime.pyindex 32d8a82..60da30f 100644--- a/apps/OpenComputerUseLinux/runtime.py+++ b/apps/OpenComputerUseLinux/runtime.py@@ -244,6 +244,18 @@ def element_value(node, show_full_text=False):return text_value(node, show_full_text=show_full_text) or numeric_value(node)+def positive_int(value, fallback):+ if isinstance(value, bool):+ return fallback+ if isinstance(value, float) and not value.is_integer():+ return fallback+ try:+ integer = int(value)+ except (TypeError, ValueError):+ return fallback+ return integer if integer > 0 else fallback++def record_for(node, index, path, window_bounds, show_full_text=False):bounds = relative_frame(node, window_bounds)role = node_role(node)@@ -262,12 +274,12 @@ def record_for(node, index, path, window_bounds, show_full_text=False):}-def render_tree(root, window_bounds, root_path, show_full_text=False):+def render_tree(root, window_bounds, root_path, show_full_text=False, max_tree_nodes=MAX_ELEMENTS, max_tree_depth=MAX_DEPTH):records = []lines = []def visit(node, depth, path):- if len(records) >= MAX_ELEMENTS or depth > MAX_DEPTH or node is None:+ if len(records) >= max_tree_nodes or depth > max_tree_depth or node is None:returnindex = len(records)record = record_for(node, index, path, window_bounds, show_full_text=show_full_text)@@ -407,11 +419,18 @@ def selected_text(app_pid, show_full_text=False):return None-def build_snapshot(query, show_full_text=False):+def build_snapshot(query, show_full_text=False, max_tree_nodes=MAX_ELEMENTS, max_tree_depth=MAX_DEPTH):app = resolve_app(query)window_index, window = main_window(app)bounds = extents(window)- records, lines = render_tree(window, bounds, [window_index], show_full_text=show_full_text)+ records, lines = render_tree(+ window,+ bounds,+ [window_index],+ show_full_text=show_full_text,+ max_tree_nodes=max_tree_nodes,+ max_tree_depth=max_tree_depth,+ )pid = node_pid(app)return {"app": {@@ -749,6 +768,8 @@ def perform_operation(operation):"snapshot": build_snapshot(operation.get("app", ""),show_full_text=bool(operation.get("show_full_text", False)),+ max_tree_nodes=positive_int(operation.get("max_tree_nodes"), MAX_ELEMENTS),+ max_tree_depth=positive_int(operation.get("max_tree_depth"), MAX_DEPTH),),}diff --git a/apps/OpenComputerUseWindows/main.go b/apps/OpenComputerUseWindows/main.goindex fbff762..4c6bcb3 100644--- a/apps/OpenComputerUseWindows/main.go+++ b/apps/OpenComputerUseWindows/main.go@@ -149,6 +149,8 @@ type psRequest struct {Value string `json:"value,omitempty"`WindowBounds *frame `json:"windowBounds,omitempty"`ShowFullText bool `json:"show_full_text,omitempty"`+ MaxTreeNodes int `json:"max_tree_nodes,omitempty"`+ MaxTreeDepth int `json:"max_tree_depth,omitempty"`}type psResponse struct {@@ -171,7 +173,15 @@ func (s *service) callTool(name string, args map[string]any) toolCallResult {case "list_apps":return s.listApps()case "get_app_state":- return s.getAppState(requiredString(args, "app"), optionalBool(args, "show_full_text"))+ maxTreeNodes, err := optionalPositiveInt(args, "max_tree_nodes")+ if err != nil {+ return textResult(err.Error(), true)+ }+ maxTreeDepth, err := optionalPositiveInt(args, "max_tree_depth")+ if err != nil {+ return textResult(err.Error(), true)+ }+ return s.getAppState(requiredString(args, "app"), optionalBool(args, "show_full_text"), maxTreeNodes, maxTreeDepth)case "click":return s.click(requiredString(args, "app"),@@ -227,11 +237,18 @@ func (s *service) listApps() toolCallResult {return textResult(response.Text, false)}-func (s *service) getAppState(app string, showFullText bool) toolCallResult {+func (s *service) getAppState(app string, showFullText bool, maxTreeNodes, maxTreeDepth *int) toolCallResult {if app == "" {return textResult("Missing required argument: app", true)}- snapshot, result := s.refreshSnapshot(app, psRequest{Tool: "get_app_state", App: app, ShowFullText: showFullText})+ request := psRequest{Tool: "get_app_state", App: app, ShowFullText: showFullText}+ if maxTreeNodes != nil {+ request.MaxTreeNodes = *maxTreeNodes+ }+ if maxTreeDepth != nil {+ request.MaxTreeDepth = *maxTreeDepth+ }+ snapshot, result := s.refreshSnapshot(app, request)if result.IsError {return result}@@ -550,6 +567,58 @@ func optionalBool(args map[string]any, key string) bool {return value}+func optionalPositiveInt(args map[string]any, key string) (*int, error) {+ value, ok := args[key]+ if !ok {+ return nil, nil+ }+ return positiveIntFromValue(value, key)+}++func positiveIntFromValue(value any, key string) (*int, error) {+ switch typed := value.(type) {+ case int:+ return positiveIntFromInt64(int64(typed), key)+ case float64:+ if !isWholeNumber(typed) {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ return positiveIntFromFloat64(typed, key)+ case json.Number:+ integer, err := typed.Int64()+ if err != nil {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ return positiveIntFromInt64(integer, key)+ default:+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+}++func positiveIntFromFloat64(value float64, key string) (*int, error) {+ if !isWholeNumber(value) || value <= 0 || value > float64(maxInt()) {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ integer := int(value)+ return &integer, nil+}++func positiveIntFromInt64(value int64, key string) (*int, error) {+ if value <= 0 || value > int64(maxInt()) {+ return nil, fmt.Errorf("%s must be a positive integer", key)+ }+ integer := int(value)+ return &integer, nil+}++func isWholeNumber(value float64) bool {+ return !math.IsNaN(value) && !math.IsInf(value, 0) && math.Trunc(value) == value+}++func maxInt() int {+ return int(^uint(0) >> 1)+}+func intValue(value *float64, fallback int) int {if value == nil {return fallback@@ -605,6 +674,8 @@ func toolDefinitions() []toolDefinition {InputSchema: objectSchema(map[string]any{"app": stringProperty("App name or bundle identifier"),"show_full_text": booleanProperty("Return full accessibility text without the default 500 character truncation. Defaults to false."),+ "max_tree_nodes": positiveIntegerProperty("Maximum accessibility tree nodes to render. Defaults to 1200."),+ "max_tree_depth": positiveIntegerProperty("Maximum accessibility tree depth to render. Defaults to 64."),}, []string{"app"}),},{@@ -707,6 +778,10 @@ func integerProperty(description string) map[string]any {return map[string]any{"type": "integer", "description": description}}+func positiveIntegerProperty(description string) map[string]any {+ return map[string]any{"type": "integer", "minimum": 1, "description": description}+}+func main() {if err := runCLI(os.Args[1:], os.Stdout); err != nil {fmt.Fprintln(os.Stderr, err)@@ -744,14 +819,21 @@ func runCLI(args []string, stdout io.Writer) error {fmt.Fprintln(stdout, result.Content[0].Text)return nilcase "snapshot":- app, showFullText, err := parseSnapshotArgs(args[1:])+ app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs(args[1:])if err != nil {return err}- result := newService().callTool("get_app_state", map[string]any{+ toolArgs := map[string]any{"app": app,"show_full_text": showFullText,- })+ }+ if maxTreeNodes != nil {+ toolArgs["max_tree_nodes"] = *maxTreeNodes+ }+ if maxTreeDepth != nil {+ toolArgs["max_tree_depth"] = *maxTreeDepth+ }+ result := newService().callTool("get_app_state", toolArgs)if result.IsError {return errors.New(result.Content[0].Text)}@@ -776,27 +858,58 @@ func runCLI(args []string, stdout io.Writer) error {}}-func parseSnapshotArgs(args []string) (string, bool, error) {+func parseSnapshotArgs(args []string) (string, bool, *int, *int, error) {var app stringshowFullText := false- for _, arg := range args {+ var maxTreeNodes *int+ var maxTreeDepth *int+ for index := 0; index < len(args); index++ {+ arg := args[index]switch arg {case "--show-full-text":showFullText = true+ case "--max-tree-nodes":+ index+++ if index >= len(args) {+ return "", false, nil, nil, errors.New("--max-tree-nodes requires a positive integer value")+ }+ value, err := parsePositiveIntegerOption(args[index], "--max-tree-nodes")+ if err != nil {+ return "", false, nil, nil, err+ }+ maxTreeNodes = &value+ case "--max-tree-depth":+ index+++ if index >= len(args) {+ return "", false, nil, nil, errors.New("--max-tree-depth requires a positive integer value")+ }+ value, err := parsePositiveIntegerOption(args[index], "--max-tree-depth")+ if err != nil {+ return "", false, nil, nil, err+ }+ maxTreeDepth = &valuedefault:if strings.HasPrefix(arg, "-") {- return "", false, fmt.Errorf("unknown snapshot option: %s", arg)+ return "", false, nil, nil, fmt.Errorf("unknown snapshot option: %s", arg)}if app != "" {- return "", false, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")+ return "", false, nil, nil, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")}app = arg}}if app == "" {- return "", false, errors.New("snapshot requires an app name, process name, window title, or pid")+ return "", false, nil, nil, errors.New("snapshot requires an app name, process name, window title, or pid")+ }+ return app, showFullText, maxTreeNodes, maxTreeDepth, nil+}++func parsePositiveIntegerOption(value, option string) (int, error) {+ integer, err := strconv.Atoi(value)+ if err != nil || integer <= 0 {+ return 0, fmt.Errorf("%s must be a positive integer", option)}- return app, showFullText, nil+ return integer, nil}func runCallCommand(args []string, svc *service) (any, bool, error) {@@ -1029,7 +1142,7 @@ func helpText(command string) string {case "call":return "Usage:\n open-computer-use.exe call <tool> [--args '<json-object>']\n open-computer-use.exe call --calls '<json-array>'\n\nThe JSON array form keeps all calls in one process so element_index state can be reused.\n"case "snapshot":- return "Usage:\n open-computer-use.exe snapshot [--show-full-text] <app>\n\nPrint the current Windows UI Automation snapshot for the target app.\n"+ return "Usage:\n open-computer-use.exe snapshot [--show-full-text] [--max-tree-nodes <positive-int>] [--max-tree-depth <positive-int>] <app>\n\nPrint the current Windows UI Automation snapshot for the target app.\n"default:return `Open Computer Use for Windowsdiff --git a/apps/OpenComputerUseWindows/main_test.go b/apps/OpenComputerUseWindows/main_test.goindex 0739433..2e9dbe2 100644--- a/apps/OpenComputerUseWindows/main_test.go+++ b/apps/OpenComputerUseWindows/main_test.go@@ -20,6 +20,20 @@ func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {if got := showFullText["type"]; got != "boolean" {t.Fatalf("show_full_text type = %v, want boolean", got)}+ maxTreeNodes := properties["max_tree_nodes"].(map[string]any)+ if got := maxTreeNodes["type"]; got != "integer" {+ t.Fatalf("max_tree_nodes type = %v, want integer", got)+ }+ if got := maxTreeNodes["minimum"]; got != 1 {+ t.Fatalf("max_tree_nodes minimum = %v, want 1", got)+ }+ maxTreeDepth := properties["max_tree_depth"].(map[string]any)+ if got := maxTreeDepth["type"]; got != "integer" {+ t.Fatalf("max_tree_depth type = %v, want integer", got)+ }+ if got := maxTreeDepth["minimum"]; got != 1 {+ t.Fatalf("max_tree_depth minimum = %v, want 1", got)+ }required := tool.InputSchema["required"].([]string)if len(required) != 1 || required[0] != "app" {t.Fatalf("required = %#v, want [app]", required)@@ -27,20 +41,40 @@ func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {}func TestParseSnapshotArgsSupportsShowFullText(t *testing.T) {- app, showFullText, err := parseSnapshotArgs([]string{"--show-full-text", "Notepad"})+ app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs([]string{"--show-full-text", "Notepad"})if err != nil {t.Fatal(err)}- if app != "Notepad" || !showFullText {- t.Fatalf("parseSnapshotArgs = (%q, %v), want (Notepad, true)", app, showFullText)+ if app != "Notepad" || !showFullText || maxTreeNodes != nil || maxTreeDepth != nil {+ t.Fatalf("parseSnapshotArgs = (%q, %v, %v, %v), want (Notepad, true, nil, nil)", app, showFullText, maxTreeNodes, maxTreeDepth)}- app, showFullText, err = parseSnapshotArgs([]string{"Notepad"})+ app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Notepad"})if err != nil {t.Fatal(err)}- if app != "Notepad" || showFullText {- t.Fatalf("parseSnapshotArgs default = (%q, %v), want (Notepad, false)", app, showFullText)+ if app != "Notepad" || showFullText || maxTreeNodes != nil || maxTreeDepth != nil {+ t.Fatalf("parseSnapshotArgs default = (%q, %v, %v, %v), want (Notepad, false, nil, nil)", app, showFullText, maxTreeNodes, maxTreeDepth)+ }++ app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"--max-tree-nodes", "3000", "--max-tree-depth", "96", "Notepad"})+ if err != nil {+ t.Fatal(err)+ }+ if app != "Notepad" || showFullText || maxTreeNodes == nil || *maxTreeNodes != 3000 || maxTreeDepth == nil || *maxTreeDepth != 96 {+ t.Fatalf("parseSnapshotArgs custom tree budget = (%q, %v, %v, %v), want (Notepad, false, 3000, 96)", app, showFullText, maxTreeNodes, maxTreeDepth)+ }+}++func TestParseSnapshotArgsRejectsInvalidTreeBudget(t *testing.T) {+ if _, _, _, _, err := parseSnapshotArgs([]string{"--max-tree-nodes", "0", "Notepad"}); err == nil || err.Error() != "--max-tree-nodes must be a positive integer" {+ t.Fatalf("invalid max_tree_nodes error = %v", err)+ }+ if _, _, _, _, err := parseSnapshotArgs([]string{"--max-tree-depth", "1.5", "Notepad"}); err == nil || err.Error() != "--max-tree-depth must be a positive integer" {+ t.Fatalf("invalid max_tree_depth error = %v", err)+ }+ if _, _, _, _, err := parseSnapshotArgs([]string{"--max-tree-nodes"}); err == nil || err.Error() != "--max-tree-nodes requires a positive integer value" {+ t.Fatalf("missing max_tree_nodes error = %v", err)}}@@ -153,6 +187,9 @@ func TestWindowsRuntimeTextLimitSupportsFullTextMode(t *testing.T) {if !strings.Contains(windowsRuntimeScript, "Build-Snapshot $operation.app ([bool]$operation.show_full_text)") {t.Fatal("Windows get_app_state should pass show_full_text into snapshot rendering")}+ if !strings.Contains(windowsRuntimeScript, "([int]$operation.max_tree_nodes) ([int]$operation.max_tree_depth)") {+ t.Fatal("Windows get_app_state should pass tree budget into snapshot rendering")+ }if !strings.Contains(windowsRuntimeScript, "$maxLength = if ($ShowFullText) { -1 } else { $script:TextCharacterLimit + 1 }") {t.Fatal("Windows selected text should use full UIA text only in full-text mode")}@@ -165,7 +202,7 @@ func TestWindowsRuntimeTreeBudgetDefaultsMatchMacOS(t *testing.T) {if !strings.Contains(windowsRuntimeScript, "$AccessibilityTreeMaxDepth = 64") {t.Fatal("Windows runtime should default to the shared 64 level tree depth")}- if !strings.Contains(windowsRuntimeScript, "$script:nextIndex -ge $script:AccessibilityTreeMaxNodeCount -or $depth -gt $script:AccessibilityTreeMaxDepth") {+ if !strings.Contains(windowsRuntimeScript, "$script:nextIndex -ge $script:MaxTreeNodes -or $depth -gt $script:MaxTreeDepth") {t.Fatal("Windows runtime should use shared tree budget constants while rendering")}}diff --git a/apps/OpenComputerUseWindows/runtime.ps1 b/apps/OpenComputerUseWindows/runtime.ps1index 47c28b9..279f0d1 100644--- a/apps/OpenComputerUseWindows/runtime.ps1+++ b/apps/OpenComputerUseWindows/runtime.ps1@@ -474,14 +474,16 @@ function Get-ElementTitle($record) {return ""}-function Render-Tree($element, $windowBounds, [bool]$ShowFullText = $false) {+function Render-Tree($element, $windowBounds, [bool]$ShowFullText = $false, [int]$MaxTreeNodes = $script:AccessibilityTreeMaxNodeCount, [int]$MaxTreeDepth = $script:AccessibilityTreeMaxDepth) {$records = New-Object System.Collections.Generic.List[object]$lines = New-Object System.Collections.Generic.List[string]$visited = New-Object System.Collections.Generic.HashSet[string]$nextIndex = 0+ $effectiveMaxTreeNodes = if ($MaxTreeNodes -gt 0) { $MaxTreeNodes } else { $script:AccessibilityTreeMaxNodeCount }+ $effectiveMaxTreeDepth = if ($MaxTreeDepth -gt 0) { $MaxTreeDepth } else { $script:AccessibilityTreeMaxDepth }function Visit($node, [int]$depth) {- if ($script:nextIndex -ge $script:AccessibilityTreeMaxNodeCount -or $depth -gt $script:AccessibilityTreeMaxDepth) {+ if ($script:nextIndex -ge $script:MaxTreeNodes -or $depth -gt $script:MaxTreeDepth) {return}$runtime = ""@@ -529,6 +531,8 @@ function Render-Tree($element, $windowBounds, [bool]$ShowFullText = $false) {$script:visited = $visited$script:nextIndex = $nextIndex$script:windowBounds = $windowBounds+ $script:MaxTreeNodes = $effectiveMaxTreeNodes+ $script:MaxTreeDepth = $effectiveMaxTreeDepthVisit $element 0[pscustomobject]@{@@ -590,11 +594,11 @@ function Get-SelectedText($processId, [bool]$ShowFullText = $false) {return $null}-function Build-Snapshot([string]$query, [bool]$ShowFullText = $false) {+function Build-Snapshot([string]$query, [bool]$ShowFullText = $false, [int]$MaxTreeNodes = $script:AccessibilityTreeMaxNodeCount, [int]$MaxTreeDepth = $script:AccessibilityTreeMaxDepth) {$process = Resolve-App $query$element = Get-MainElement $process$bounds = Get-WindowBounds $process $element- $rendered = Render-Tree $element $bounds $ShowFullText+ $rendered = Render-Tree $element $bounds $ShowFullText $MaxTreeNodes $MaxTreeDepth[pscustomobject]@{app = [pscustomobject]@{name = $process.ProcessName@@ -877,7 +881,7 @@ try {if ($operation.tool -eq "list_apps") {$response = [pscustomobject]@{ ok = $true; text = (List-Apps) }} elseif ($operation.tool -eq "get_app_state") {- $response = [pscustomobject]@{ ok = $true; snapshot = (Build-Snapshot $operation.app ([bool]$operation.show_full_text)) }+ $response = [pscustomobject]@{ ok = $true; snapshot = (Build-Snapshot $operation.app ([bool]$operation.show_full_text) ([int]$operation.max_tree_nodes) ([int]$operation.max_tree_depth)) }} else {$process = Resolve-App $operation.app$hwnd = [IntPtr]$process.MainWindowHandlediff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 6127364..81f353a 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -62,7 +62,7 @@- `ComputerUseService` 负责把 Computer Use tool 请求映射到本地能力,`ComputerUseToolDispatcher` 则把 9 个 tool 的参数解析与 service 方法分发收敛成 MCP server 和 `open-computer-use call` 共用的一层。- `list_apps` 通过 Spotlight metadata query 拉取标准 application 目录里的 app bundle,并读取 `kMDItemUseCount` / `kMDItemLastUsedDate_Ranking` 这类系统元数据;再与 `NSWorkspace` 的运行态 app 合并,输出“当前运行中 + 近 14 天用过”的视图。-- `get_app_state` 优先走真实 AX / 窗口截图;真实 app 必须同时有未最小化的 `AXWindow` 和可匹配的 on-screen `CGWindow`。如果目标 app 只是隐藏或暂时没有 on-screen window,会先 best-effort unhide / activate / `open -b` / `AXRaise` 并短暂重试,以贴近官方 `computer-use` 会把 Lark / Electron 窗口拉回再采集的行为;恢复后仍无法匹配时返回官方风格的 `Apple event error -10005: cgWindowNotFound`,不再把 application 根节点或无截图窗口伪装成可操作状态。当目标是仓库内 fixture app 时,回退到 fixture 导出的合成状态。真实 AX tree 默认在 macOS、Linux、Windows 上最多渲染 1200 个节点、64 层深度;对 Electron/WebView 这类深层 UI 会压缩空 `AXGroup` / `AXUnknown` wrapper、过滤 `AXScrollToVisible` 噪音和空字符串属性,避免 action-critical 的输入框被无语义容器挤出节点预算;对原生 open panel / Finder column view 这类把内容放在 `AXContents` / `AXVisibleChildren` 里的控件,也会把可见文件项纳入元素树。+- `get_app_state` 优先走真实 AX / 窗口截图;真实 app 必须同时有未最小化的 `AXWindow` 和可匹配的 on-screen `CGWindow`。如果目标 app 只是隐藏或暂时没有 on-screen window,会先 best-effort unhide / activate / `open -b` / `AXRaise` 并短暂重试,以贴近官方 `computer-use` 会把 Lark / Electron 窗口拉回再采集的行为;恢复后仍无法匹配时返回官方风格的 `Apple event error -10005: cgWindowNotFound`,不再把 application 根节点或无截图窗口伪装成可操作状态。当目标是仓库内 fixture app 时,回退到 fixture 导出的合成状态。真实 AX tree 默认在 macOS、Linux、Windows 上最多渲染 1200 个节点、64 层深度;显式 `get_app_state` / `snapshot` 可通过 `max_tree_nodes` / `max_tree_depth` 覆盖预算,action tools 的刷新结果仍使用默认预算。对 Electron/WebView 这类深层 UI 会压缩空 `AXGroup` / `AXUnknown` wrapper、过滤 `AXScrollToVisible` 噪音和空字符串属性,避免 action-critical 的输入框被无语义容器挤出节点预算;对原生 open panel / Finder column view 这类把内容放在 `AXContents` / `AXVisibleChildren` 里的控件,也会把可见文件项纳入元素树。- MCP `tools/list` 的 description / input schema 当前按官方 `computer-use` 的 9 个 tools 文案和参数面收敛,尽量减少 host 侧提示词和 tool surface 偏差。- `open-computer-use call <tool> --args '{...}'` 会直接输出 MCP-style JSON result;`open-computer-use call --calls '[...]'` / `--calls-file <path>` 会在同一进程里顺序执行 JSON 数组里的 tool calls,并复用同一个 `ComputerUseService` 内存态,因此 `get_app_state` 之后的 action tool 可以继续使用同一轮 snapshot 的 `element_index`。序列执行默认会在成功的相邻操作之间 sleep 1 秒,也可以用 `--sleep <seconds>` 覆盖;遇到 `isError=true` 的 tool result 后停止。- 对真实 app 的 `get_app_state` / action tool 入口,当前只保留一层密码管理器 bundle denylist:bundle-id 直传时直接返回 safety denial;名称匹配时默认不解析到这些 app。终端、Chrome / Atlas 和系统组件不再属于内置阻止目标。@@ -119,7 +119,7 @@- Go runtime 通过 `go:embed` 带上 `runtime.py`,执行 tool call 时临时落盘并调用 `python3`。Python bridge 使用 GNOME/GObject Introspection 暴露的 AT-SPI2 接口做 app/window discovery、accessibility tree rendering、semantic action、editable text、value set,以及 best-effort 的 key/mouse fallback。- Linux 上最接近 macOS AX 的是 AT-SPI2/D-Bus accessibility,而不是一套统一的后台键鼠输入模型。第一版优先使用元素暴露的 AT-SPI action、EditableText 和 Value 接口;coordinate `click` / `drag` 与 `press_key` 使用 AT-SPI event synthesis fallback,在 Wayland 下只能按 best-effort 处理。- Linux runtime 需要运行在已登录桌面用户 session 里。缺少 `XDG_RUNTIME_DIR`、`DBUS_SESSION_BUS_ADDRESS` 或 display 环境时,Go runtime 会在启动 Python AT-SPI bridge 前尝试从 `/run/user/<uid>` 和常见桌面进程自动发现当前用户的 session bus、display / Wayland 值;纯 SSH tty 如果找不到已登录桌面 session,可以启动二进制,但不能直接 inspect 或操作 GUI session。-- `get_app_state` 的 accessibility tree 在 GTK/GNOME app 上可能很深,Linux bridge 使用与 macOS / Windows 一致的 1200 节点、64 层默认 tree budget。截图通过 GDK root window best-effort capture;GNOME Wayland 可能返回黑图,bridge 会检测全黑采样并省略 image block。+- `get_app_state` 的 accessibility tree 在 GTK/GNOME app 上可能很深,Linux bridge 使用与 macOS / Windows 一致的 1200 节点、64 层默认 tree budget,并支持显式提高 `max_tree_nodes` / `max_tree_depth`。截图通过 GDK root window best-effort capture;GNOME Wayland 可能返回黑图,bridge 会检测全黑采样并省略 image block。- 这 9 个 tool 的协议面与 macOS / Windows 保持一致:`list_apps`、`get_app_state`、`click`、`perform_secondary_action`、`scroll`、`drag`、`type_text`、`press_key`、`set_value`。其中 element-targeted action 会优先复用上一轮 `get_app_state` 的 runtime path metadata,coordinate action 使用 screenshot/window-relative 坐标。- 当前 Linux 侧仍是功能性第一版:没有 visual cursor overlay、没有 installer/desktop entry,也没有独立 Linux fixture。后续 TODO 记录在 `docs/exec-plans/active/20260422-linux-computer-use-runtime.md`。diff --git a/docs/histories/2026-06/20260630-1635-unify-snapshot-tree-budget-defaults.md b/docs/histories/2026-06/20260630-1635-unify-snapshot-tree-budget-defaults.mdindex a67cdc5..b818431 100644--- a/docs/histories/2026-06/20260630-1635-unify-snapshot-tree-budget-defaults.md+++ b/docs/histories/2026-06/20260630-1635-unify-snapshot-tree-budget-defaults.md@@ -27,3 +27,9 @@ The previous platform defaults had drifted: macOS used `1200/64`, Linux used `50- `apps/OpenComputerUseWindows/main_test.go`- `docs/ARCHITECTURE.md`- `skills/open-computer-use/references/troubleshooting.md`++### Follow-up: Configurable Tree Budgets++**[2026-06-30]** Added explicit `max_tree_nodes` / `max_tree_depth` tool arguments and `--max-tree-nodes` / `--max-tree-depth` CLI flags for `get_app_state` and `snapshot`.++The defaults remain `1200/64`, and action tools continue returning refreshed state with default budgets. The new parameters are for deliberate long page, long list, table, or web app inspection where the visible UI is larger than the default accessibility tree budget.diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swiftindex 8b7b6d9..58f49ee 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift@@ -37,8 +37,32 @@ enum SnapshotMode {case fixture}-let accessibilityTreeMaxNodeCount = 1200-let accessibilityTreeMaxDepth = 64+public struct AccessibilityTreeLimits: Equatable, Sendable {+ public static let defaultMaxNodeCount = 1200+ public static let defaultMaxDepth = 64+ public static let defaults = AccessibilityTreeLimits(+ maxNodeCount: defaultMaxNodeCount,+ maxDepth: defaultMaxDepth+ )++ public let maxNodeCount: Int+ public let maxDepth: Int++ public init(maxNodeCount: Int = defaultMaxNodeCount, maxDepth: Int = defaultMaxDepth) {+ self.maxNodeCount = maxNodeCount+ self.maxDepth = maxDepth+ }++ public func replacing(maxNodeCount: Int? = nil, maxDepth: Int? = nil) -> AccessibilityTreeLimits {+ AccessibilityTreeLimits(+ maxNodeCount: maxNodeCount ?? self.maxNodeCount,+ maxDepth: maxDepth ?? self.maxDepth+ )+ }+}++let accessibilityTreeMaxNodeCount = AccessibilityTreeLimits.defaultMaxNodeCount+let accessibilityTreeMaxDepth = AccessibilityTreeLimits.defaultMaxDepthlet screenshotCaptureTimeout: TimeInterval = 5let screenshotResultMaxPNGBytes = 900_000let screenshotResultMaxDimension: CGFloat = 1280@@ -95,7 +119,11 @@ public enum SnapshotTextStyle {}enum SnapshotBuilder {- static func build(for app: RunningAppDescriptor, showFullText: Bool = false) throws -> AppSnapshot {+ static func build(+ for app: RunningAppDescriptor,+ showFullText: Bool = false,+ treeLimits: AccessibilityTreeLimits = .defaults+ ) throws -> AppSnapshot {if app.name == FixtureBridge.appName, let fixtureState = try FixtureBridge.readState() {return buildFixtureSnapshot(app: app, state: fixtureState)}@@ -144,7 +172,8 @@ enum SnapshotBuilder {windowCapture: windowCapture,focusedApplication: focusedApplication,systemWide: systemWide,- showFullText: showFullText+ showFullText: showFullText,+ treeLimits: treeLimits)}@@ -156,7 +185,8 @@ enum SnapshotBuilder {windowCapture: WindowCapture,focusedApplication: AXUIElement?,systemWide: AXUIElement,- showFullText: Bool+ showFullText: Bool,+ treeLimits: AccessibilityTreeLimits) -> AppSnapshot {let windowBounds = windowCapture.boundslet screenshotPNGData = windowCapture.pngDataIfAvailable()@@ -166,7 +196,8 @@ enum SnapshotBuilder {let context = RenderContext(windowBounds: windowBounds,focusedElement: focusedElement,- textCharacterLimit: textCharacterLimit+ textCharacterLimit: textCharacterLimit,+ treeLimits: treeLimits)var renderer = TreeRenderer(context: context)@@ -599,6 +630,7 @@ private struct RenderContext {let windowBounds: CGRect?let focusedElement: AXUIElement?let textCharacterLimit: Int?+ let treeLimits: AccessibilityTreeLimits}private struct TreeRenderer {@@ -614,7 +646,7 @@ private struct TreeRenderer {}mutating func render(_ root: AXUIElement, depth: Int = 0, ancestors: [AXUIElement] = []) {- guard shouldContinueRendering(nextIndex: nextIndex, depth: depth) else {+ guard shouldContinueRendering(nextIndex: nextIndex, depth: depth, limits: context.treeLimits) else {return}@@ -788,7 +820,7 @@ private struct TreeRenderer {}private mutating func renderSyntheticText(_ text: String, representedBy element: AXUIElement, depth: Int) {- guard shouldContinueRendering(nextIndex: nextIndex, depth: depth) else {+ guard shouldContinueRendering(nextIndex: nextIndex, depth: depth, limits: context.treeLimits) else {return}@@ -896,8 +928,12 @@ private func shouldSkipChild(_ child: AXUIElement, of parent: AXUIElement) -> Boreturn stringValue(of: child, attribute: kAXTitleAttribute) == "Apple"}-func shouldContinueRendering(nextIndex: Int, depth: Int) -> Bool {- nextIndex < accessibilityTreeMaxNodeCount && depth < accessibilityTreeMaxDepth+func shouldContinueRendering(+ nextIndex: Int,+ depth: Int,+ limits: AccessibilityTreeLimits = .defaults+) -> Bool {+ nextIndex < limits.maxNodeCount && depth < limits.maxDepth}private func summarizeTraits(of element: AXUIElement) -> [String] {diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swiftindex c892773..08597b7 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift@@ -360,8 +360,12 @@ public final class ComputerUseService {)}- public func getAppState(app query: String, showFullText: Bool = false) throws -> ToolCallResult {- snapshotResult(for: try refreshSnapshot(for: query, showFullText: showFullText), style: .fullState)+ public func getAppState(+ app query: String,+ showFullText: Bool = false,+ treeLimits: AccessibilityTreeLimits = .defaults+ ) throws -> ToolCallResult {+ snapshotResult(for: try refreshSnapshot(for: query, showFullText: showFullText, treeLimits: treeLimits), style: .fullState)}public func click(app query: String, elementIndex: String?, x: Double?, y: Double?, clickCount: Int, mouseButton: String) throws -> ToolCallResult {@@ -655,9 +659,13 @@ public final class ComputerUseService {}@discardableResult- private func refreshSnapshot(for query: String, showFullText: Bool = false) throws -> AppSnapshot {+ private func refreshSnapshot(+ for query: String,+ showFullText: Bool = false,+ treeLimits: AccessibilityTreeLimits = .defaults+ ) throws -> AppSnapshot {let app = try AppDiscovery.resolve(query)- let snapshot = try SnapshotBuilder.build(for: app, showFullText: showFullText)+ let snapshot = try SnapshotBuilder.build(for: app, showFullText: showFullText, treeLimits: treeLimits)let keys = Set([query.lowercased(),diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swiftindex 892128f..227a7f1 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift@@ -50,7 +50,11 @@ public final class ComputerUseToolDispatcher {case "get_app_state":return try service.getAppState(app: requireString("app", in: arguments),- showFullText: optionalBool("show_full_text", in: arguments) ?? false+ showFullText: optionalBool("show_full_text", in: arguments) ?? false,+ treeLimits: AccessibilityTreeLimits.defaults.replacing(+ maxNodeCount: try optionalPositiveInt("max_tree_nodes", in: arguments),+ maxDepth: try optionalPositiveInt("max_tree_depth", in: arguments)+ ))case "click":return try service.click(@@ -178,6 +182,48 @@ public final class ComputerUseToolDispatcher {return nil}++ private func optionalPositiveInt(_ key: String, in arguments: [String: Any]) throws -> Int? {+ guard let value = arguments[key] else {+ return nil+ }++ if let integer = value as? Int {+ return try validatePositiveInt(integer, key: key)+ }++ if let double = value as? Double {+ return try validatePositiveWholeNumber(double, key: key)+ }++ if let number = value as? NSNumber {+ if CFGetTypeID(number as CFTypeRef) == CFBooleanGetTypeID() {+ throw ComputerUseError.invalidArguments("\(key) must be a positive integer")+ }+ return try validatePositiveWholeNumber(number.doubleValue, key: key)+ }++ throw ComputerUseError.invalidArguments("\(key) must be a positive integer")+ }++ private func validatePositiveWholeNumber(_ value: Double, key: String) throws -> Int {+ guard value.isFinite, value.rounded(.towardZero) == value else {+ throw ComputerUseError.invalidArguments("\(key) must be a positive integer")+ }++ guard value >= Double(Int.min), value <= Double(Int.max) else {+ throw ComputerUseError.invalidArguments("\(key) is outside the supported integer range")+ }++ return try validatePositiveInt(Int(value), key: key)+ }++ private func validatePositiveInt(_ value: Int, key: String) throws -> Int {+ guard value > 0 else {+ throw ComputerUseError.invalidArguments("\(key) must be a positive integer")+ }+ return value+ }}public struct OpenComputerUseCallSpec {diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swiftindex 24d90da..96e60c0 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift@@ -5,7 +5,7 @@ public enum OpenComputerUseCLICommand: Equatable {case mcpcase doctorcase listApps- case snapshot(app: String, showFullText: Bool = false)+ case snapshot(app: String, showFullText: Bool = false, treeLimits: AccessibilityTreeLimits = .defaults)case call(OpenComputerUseCallInvocation)case turnEnded(payload: String?)case help(command: String?)@@ -148,13 +148,15 @@ public func openComputerUseHelpText(command: String? = nil) -> String {case "snapshot":return """Usage:- open-computer-use snapshot [--show-full-text] <app>+ open-computer-use snapshot [--show-full-text] [--max-tree-nodes <positive-int>] [--max-tree-depth <positive-int>] <app>Arguments:<app> App name or bundle identifier to inspect.Options:--show-full-text Do not truncate accessibility text to 500 characters.+ --max-tree-nodes Override the default 1200 node accessibility tree budget.+ --max-tree-depth Override the default 64 level accessibility tree depth.Print the current accessibility snapshot for the target app."""@@ -274,11 +276,27 @@ private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLICommvar app: String?var showFullText = false+ var maxTreeNodes: Int?+ var maxTreeDepth: Int?- for argument in arguments {+ var index = 0+ while index < arguments.count {+ let argument = arguments[index]switch argument {case "--show-full-text":showFullText = true+ case "--max-tree-nodes":+ index += 1+ guard index < arguments.count else {+ throw OpenComputerUseCLIError(message: "--max-tree-nodes requires a positive integer value", helpCommand: "snapshot")+ }+ maxTreeNodes = try parsePositiveIntegerOption(arguments[index], option: "--max-tree-nodes")+ case "--max-tree-depth":+ index += 1+ guard index < arguments.count else {+ throw OpenComputerUseCLIError(message: "--max-tree-depth requires a positive integer value", helpCommand: "snapshot")+ }+ maxTreeDepth = try parsePositiveIntegerOption(arguments[index], option: "--max-tree-depth")case "-h", "--help":throw OpenComputerUseCLIError(message: "snapshot help must be requested as `open-computer-use snapshot --help`", helpCommand: "snapshot")default:@@ -292,13 +310,28 @@ private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLICommapp = argument}+ index += 1}guard let app else {throw OpenComputerUseCLIError(message: "snapshot requires an app name or bundle identifier", helpCommand: "snapshot")}- return .snapshot(app: app, showFullText: showFullText)+ return .snapshot(+ app: app,+ showFullText: showFullText,+ treeLimits: AccessibilityTreeLimits.defaults.replacing(+ maxNodeCount: maxTreeNodes,+ maxDepth: maxTreeDepth+ )+ )+}++private func parsePositiveIntegerOption(_ value: String, option: String) throws -> Int {+ guard let integer = Int(value), integer > 0 else {+ throw OpenComputerUseCLIError(message: "\(option) must be a positive integer", helpCommand: "snapshot")+ }+ return integer}private func parseCall(arguments: [String]) throws -> OpenComputerUseCLICommand {diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swiftindex e27e14f..caffc3b 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift@@ -72,6 +72,8 @@ public enum ToolDefinitions {properties: ["app": stringProperty(description: "App name or bundle identifier"),"show_full_text": booleanProperty(description: "Return full accessibility text without the default 500 character truncation. Defaults to false."),+ "max_tree_nodes": positiveIntegerProperty(description: "Maximum accessibility tree nodes to render. Defaults to 1200."),+ "max_tree_depth": positiveIntegerProperty(description: "Maximum accessibility tree depth to render. Defaults to 64."),],required: ["app"])@@ -206,6 +208,14 @@ private func integerProperty(description: String) -> [String: Any] {]}+private func positiveIntegerProperty(description: String) -> [String: Any] {+ [+ "type": "integer",+ "minimum": 1,+ "description": description,+ ]+}+private func numberProperty(description: String) -> [String: Any] {["type": "number",diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex 4691fc9..e52550d 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -88,6 +88,43 @@ final class OpenComputerUseKitTests: XCTestCase {try parseOpenComputerUseCLI(arguments: ["snapshot", "TextEdit", "--show-full-text"]),.snapshot(app: "TextEdit", showFullText: true))+ XCTAssertEqual(+ try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-nodes", "3000", "--max-tree-depth", "96", "TextEdit"]),+ .snapshot(+ app: "TextEdit",+ showFullText: false,+ treeLimits: AccessibilityTreeLimits(maxNodeCount: 3000, maxDepth: 96)+ )+ )+ XCTAssertEqual(+ try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-nodes", "3000", "TextEdit"]),+ .snapshot(+ app: "TextEdit",+ showFullText: false,+ treeLimits: AccessibilityTreeLimits(maxNodeCount: 3000, maxDepth: accessibilityTreeMaxDepth)+ )+ )+ }++ func testCLIRejectsInvalidSnapshotTreeBudget() {+ XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-nodes", "0", "TextEdit"])) { error in+ XCTAssertEqual(+ error as? OpenComputerUseCLIError,+ OpenComputerUseCLIError(message: "--max-tree-nodes must be a positive integer", helpCommand: "snapshot")+ )+ }+ XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-depth", "1.5", "TextEdit"])) { error in+ XCTAssertEqual(+ error as? OpenComputerUseCLIError,+ OpenComputerUseCLIError(message: "--max-tree-depth must be a positive integer", helpCommand: "snapshot")+ )+ }+ XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-nodes"])) { error in+ XCTAssertEqual(+ error as? OpenComputerUseCLIError,+ OpenComputerUseCLIError(message: "--max-tree-nodes requires a positive integer value", helpCommand: "snapshot")+ )+ }}func testCLIRejectsMixedCallSequenceInputs() {@@ -570,6 +607,10 @@ final class OpenComputerUseKitTests: XCTestCase {let getAppStateSchema = tools["get_app_state"]?.inputSchemalet getAppStateProperties = getAppStateSchema?["properties"] as? [String: [String: Any]]XCTAssertEqual(getAppStateProperties?["show_full_text"]?["type"] as? String, "boolean")+ XCTAssertEqual(getAppStateProperties?["max_tree_nodes"]?["type"] as? String, "integer")+ XCTAssertEqual(getAppStateProperties?["max_tree_nodes"]?["minimum"] as? Int, 1)+ XCTAssertEqual(getAppStateProperties?["max_tree_depth"]?["type"] as? String, "integer")+ XCTAssertEqual(getAppStateProperties?["max_tree_depth"]?["minimum"] as? Int, 1)XCTAssertEqual(getAppStateSchema?["required"] as? [String], ["app"])let scrollPages = (tools["scroll"]?.inputSchema["properties"] as? [String: [String: Any]])?["pages"]XCTAssertEqual(scrollPages?["type"] as? String, "number")@@ -861,6 +902,10 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertTrue(shouldContinueRendering(nextIndex: 1199, depth: 63))XCTAssertFalse(shouldContinueRendering(nextIndex: 1200, depth: 20))XCTAssertFalse(shouldContinueRendering(nextIndex: 120, depth: 64))+ let customLimits = AccessibilityTreeLimits(maxNodeCount: 3000, maxDepth: 96)+ XCTAssertTrue(shouldContinueRendering(nextIndex: 1200, depth: 64, limits: customLimits))+ XCTAssertFalse(shouldContinueRendering(nextIndex: 3000, depth: 20, limits: customLimits))+ XCTAssertFalse(shouldContinueRendering(nextIndex: 20, depth: 96, limits: customLimits))}func testAccessibilityRendererElidesEmptyGenericElectronWrappers() {diff --git a/skills/open-computer-use/SKILL.md b/skills/open-computer-use/SKILL.mdindex 42f9898..982428e 100644--- a/skills/open-computer-use/SKILL.md+++ b/skills/open-computer-use/SKILL.md@@ -20,10 +20,11 @@ It supports the same core tool surface across macOS, Linux, and Windows:3. Inspect available apps before acting: `open-computer-use call list_apps`.4. Capture current UI state with `open-computer-use call get_app_state --args '{"app":"TextEdit"}'`. The default state is usually enough for UI operation.5. When the task needs complete long text, such as chat history, email bodies, document text, or long form content, call `get_app_state` with `show_full_text: true`.-6. Prefer element-targeted actions using `element_index` from the latest `get_app_state` result.-7. For multi-step CLI work, use `open-computer-use call --calls '<json-array>'` so one process can reuse the latest element index mapping.-8. For agent runtimes that support local MCP servers, configure `open-computer-use mcp` or `ocu mcp` and call the exposed Computer Use tools directly. Read [references/usage.md](references/usage.md).-9. If communication, permission, or desktop-session access fails, read [references/troubleshooting.md](references/troubleshooting.md).+6. When visible long pages or lists appear incomplete even after scrolling, call `get_app_state` with a larger `max_tree_nodes` or `max_tree_depth`.+7. Prefer element-targeted actions using `element_index` from the latest `get_app_state` result.+8. For multi-step CLI work, use `open-computer-use call --calls '<json-array>'` so one process can reuse the latest element index mapping.+9. For agent runtimes that support local MCP servers, configure `open-computer-use mcp` or `ocu mcp` and call the exposed Computer Use tools directly. Read [references/usage.md](references/usage.md).+10. If communication, permission, or desktop-session access fails, read [references/troubleshooting.md](references/troubleshooting.md).## Operating Rules@@ -45,6 +46,7 @@ open-computer-use call list_appsocu call list_appsopen-computer-use call get_app_state --args '{"app":"TextEdit"}'open-computer-use call get_app_state --args '{"app":"TextEdit","show_full_text":true}'+open-computer-use call get_app_state --args '{"app":"Google Chrome","max_tree_nodes":3000,"max_tree_depth":96}'open-computer-use call click --args '{"app":"TextEdit","element_index":"0"}'open-computer-use call type_text --args '{"app":"TextEdit","text":"Hello from Open Computer Use"}'```diff --git a/skills/open-computer-use/references/troubleshooting.md b/skills/open-computer-use/references/troubleshooting.mdindex 9e0b6b3..43f7c3f 100644--- a/skills/open-computer-use/references/troubleshooting.md+++ b/skills/open-computer-use/references/troubleshooting.md@@ -50,6 +50,19 @@ open-computer-use snapshot --show-full-text TextEdit`show_full_text` only disables the text character limit. It does not remove the default 1200 node count limit, 64 level tree depth limit, screenshot size, permission, or desktop-session protections.+## Incomplete Long Pages Or Lists++If the screenshot clearly shows more visible content than the accessibility tree returns, the snapshot may have hit its default 1200 node or 64 level tree budget. Do not treat that as proof that the page failed to load.++Request a larger tree budget explicitly:++```sh+open-computer-use call get_app_state --args '{"app":"Google Chrome","max_tree_nodes":3000,"max_tree_depth":96}'+open-computer-use snapshot --max-tree-nodes 3000 --max-tree-depth 96 "Google Chrome"+```++Increasing the tree budget does not change text truncation, screenshot limits, permissions, or desktop-session requirements.+## Element Action FailsIf an element-targeted action fails:diff --git a/skills/open-computer-use/references/usage.md b/skills/open-computer-use/references/usage.mdindex 3e39bfc..8ce0ee9 100644--- a/skills/open-computer-use/references/usage.md+++ b/skills/open-computer-use/references/usage.md@@ -83,6 +83,19 @@ The same `show_full_text` tool argument and `--show-full-text` snapshot flag appAction tools return refreshed app state with the default 500 character text limit. If full text is still needed after an action, run `get_app_state` again with `show_full_text: true`.+## Larger Tree Budgets++Accessibility tree rendering defaults to 1200 nodes and 64 levels on macOS, Linux, and Windows. This keeps normal snapshots bounded while preserving most interactive UI.++Use a larger tree budget when a visible long page, list, table, or web app appears incomplete even after scrolling:++```sh+open-computer-use call get_app_state --args '{"app":"Google Chrome","max_tree_nodes":3000,"max_tree_depth":96}'+open-computer-use snapshot --max-tree-nodes 3000 --max-tree-depth 96 "Google Chrome"+```++`max_tree_nodes` and `max_tree_depth` must be positive integers. They only affect explicit `get_app_state` and `snapshot` calls; action tools still return refreshed state with the default tree budget.+## Choosing Targets- Prefer app names or bundle identifiers returned by `list_apps`.