@alan-ai-hq/agent-manager-linux-arm64 0.1.199 → 0.1.201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/alan-agent.cjs +8928 -5241
  2. package/alan-holder.cjs +5364 -3401
  3. package/alan-lease.cjs +808 -200
  4. package/builtin-skills/agent-desktop/SKILL.md +94 -0
  5. package/builtin-skills/alan-artifact/SKILL.md +128 -0
  6. package/builtin-skills/alan-artifact/examples/interactive-diagram.md +50 -0
  7. package/builtin-skills/alan-artifact/examples/prototype.md +53 -0
  8. package/builtin-skills/alan-artifact/examples/test-report.md +55 -0
  9. package/builtin-skills/alan-artifact/references/design.md +39 -0
  10. package/builtin-skills/alan-artifact/references/diagrams.md +20 -0
  11. package/builtin-skills/alan-deck/SKILL.md +189 -0
  12. package/builtin-skills/alan-diagrams/SKILL.md +105 -0
  13. package/builtin-skills/alan-diagrams/references/diagram-catalogue.md +847 -0
  14. package/builtin-skills/alan-docs/SKILL.md +143 -0
  15. package/builtin-skills/alan-docs/references/administration/members-and-teams.md +48 -0
  16. package/builtin-skills/alan-docs/references/administration/org-dashboard.md +19 -0
  17. package/builtin-skills/alan-docs/references/administration/organisation-settings.md +41 -0
  18. package/builtin-skills/alan-docs/references/agents-and-sessions/code-context.md +60 -0
  19. package/builtin-skills/alan-docs/references/agents-and-sessions/coding-agents-and-models.md +78 -0
  20. package/builtin-skills/alan-docs/references/agents-and-sessions/session-lifecycle.md +62 -0
  21. package/builtin-skills/alan-docs/references/agents-and-sessions/start-a-session.md +110 -0
  22. package/builtin-skills/alan-docs/references/automations/automation-runs.md +69 -0
  23. package/builtin-skills/alan-docs/references/automations/create-an-automation.md +143 -0
  24. package/builtin-skills/alan-docs/references/automations/overview.md +77 -0
  25. package/builtin-skills/alan-docs/references/cloud-and-local/cloud-images.md +64 -0
  26. package/builtin-skills/alan-docs/references/cloud-and-local/cloud-sessions-and-execution.md +89 -0
  27. package/builtin-skills/alan-docs/references/cloud-and-local/cloud-setup.md +128 -0
  28. package/builtin-skills/alan-docs/references/cloud-and-local/codex-cli-connector.md +92 -0
  29. package/builtin-skills/alan-docs/references/cloud-and-local/local-execution.md +213 -0
  30. package/builtin-skills/alan-docs/references/cloud-and-local/runtime-recovery.md +60 -0
  31. package/builtin-skills/alan-docs/references/cloud-and-local/sandboxes.md +74 -0
  32. package/builtin-skills/alan-docs/references/cloud-and-local/troubleshooting-and-faq.md +102 -0
  33. package/builtin-skills/alan-docs/references/get-started/connect-azure-devops.md +89 -0
  34. package/builtin-skills/alan-docs/references/get-started/connect-bitbucket.md +86 -0
  35. package/builtin-skills/alan-docs/references/get-started/connect-github.md +114 -0
  36. package/builtin-skills/alan-docs/references/get-started/join-a-team.md +114 -0
  37. package/builtin-skills/alan-docs/references/get-started/product-map.md +96 -0
  38. package/builtin-skills/alan-docs/references/get-started/quickstart.md +158 -0
  39. package/builtin-skills/alan-docs/references/get-started/set-up-your-team.md +200 -0
  40. package/builtin-skills/alan-docs/references/get-started/sign-in.md +104 -0
  41. package/builtin-skills/alan-docs/references/get-started/welcome.md +39 -0
  42. package/builtin-skills/alan-docs/references/integrations/connect-microsoft-teams.md +116 -0
  43. package/builtin-skills/alan-docs/references/integrations/connect-slack.md +164 -0
  44. package/builtin-skills/alan-docs/references/integrations/import-from-linear.md +172 -0
  45. package/builtin-skills/alan-docs/references/plans-and-billing/plans-and-limits.md +115 -0
  46. package/builtin-skills/alan-docs/references/plans-and-billing/usage-and-credits.md +47 -0
  47. package/builtin-skills/alan-docs/references/reference/documents-and-artifacts.md +52 -0
  48. package/builtin-skills/alan-docs/references/reference/faq.md +89 -0
  49. package/builtin-skills/alan-docs/references/reference/feature-catalog.md +89 -0
  50. package/builtin-skills/alan-docs/references/reference/glossary.md +96 -0
  51. package/builtin-skills/alan-docs/references/reference/links-and-ids.md +80 -0
  52. package/builtin-skills/alan-docs/references/reference/roles-and-permissions.md +64 -0
  53. package/builtin-skills/alan-docs/references/reference/statuses.md +86 -0
  54. package/builtin-skills/alan-docs/references/reviews-testing-deploys/deployments.md +28 -0
  55. package/builtin-skills/alan-docs/references/reviews-testing-deploys/pull-requests.md +85 -0
  56. package/builtin-skills/alan-docs/references/reviews-testing-deploys/review-work.md +55 -0
  57. package/builtin-skills/alan-docs/references/reviews-testing-deploys/testing-evidence.md +52 -0
  58. package/builtin-skills/alan-docs/references/skills/plugins-and-mcp.md +24 -0
  59. package/builtin-skills/alan-docs/references/skills/skills.md +103 -0
  60. package/builtin-skills/alan-docs/references/tasks/complete-a-task.md +79 -0
  61. package/builtin-skills/alan-docs/references/tasks/create-a-task.md +67 -0
  62. package/builtin-skills/alan-docs/references/tasks/subtasks-and-status.md +55 -0
  63. package/builtin-skills/alan-docs/references/tasks/task-artifacts.md +56 -0
  64. package/builtin-skills/alan-docs/references/tasks/task-detail.md +65 -0
  65. package/builtin-skills/alan-docs/references/teams-and-planning/cycles.md +93 -0
  66. package/builtin-skills/alan-docs/references/teams-and-planning/documents.md +66 -0
  67. package/builtin-skills/alan-docs/references/teams-and-planning/epics.md +95 -0
  68. package/builtin-skills/alan-docs/references/teams-and-planning/whiteboard.md +52 -0
  69. package/builtin-skills/alan-docs/references/troubleshooting/agent-blocked.md +38 -0
  70. package/builtin-skills/alan-docs/references/troubleshooting/common-problems.md +118 -0
  71. package/builtin-skills/alan-docs/references/troubleshooting/github-access.md +41 -0
  72. package/builtin-skills/alan-docs/references/troubleshooting/missing-artifact.md +47 -0
  73. package/builtin-skills/alan-docs/references/troubleshooting/report-an-issue.md +74 -0
  74. package/builtin-skills/alan-docs/references/troubleshooting/runtime-unavailable.md +49 -0
  75. package/builtin-skills/alan-docs/scripts/generate-references.mjs +363 -0
  76. package/builtin-skills/alan-environment-setup/SKILL.md +368 -0
  77. package/builtin-skills/alan-environment-setup/references/android.md +118 -0
  78. package/builtin-skills/alan-environment-setup/references/troubleshooting.md +38 -0
  79. package/builtin-skills/alan-skill-authoring/SKILL.md +83 -0
  80. package/builtin-skills/alan-tasks/SKILL.md +195 -0
  81. package/builtin-skills/alan-test-android/SKILL.md +224 -0
  82. package/builtin-skills/alan-test-android/scripts/android-up.sh +227 -0
  83. package/builtin-skills/alan-test-android/scripts/install-launch.sh +38 -0
  84. package/builtin-skills/alan-test-android/scripts/record.sh +64 -0
  85. package/builtin-skills/alan-test-android/scripts/ui.py +367 -0
  86. package/builtin-skills/alan-test-desktop/SKILL.md +107 -0
  87. package/builtin-skills/alan-test-desktop/references/linux-recording.md +31 -0
  88. package/builtin-skills/alan-test-feature/SKILL.md +243 -0
  89. package/builtin-skills/alan-test-mobile/SKILL.md +65 -0
  90. package/builtin-skills/alan-test-web/SKILL.md +113 -0
  91. package/builtin-skills/alan-walkthrough/SKILL.md +152 -0
  92. package/builtin-skills/alan-walkthrough/scripts/mark-changes.js +419 -0
  93. package/builtin-skills/alan-walkthrough/scripts/publish-capture.mjs +288 -0
  94. package/builtin-skills/alan-workflows/SKILL.md +235 -0
  95. package/builtin-skills/manifest.json +19 -0
  96. package/package.json +3 -2
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+ # Install an APK, launch its launcher activity, and prove the process survives.
3
+ # Usage: install-launch.sh <serial> <apk> [<applicationId>]
4
+ set -uo pipefail
5
+
6
+ SERIAL="${1:?serial}"
7
+ APK="${2:?apk path}"
8
+ PKG="${3:-}"
9
+ ADB="${ADB:-adb}"
10
+
11
+ fail() { echo "[install-launch] FAILED: $*" >&2; exit 2; }
12
+ [ -f "$APK" ] || fail "no APK at $APK"
13
+
14
+ if [ -z "$PKG" ]; then
15
+ AAPT="$(ls -1 "${ANDROID_HOME:-/opt/android-sdk}"/build-tools/*/aapt2 2>/dev/null | tail -1)"
16
+ [ -n "$AAPT" ] && PKG="$("$AAPT" dump packagename "$APK" 2>/dev/null)"
17
+ [ -n "$PKG" ] || fail "could not read the application id; pass it as the third argument"
18
+ fi
19
+
20
+ OUT="$("$ADB" -s "$SERIAL" install -r -t -g "$APK" 2>&1)"
21
+ echo "$OUT" | grep -q Success || fail "install: $(echo "$OUT" | tail -2)"
22
+
23
+ "$ADB" -s "$SERIAL" logcat -c >/dev/null 2>&1
24
+ ACTIVITY="$("$ADB" -s "$SERIAL" shell cmd package resolve-activity --brief -c android.intent.category.LAUNCHER "$PKG" | tr -d '\r' | tail -1)"
25
+ case "$ACTIVITY" in */*) ;; *) fail "$PKG has no launcher activity ($ACTIVITY)" ;; esac
26
+
27
+ "$ADB" -s "$SERIAL" shell am start -W -n "$ACTIVITY" >/dev/null || fail "am start $ACTIVITY"
28
+ sleep 5
29
+ PID="$("$ADB" -s "$SERIAL" shell pidof "$PKG" | tr -d '\r')"
30
+ if [ -z "$PID" ]; then
31
+ "$ADB" -s "$SERIAL" logcat -d -b crash | tail -30 >&2
32
+ fail "$PKG died within 5s of launch"
33
+ fi
34
+
35
+ VERSION="$("$ADB" -s "$SERIAL" shell dumpsys package "$PKG" | grep -m1 versionName | tr -d '\r ' )"
36
+ SHA="$( (shasum -a 256 "$APK" 2>/dev/null || sha256sum "$APK") | cut -c1-12)"
37
+ BUILT="$(date -r "$APK" '+%Y-%m-%dT%H:%M:%S' 2>/dev/null)"
38
+ echo "package=$PKG activity=$ACTIVITY pid=$PID ${VERSION} apk_sha256=$SHA apk_built=$BUILT"
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env bash
2
+ # Record the device screen with Android's screenrecord (180s cap per file).
3
+ # Usage: record.sh <serial> start <local.mp4> | status | stop
4
+ set -uo pipefail
5
+
6
+ SERIAL="${1:?serial}"
7
+ ACTION="${2:?start|stop}"
8
+ ADB="${ADB:-adb}"
9
+ STATE="/tmp/alan-android/record-$(echo "$SERIAL" | tr ':/' '__')"
10
+ REMOTE=/sdcard/alan-recording.mp4
11
+ mkdir -p /tmp/alan-android
12
+
13
+ case "$ACTION" in
14
+ start)
15
+ LOCAL="${3:?local output path}"
16
+ [ -f "$STATE" ] && { echo "[record] already recording; stop first" >&2; exit 2; }
17
+ "$ADB" -s "$SERIAL" shell rm -f "$REMOTE"
18
+ nohup "$ADB" -s "$SERIAL" shell screenrecord --time-limit 180 --bit-rate 4000000 "$REMOTE" \
19
+ >/tmp/alan-android/screenrecord.log 2>&1 &
20
+ echo "$! $LOCAL $(date +%s)" >"$STATE"
21
+ sleep 1
22
+ "$ADB" -s "$SERIAL" shell pidof screenrecord >/dev/null || {
23
+ rm -f "$STATE"; echo "[record] screenrecord did not start: $(cat /tmp/alan-android/screenrecord.log)" >&2; exit 2; }
24
+ echo "recording to $LOCAL (Android stops it after 180s; check with: record.sh $SERIAL status)"
25
+ ;;
26
+ status)
27
+ [ -f "$STATE" ] || { echo "not recording"; exit 0; }
28
+ read -r _ LOCAL STARTED <"$STATE"
29
+ ELAPSED=$(( $(date +%s) - STARTED ))
30
+ if [ "$ELAPSED" -ge 180 ]; then
31
+ echo "capped: $LOCAL stopped capturing ${ELAPSED}s ago-180s; stop and start a new file"
32
+ else
33
+ echo "recording $LOCAL: ${ELAPSED}s elapsed, $((180 - ELAPSED))s left"
34
+ fi
35
+ ;;
36
+ stop)
37
+ [ -f "$STATE" ] || { echo "[record] not recording"; exit 0; }
38
+ read -r HOST_PID LOCAL STARTED <"$STATE"
39
+ "$ADB" -s "$SERIAL" shell pkill -INT screenrecord >/dev/null 2>&1
40
+ for _ in $(seq 1 20); do kill -0 "$HOST_PID" 2>/dev/null || break; sleep 0.5; done
41
+ rm -f "$STATE"
42
+ sleep 1
43
+ mkdir -p "$(dirname "$LOCAL")"
44
+ "$ADB" -s "$SERIAL" pull "$REMOTE" "$LOCAL" >/dev/null 2>&1 || { echo "[record] pull failed" >&2; exit 2; }
45
+ ELAPSED=$(( $(date +%s) - STARTED ))
46
+ [ "$ELAPSED" -ge 180 ] && echo "[record] hit the 180s cap; later actions are not in this file" >&2
47
+ if ! command -v ffprobe >/dev/null 2>&1; then
48
+ echo "$LOCAL (ffprobe missing; stream not verified)"
49
+ exit 0
50
+ fi
51
+ STREAM="$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height -of csv=p=0 "$LOCAL")"
52
+ [ -n "$STREAM" ] || { echo "[record] $LOCAL has no video stream" >&2; exit 2; }
53
+ FRAMES="$(ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of csv=p=0 "$LOCAL")"
54
+ DURATION="$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$LOCAL")"
55
+ case "$DURATION" in ''|N/A) DURATION=0 ;; esac
56
+ FRAME="${LOCAL%.*}-last.png"
57
+ # screenrecord output is variable-frame-rate, so seeking from the end can land on an older frame.
58
+ ffmpeg -v error -y -i "$LOCAL" -fps_mode passthrough -update 1 "$FRAME" 2>/dev/null || FRAME="(frame extract failed)"
59
+ # screenrecord only writes a frame when the screen changes, so one frame means nothing moved.
60
+ [ "${FRAMES:-0}" -le 1 ] && echo "[record] only ${FRAMES:-0} frame: the screen never changed during this recording" >&2
61
+ printf '%s video=%s frames=%s duration=%.1fs last_frame=%s\n' "$LOCAL" "$STREAM" "${FRAMES:-0}" "$DURATION" "$FRAME"
62
+ ;;
63
+ *) echo "usage: record.sh <serial> start <file> | status | stop" >&2; exit 64 ;;
64
+ esac
@@ -0,0 +1,367 @@
1
+ """Drive an Android screen through the accessibility tree.
2
+
3
+ Usage:
4
+ ui.py SERIAL dump [--all]
5
+ ui.py SERIAL tap (--text T | --id ID | --desc D) [--index N] [--long]
6
+ ui.py SERIAL type (--text T | --id ID | --desc D) [--index N] VALUE [--no-clear]
7
+ ui.py SERIAL wait (--text T | --id ID | --desc D) [--exact | --regex] [--timeout S] [--gone]
8
+ ui.py SERIAL state [PACKAGE] resumed activity, crash/ANR dialog, crashes since the last state call
9
+ ui.py SERIAL relaunch PACKAGE force-stop, then start the launcher activity
10
+ ui.py SERIAL dismiss-anr tap Wait on a System UI not-responding dialog; app dialogs are left alone
11
+ ui.py SERIAL shot PATH
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import argparse
17
+ import os
18
+ import re
19
+ import subprocess
20
+ import sys
21
+ import time
22
+ import xml.etree.ElementTree as ET
23
+ from dataclasses import dataclass
24
+
25
+ ADB = os.environ.get("ADB", "adb")
26
+ BOUNDS = re.compile(r"\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]")
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class Node:
31
+ text: str
32
+ hint: str
33
+ resource_id: str
34
+ desc: str
35
+ cls: str
36
+ clickable: bool
37
+ editable: bool
38
+ enabled: bool
39
+ focused: bool
40
+ checked: bool | None
41
+ bounds: tuple[int, int, int, int]
42
+
43
+ @property
44
+ def center(self) -> tuple[int, int]:
45
+ x1, y1, x2, y2 = self.bounds
46
+ return (x1 + x2) // 2, (y1 + y2) // 2
47
+
48
+ @property
49
+ def short_id(self) -> str:
50
+ return self.resource_id.split("/", 1)[-1]
51
+
52
+ @property
53
+ def visible(self) -> bool:
54
+ x1, y1, x2, y2 = self.bounds
55
+ return x2 > x1 and y2 > y1
56
+
57
+ @property
58
+ def interesting(self) -> bool:
59
+ return self.visible and (self.clickable or self.editable or bool(self.text or self.desc))
60
+
61
+
62
+ def adb(serial: str, *args: str, binary: bool = False) -> bytes | str:
63
+ result = subprocess.run([ADB, "-s", serial, *args], capture_output=True, timeout=60)
64
+ if result.returncode != 0:
65
+ raise SystemExit(f"adb {' '.join(args)} failed: {result.stderr.decode(errors='replace').strip()}")
66
+ return result.stdout if binary else result.stdout.decode(errors="replace")
67
+
68
+
69
+ def read_tree(serial: str) -> list[Node]:
70
+ for _ in range(3):
71
+ raw = adb(serial, "exec-out", "uiautomator", "dump", "/dev/tty")
72
+ assert isinstance(raw, str)
73
+ start = raw.find("<?xml")
74
+ end = raw.rfind("</hierarchy>")
75
+ if start != -1 and end != -1:
76
+ return parse_tree(raw[start : end + len("</hierarchy>")])
77
+ time.sleep(1)
78
+ raise SystemExit("uiautomator returned no hierarchy (screen may be animating or secure)")
79
+
80
+
81
+ def parse_tree(xml: str) -> list[Node]:
82
+ nodes: list[Node] = []
83
+ for element in ET.fromstring(xml).iter("node"):
84
+ match = BOUNDS.fullmatch(element.get("bounds", ""))
85
+ if not match:
86
+ continue
87
+ x1, y1, x2, y2 = (int(value) for value in match.groups())
88
+ cls = element.get("class", "")
89
+ nodes.append(
90
+ Node(
91
+ text=element.get("text", ""),
92
+ hint=element.get("hint", ""),
93
+ resource_id=element.get("resource-id", ""),
94
+ desc=element.get("content-desc", ""),
95
+ cls=cls.rsplit(".", 1)[-1],
96
+ clickable=element.get("clickable") == "true" or element.get("long-clickable") == "true",
97
+ editable="EditText" in cls or element.get("editable") == "true",
98
+ enabled=element.get("enabled") != "false",
99
+ focused=element.get("focused") == "true",
100
+ checked=None if element.get("checkable") != "true" else element.get("checked") == "true",
101
+ bounds=(x1, y1, x2, y2),
102
+ )
103
+ )
104
+ return nodes
105
+
106
+
107
+ def text_matches(actual: str, wanted: str, args: argparse.Namespace) -> bool:
108
+ if getattr(args, "regex", False):
109
+ return re.search(wanted, actual) is not None
110
+ if getattr(args, "exact", False):
111
+ return actual == wanted
112
+ return wanted.lower() in actual.lower()
113
+
114
+
115
+ def matches(node: Node, args: argparse.Namespace) -> bool:
116
+ if args.text is not None and not text_matches(node.text, args.text, args):
117
+ return False
118
+ if args.id is not None and node.short_id != args.id and node.resource_id != args.id:
119
+ return False
120
+ if args.desc is not None and args.desc.lower() not in node.desc.lower():
121
+ return False
122
+ return node.visible
123
+
124
+
125
+ def select(serial: str, args: argparse.Namespace) -> Node:
126
+ found = [node for node in read_tree(serial) if matches(node, args)]
127
+ exact = [node for node in found if args.text is not None and node.text.lower() == args.text.lower()]
128
+ candidates = exact if len(exact) == 1 and args.index is None else found
129
+ if args.index is not None:
130
+ if args.index >= len(candidates):
131
+ raise SystemExit(f"index {args.index} out of range; {len(candidates)} match")
132
+ return candidates[args.index]
133
+ if not candidates:
134
+ raise SystemExit(f"no element matches {describe(args)}; run dump")
135
+ if len(candidates) > 1:
136
+ listing = "\n".join(f" [{i}] {format_node(node)}" for i, node in enumerate(candidates))
137
+ raise SystemExit(f"{len(candidates)} elements match {describe(args)}; pass --index:\n{listing}")
138
+ return candidates[0]
139
+
140
+
141
+ def describe(args: argparse.Namespace) -> str:
142
+ parts = [f"{key}={getattr(args, key)!r}" for key in ("text", "id", "desc") if getattr(args, key) is not None]
143
+ return " ".join(parts)
144
+
145
+
146
+ def format_node(node: Node) -> str:
147
+ flags = [
148
+ flag
149
+ for flag, on in (
150
+ ("click", node.clickable),
151
+ ("edit", node.editable),
152
+ ("focused", node.focused),
153
+ ("disabled", not node.enabled),
154
+ ("checked", node.checked is True),
155
+ ("unchecked", node.checked is False),
156
+ )
157
+ if on
158
+ ]
159
+ label = " ".join(
160
+ part
161
+ for part in (
162
+ f'text="{node.text}"' if node.text else "",
163
+ f'desc="{node.desc}"' if node.desc else "",
164
+ f"id={node.short_id}" if node.short_id else "",
165
+ )
166
+ if part
167
+ )
168
+ return f"{node.cls} {label} {','.join(flags)} @{node.center[0]},{node.center[1]}".strip()
169
+
170
+
171
+ def shell_text(value: str) -> str:
172
+ escaped = re.sub(r"([\\\"'`$&|;<>()*?!#~{}\[\]])", r"\\\1", value)
173
+ return escaped.replace(" ", "%s")
174
+
175
+
176
+ def resumed_activity(serial: str) -> str:
177
+ # mCurrentFocus can keep a dismissed crash dialog; the resumed activity is what the user sees.
178
+ out = adb(serial, "shell", "dumpsys", "activity", "activities")
179
+ assert isinstance(out, str)
180
+ for line in out.splitlines():
181
+ if "topResumedActivity" in line or "mResumedActivity" in line:
182
+ match = re.search(r"u\d+ (\S+)", line)
183
+ return match.group(1) if match else line.strip()
184
+ return "none"
185
+
186
+
187
+ def blocking_dialog(serial: str) -> str | None:
188
+ out = adb(serial, "shell", "dumpsys", "window", "windows")
189
+ assert isinstance(out, str)
190
+ for line in out.splitlines():
191
+ if "Window{" in line and ("Application Error" in line or "Application Not Responding" in line):
192
+ return line.split("u0 ", 1)[-1].rstrip("}: ").strip()
193
+ return None
194
+
195
+
196
+ def command_dump(serial: str, args: argparse.Namespace) -> None:
197
+ print(f"resumed: {resumed_activity(serial)}")
198
+ dialog = blocking_dialog(serial)
199
+ if dialog:
200
+ print(f"dialog: {dialog}")
201
+ for index, node in enumerate(read_tree(serial)):
202
+ if args.all or node.interesting:
203
+ print(f"{index:3d} {format_node(node)}")
204
+
205
+
206
+ def command_tap(serial: str, args: argparse.Namespace) -> None:
207
+ node = select(serial, args)
208
+ x, y = node.center
209
+ if args.long:
210
+ adb(serial, "shell", "input", "swipe", str(x), str(y), str(x), str(y), "800")
211
+ else:
212
+ adb(serial, "shell", "input", "tap", str(x), str(y))
213
+ print(f"tapped {format_node(node)}")
214
+
215
+
216
+ def command_type(serial: str, args: argparse.Namespace) -> None:
217
+ node = select(serial, args)
218
+ x, y = node.center
219
+ adb(serial, "shell", "input", "tap", str(x), str(y))
220
+ time.sleep(0.3)
221
+ existing = 0 if not node.text or node.text == node.hint else len(node.text)
222
+ if existing and not args.no_clear:
223
+ adb(serial, "shell", "input", "keyevent", "KEYCODE_MOVE_END")
224
+ adb(serial, "shell", "input", "keyevent", *(["KEYCODE_DEL"] * existing))
225
+ if args.value:
226
+ adb(serial, "shell", "input", "text", shell_text(args.value))
227
+ print(f"typed {len(args.value)} chars into {format_node(node)}")
228
+
229
+
230
+ def command_wait(serial: str, args: argparse.Namespace) -> None:
231
+ deadline = time.monotonic() + args.timeout
232
+ while time.monotonic() < deadline:
233
+ found = [node for node in read_tree(serial) if matches(node, args)]
234
+ if bool(found) != args.gone:
235
+ print(f"gone: {describe(args)}" if args.gone else f"found: {format_node(found[0])}")
236
+ return
237
+ time.sleep(1)
238
+ raise SystemExit(f"timed out after {args.timeout}s waiting for {describe(args)}{' to disappear' if args.gone else ''}")
239
+
240
+
241
+ def command_state(serial: str, args: argparse.Namespace) -> None:
242
+ resumed = resumed_activity(serial)
243
+ dialog = blocking_dialog(serial)
244
+ crashes = adb(serial, "logcat", "-d", "-b", "crash")
245
+ assert isinstance(crashes, str)
246
+ adb(serial, "logcat", "-c", "-b", "crash")
247
+ pid = ""
248
+ if args.package:
249
+ out = subprocess.run([ADB, "-s", serial, "shell", "pidof", args.package], capture_output=True, text=True)
250
+ pid = out.stdout.strip()
251
+ foreground = bool(args.package) and resumed.startswith(f"{args.package}/") and dialog is None
252
+ print(f"resumed: {resumed}")
253
+ print(f"dialog: {dialog or 'none'}")
254
+ if args.package:
255
+ print(f"pid: {pid or 'none'}")
256
+ print(f"foreground: {'yes' if foreground else 'no'}")
257
+ fatal = [line for line in crashes.splitlines() if "FATAL EXCEPTION" in line or " E AndroidRuntime" in line]
258
+ print(f"new_crashes: {len([line for line in fatal if 'FATAL EXCEPTION' in line])}")
259
+ for line in fatal[:24]:
260
+ print(f" {line.split(': ', 1)[-1]}")
261
+
262
+
263
+ SYSTEM_UI_PACKAGE = "com.android.systemui"
264
+
265
+
266
+ def command_dismiss_anr(serial: str, _args: argparse.Namespace) -> None:
267
+ dialog = blocking_dialog(serial)
268
+ if dialog is None:
269
+ print("dialog: none")
270
+ return
271
+ # An ANR in the app under test is a finding to report, never something to wave away.
272
+ if "Application Not Responding" not in dialog or SYSTEM_UI_PACKAGE not in dialog:
273
+ print(f"dialog: {dialog} (left open)")
274
+ return
275
+ for node in read_tree(serial):
276
+ if node.visible and node.text.strip().lower() == "wait":
277
+ x, y = node.center
278
+ adb(serial, "shell", "input", "tap", str(x), str(y))
279
+ print(f"dismissed: {dialog}")
280
+ return
281
+ raise SystemExit(f"{dialog} has no Wait button to tap")
282
+
283
+
284
+ def command_relaunch(serial: str, args: argparse.Namespace) -> None:
285
+ adb(serial, "shell", "am", "force-stop", args.package)
286
+ activity = adb(serial, "shell", "cmd", "package", "resolve-activity", "--brief", "-c",
287
+ "android.intent.category.LAUNCHER", args.package)
288
+ assert isinstance(activity, str)
289
+ component = activity.strip().splitlines()[-1].strip()
290
+ if "/" not in component:
291
+ raise SystemExit(f"{args.package} has no launcher activity")
292
+ adb(serial, "shell", "am", "start", "-W", "-n", component)
293
+ print(f"relaunched {component}")
294
+
295
+
296
+ def command_shot(serial: str, args: argparse.Namespace) -> None:
297
+ png = adb(serial, "exec-out", "screencap", "-p", binary=True)
298
+ assert isinstance(png, bytes)
299
+ if len(png) < 20000:
300
+ print(f"warning: {len(png)}-byte screenshot is probably blank", file=sys.stderr)
301
+ os.makedirs(os.path.dirname(os.path.abspath(args.path)), exist_ok=True)
302
+ with open(args.path, "wb") as handle:
303
+ handle.write(png)
304
+ print(args.path)
305
+
306
+
307
+ def add_selector(parser: argparse.ArgumentParser) -> None:
308
+ parser.add_argument("--text")
309
+ parser.add_argument("--id")
310
+ parser.add_argument("--desc")
311
+ parser.add_argument("--index", type=int)
312
+
313
+
314
+ def main() -> None:
315
+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
316
+ parser.add_argument("serial")
317
+ commands = parser.add_subparsers(dest="command", required=True)
318
+
319
+ dump = commands.add_parser("dump")
320
+ dump.add_argument("--all", action="store_true")
321
+
322
+ tap = commands.add_parser("tap")
323
+ add_selector(tap)
324
+ tap.add_argument("--long", action="store_true")
325
+
326
+ type_ = commands.add_parser("type")
327
+ add_selector(type_)
328
+ type_.add_argument("value")
329
+ type_.add_argument("--no-clear", action="store_true")
330
+
331
+ wait = commands.add_parser("wait")
332
+ add_selector(wait)
333
+ wait.add_argument("--timeout", type=float, default=15)
334
+ wait.add_argument("--gone", action="store_true")
335
+ mode = wait.add_mutually_exclusive_group()
336
+ mode.add_argument("--exact", action="store_true")
337
+ mode.add_argument("--regex", action="store_true")
338
+
339
+ state = commands.add_parser("state")
340
+ state.add_argument("package", nargs="?")
341
+
342
+ relaunch = commands.add_parser("relaunch")
343
+ relaunch.add_argument("package")
344
+
345
+ shot = commands.add_parser("shot")
346
+ shot.add_argument("path")
347
+
348
+ commands.add_parser("dismiss-anr")
349
+
350
+ args = parser.parse_args()
351
+ if args.command in {"tap", "type", "wait"} and not describe(args):
352
+ parser.error(f"{args.command} needs --text, --id, or --desc")
353
+ handlers = {
354
+ "dump": command_dump,
355
+ "tap": command_tap,
356
+ "type": command_type,
357
+ "wait": command_wait,
358
+ "state": command_state,
359
+ "relaunch": command_relaunch,
360
+ "shot": command_shot,
361
+ "dismiss-anr": command_dismiss_anr,
362
+ }
363
+ handlers[args.command](args.serial, args)
364
+
365
+
366
+ if __name__ == "__main__":
367
+ main()
@@ -0,0 +1,107 @@
1
+ ---
2
+ name: alan-test-desktop
3
+ version: 1.5.0
4
+ description: "Use when a test charter targets a desktop application in an Alan cloud sandbox: Electron or another CDP-enabled renderer (preferred path), or a native app with no CDP endpoint driven through the accessibility tree. Launch or attach to the actual app, verify its identity, exercise the charter, and return observations and sandbox captures. Report interactions the driver cannot reach as gaps. Do not use for browser pages, native mobile apps, publishing evidence, or writing reports."
5
+ ---
6
+
7
+ # Run a charter in a desktop app
8
+
9
+ Run this workflow only in an Alan cloud sandbox. If the cloud session or a
10
+ required capability is unavailable, report the blocker; do not switch to a
11
+ developer machine, local container, or CI runner.
12
+
13
+ This surface driver runs one charter and returns a short result. It never calls
14
+ `create_test_report`, never publishes captures, and never decides the overall
15
+ run status. Read `agent-browser skills get electron` for current attachment
16
+ mechanics; use `/alan-test-web` for the renderer's snapshot-and-ref loop.
17
+
18
+ ## Pick the driver before building anything
19
+
20
+ | Target | Driver |
21
+ | --- | --- |
22
+ | Chromium renderer with a CDP endpoint (Electron, Chromium) | `agent-browser --cdp <port>` |
23
+ | Native app, OS dialog, native menu, tray, window management | `agent-desktop` (the `agent-desktop` skill) |
24
+
25
+ CDP is the default and the cheaper path: same app, one measured login flow
26
+ cost 4 calls and 59 ms over CDP versus 7 calls and 2.8 s through the
27
+ accessibility tree. Attach over CDP whenever the app can expose a port; fall
28
+ back to the accessibility tree only when it cannot, and say which one you used.
29
+
30
+ ## Input and readiness
31
+
32
+ The caller supplies the mission, app entry point, risks with oracles, auth,
33
+ evidence directory, and repository launch or build command.
34
+
35
+ 1. Build or start the app using its documented procedure. Enable CDP through
36
+ its supported configuration. Launch on the cloud sandbox's streamed
37
+ desktop so the user can watch. If the display is unavailable, return the
38
+ cloud desktop capability gap.
39
+ 2. Wait for the CDP version and target endpoints to answer. Select the target
40
+ whose URL and title identify the expected app. For Electron, also confirm
41
+ the renderer User-Agent contains `Electron/`.
42
+ 3. Use your own named session and explicit numeric CDP port on every command:
43
+
44
+ ```sh
45
+ agent-browser --session <charter-slug> --cdp <port> snapshot -i
46
+ agent-browser --session <charter-slug> --cdp <port> eval '({url: location.href, title: document.title, userAgent: navigator.userAgent})'
47
+ ```
48
+
49
+ A successful command alone does not prove native attachment. Resolve an
50
+ identity mismatch before interacting. A browser page at the app's web URL is
51
+ not native desktop evidence. If the host cannot drive the target, return the
52
+ exact capability gap rather than assuming every desktop framework exposes CDP.
53
+
54
+ Record the PID of any app you launch. Charters sharing a single-instance app
55
+ run sequentially. If launch reuses an existing instance, treat it as attached;
56
+ do not claim ownership of that process.
57
+
58
+ ## Fallback when the app exposes no CDP endpoint
59
+
60
+ Use the `agent-desktop` skill: it drives the same window through the OS
61
+ accessibility tree. Confirm readiness with `agent-desktop status` before the
62
+ first command and mark the run `partial` if accessibility is denied.
63
+
64
+ Carry these limits into the result instead of working around them silently:
65
+
66
+ - No console, page-error, or network channel, so those oracles are `unverified`.
67
+ - A Chromium text field rejects `set-value`; typing is `--headed` physical
68
+ input and takes focus from the user watching the desktop.
69
+ - Native menus and dialogs are not always exposed; confirm the surface before
70
+ asserting on it.
71
+ - Viewport work is a window resize, not mobile emulation.
72
+
73
+ ## Run and record
74
+
75
+ Establish recording before the first interaction, then recheck app identity.
76
+ Keep the same native target throughout; never create a replacement browser
77
+ context to make recording work. Bound recorder commands with host-supported
78
+ deadlines and clean up a pending command before retrying it.
79
+
80
+ Stop recording on completion or failure. Inspect duration, a video stream,
81
+ and representative frames across the flow: they must show the actual app and
82
+ the claimed transitions. A real-app opening frame does not prove the rest of
83
+ a flow when the video freezes. Replay missing or invalid evidence with an
84
+ available native display recorder. For Linux/X11, load
85
+ [the recording recipe](references/linux-recording.md) only when needed.
86
+ Otherwise return screenshots and an explicit recording gap.
87
+
88
+ For a UI-change charter, capture the base and the changed state of each
89
+ screen at the same size. On a CDP renderer, inject `/alan-walkthrough`
90
+ `scripts/mark-changes.js` and number every distinct change on both captures as
91
+ the web driver does; a native window cannot take the overlay, so return the
92
+ unmarked pair with the numbered changed regions listed and name the gap.
93
+
94
+ Drive the charter using snapshots and refs. Capture meaningful states, check
95
+ console and renderer errors, verify persistence when cheap, and reproduce a
96
+ finding once. Name interactions the driver cannot reach, such as OS dialogs,
97
+ tray controls, or native menus; do not infer their behavior from the renderer.
98
+
99
+ ## Output and cleanup
100
+
101
+ Return outcome (`completed`, `partial`, `blocked`), replayable observations
102
+ (including the app build and display), findings with evidence paths,
103
+ unverified items, and capture paths.
104
+
105
+ Close only your named automation session. Stop only processes you launched,
106
+ by their recorded PIDs, and confirm they exited. Never kill an instance you
107
+ attached to or use `close --all`.
@@ -0,0 +1,31 @@
1
+ # Record a Linux/X11 desktop
2
+
3
+ Use this fallback only when renderer recording fails or misses transitions.
4
+ Set `evidence_dir` to the charter capture directory before running the recipe.
5
+
6
+ For the Alan cloud sandbox's Linux/X11 streamed desktop, check
7
+ `ffmpeg` and `xdpyinfo`, and read the display size from `xdpyinfo -display "$DISPLAY"`.
8
+ Use those measured dimensions as `display_size`, not an assumed viewport.
9
+ Start a bounded recording before interacting:
10
+
11
+ ```sh
12
+ ffmpeg -nostdin -y -f x11grab -framerate 15 \
13
+ -video_size "$display_size" -i "$DISPLAY" \
14
+ -t 120 -vf 'pad=ceil(iw/2)*2:ceil(ih/2)*2' \
15
+ -c:v libx264 -preset ultrafast -pix_fmt yuv420p \
16
+ "$evidence_dir/desktop.mp4" >"$evidence_dir/recorder.log" 2>&1 &
17
+ recorder_pid=$!
18
+ ```
19
+
20
+ Wait for the recorder log to show captured frames and verify it remains
21
+ running. Keep one segment under two minutes; use a new filename for each
22
+ segment. At the end or on failure, send SIGINT only to `recorder_pid`, wait
23
+ at most five seconds for it to exit, then send SIGTERM if it is still running
24
+ and confirm it exited. Never use `pkill`, kill a process group, or stop the
25
+ app to stop a recording. Arrange this cleanup before starting interactions.
26
+
27
+ Verify the finished file with `ffprobe`: nonzero duration, a video stream,
28
+ and at least one extracted frame showing the actual app. A missing, blank,
29
+ or wrong-app recording is a gap until recaptured. FFmpeg's
30
+ [X11 capture documentation](https://www.ffmpeg.org/ffmpeg-devices.html#x11grab)
31
+ explains display selection and dimensions.