Skip to content

👾 Open Computer Use – Open-Source Alternative to Codex Computer Use

feat(snapshot)!: 用 text_limit 替换全文开关

tisfeng0b613c339431
diff --git a/apps/OpenComputerUse/Sources/OpenComputerUse/MacOSAppAgentProxy.swift b/apps/OpenComputerUse/Sources/OpenComputerUse/MacOSAppAgentProxy.swift
index 4d9fc75..04cdd75 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, treeLimits):
+ case let .snapshot(app, textLimit, treeLimits):
let service = ComputerUseService()
- let text = try service.getAppState(app: app, showFullText: showFullText, treeLimits: treeLimits).primaryText ?? ""
+ let text = try service.getAppState(app: app, textLimit: textLimit, 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.swift
index f5a14f0..a323e02 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, treeLimits):
+ case let .snapshot(app, textLimit, treeLimits):
let service = ComputerUseService()
- print(try service.getAppState(app: app, showFullText: showFullText, treeLimits: treeLimits).primaryText ?? "")
+ print(try service.getAppState(app: app, textLimit: textLimit, 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.go
index ace0e67..61be7fd 100644
--- a/apps/OpenComputerUseLinux/main.go
+++ b/apps/OpenComputerUseLinux/main.go
@@ -151,11 +151,23 @@ type linuxRequest struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
WindowBounds *frame `json:"windowBounds,omitempty"`
- ShowFullText bool `json:"show_full_text,omitempty"`
+ TextLimit any `json:"text_limit,omitempty"`
MaxTreeNodes int `json:"max_tree_nodes,omitempty"`
MaxTreeDepth int `json:"max_tree_depth,omitempty"`
}
+type textLimit struct {
+ max bool
+ count int
+}
+
+func (limit textLimit) runtimeValue() any {
+ if limit.max {
+ return "max"
+ }
+ return limit.count
+}
+
type linuxResponse struct {
OK bool `json:"ok"`
Text string `json:"text,omitempty"`
@@ -184,7 +196,11 @@ func (s *service) callTool(name string, args map[string]any) toolCallResult {
if err != nil {
return textResult(err.Error(), true)
}
- return s.getAppState(requiredString(args, "app"), optionalBool(args, "show_full_text"), maxTreeNodes, maxTreeDepth)
+ textLimit, err := optionalTextLimit(args, "text_limit")
+ if err != nil {
+ return textResult(err.Error(), true)
+ }
+ return s.getAppState(requiredString(args, "app"), textLimit, maxTreeNodes, maxTreeDepth)
case "click":
return s.click(
requiredString(args, "app"),
@@ -240,11 +256,14 @@ func (s *service) listApps() toolCallResult {
return textResult(response.Text, false)
}
-func (s *service) getAppState(app string, showFullText bool, maxTreeNodes, maxTreeDepth *int) toolCallResult {
+func (s *service) getAppState(app string, textLimit *textLimit, maxTreeNodes, maxTreeDepth *int) toolCallResult {
if app == "" {
return textResult("Missing required argument: app", true)
}
- request := linuxRequest{Tool: "get_app_state", App: app, ShowFullText: showFullText}
+ request := linuxRequest{Tool: "get_app_state", App: app}
+ if textLimit != nil {
+ request.TextLimit = textLimit.runtimeValue()
+ }
if maxTreeNodes != nil {
request.MaxTreeNodes = *maxTreeNodes
}
@@ -979,9 +998,26 @@ func optionalFloat(args map[string]any, key string) *float64 {
return nil
}
-func optionalBool(args map[string]any, key string) bool {
- value, _ := args[key].(bool)
- return value
+func optionalTextLimit(args map[string]any, key string) (*textLimit, error) {
+ value, ok := args[key]
+ if !ok {
+ return nil, nil
+ }
+ return textLimitFromValue(value, key)
+}
+
+func textLimitFromValue(value any, key string) (*textLimit, error) {
+ if stringValue, ok := value.(string); ok {
+ if strings.EqualFold(stringValue, "max") {
+ return &textLimit{max: true}, nil
+ }
+ return nil, fmt.Errorf("%s must be a positive integer or max", key)
+ }
+ integer, err := positiveIntFromValue(value, key)
+ if err != nil {
+ return nil, fmt.Errorf("%s must be a positive integer or max", key)
+ }
+ return &textLimit{count: *integer}, nil
}
func optionalPositiveInt(args map[string]any, key string) (*int, error) {
@@ -1090,7 +1126,7 @@ func toolDefinitions() []toolDefinition {
Annotations: readOnlyAnnotations(),
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."),
+ "text_limit": textLimitProperty("Maximum text characters to return. Use \"max\" for full text. Defaults to 500."),
"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"}),
@@ -1177,10 +1213,6 @@ func stringProperty(description string) map[string]any {
return map[string]any{"type": "string", "description": description}
}
-func booleanProperty(description string) map[string]any {
- return map[string]any{"type": "boolean", "description": description}
-}
-
func enumStringProperty(description string, values []string) map[string]any {
property := stringProperty(description)
property["enum"] = values
@@ -1199,6 +1231,16 @@ func positiveIntegerProperty(description string) map[string]any {
return map[string]any{"type": "integer", "minimum": 1, "description": description}
}
+func textLimitProperty(description string) map[string]any {
+ return map[string]any{
+ "anyOf": []any{
+ map[string]any{"type": "integer", "minimum": 1},
+ map[string]any{"type": "string", "enum": []string{"max"}},
+ },
+ "description": description,
+ }
+}
+
func main() {
if err := runCLI(os.Args[1:], os.Stdout); err != nil {
fmt.Fprintln(os.Stderr, err)
@@ -1236,13 +1278,15 @@ func runCLI(args []string, stdout io.Writer) error {
fmt.Fprintln(stdout, result.Content[0].Text)
return nil
case "snapshot":
- app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs(args[1:])
+ app, textLimit, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs(args[1:])
if err != nil {
return err
}
toolArgs := map[string]any{
- "app": app,
- "show_full_text": showFullText,
+ "app": app,
+ }
+ if textLimit != nil {
+ toolArgs["text_limit"] = textLimit.runtimeValue()
}
if maxTreeNodes != nil {
toolArgs["max_tree_nodes"] = *maxTreeNodes
@@ -1275,50 +1319,69 @@ func runCLI(args []string, stdout io.Writer) error {
}
}
-func parseSnapshotArgs(args []string) (string, bool, *int, *int, error) {
+func parseSnapshotArgs(args []string) (string, *textLimit, *int, *int, error) {
var app string
- showFullText := false
+ var textLimit *textLimit
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 "--text-limit":
+ index++
+ if index >= len(args) {
+ return "", nil, nil, nil, errors.New("--text-limit requires a positive integer or max value")
+ }
+ value, err := parseTextLimitOption(args[index], "--text-limit")
+ if err != nil {
+ return "", nil, nil, nil, err
+ }
+ textLimit = value
case "--max-tree-nodes":
index++
if index >= len(args) {
- return "", false, nil, nil, errors.New("--max-tree-nodes requires a positive integer value")
+ return "", nil, 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
+ return "", nil, 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")
+ return "", nil, 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
+ return "", nil, nil, nil, err
}
maxTreeDepth = &value
default:
if strings.HasPrefix(arg, "-") {
- return "", false, nil, nil, fmt.Errorf("unknown snapshot option: %s", arg)
+ return "", nil, nil, nil, fmt.Errorf("unknown snapshot option: %s", arg)
}
if app != "" {
- return "", false, nil, nil, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")
+ return "", nil, nil, nil, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")
}
app = arg
}
}
if app == "" {
- return "", false, nil, nil, errors.New("snapshot requires an app name, process name, window title, or pid")
+ return "", nil, nil, nil, errors.New("snapshot requires an app name, process name, window title, or pid")
+ }
+ return app, textLimit, maxTreeNodes, maxTreeDepth, nil
+}
+
+func parseTextLimitOption(value, option string) (*textLimit, error) {
+ if strings.EqualFold(value, "max") {
+ return &textLimit{max: true}, nil
+ }
+ integer, err := strconv.Atoi(value)
+ if err != nil || integer <= 0 {
+ return nil, fmt.Errorf("%s must be a positive integer or max", option)
}
- return app, showFullText, maxTreeNodes, maxTreeDepth, nil
+ return &textLimit{count: integer}, nil
}
func parsePositiveIntegerOption(value, option string) (int, error) {
@@ -1559,7 +1622,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] [--max-tree-nodes <positive-int>] [--max-tree-depth <positive-int>] <app>\n\nPrint the current Linux AT-SPI snapshot for the target app.\n"
+ return "Usage:\n open-computer-use snapshot [--text-limit <positive-int|max>] [--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 Linux
diff --git a/apps/OpenComputerUseLinux/main_test.go b/apps/OpenComputerUseLinux/main_test.go
index c0fe229..f4124cb 100644
--- a/apps/OpenComputerUseLinux/main_test.go
+++ b/apps/OpenComputerUseLinux/main_test.go
@@ -16,12 +16,28 @@ func TestToolDefinitionCount(t *testing.T) {
}
}
-func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {
+func TestGetAppStateSchemaIncludesTextLimit(t *testing.T) {
tool := findToolDefinition(t, "get_app_state")
properties := tool.InputSchema["properties"].(map[string]any)
- showFullText := properties["show_full_text"].(map[string]any)
- if got := showFullText["type"]; got != "boolean" {
- t.Fatalf("show_full_text type = %v, want boolean", got)
+ if _, ok := properties["show_full_text"]; ok {
+ t.Fatal("get_app_state schema should not expose show_full_text")
+ }
+ textLimit := properties["text_limit"].(map[string]any)
+ anyOf := textLimit["anyOf"].([]any)
+ integerLimit := anyOf[0].(map[string]any)
+ if got := integerLimit["type"]; got != "integer" {
+ t.Fatalf("text_limit integer type = %v, want integer", got)
+ }
+ if got := integerLimit["minimum"]; got != 1 {
+ t.Fatalf("text_limit integer minimum = %v, want 1", got)
+ }
+ maxLimit := anyOf[1].(map[string]any)
+ if got := maxLimit["type"]; got != "string" {
+ t.Fatalf("text_limit max type = %v, want string", got)
+ }
+ enum := maxLimit["enum"].([]string)
+ if len(enum) != 1 || enum[0] != "max" {
+ t.Fatalf("text_limit enum = %#v, want [max]", enum)
}
maxTreeNodes := properties["max_tree_nodes"].(map[string]any)
if got := maxTreeNodes["type"]; got != "integer" {
@@ -43,29 +59,51 @@ func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {
}
}
-func TestParseSnapshotArgsSupportsShowFullText(t *testing.T) {
- app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs([]string{"--show-full-text", "Text Editor"})
+func TestParseSnapshotArgsSupportsTextLimit(t *testing.T) {
+ app, textLimit, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs([]string{"--text-limit", "1000", "Text Editor"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if app != "Text Editor" || textLimit == nil || textLimit.runtimeValue() != 1000 || maxTreeNodes != nil || maxTreeDepth != nil {
+ t.Fatalf("parseSnapshotArgs = (%q, %#v, %v, %v), want (Text Editor, 1000, nil, nil)", app, textLimit, maxTreeNodes, maxTreeDepth)
+ }
+
+ app, textLimit, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Text Editor", "--text-limit", "max"})
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)
+ if app != "Text Editor" || textLimit == nil || textLimit.runtimeValue() != "max" || maxTreeNodes != nil || maxTreeDepth != nil {
+ t.Fatalf("parseSnapshotArgs max = (%q, %#v, %v, %v), want (Text Editor, max, nil, nil)", app, textLimit, maxTreeNodes, maxTreeDepth)
}
- app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Text Editor"})
+ app, textLimit, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Text Editor"})
if err != nil {
t.Fatal(err)
}
- 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)
+ if app != "Text Editor" || textLimit != nil || maxTreeNodes != nil || maxTreeDepth != nil {
+ t.Fatalf("parseSnapshotArgs default = (%q, %#v, %v, %v), want (Text Editor, nil, nil, nil)", app, textLimit, maxTreeNodes, maxTreeDepth)
}
- app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"--max-tree-nodes", "3000", "--max-tree-depth", "96", "Text Editor"})
+ app, textLimit, 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 || 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)
+ if app != "Text Editor" || textLimit != nil || maxTreeNodes == nil || *maxTreeNodes != 3000 || maxTreeDepth == nil || *maxTreeDepth != 96 {
+ t.Fatalf("parseSnapshotArgs custom tree budget = (%q, %#v, %v, %v), want (Text Editor, nil, 3000, 96)", app, textLimit, maxTreeNodes, maxTreeDepth)
+ }
+}
+
+func TestParseSnapshotArgsRejectsInvalidTextLimit(t *testing.T) {
+ for _, value := range []string{"0", "-1", "1.5", "full"} {
+ if _, _, _, _, err := parseSnapshotArgs([]string{"--text-limit", value, "Text Editor"}); err == nil || err.Error() != "--text-limit must be a positive integer or max" {
+ t.Fatalf("invalid text_limit %q error = %v", value, err)
+ }
+ }
+ if _, _, _, _, err := parseSnapshotArgs([]string{"--text-limit"}); err == nil || err.Error() != "--text-limit requires a positive integer or max value" {
+ t.Fatalf("missing text_limit error = %v", err)
+ }
+ if _, _, _, _, err := parseSnapshotArgs([]string{"--show-full-text", "Text Editor"}); err == nil || err.Error() != "unknown snapshot option: --show-full-text" {
+ t.Fatalf("old show_full_text flag error = %v", err)
}
}
@@ -170,12 +208,15 @@ func TestLinuxRuntimeDocumentsATSPIAndFallbackBoundary(t *testing.T) {
}
}
-func TestLinuxRuntimeTextLimitSupportsFullTextMode(t *testing.T) {
- if !strings.Contains(linuxRuntimeScript, "TEXT_CHARACTER_LIMIT = 500") {
+func TestLinuxRuntimeTextLimitSupportsMaxMode(t *testing.T) {
+ if !strings.Contains(linuxRuntimeScript, "DEFAULT_TEXT_LIMIT = 500") {
t.Fatal("Linux runtime should define the shared 500 character text limit")
}
- 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, "text_limit=parse_text_limit(operation.get(\"text_limit\"), DEFAULT_TEXT_LIMIT)") {
+ t.Fatal("Linux get_app_state should pass text_limit into snapshot rendering")
+ }
+ if !strings.Contains(linuxRuntimeScript, "if isinstance(value, str) and value.lower() == \"max\"") {
+ t.Fatal("Linux runtime should support max text limit mode")
}
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")
@@ -183,7 +224,7 @@ func TestLinuxRuntimeTextLimitSupportsFullTextMode(t *testing.T) {
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") {
+ if !strings.Contains(linuxRuntimeScript, "text_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.py
index 60da30f..493e9af 100644
--- a/apps/OpenComputerUseLinux/runtime.py
+++ b/apps/OpenComputerUseLinux/runtime.py
@@ -26,7 +26,7 @@ from gi.repository import Atspi
MAX_ELEMENTS = 1200
MAX_DEPTH = 64
-TEXT_CHARACTER_LIMIT = 500
+DEFAULT_TEXT_LIMIT = 500
def frame(x, y, width, height):
@@ -79,12 +79,12 @@ def node_name(node):
return str(safe(node.get_name, "") or "")
-def limit_text(value, show_full_text=False):
+def limit_text(value, text_limit=DEFAULT_TEXT_LIMIT):
text = str(value or "")
- if show_full_text:
+ if text_limit is None:
return text
- if len(text) > TEXT_CHARACTER_LIMIT:
- return text[:TEXT_CHARACTER_LIMIT] + "..."
+ if len(text) > text_limit:
+ return text[:text_limit] + "..."
return text
@@ -216,7 +216,7 @@ def accessible_id(node):
return str(safe(node.get_accessible_id, "") or "")
-def text_value(node, show_full_text=False):
+def text_value(node, text_limit=DEFAULT_TEXT_LIMIT):
if not bool(safe(node.is_text, False)):
return ""
text_iface = safe(node.get_text_iface)
@@ -225,9 +225,9 @@ def text_value(node, show_full_text=False):
count = int(safe(lambda: Atspi.Text.get_character_count(text_iface), 0) or 0)
if count <= 0:
return ""
- end_offset = count if show_full_text else min(count, TEXT_CHARACTER_LIMIT + 1)
+ end_offset = count if text_limit is None else min(count, text_limit + 1)
value = str(safe(lambda: Atspi.Text.get_text(text_iface, 0, end_offset), "") or "")
- return limit_text(value, show_full_text=show_full_text)
+ return limit_text(value, text_limit=text_limit)
def numeric_value(node):
@@ -240,8 +240,8 @@ def numeric_value(node):
return str(current)
-def element_value(node, show_full_text=False):
- return text_value(node, show_full_text=show_full_text) or numeric_value(node)
+def element_value(node, text_limit=DEFAULT_TEXT_LIMIT):
+ return text_value(node, text_limit=text_limit) or numeric_value(node)
def positive_int(value, fallback):
@@ -256,25 +256,31 @@ def positive_int(value, fallback):
return integer if integer > 0 else fallback
-def record_for(node, index, path, window_bounds, show_full_text=False):
+def parse_text_limit(value, fallback=DEFAULT_TEXT_LIMIT):
+ if isinstance(value, str) and value.lower() == "max":
+ return None
+ return positive_int(value, fallback)
+
+
+def record_for(node, index, path, window_bounds, text_limit=DEFAULT_TEXT_LIMIT):
bounds = relative_frame(node, window_bounds)
role = node_role(node)
return {
"index": index,
"runtimeId": path[:],
"automationId": accessible_id(node),
- "name": limit_text(node_name(node), show_full_text=show_full_text),
+ "name": limit_text(node_name(node), text_limit=text_limit),
"controlType": role,
"localizedControlType": role,
"className": str(safe(node.get_toolkit_name, "") or ""),
- "value": element_value(node, show_full_text=show_full_text),
+ "value": element_value(node, text_limit=text_limit),
"nativeWindowHandle": 0,
"frame": bounds,
"actions": action_names(node),
}
-def render_tree(root, window_bounds, root_path, show_full_text=False, max_tree_nodes=MAX_ELEMENTS, max_tree_depth=MAX_DEPTH):
+def render_tree(root, window_bounds, root_path, text_limit=DEFAULT_TEXT_LIMIT, max_tree_nodes=MAX_ELEMENTS, max_tree_depth=MAX_DEPTH):
records = []
lines = []
@@ -282,7 +288,7 @@ def render_tree(root, window_bounds, root_path, show_full_text=False, max_tree_n
if len(records) >= max_tree_nodes or depth > max_tree_depth or node is None:
return
index = len(records)
- record = record_for(node, index, path, window_bounds, show_full_text=show_full_text)
+ record = record_for(node, index, path, window_bounds, text_limit=text_limit)
records.append(record)
role = record["localizedControlType"] or record["controlType"] or "element"
@@ -373,7 +379,7 @@ def pixbuf_looks_black(pixbuf):
return False
-def focused_summary(app_pid, show_full_text=False):
+def focused_summary(app_pid, text_limit=DEFAULT_TEXT_LIMIT):
try:
root = desktop()
for app in iter_apps():
@@ -386,13 +392,13 @@ def focused_summary(app_pid, show_full_text=False):
if focused is None:
return None
role = node_role(focused)
- name = limit_text(node_name(focused), show_full_text=show_full_text)
+ name = limit_text(node_name(focused), text_limit=text_limit)
return (role + " " + name).strip()
except Exception:
return None
-def selected_text(app_pid, show_full_text=False):
+def selected_text(app_pid, text_limit=DEFAULT_TEXT_LIMIT):
try:
for app in iter_apps():
if node_pid(app) != app_pid:
@@ -408,18 +414,18 @@ def selected_text(app_pid, show_full_text=False):
if selections:
selection = selections[0]
end_offset = selection.end_offset
- if not show_full_text:
- end_offset = min(end_offset, selection.start_offset + TEXT_CHARACTER_LIMIT + 1)
+ if text_limit is not None:
+ end_offset = min(end_offset, selection.start_offset + text_limit + 1)
value = Atspi.Text.get_text(
text_iface, selection.start_offset, end_offset
)
- return limit_text(value, show_full_text=show_full_text)
+ return limit_text(value, text_limit=text_limit)
except Exception:
return None
return None
-def build_snapshot(query, show_full_text=False, max_tree_nodes=MAX_ELEMENTS, max_tree_depth=MAX_DEPTH):
+def build_snapshot(query, text_limit=DEFAULT_TEXT_LIMIT, max_tree_nodes=MAX_ELEMENTS, max_tree_depth=MAX_DEPTH):
app = resolve_app(query)
window_index, window = main_window(app)
bounds = extents(window)
@@ -427,7 +433,7 @@ def build_snapshot(query, show_full_text=False, max_tree_nodes=MAX_ELEMENTS, max
window,
bounds,
[window_index],
- show_full_text=show_full_text,
+ text_limit=text_limit,
max_tree_nodes=max_tree_nodes,
max_tree_depth=max_tree_depth,
)
@@ -438,12 +444,12 @@ def build_snapshot(query, show_full_text=False, max_tree_nodes=MAX_ELEMENTS, max
"bundleIdentifier": node_name(app),
"pid": pid,
},
- "windowTitle": limit_text(node_name(window), show_full_text=show_full_text),
+ "windowTitle": limit_text(node_name(window), text_limit=text_limit),
"windowBounds": bounds,
"screenshotPngBase64": capture_window_png(bounds),
"treeLines": lines,
- "focusedSummary": focused_summary(pid, show_full_text=show_full_text),
- "selectedText": selected_text(pid, show_full_text=show_full_text),
+ "focusedSummary": focused_summary(pid, text_limit=text_limit),
+ "selectedText": selected_text(pid, text_limit=text_limit),
"elements": records,
}
@@ -767,7 +773,7 @@ def perform_operation(operation):
"ok": True,
"snapshot": build_snapshot(
operation.get("app", ""),
- show_full_text=bool(operation.get("show_full_text", False)),
+ text_limit=parse_text_limit(operation.get("text_limit"), DEFAULT_TEXT_LIMIT),
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.go
index 4c6bcb3..9ad50a9 100644
--- a/apps/OpenComputerUseWindows/main.go
+++ b/apps/OpenComputerUseWindows/main.go
@@ -148,11 +148,23 @@ type psRequest struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
WindowBounds *frame `json:"windowBounds,omitempty"`
- ShowFullText bool `json:"show_full_text,omitempty"`
+ TextLimit any `json:"text_limit,omitempty"`
MaxTreeNodes int `json:"max_tree_nodes,omitempty"`
MaxTreeDepth int `json:"max_tree_depth,omitempty"`
}
+type textLimit struct {
+ max bool
+ count int
+}
+
+func (limit textLimit) runtimeValue() any {
+ if limit.max {
+ return "max"
+ }
+ return limit.count
+}
+
type psResponse struct {
OK bool `json:"ok"`
Text string `json:"text,omitempty"`
@@ -181,7 +193,11 @@ func (s *service) callTool(name string, args map[string]any) toolCallResult {
if err != nil {
return textResult(err.Error(), true)
}
- return s.getAppState(requiredString(args, "app"), optionalBool(args, "show_full_text"), maxTreeNodes, maxTreeDepth)
+ textLimit, err := optionalTextLimit(args, "text_limit")
+ if err != nil {
+ return textResult(err.Error(), true)
+ }
+ return s.getAppState(requiredString(args, "app"), textLimit, maxTreeNodes, maxTreeDepth)
case "click":
return s.click(
requiredString(args, "app"),
@@ -237,11 +253,14 @@ func (s *service) listApps() toolCallResult {
return textResult(response.Text, false)
}
-func (s *service) getAppState(app string, showFullText bool, maxTreeNodes, maxTreeDepth *int) toolCallResult {
+func (s *service) getAppState(app string, textLimit *textLimit, maxTreeNodes, maxTreeDepth *int) toolCallResult {
if app == "" {
return textResult("Missing required argument: app", true)
}
- request := psRequest{Tool: "get_app_state", App: app, ShowFullText: showFullText}
+ request := psRequest{Tool: "get_app_state", App: app}
+ if textLimit != nil {
+ request.TextLimit = textLimit.runtimeValue()
+ }
if maxTreeNodes != nil {
request.MaxTreeNodes = *maxTreeNodes
}
@@ -562,9 +581,26 @@ func optionalFloat(args map[string]any, key string) *float64 {
return nil
}
-func optionalBool(args map[string]any, key string) bool {
- value, _ := args[key].(bool)
- return value
+func optionalTextLimit(args map[string]any, key string) (*textLimit, error) {
+ value, ok := args[key]
+ if !ok {
+ return nil, nil
+ }
+ return textLimitFromValue(value, key)
+}
+
+func textLimitFromValue(value any, key string) (*textLimit, error) {
+ if stringValue, ok := value.(string); ok {
+ if strings.EqualFold(stringValue, "max") {
+ return &textLimit{max: true}, nil
+ }
+ return nil, fmt.Errorf("%s must be a positive integer or max", key)
+ }
+ integer, err := positiveIntFromValue(value, key)
+ if err != nil {
+ return nil, fmt.Errorf("%s must be a positive integer or max", key)
+ }
+ return &textLimit{count: *integer}, nil
}
func optionalPositiveInt(args map[string]any, key string) (*int, error) {
@@ -673,7 +709,7 @@ func toolDefinitions() []toolDefinition {
Annotations: readOnlyAnnotations(),
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."),
+ "text_limit": textLimitProperty("Maximum text characters to return. Use \"max\" for full text. Defaults to 500."),
"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"}),
@@ -760,10 +796,6 @@ func stringProperty(description string) map[string]any {
return map[string]any{"type": "string", "description": description}
}
-func booleanProperty(description string) map[string]any {
- return map[string]any{"type": "boolean", "description": description}
-}
-
func enumStringProperty(description string, values []string) map[string]any {
property := stringProperty(description)
property["enum"] = values
@@ -782,6 +814,16 @@ func positiveIntegerProperty(description string) map[string]any {
return map[string]any{"type": "integer", "minimum": 1, "description": description}
}
+func textLimitProperty(description string) map[string]any {
+ return map[string]any{
+ "anyOf": []any{
+ map[string]any{"type": "integer", "minimum": 1},
+ map[string]any{"type": "string", "enum": []string{"max"}},
+ },
+ "description": description,
+ }
+}
+
func main() {
if err := runCLI(os.Args[1:], os.Stdout); err != nil {
fmt.Fprintln(os.Stderr, err)
@@ -819,13 +861,15 @@ func runCLI(args []string, stdout io.Writer) error {
fmt.Fprintln(stdout, result.Content[0].Text)
return nil
case "snapshot":
- app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs(args[1:])
+ app, textLimit, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs(args[1:])
if err != nil {
return err
}
toolArgs := map[string]any{
- "app": app,
- "show_full_text": showFullText,
+ "app": app,
+ }
+ if textLimit != nil {
+ toolArgs["text_limit"] = textLimit.runtimeValue()
}
if maxTreeNodes != nil {
toolArgs["max_tree_nodes"] = *maxTreeNodes
@@ -858,50 +902,69 @@ func runCLI(args []string, stdout io.Writer) error {
}
}
-func parseSnapshotArgs(args []string) (string, bool, *int, *int, error) {
+func parseSnapshotArgs(args []string) (string, *textLimit, *int, *int, error) {
var app string
- showFullText := false
+ var textLimit *textLimit
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 "--text-limit":
+ index++
+ if index >= len(args) {
+ return "", nil, nil, nil, errors.New("--text-limit requires a positive integer or max value")
+ }
+ value, err := parseTextLimitOption(args[index], "--text-limit")
+ if err != nil {
+ return "", nil, nil, nil, err
+ }
+ textLimit = value
case "--max-tree-nodes":
index++
if index >= len(args) {
- return "", false, nil, nil, errors.New("--max-tree-nodes requires a positive integer value")
+ return "", nil, 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
+ return "", nil, 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")
+ return "", nil, 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
+ return "", nil, nil, nil, err
}
maxTreeDepth = &value
default:
if strings.HasPrefix(arg, "-") {
- return "", false, nil, nil, fmt.Errorf("unknown snapshot option: %s", arg)
+ return "", nil, nil, nil, fmt.Errorf("unknown snapshot option: %s", arg)
}
if app != "" {
- return "", false, nil, nil, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")
+ return "", nil, nil, nil, errors.New("snapshot accepts exactly one app name, process name, window title, or pid")
}
app = arg
}
}
if app == "" {
- return "", false, nil, nil, errors.New("snapshot requires an app name, process name, window title, or pid")
+ return "", nil, nil, nil, errors.New("snapshot requires an app name, process name, window title, or pid")
+ }
+ return app, textLimit, maxTreeNodes, maxTreeDepth, nil
+}
+
+func parseTextLimitOption(value, option string) (*textLimit, error) {
+ if strings.EqualFold(value, "max") {
+ return &textLimit{max: true}, nil
+ }
+ integer, err := strconv.Atoi(value)
+ if err != nil || integer <= 0 {
+ return nil, fmt.Errorf("%s must be a positive integer or max", option)
}
- return app, showFullText, maxTreeNodes, maxTreeDepth, nil
+ return &textLimit{count: integer}, nil
}
func parsePositiveIntegerOption(value, option string) (int, error) {
@@ -1142,7 +1205,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] [--max-tree-nodes <positive-int>] [--max-tree-depth <positive-int>] <app>\n\nPrint the current Windows UI Automation snapshot for the target app.\n"
+ return "Usage:\n open-computer-use.exe snapshot [--text-limit <positive-int|max>] [--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 Windows
diff --git a/apps/OpenComputerUseWindows/main_test.go b/apps/OpenComputerUseWindows/main_test.go
index 2e9dbe2..816b610 100644
--- a/apps/OpenComputerUseWindows/main_test.go
+++ b/apps/OpenComputerUseWindows/main_test.go
@@ -13,12 +13,28 @@ func TestToolDefinitionCount(t *testing.T) {
}
}
-func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {
+func TestGetAppStateSchemaIncludesTextLimit(t *testing.T) {
tool := findToolDefinition(t, "get_app_state")
properties := tool.InputSchema["properties"].(map[string]any)
- showFullText := properties["show_full_text"].(map[string]any)
- if got := showFullText["type"]; got != "boolean" {
- t.Fatalf("show_full_text type = %v, want boolean", got)
+ if _, ok := properties["show_full_text"]; ok {
+ t.Fatal("get_app_state schema should not expose show_full_text")
+ }
+ textLimit := properties["text_limit"].(map[string]any)
+ anyOf := textLimit["anyOf"].([]any)
+ integerLimit := anyOf[0].(map[string]any)
+ if got := integerLimit["type"]; got != "integer" {
+ t.Fatalf("text_limit integer type = %v, want integer", got)
+ }
+ if got := integerLimit["minimum"]; got != 1 {
+ t.Fatalf("text_limit integer minimum = %v, want 1", got)
+ }
+ maxLimit := anyOf[1].(map[string]any)
+ if got := maxLimit["type"]; got != "string" {
+ t.Fatalf("text_limit max type = %v, want string", got)
+ }
+ enum := maxLimit["enum"].([]string)
+ if len(enum) != 1 || enum[0] != "max" {
+ t.Fatalf("text_limit enum = %#v, want [max]", enum)
}
maxTreeNodes := properties["max_tree_nodes"].(map[string]any)
if got := maxTreeNodes["type"]; got != "integer" {
@@ -40,29 +56,51 @@ func TestGetAppStateSchemaIncludesShowFullText(t *testing.T) {
}
}
-func TestParseSnapshotArgsSupportsShowFullText(t *testing.T) {
- app, showFullText, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs([]string{"--show-full-text", "Notepad"})
+func TestParseSnapshotArgsSupportsTextLimit(t *testing.T) {
+ app, textLimit, maxTreeNodes, maxTreeDepth, err := parseSnapshotArgs([]string{"--text-limit", "1000", "Notepad"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if app != "Notepad" || textLimit == nil || textLimit.runtimeValue() != 1000 || maxTreeNodes != nil || maxTreeDepth != nil {
+ t.Fatalf("parseSnapshotArgs = (%q, %#v, %v, %v), want (Notepad, 1000, nil, nil)", app, textLimit, maxTreeNodes, maxTreeDepth)
+ }
+
+ app, textLimit, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Notepad", "--text-limit", "max"})
if err != nil {
t.Fatal(err)
}
- if app != "Notepad" || !showFullText || maxTreeNodes != nil || maxTreeDepth != nil {
- t.Fatalf("parseSnapshotArgs = (%q, %v, %v, %v), want (Notepad, true, nil, nil)", app, showFullText, maxTreeNodes, maxTreeDepth)
+ if app != "Notepad" || textLimit == nil || textLimit.runtimeValue() != "max" || maxTreeNodes != nil || maxTreeDepth != nil {
+ t.Fatalf("parseSnapshotArgs max = (%q, %#v, %v, %v), want (Notepad, max, nil, nil)", app, textLimit, maxTreeNodes, maxTreeDepth)
}
- app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Notepad"})
+ app, textLimit, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"Notepad"})
if err != nil {
t.Fatal(err)
}
- 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)
+ if app != "Notepad" || textLimit != nil || maxTreeNodes != nil || maxTreeDepth != nil {
+ t.Fatalf("parseSnapshotArgs default = (%q, %#v, %v, %v), want (Notepad, nil, nil, nil)", app, textLimit, maxTreeNodes, maxTreeDepth)
}
- app, showFullText, maxTreeNodes, maxTreeDepth, err = parseSnapshotArgs([]string{"--max-tree-nodes", "3000", "--max-tree-depth", "96", "Notepad"})
+ app, textLimit, 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)
+ if app != "Notepad" || textLimit != nil || maxTreeNodes == nil || *maxTreeNodes != 3000 || maxTreeDepth == nil || *maxTreeDepth != 96 {
+ t.Fatalf("parseSnapshotArgs custom tree budget = (%q, %#v, %v, %v), want (Notepad, nil, 3000, 96)", app, textLimit, maxTreeNodes, maxTreeDepth)
+ }
+}
+
+func TestParseSnapshotArgsRejectsInvalidTextLimit(t *testing.T) {
+ for _, value := range []string{"0", "-1", "1.5", "full"} {
+ if _, _, _, _, err := parseSnapshotArgs([]string{"--text-limit", value, "Notepad"}); err == nil || err.Error() != "--text-limit must be a positive integer or max" {
+ t.Fatalf("invalid text_limit %q error = %v", value, err)
+ }
+ }
+ if _, _, _, _, err := parseSnapshotArgs([]string{"--text-limit"}); err == nil || err.Error() != "--text-limit requires a positive integer or max value" {
+ t.Fatalf("missing text_limit error = %v", err)
+ }
+ if _, _, _, _, err := parseSnapshotArgs([]string{"--show-full-text", "Notepad"}); err == nil || err.Error() != "unknown snapshot option: --show-full-text" {
+ t.Fatalf("old show_full_text flag error = %v", err)
}
}
@@ -180,18 +218,21 @@ func TestUTF8EncodingInPowerShellScript(t *testing.T) {
}
}
-func TestWindowsRuntimeTextLimitSupportsFullTextMode(t *testing.T) {
- if !strings.Contains(windowsRuntimeScript, "$TextCharacterLimit = 500") {
+func TestWindowsRuntimeTextLimitSupportsMaxMode(t *testing.T) {
+ if !strings.Contains(windowsRuntimeScript, "$DefaultTextLimit = 500") {
t.Fatal("Windows runtime should define the shared 500 character text limit")
}
- 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, "Build-Snapshot $operation.app (Resolve-TextLimit $operation.text_limit)") {
+ t.Fatal("Windows get_app_state should pass text_limit into snapshot rendering")
+ }
+ if !strings.Contains(windowsRuntimeScript, "$Value -is [string] -and $Value.Trim().ToLowerInvariant() -eq \"max\"") {
+ t.Fatal("Windows runtime should support max text limit mode")
}
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")
+ if !strings.Contains(windowsRuntimeScript, "$maxLength = if ($null -eq $TextLimit) { -1 } else { [int]$TextLimit + 1 }") {
+ t.Fatal("Windows selected text should use full UIA text only in max text mode")
}
}
diff --git a/apps/OpenComputerUseWindows/runtime.ps1 b/apps/OpenComputerUseWindows/runtime.ps1
index 279f0d1..bc2f16f 100644
--- a/apps/OpenComputerUseWindows/runtime.ps1
+++ b/apps/OpenComputerUseWindows/runtime.ps1
@@ -4,7 +4,7 @@ param(
)
$ErrorActionPreference = "Stop"
-$TextCharacterLimit = 500
+$DefaultTextLimit = 500
$AccessibilityTreeMaxNodeCount = 1200
$AccessibilityTreeMaxDepth = 64
@@ -418,20 +418,41 @@ function Get-ElementControlTypeName($element) {
}
}
-function Limit-Text([string]$Text, [bool]$ShowFullText = $false) {
+function Resolve-TextLimit($Value) {
+ if ($null -eq $Value) {
+ return $script:DefaultTextLimit
+ }
+ if ($Value -is [string] -and $Value.Trim().ToLowerInvariant() -eq "max") {
+ return $null
+ }
+ if ($Value -is [bool]) {
+ return $script:DefaultTextLimit
+ }
+ try {
+ $integer = [int]$Value
+ if ($integer -gt 0) {
+ return $integer
+ }
+ } catch {
+ }
+ return $script:DefaultTextLimit
+}
+
+function Limit-Text([string]$Text, $TextLimit = $script:DefaultTextLimit) {
if ($null -eq $Text) {
return ""
}
- if ($ShowFullText) {
+ if ($null -eq $TextLimit) {
return $Text
}
- if ($Text.Length -gt $script:TextCharacterLimit) {
- return $Text.Substring(0, $script:TextCharacterLimit) + "..."
+ $effectiveTextLimit = [int]$TextLimit
+ if ($Text.Length -gt $effectiveTextLimit) {
+ return $Text.Substring(0, $effectiveTextLimit) + "..."
}
return $Text
}
-function Get-ElementValue($element, [bool]$ShowFullText = $false) {
+function Get-ElementValue($element, $TextLimit = $script:DefaultTextLimit) {
try {
$valuePattern = $element.GetCurrentPattern([Windows.Automation.ValuePattern]::Pattern)
$value = $valuePattern.Current.Value
@@ -439,13 +460,13 @@ function Get-ElementValue($element, [bool]$ShowFullText = $false) {
return ""
}
$text = [string]$value
- return Limit-Text $text $ShowFullText
+ return Limit-Text $text $TextLimit
} catch {
return ""
}
}
-function Get-ElementRecord($element, [int]$index, $windowBounds, [bool]$ShowFullText = $false) {
+function Get-ElementRecord($element, [int]$index, $windowBounds, $TextLimit = $script:DefaultTextLimit) {
$frame = Get-ElementFrame $element $windowBounds
$runtimeId = @()
try { $runtimeId = @($element.GetRuntimeId()) } catch {}
@@ -453,11 +474,11 @@ function Get-ElementRecord($element, [int]$index, $windowBounds, [bool]$ShowFull
index = $index
runtimeId = $runtimeId
automationId = Get-ElementString $element "AutomationId"
- name = Limit-Text (Get-ElementString $element "Name") $ShowFullText
+ name = Limit-Text (Get-ElementString $element "Name") $TextLimit
controlType = Get-ElementControlTypeName $element
localizedControlType = Get-ElementString $element "LocalizedControlType"
className = Get-ElementString $element "ClassName"
- value = Get-ElementValue $element $ShowFullText
+ value = Get-ElementValue $element $TextLimit
nativeWindowHandle = Get-ElementInt64 $element "NativeWindowHandle"
frame = $frame
actions = @(Get-PatternNames $element)
@@ -474,7 +495,7 @@ function Get-ElementTitle($record) {
return ""
}
-function Render-Tree($element, $windowBounds, [bool]$ShowFullText = $false, [int]$MaxTreeNodes = $script:AccessibilityTreeMaxNodeCount, [int]$MaxTreeDepth = $script:AccessibilityTreeMaxDepth) {
+function Render-Tree($element, $windowBounds, $TextLimit = $script:DefaultTextLimit, [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]
@@ -494,7 +515,7 @@ function Render-Tree($element, $windowBounds, [bool]$ShowFullText = $false, [int
$index = $script:nextIndex
$script:nextIndex++
- $record = Get-ElementRecord $node $index $script:windowBounds $ShowFullText
+ $record = Get-ElementRecord $node $index $script:windowBounds $TextLimit
$script:records.Add($record)
$role = $record.localizedControlType
@@ -561,12 +582,12 @@ function Capture-WindowPngBase64($bounds) {
}
}
-function Get-FocusedSummary($processId, [bool]$ShowFullText = $false) {
+function Get-FocusedSummary($processId, $TextLimit = $script:DefaultTextLimit) {
try {
$focused = [Windows.Automation.AutomationElement]::FocusedElement
if ($null -ne $focused -and $focused.Current.ProcessId -eq $processId) {
$role = $focused.Current.LocalizedControlType
- $name = Limit-Text $focused.Current.Name $ShowFullText
+ $name = Limit-Text $focused.Current.Name $TextLimit
if ([string]::IsNullOrWhiteSpace($name)) {
return $role
}
@@ -577,7 +598,7 @@ function Get-FocusedSummary($processId, [bool]$ShowFullText = $false) {
return $null
}
-function Get-SelectedText($processId, [bool]$ShowFullText = $false) {
+function Get-SelectedText($processId, $TextLimit = $script:DefaultTextLimit) {
try {
$focused = [Windows.Automation.AutomationElement]::FocusedElement
if ($null -eq $focused -or $focused.Current.ProcessId -ne $processId) {
@@ -586,31 +607,31 @@ function Get-SelectedText($processId, [bool]$ShowFullText = $false) {
$textPattern = $focused.GetCurrentPattern([Windows.Automation.TextPattern]::Pattern)
$selection = $textPattern.GetSelection()
if ($selection.Count -gt 0) {
- $maxLength = if ($ShowFullText) { -1 } else { $script:TextCharacterLimit + 1 }
- return Limit-Text ($selection.Item(0).GetText($maxLength)) $ShowFullText
+ $maxLength = if ($null -eq $TextLimit) { -1 } else { [int]$TextLimit + 1 }
+ return Limit-Text ($selection.Item(0).GetText($maxLength)) $TextLimit
}
} catch {
}
return $null
}
-function Build-Snapshot([string]$query, [bool]$ShowFullText = $false, [int]$MaxTreeNodes = $script:AccessibilityTreeMaxNodeCount, [int]$MaxTreeDepth = $script:AccessibilityTreeMaxDepth) {
+function Build-Snapshot([string]$query, $TextLimit = $script:DefaultTextLimit, [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 $MaxTreeNodes $MaxTreeDepth
+ $rendered = Render-Tree $element $bounds $TextLimit $MaxTreeNodes $MaxTreeDepth
[pscustomobject]@{
app = [pscustomobject]@{
name = $process.ProcessName
bundleIdentifier = $process.ProcessName
pid = [int]$process.Id
}
- windowTitle = Limit-Text $process.MainWindowTitle $ShowFullText
+ windowTitle = Limit-Text $process.MainWindowTitle $TextLimit
windowBounds = $bounds
screenshotPngBase64 = Capture-WindowPngBase64 $bounds
treeLines = @($rendered.lines)
- focusedSummary = Get-FocusedSummary $process.Id $ShowFullText
- selectedText = Get-SelectedText $process.Id $ShowFullText
+ focusedSummary = Get-FocusedSummary $process.Id $TextLimit
+ selectedText = Get-SelectedText $process.Id $TextLimit
elements = @($rendered.records)
}
}
@@ -881,7 +902,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) ([int]$operation.max_tree_nodes) ([int]$operation.max_tree_depth)) }
+ $response = [pscustomobject]@{ ok = $true; snapshot = (Build-Snapshot $operation.app (Resolve-TextLimit $operation.text_limit) ([int]$operation.max_tree_nodes) ([int]$operation.max_tree_depth)) }
} else {
$process = Resolve-App $operation.app
$hwnd = [IntPtr]$process.MainWindowHandle
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 81f353a..dab42e5 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 层深度;显式 `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` 里的控件,也会把可见文件项纳入元素树。
+- `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 的刷新结果仍使用默认预算。snapshot 文本默认截断到 500 字符;显式 `get_app_state` / `snapshot` 可通过 `text_limit` 正整数或 `"max"` 覆盖,action tools 的刷新结果仍使用 500 字符默认值。对 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 和系统组件不再属于内置阻止目标。
diff --git a/docs/histories/2026-06/20260605-1640-unify-snapshot-text-limit.md b/docs/histories/2026-06/20260605-1640-unify-snapshot-text-limit.md
index fd98f27..afd5e01 100644
--- a/docs/histories/2026-06/20260605-1640-unify-snapshot-text-limit.md
+++ b/docs/histories/2026-06/20260605-1640-unify-snapshot-text-limit.md
@@ -39,3 +39,28 @@ Default truncation protects snapshot size and preserves upstream-compatible beha
- `skills/open-computer-use/SKILL.md`
- `skills/open-computer-use/references/usage.md`
- `skills/open-computer-use/references/troubleshooting.md`
+
+### Follow-up 2026-06-30
+
+**Scope:** Snapshot text-limit public API and agent-facing docs.
+
+**Key Actions:**
+- Replaced `show_full_text` / `--show-full-text` with the unified breaking API `text_limit` / `--text-limit`.
+- Kept the default text limit at 500 characters and preserved `...` when truncation happens.
+- Added support for `text_limit: "max"` and `--text-limit max` to request full accessibility text without project-level text truncation.
+- Kept action-tool refreshed state on the default 500 character text limit; custom `text_limit` applies only to explicit `get_app_state` and `snapshot`.
+- Updated skill docs and troubleshooting guidance so agents use `text_limit: 1000` for longer text or `text_limit: "max"` only when full text is required.
+
+**Files Modified:**
+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift`
+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift`
+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift`
+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift`
+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift`
+- `apps/OpenComputerUseLinux/main.go`
+- `apps/OpenComputerUseLinux/runtime.py`
+- `apps/OpenComputerUseWindows/main.go`
+- `apps/OpenComputerUseWindows/runtime.ps1`
+- `skills/open-computer-use/SKILL.md`
+- `skills/open-computer-use/references/usage.md`
+- `skills/open-computer-use/references/troubleshooting.md`
diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift
index 58f49ee..c7c78f5 100644
--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift
+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift
@@ -61,13 +61,32 @@ public struct AccessibilityTreeLimits: Equatable, Sendable {
}
}
+@usableFromInline
+let defaultTextLimit = 500
+
+public struct SnapshotTextLimit: Equatable, Sendable {
+ public static let maxKeyword = "max"
+ public static let defaults = SnapshotTextLimit(maxCount: defaultTextLimit)
+ public static let max = SnapshotTextLimit(maxCount: nil)
+
+ public let maxCount: Int?
+
+ public init(maxCount: Int = defaultTextLimit) {
+ precondition(maxCount > 0, "text limit must be positive")
+ self.maxCount = maxCount
+ }
+
+ private init(maxCount: Int?) {
+ self.maxCount = maxCount
+ }
+}
+
let accessibilityTreeMaxNodeCount = AccessibilityTreeLimits.defaultMaxNodeCount
let accessibilityTreeMaxDepth = AccessibilityTreeLimits.defaultMaxDepth
let screenshotCaptureTimeout: TimeInterval = 5
let screenshotResultMaxPNGBytes = 900_000
let screenshotResultMaxDimension: CGFloat = 1280
let screenshotResultMinScale: CGFloat = 0.25
-let snapshotTextDefaultCharacterLimit = 500
private let windowVisibilityRecoveryDelay: TimeInterval = 0.7
private let axWebAreaRole = "AXWebArea"
private let axContentsAttribute = "AXContents"
@@ -121,7 +140,7 @@ public enum SnapshotTextStyle {
enum SnapshotBuilder {
static func build(
for app: RunningAppDescriptor,
- showFullText: Bool = false,
+ textLimit: SnapshotTextLimit = .defaults,
treeLimits: AccessibilityTreeLimits = .defaults
) throws -> AppSnapshot {
if app.name == FixtureBridge.appName, let fixtureState = try FixtureBridge.readState() {
@@ -172,7 +191,7 @@ enum SnapshotBuilder {
windowCapture: windowCapture,
focusedApplication: focusedApplication,
systemWide: systemWide,
- showFullText: showFullText,
+ textLimit: textLimit,
treeLimits: treeLimits
)
}
@@ -185,18 +204,17 @@ enum SnapshotBuilder {
windowCapture: WindowCapture,
focusedApplication: AXUIElement?,
systemWide: AXUIElement,
- showFullText: Bool,
+ textLimit: SnapshotTextLimit,
treeLimits: AccessibilityTreeLimits
) -> AppSnapshot {
let windowBounds = windowCapture.bounds
let screenshotPNGData = windowCapture.pngDataIfAvailable()
let focusedElement = preferredFocusedElement(appElement: appElement, appPID: app.pid, focusedApplication: focusedApplication, systemWide: systemWide)
- let textCharacterLimit = showFullText ? nil : snapshotTextDefaultCharacterLimit
- let selectedText = focusedElement.flatMap { copySelectedText($0, characterLimit: textCharacterLimit) }
+ let selectedText = focusedElement.flatMap { copySelectedText($0, textLimit: textLimit) }
let context = RenderContext(
windowBounds: windowBounds,
focusedElement: focusedElement,
- textCharacterLimit: textCharacterLimit,
+ textLimit: textLimit,
treeLimits: treeLimits
)
@@ -629,7 +647,7 @@ enum BlockingAsyncBridge {
private struct RenderContext {
let windowBounds: CGRect?
let focusedElement: AXUIElement?
- let textCharacterLimit: Int?
+ let textLimit: SnapshotTextLimit
let treeLimits: AccessibilityTreeLimits
}
@@ -661,24 +679,24 @@ private struct TreeRenderer {
let subrole = stringValue(of: root, attribute: kAXSubroleAttribute)
let baseRoleText = roleDescription(of: root, role: role, subrole: subrole)
let label = stringValue(of: root, attribute: kAXDescriptionAttribute)
- .map { sanitizeText($0, characterLimit: context.textCharacterLimit) }
+ .map { sanitizeText($0, textLimit: context.textLimit) }
let help = stringValue(of: root, attribute: kAXHelpAttribute)
- .map { sanitizeText($0, characterLimit: context.textCharacterLimit) }
- let value = sanitizedValue(of: root, characterLimit: context.textCharacterLimit)
+ .map { sanitizeText($0, textLimit: context.textLimit) }
+ let value = sanitizedValue(of: root, textLimit: context.textLimit)
let axIdentifier = displayIdentifier(stringValue(of: root, attribute: kAXIdentifierAttribute))
let traits = summarizeTraits(of: root)
let actions = copyActions(root) ?? []
let prettyActions = meaningfulActions(actions, role: role)
- let placeholder = placeholderValue(of: root, characterLimit: context.textCharacterLimit)
+ let placeholder = placeholderValue(of: root, textLimit: context.textLimit)
let webAreaDepth = webAreaDepth(role: role, ancestors: ancestors)
let localFrame = resolveLocalFrame(of: root, windowBounds: context.windowBounds)
- let rowTexts = role == kAXRowRole as String ? flattenedRowTexts(of: root, characterLimit: context.textCharacterLimit) : []
+ let rowTexts = role == kAXRowRole as String ? flattenedRowTexts(of: root, textLimit: context.textLimit) : []
let childElements = children(of: root)
let genericTextSummary = summarizedGenericText(
of: root,
role: role,
childElements: childElements,
- characterLimit: context.textCharacterLimit
+ textLimit: context.textLimit
)
let summaryImageChildren = genericTextSummary == nil ? [] : summaryImageDescendants(of: root)
let rendersSummaryAsChildren = shouldRenderGenericTextSummaryAsChildren(
@@ -692,9 +710,9 @@ private struct TreeRenderer {
identifier: axIdentifier,
explicitValue: value,
rowTexts: rowTexts,
- characterLimit: context.textCharacterLimit
+ textLimit: context.textLimit
)
- let linkText = role == "AXLink" ? markdownLinkText(for: root, title: title, label: label, value: value, characterLimit: context.textCharacterLimit) : nil
+ let linkText = role == "AXLink" ? markdownLinkText(for: root, title: title, label: label, value: value, textLimit: context.textLimit) : nil
let displayTitle = linkText ?? title
let inlineRowSummary = outlineRowSummary(for: root, role: role)
let hidesChildren = shouldSuppressChildren(
@@ -741,7 +759,7 @@ private struct TreeRenderer {
let titleSegment = displayTitle.map { " \($0)" } ?? ""
let rowSummary = inlineRowSummary ?? (rendersSummaryAsChildren ? nil : genericTextSummary)
let rowSummarySegment = rowSummary.map { " \($0)" } ?? ""
- let labelSegment = formattedLabelSegment(label, title: displayTitle, linkText: linkText, characterLimit: context.textCharacterLimit)
+ let labelSegment = formattedLabelSegment(label, title: displayTitle, linkText: linkText, textLimit: context.textLimit)
let helpSegment = {
guard let help else {
return ""
@@ -751,7 +769,7 @@ private struct TreeRenderer {
}
return " Help: \(help)"
}()
- let urlSegment = formattedURLSegment(for: root, title: displayTitle, label: label, characterLimit: context.textCharacterLimit)
+ let urlSegment = formattedURLSegment(for: root, title: displayTitle, label: label, textLimit: context.textLimit)
let identifierSegment = displayIdentifierSegment(for: root, role: role, identifier: axIdentifier, title: displayTitle)
let rawValueSegment = formattedValueSegment(for: root, roleText: roleText, title: displayTitle, value: value)
let valueSegment = formattedValueSegmentWithSeparator(
@@ -1042,12 +1060,12 @@ private func stringValue(of element: AXUIElement, attribute: String) -> String?
return nil
}
-private func copySelectedText(_ element: AXUIElement, characterLimit: Int? = snapshotTextDefaultCharacterLimit) -> String? {
+private func copySelectedText(_ element: AXUIElement, textLimit: SnapshotTextLimit = .defaults) -> String? {
guard let value = stringValue(of: element, attribute: kAXSelectedTextAttribute) else {
return nil
}
- let sanitized = sanitizeText(value, characterLimit: characterLimit)
+ let sanitized = sanitizeText(value, textLimit: textLimit)
return sanitized.isEmpty ? nil : sanitized
}
@@ -1071,9 +1089,9 @@ private func isSettable(of element: AXUIElement, attribute: String) -> Bool {
return error == .success && settable.boolValue
}
-private func sanitizedValue(of element: AXUIElement, characterLimit: Int? = snapshotTextDefaultCharacterLimit) -> String? {
+private func sanitizedValue(of element: AXUIElement, textLimit: SnapshotTextLimit = .defaults) -> String? {
if let string = stringValue(of: element, attribute: kAXValueAttribute) {
- let sanitized = sanitizeText(string, characterLimit: characterLimit)
+ let sanitized = sanitizeText(string, textLimit: textLimit)
return sanitized.isEmpty ? nil : sanitized
}
@@ -1092,10 +1110,10 @@ private func sanitizedValue(of element: AXUIElement, characterLimit: Int? = snap
return nil
}
-private func placeholderValue(of element: AXUIElement, characterLimit: Int? = snapshotTextDefaultCharacterLimit) -> String? {
+private func placeholderValue(of element: AXUIElement, textLimit: SnapshotTextLimit = .defaults) -> String? {
for attribute in ["AXPlaceholderValue", "AXPlaceholder"] {
if let string = stringValue(of: element, attribute: attribute) {
- let sanitized = sanitizeText(string, characterLimit: characterLimit)
+ let sanitized = sanitizeText(string, textLimit: textLimit)
if !sanitized.isEmpty {
return sanitized
}
@@ -1133,10 +1151,10 @@ private func preferredDisplayTitle(
identifier: String?,
explicitValue: String?,
rowTexts: [String],
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String? {
if let title = stringValue(of: element, attribute: kAXTitleAttribute), !title.isEmpty {
- return sanitizeText(title, characterLimit: characterLimit)
+ return sanitizeText(title, textLimit: textLimit)
}
if role == kAXRowRole as String {
@@ -1148,18 +1166,18 @@ private func preferredDisplayTitle(
}
if (role == kAXButtonRole as String || role == kAXPopUpButtonRole as String), let label, !label.isEmpty {
- return sanitizeText(label, characterLimit: characterLimit)
+ return sanitizeText(label, textLimit: textLimit)
}
if role == kAXImageRole as String, let label, !label.isEmpty {
- return sanitizeText(label, characterLimit: characterLimit)
+ return sanitizeText(label, textLimit: textLimit)
}
if (role == kAXGroupRole as String || role == kAXUnknownRole as String || role == "AXWebArea"),
let label,
!label.isEmpty
{
- return sanitizeText(label, characterLimit: characterLimit)
+ return sanitizeText(label, textLimit: textLimit)
}
guard roleDescription(of: element, role: role, subrole: stringValue(of: element, attribute: kAXSubroleAttribute)) == "search text field" else {
@@ -1174,9 +1192,9 @@ private func markdownLinkText(
title: String?,
label: String?,
value: String?,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String? {
- guard let url = urlValue(of: element, attribute: kAXURLAttribute, characterLimit: characterLimit), !url.isEmpty else {
+ guard let url = urlValue(of: element, attribute: kAXURLAttribute, textLimit: textLimit), !url.isEmpty else {
return nil
}
@@ -1185,7 +1203,7 @@ private func markdownLinkText(
guard let candidate else {
return nil
}
- let sanitized = sanitizeText(candidate, characterLimit: characterLimit)
+ let sanitized = sanitizeText(candidate, textLimit: textLimit)
return sanitized.isEmpty ? nil : sanitized
}
.first
@@ -1249,13 +1267,13 @@ func formattedLabelSegment(
_ label: String?,
title: String?,
linkText: String?,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String {
guard let label, label != title else {
return ""
}
- let sanitizedLabel = sanitizeText(label, characterLimit: characterLimit)
+ let sanitizedLabel = sanitizeText(label, textLimit: textLimit)
guard !sanitizedLabel.isEmpty, sanitizedLabel != title else {
return ""
}
@@ -1305,13 +1323,13 @@ private func formattedURLSegment(
for element: AXUIElement,
title: String?,
label: String?,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String {
guard stringValue(of: element, attribute: kAXRoleAttribute) == "AXWebArea" else {
return ""
}
- guard let url = urlValue(of: element, attribute: kAXURLAttribute, characterLimit: characterLimit), !url.isEmpty else {
+ guard let url = urlValue(of: element, attribute: kAXURLAttribute, textLimit: textLimit), !url.isEmpty else {
return ""
}
@@ -1325,19 +1343,19 @@ private func formattedURLSegment(
private func urlValue(
of element: AXUIElement,
attribute: String,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String? {
guard let value = attributeValue(of: element, attribute: attribute) else {
return nil
}
if CFGetTypeID(value) == CFStringGetTypeID(), let string = value as? String {
- let sanitized = sanitizeText(string, characterLimit: characterLimit)
+ let sanitized = sanitizeText(string, textLimit: textLimit)
return sanitized.isEmpty ? nil : sanitized
}
if CFGetTypeID(value) == CFURLGetTypeID(), let url = value as? URL {
- let sanitized = sanitizeText(url.absoluteString, characterLimit: characterLimit)
+ let sanitized = sanitizeText(url.absoluteString, textLimit: textLimit)
return sanitized.isEmpty ? nil : sanitized
}
@@ -1470,7 +1488,7 @@ private func summarizedGenericText(
of element: AXUIElement,
role: String,
childElements: [AXUIElement],
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String? {
guard role == kAXGroupRole as String || role == kAXUnknownRole as String else {
return nil
@@ -1484,7 +1502,7 @@ private func summarizedGenericText(
return nil
}
- let texts = descendantTextsForSummary(of: element, characterLimit: characterLimit)
+ let texts = descendantTextsForSummary(of: element, textLimit: textLimit)
guard texts.count >= 2 else {
return nil
}
@@ -1493,7 +1511,7 @@ private func summarizedGenericText(
return nil
}
- let joined = sanitizeText(texts.joined(separator: " "), characterLimit: characterLimit)
+ let joined = sanitizeText(texts.joined(separator: " "), textLimit: textLimit)
.replacingOccurrences(of: " : ", with: " : ")
return joined.isEmpty ? nil : joined
}
@@ -1715,13 +1733,13 @@ private func splitCamelCase(_ value: String) -> String {
return result
}
-func sanitizeText(_ value: String, characterLimit: Int? = snapshotTextDefaultCharacterLimit) -> String {
+func sanitizeText(_ value: String, textLimit: SnapshotTextLimit = .defaults) -> String {
let collapsed = value
.replacingOccurrences(of: "\n", with: "\\n")
.trimmingCharacters(in: .whitespacesAndNewlines)
- if let characterLimit, characterLimit >= 0, collapsed.count > characterLimit {
- return String(collapsed.prefix(characterLimit)) + "..."
+ if let maxCount = textLimit.maxCount, collapsed.count > maxCount {
+ return String(collapsed.prefix(maxCount)) + "..."
}
return collapsed
@@ -1729,12 +1747,12 @@ func sanitizeText(_ value: String, characterLimit: Int? = snapshotTextDefaultCha
private func flattenedRowTexts(
of element: AXUIElement,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> [String] {
let cells = copyArray(element, attribute: kAXChildrenAttribute) ?? []
let texts = cells
- .flatMap { descendantTexts(of: $0, characterLimit: characterLimit) }
- .map { sanitizeText($0, characterLimit: characterLimit) }
+ .flatMap { descendantTexts(of: $0, textLimit: textLimit) }
+ .map { sanitizeText($0, textLimit: textLimit) }
.filter { !$0.isEmpty }
var unique: [String] = []
@@ -1751,7 +1769,7 @@ private func flattenedRowTexts(
private func descendantTexts(
of element: AXUIElement,
depth: Int = 0,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> [String] {
guard depth < 4 else {
return []
@@ -1760,15 +1778,15 @@ private func descendantTexts(
var values: [String] = []
let role = stringValue(of: element, attribute: kAXRoleAttribute) ?? ""
if role == kAXStaticTextRole as String || role == kAXTextFieldRole as String {
- if let value = sanitizedValue(of: element, characterLimit: characterLimit) {
+ if let value = sanitizedValue(of: element, textLimit: textLimit) {
values.append(value)
} else if let title = stringValue(of: element, attribute: kAXTitleAttribute) {
- values.append(sanitizeText(title, characterLimit: characterLimit))
+ values.append(sanitizeText(title, textLimit: textLimit))
}
}
for child in copyArray(element, attribute: kAXChildrenAttribute) ?? [] {
- values.append(contentsOf: descendantTexts(of: child, depth: depth + 1, characterLimit: characterLimit))
+ values.append(contentsOf: descendantTexts(of: child, depth: depth + 1, textLimit: textLimit))
}
return values
@@ -1777,44 +1795,44 @@ private func descendantTexts(
private func descendantTextsForSummary(
of element: AXUIElement,
depth: Int = 0,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> [String] {
guard depth < 8 else {
return []
}
let role = stringValue(of: element, attribute: kAXRoleAttribute) ?? ""
- if role == "AXLink", let linkText = summaryTextForLink(element, characterLimit: characterLimit) {
+ if role == "AXLink", let linkText = summaryTextForLink(element, textLimit: textLimit) {
return [linkText]
}
if role == kAXStaticTextRole as String || role == kAXTextFieldRole as String {
- if let value = sanitizedValue(of: element, characterLimit: characterLimit), !value.isEmpty {
+ if let value = sanitizedValue(of: element, textLimit: textLimit), !value.isEmpty {
return [value]
}
if let title = stringValue(of: element, attribute: kAXTitleAttribute) {
- let sanitized = sanitizeText(title, characterLimit: characterLimit)
+ let sanitized = sanitizeText(title, textLimit: textLimit)
return sanitized.isEmpty ? [] : [sanitized]
}
}
return (copyArray(element, attribute: kAXChildrenAttribute) ?? [])
- .flatMap { descendantTextsForSummary(of: $0, depth: depth + 1, characterLimit: characterLimit) }
+ .flatMap { descendantTextsForSummary(of: $0, depth: depth + 1, textLimit: textLimit) }
}
private func summaryTextForLink(
_ element: AXUIElement,
- characterLimit: Int? = snapshotTextDefaultCharacterLimit
+ textLimit: SnapshotTextLimit = .defaults
) -> String? {
- guard let url = urlValue(of: element, attribute: kAXURLAttribute, characterLimit: characterLimit), !url.isEmpty else {
+ guard let url = urlValue(of: element, attribute: kAXURLAttribute, textLimit: textLimit), !url.isEmpty else {
return nil
}
let childText = (copyArray(element, attribute: kAXChildrenAttribute) ?? [])
- .flatMap { descendantTextsForSummary(of: $0, characterLimit: characterLimit) }
+ .flatMap { descendantTextsForSummary(of: $0, textLimit: textLimit) }
.joined(separator: " ")
- let sanitized = sanitizeText(childText, characterLimit: characterLimit)
+ let sanitized = sanitizeText(childText, textLimit: textLimit)
guard !sanitized.isEmpty else {
return nil
}
diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift
index 08597b7..310e6ae 100644
--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift
+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift
@@ -362,10 +362,10 @@ public final class ComputerUseService {
public func getAppState(
app query: String,
- showFullText: Bool = false,
+ textLimit: SnapshotTextLimit = .defaults,
treeLimits: AccessibilityTreeLimits = .defaults
) throws -> ToolCallResult {
- snapshotResult(for: try refreshSnapshot(for: query, showFullText: showFullText, treeLimits: treeLimits), style: .fullState)
+ snapshotResult(for: try refreshSnapshot(for: query, textLimit: textLimit, treeLimits: treeLimits), style: .fullState)
}
public func click(app query: String, elementIndex: String?, x: Double?, y: Double?, clickCount: Int, mouseButton: String) throws -> ToolCallResult {
@@ -661,11 +661,11 @@ public final class ComputerUseService {
@discardableResult
private func refreshSnapshot(
for query: String,
- showFullText: Bool = false,
+ textLimit: SnapshotTextLimit = .defaults,
treeLimits: AccessibilityTreeLimits = .defaults
) throws -> AppSnapshot {
let app = try AppDiscovery.resolve(query)
- let snapshot = try SnapshotBuilder.build(for: app, showFullText: showFullText, treeLimits: treeLimits)
+ let snapshot = try SnapshotBuilder.build(for: app, textLimit: textLimit, treeLimits: treeLimits)
let keys = Set([
query.lowercased(),
diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift
index 227a7f1..7d87a23 100644
--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift
+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift
@@ -50,7 +50,7 @@ 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,
+ textLimit: try optionalTextLimit("text_limit", in: arguments) ?? .defaults,
treeLimits: AccessibilityTreeLimits.defaults.replacing(
maxNodeCount: try optionalPositiveInt("max_tree_nodes", in: arguments),
maxDepth: try optionalPositiveInt("max_tree_depth", in: arguments)
@@ -133,18 +133,20 @@ public final class ComputerUseToolDispatcher {
arguments[key] as? String
}
- private func optionalBool(_ key: String, in arguments: [String: Any]) -> Bool? {
- if let bool = arguments[key] as? Bool {
- return bool
+ private func optionalTextLimit(_ key: String, in arguments: [String: Any]) throws -> SnapshotTextLimit? {
+ guard let value = arguments[key] else {
+ return nil
}
- if let number = arguments[key] as? NSNumber,
- CFGetTypeID(number as CFTypeRef) == CFBooleanGetTypeID()
- {
- return number.boolValue
+ if let string = value as? String {
+ guard string.lowercased() == SnapshotTextLimit.maxKeyword else {
+ throw ComputerUseError.invalidArguments("\(key) must be a positive integer or max")
+ }
+ return .max
}
- return nil
+ let maxCount = try positiveInt(from: value, key: key, expectedDescription: "a positive integer or max")
+ return SnapshotTextLimit(maxCount: maxCount)
}
private func requireElementIndex(in arguments: [String: Any]) throws -> String {
@@ -188,39 +190,43 @@ public final class ComputerUseToolDispatcher {
return nil
}
+ return try positiveInt(from: value, key: key, expectedDescription: "a positive integer")
+ }
+
+ private func positiveInt(from value: Any, key: String, expectedDescription: String) throws -> Int {
if let integer = value as? Int {
- return try validatePositiveInt(integer, key: key)
+ return try validatePositiveInt(integer, key: key, expectedDescription: expectedDescription)
}
if let double = value as? Double {
- return try validatePositiveWholeNumber(double, key: key)
+ return try validatePositiveWholeNumber(double, key: key, expectedDescription: expectedDescription)
}
if let number = value as? NSNumber {
if CFGetTypeID(number as CFTypeRef) == CFBooleanGetTypeID() {
- throw ComputerUseError.invalidArguments("\(key) must be a positive integer")
+ throw ComputerUseError.invalidArguments("\(key) must be \(expectedDescription)")
}
- return try validatePositiveWholeNumber(number.doubleValue, key: key)
+ return try validatePositiveWholeNumber(number.doubleValue, key: key, expectedDescription: expectedDescription)
}
- throw ComputerUseError.invalidArguments("\(key) must be a positive integer")
+ throw ComputerUseError.invalidArguments("\(key) must be \(expectedDescription)")
}
- private func validatePositiveWholeNumber(_ value: Double, key: String) throws -> Int {
+ private func validatePositiveWholeNumber(_ value: Double, key: String, expectedDescription: String) throws -> Int {
guard value.isFinite, value.rounded(.towardZero) == value else {
- throw ComputerUseError.invalidArguments("\(key) must be a positive integer")
+ throw ComputerUseError.invalidArguments("\(key) must be \(expectedDescription)")
}
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)
+ return try validatePositiveInt(Int(value), key: key, expectedDescription: expectedDescription)
}
- private func validatePositiveInt(_ value: Int, key: String) throws -> Int {
+ private func validatePositiveInt(_ value: Int, key: String, expectedDescription: String) throws -> Int {
guard value > 0 else {
- throw ComputerUseError.invalidArguments("\(key) must be a positive integer")
+ throw ComputerUseError.invalidArguments("\(key) must be \(expectedDescription)")
}
return value
}
diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift
index 96e60c0..183b067 100644
--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift
+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift
@@ -5,7 +5,7 @@ public enum OpenComputerUseCLICommand: Equatable {
case mcp
case doctor
case listApps
- case snapshot(app: String, showFullText: Bool = false, treeLimits: AccessibilityTreeLimits = .defaults)
+ case snapshot(app: String, textLimit: SnapshotTextLimit = .defaults, treeLimits: AccessibilityTreeLimits = .defaults)
case call(OpenComputerUseCallInvocation)
case turnEnded(payload: String?)
case help(command: String?)
@@ -148,13 +148,13 @@ public func openComputerUseHelpText(command: String? = nil) -> String {
case "snapshot":
return """
Usage:
- open-computer-use snapshot [--show-full-text] [--max-tree-nodes <positive-int>] [--max-tree-depth <positive-int>] <app>
+ open-computer-use snapshot [--text-limit <positive-int|max>] [--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.
+ --text-limit Override the default 500 character text limit. Use `max` for full text.
--max-tree-nodes Override the default 1200 node accessibility tree budget.
--max-tree-depth Override the default 64 level accessibility tree depth.
@@ -275,7 +275,7 @@ private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLIComm
}
var app: String?
- var showFullText = false
+ var textLimit = SnapshotTextLimit.defaults
var maxTreeNodes: Int?
var maxTreeDepth: Int?
@@ -283,8 +283,12 @@ private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLIComm
while index < arguments.count {
let argument = arguments[index]
switch argument {
- case "--show-full-text":
- showFullText = true
+ case "--text-limit":
+ index += 1
+ guard index < arguments.count else {
+ throw OpenComputerUseCLIError(message: "--text-limit requires a positive integer or max value", helpCommand: "snapshot")
+ }
+ textLimit = try parseTextLimitOption(arguments[index], option: "--text-limit")
case "--max-tree-nodes":
index += 1
guard index < arguments.count else {
@@ -319,7 +323,7 @@ private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLIComm
return .snapshot(
app: app,
- showFullText: showFullText,
+ textLimit: textLimit,
treeLimits: AccessibilityTreeLimits.defaults.replacing(
maxNodeCount: maxTreeNodes,
maxDepth: maxTreeDepth
@@ -327,6 +331,17 @@ private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLIComm
)
}
+private func parseTextLimitOption(_ value: String, option: String) throws -> SnapshotTextLimit {
+ if value.lowercased() == SnapshotTextLimit.maxKeyword {
+ return .max
+ }
+
+ guard let integer = Int(value), integer > 0 else {
+ throw OpenComputerUseCLIError(message: "\(option) must be a positive integer or max", helpCommand: "snapshot")
+ }
+ return SnapshotTextLimit(maxCount: integer)
+}
+
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")
diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift
index caffc3b..7393438 100644
--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift
+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift
@@ -71,7 +71,7 @@ public enum ToolDefinitions {
inputSchema: objectSchema(
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."),
+ "text_limit": textLimitProperty(description: "Maximum text characters to return. Use \"max\" for full text. Defaults to 500."),
"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."),
],
@@ -194,24 +194,33 @@ private func stringProperty(description: String, enumValues: [String]? = nil) ->
return property
}
-private func booleanProperty(description: String) -> [String: Any] {
+private func integerProperty(description: String) -> [String: Any] {
[
- "type": "boolean",
+ "type": "integer",
"description": description,
]
}
-private func integerProperty(description: String) -> [String: Any] {
+private func positiveIntegerProperty(description: String) -> [String: Any] {
[
"type": "integer",
+ "minimum": 1,
"description": description,
]
}
-private func positiveIntegerProperty(description: String) -> [String: Any] {
+private func textLimitProperty(description: String) -> [String: Any] {
[
- "type": "integer",
- "minimum": 1,
+ "anyOf": [
+ [
+ "type": "integer",
+ "minimum": 1,
+ ],
+ [
+ "type": "string",
+ "enum": [SnapshotTextLimit.maxKeyword],
+ ],
+ ],
"description": description,
]
}
diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift
index e52550d..12334b4 100644
--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift
+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift
@@ -75,24 +75,23 @@ final class OpenComputerUseKitTests: XCTestCase {
}
}
- func testCLIRecognizesSnapshotFullTextFlag() throws {
+ func testCLIRecognizesSnapshotTextLimitFlag() throws {
XCTAssertEqual(
try parseOpenComputerUseCLI(arguments: ["snapshot", "TextEdit"]),
- .snapshot(app: "TextEdit", showFullText: false)
+ .snapshot(app: "TextEdit")
)
XCTAssertEqual(
- try parseOpenComputerUseCLI(arguments: ["snapshot", "--show-full-text", "TextEdit"]),
- .snapshot(app: "TextEdit", showFullText: true)
+ try parseOpenComputerUseCLI(arguments: ["snapshot", "--text-limit", "1000", "TextEdit"]),
+ .snapshot(app: "TextEdit", textLimit: SnapshotTextLimit(maxCount: 1000))
)
XCTAssertEqual(
- try parseOpenComputerUseCLI(arguments: ["snapshot", "TextEdit", "--show-full-text"]),
- .snapshot(app: "TextEdit", showFullText: true)
+ try parseOpenComputerUseCLI(arguments: ["snapshot", "TextEdit", "--text-limit", "max"]),
+ .snapshot(app: "TextEdit", textLimit: .max)
)
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)
)
)
@@ -100,12 +99,37 @@ final class OpenComputerUseKitTests: XCTestCase {
try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-nodes", "3000", "TextEdit"]),
.snapshot(
app: "TextEdit",
- showFullText: false,
treeLimits: AccessibilityTreeLimits(maxNodeCount: 3000, maxDepth: accessibilityTreeMaxDepth)
)
)
}
+ func testCLIRejectsOldSnapshotFullTextFlag() {
+ XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--show-full-text", "TextEdit"])) { error in
+ XCTAssertEqual(
+ error as? OpenComputerUseCLIError,
+ OpenComputerUseCLIError(message: "Unknown snapshot option: --show-full-text", helpCommand: "snapshot")
+ )
+ }
+ }
+
+ func testCLIRejectsInvalidSnapshotTextLimit() {
+ for value in ["0", "-1", "1.5", "full"] {
+ XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--text-limit", value, "TextEdit"])) { error in
+ XCTAssertEqual(
+ error as? OpenComputerUseCLIError,
+ OpenComputerUseCLIError(message: "--text-limit must be a positive integer or max", helpCommand: "snapshot")
+ )
+ }
+ }
+ XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--text-limit"])) { error in
+ XCTAssertEqual(
+ error as? OpenComputerUseCLIError,
+ OpenComputerUseCLIError(message: "--text-limit requires a positive integer or max value", helpCommand: "snapshot")
+ )
+ }
+ }
+
func testCLIRejectsInvalidSnapshotTreeBudget() {
XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot", "--max-tree-nodes", "0", "TextEdit"])) { error in
XCTAssertEqual(
@@ -606,7 +630,12 @@ final class OpenComputerUseKitTests: XCTestCase {
)
let getAppStateSchema = tools["get_app_state"]?.inputSchema
let getAppStateProperties = getAppStateSchema?["properties"] as? [String: [String: Any]]
- XCTAssertEqual(getAppStateProperties?["show_full_text"]?["type"] as? String, "boolean")
+ XCTAssertNil(getAppStateProperties?["show_full_text"])
+ let textLimitAnyOf = getAppStateProperties?["text_limit"]?["anyOf"] as? [[String: Any]]
+ XCTAssertEqual(textLimitAnyOf?[0]["type"] as? String, "integer")
+ XCTAssertEqual(textLimitAnyOf?[0]["minimum"] as? Int, 1)
+ XCTAssertEqual(textLimitAnyOf?[1]["type"] as? String, "string")
+ XCTAssertEqual(textLimitAnyOf?[1]["enum"] as? [String], ["max"])
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")
@@ -1105,14 +1134,19 @@ final class OpenComputerUseKitTests: XCTestCase {
)
}
- func testSnapshotTextLimitDefaultsTo500AndSupportsFullText() {
- let longText = String(repeating: "候", count: snapshotTextDefaultCharacterLimit + 20)
+ func testSnapshotTextLimitDefaultsTo500AndSupportsMax() {
+ let longText = String(repeating: "候", count: defaultTextLimit + 20)
+ let customLimitText = String(repeating: "候", count: 1_020)
XCTAssertEqual(
sanitizeText(longText),
- String(longText.prefix(snapshotTextDefaultCharacterLimit)) + "..."
+ String(longText.prefix(defaultTextLimit)) + "..."
+ )
+ XCTAssertEqual(
+ sanitizeText(customLimitText, textLimit: SnapshotTextLimit(maxCount: 1_000)),
+ String(customLimitText.prefix(1_000)) + "..."
)
- XCTAssertEqual(sanitizeText(longText, characterLimit: nil), longText)
+ XCTAssertEqual(sanitizeText(longText, textLimit: .max), longText)
}
func testAccessibilityRendererSuppressesDuplicateDescriptionForSameTextMarkdownLinks() {
@@ -1125,7 +1159,7 @@ final class OpenComputerUseKitTests: XCTestCase {
""
)
let longURL = "https://example.com/docs?" + String(repeating: "query=value&", count: 60)
- let truncatedURL = String(longURL.prefix(snapshotTextDefaultCharacterLimit)) + "..."
+ let truncatedURL = String(longURL.prefix(defaultTextLimit)) + "..."
XCTAssertEqual(
formattedLabelSegment(
longURL,
diff --git a/skills/open-computer-use/SKILL.md b/skills/open-computer-use/SKILL.md
index 982428e..5af453b 100644
--- a/skills/open-computer-use/SKILL.md
+++ b/skills/open-computer-use/SKILL.md
@@ -19,7 +19,7 @@ It supports the same core tool surface across macOS, Linux, and Windows:
2. On macOS, run `open-computer-use doctor` before the first real GUI task. If permissions are missing, ask the user to approve Accessibility and Screen Recording in the onboarding UI.
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`.
+5. When the task needs longer semantic text, such as chat history, email bodies, document text, or long form content, call `get_app_state` with `text_limit: 1000` or `text_limit: "max"`.
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.
@@ -45,7 +45,8 @@ open-computer-use doctor
open-computer-use call list_apps
ocu call list_apps
open-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":"TextEdit","text_limit":1000}'
+open-computer-use call get_app_state --args '{"app":"TextEdit","text_limit":"max"}'
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.md
index 43f7c3f..f53f78a 100644
--- a/skills/open-computer-use/references/troubleshooting.md
+++ b/skills/open-computer-use/references/troubleshooting.md
@@ -41,14 +41,16 @@ Ask the user to bring the target app/window into a visible state when automation
Snapshot text is limited to 500 characters by default. If a visible chat message, email body, document paragraph, or form value ends with `...`, do not assume the page itself is missing content.
-Request full accessibility text explicitly:
+Request a larger or unlimited text limit explicitly:
```sh
-open-computer-use call get_app_state --args '{"app":"TextEdit","show_full_text":true}'
-open-computer-use snapshot --show-full-text TextEdit
+open-computer-use call get_app_state --args '{"app":"TextEdit","text_limit":1000}'
+open-computer-use call get_app_state --args '{"app":"TextEdit","text_limit":"max"}'
+open-computer-use snapshot --text-limit 1000 TextEdit
+open-computer-use snapshot --text-limit max 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.
+`text_limit: "max"` 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
diff --git a/skills/open-computer-use/references/usage.md b/skills/open-computer-use/references/usage.md
index 8ce0ee9..bd03ac5 100644
--- a/skills/open-computer-use/references/usage.md
+++ b/skills/open-computer-use/references/usage.md
@@ -68,20 +68,22 @@ Use `--calls-file` when the sequence is too large for a readable shell command:
open-computer-use call --calls-file examples/textedit-overlay-seq.json --sleep 0.5
```
-## Full Text Snapshots
+## Text Limits
Snapshot text is truncated to 500 characters by default and ends with `...` when truncation happens. This keeps normal UI state compact for agent planning and element-targeted actions.
-Use full-text mode when the task depends on complete semantic text, such as chat histories, email bodies, document text, or long form content:
+Use a larger text limit when the task depends on longer semantic text, such as chat histories, email bodies, document text, or long form content. Use `max` only when complete text is required:
```sh
-open-computer-use call get_app_state --args '{"app":"TextEdit","show_full_text":true}'
-open-computer-use snapshot --show-full-text TextEdit
+open-computer-use call get_app_state --args '{"app":"TextEdit","text_limit":1000}'
+open-computer-use call get_app_state --args '{"app":"TextEdit","text_limit":"max"}'
+open-computer-use snapshot --text-limit 1000 TextEdit
+open-computer-use snapshot --text-limit max TextEdit
```
-The same `show_full_text` tool argument and `--show-full-text` snapshot flag apply on macOS, Linux, and Windows.
+The same `text_limit` tool argument and `--text-limit` snapshot flag apply on macOS, Linux, and Windows. `text_limit` accepts a positive integer or the string `"max"`.
-Action 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`.
+Action tools return refreshed app state with the default 500 character text limit. If longer text is still needed after an action, run `get_app_state` again with `text_limit: 1000` or `text_limit: "max"`.
## Larger Tree Budgets