@neta-art/cohub-cli 10.23.0 → 10.25.0
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.
- package/README.md +18 -5
- package/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +309 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2511 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -118
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -64
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2139
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -6
- package/dist/session-status.js +0 -16
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
|
@@ -1,620 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { dirname, join, resolve } from "node:path";
|
|
5
|
-
import { compileDisplayPlan, DISPLAY_ELEMENT_REF_PATTERN, DISPLAY_ELEMENT_ROLES, DISPLAY_SYSTEM_ACTIONS, DISPLAY_HANDOVER_DEFAULT_MS, DISPLAY_HANDOVER_MAX_MS, DISPLAY_HANDOVER_WAIT_MS, DisplayActionError, } from "@neta-art/cohub";
|
|
6
|
-
import { Option } from "commander";
|
|
7
|
-
import { createClient } from "../client.js";
|
|
8
|
-
import { error, handleHttp, json as outJson, jsonRequested, ok, table, warn } from "../output.js";
|
|
9
|
-
import { resolveSpace } from "../space.js";
|
|
10
|
-
import { webUrl } from "../web.js";
|
|
11
|
-
const DIRECTIONS = ["up", "down", "left", "right"];
|
|
12
|
-
const BUTTONS = ["primary", "secondary", "middle"];
|
|
13
|
-
const TREES = ["compact", "full", "none"];
|
|
14
|
-
const DEFAULT_MAX_SIZE = 1280;
|
|
15
|
-
const HANDOVER_RETRY_MS = 60_000;
|
|
16
|
-
const HANDOVER_RETRY_GAP_MS = 2_000;
|
|
17
|
-
const CACHE_DIR = join(homedir(), ".cache", "cohub-cli");
|
|
18
|
-
const FRAMES_PATH = join(CACHE_DIR, "display-frames.json");
|
|
19
|
-
// In the workspace, where a Runtime's fenced file tools reach them.
|
|
20
|
-
const IMAGE_DIR = join(".cache", "cohub", "displays");
|
|
21
|
-
const KEPT_IMAGES = 20;
|
|
22
|
-
const NO_DISPLAY_HINT = "Share one first: set up phone control in the Cohub Android app, run `cohub runtime up --display` on a computer, or `cohub spaces displays start` for a virtual screen.";
|
|
23
|
-
function parseSize(value) {
|
|
24
|
-
const match = /^(\d{1,5})x(\d{1,5})$/i.exec(value.trim());
|
|
25
|
-
const width = Number(match?.[1]);
|
|
26
|
-
const height = Number(match?.[2]);
|
|
27
|
-
if (!match || width < 1 || height < 1)
|
|
28
|
-
return error("Invalid size", "Use WIDTHxHEIGHT, e.g. 576x1280.");
|
|
29
|
-
return { width, height };
|
|
30
|
-
}
|
|
31
|
-
function parseNumber(name, value) {
|
|
32
|
-
const number = Number(value);
|
|
33
|
-
if (!Number.isFinite(number))
|
|
34
|
-
return error(`Invalid ${name}`, `${name} must be a number.`);
|
|
35
|
-
return number;
|
|
36
|
-
}
|
|
37
|
-
function isRef(value) {
|
|
38
|
-
return DISPLAY_ELEMENT_REF_PATTERN.test(value);
|
|
39
|
-
}
|
|
40
|
-
async function readFrames() {
|
|
41
|
-
try {
|
|
42
|
-
return JSON.parse(await readFile(FRAMES_PATH, "utf8"));
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function rememberFrame(spaceId, display, size) {
|
|
49
|
-
const frames = await readFrames();
|
|
50
|
-
frames[`${spaceId}/${display.id}`] = { width: size.width, height: size.height, display: { width: display.width, height: display.height } };
|
|
51
|
-
await mkdir(dirname(FRAMES_PATH), { recursive: true });
|
|
52
|
-
await writeFile(FRAMES_PATH, JSON.stringify(frames));
|
|
53
|
-
}
|
|
54
|
-
async function frameOf(spaceId, display, size) {
|
|
55
|
-
if (size)
|
|
56
|
-
return parseSize(size);
|
|
57
|
-
const frame = (await readFrames())[`${spaceId}/${display.id}`];
|
|
58
|
-
if (frame && frame.display.width === display.width && frame.display.height === display.height)
|
|
59
|
-
return frame;
|
|
60
|
-
return { width: display.width, height: display.height };
|
|
61
|
-
}
|
|
62
|
-
function pickDisplay(displays, requested) {
|
|
63
|
-
if (requested) {
|
|
64
|
-
const found = displays.find((display) => display.id === requested);
|
|
65
|
-
if (!found)
|
|
66
|
-
return error(`Display "${requested}" is not shared`, `Shared displays: ${displays.map((display) => display.id).join(", ") || "none"}`);
|
|
67
|
-
return found;
|
|
68
|
-
}
|
|
69
|
-
const agents = displays.filter((display) => display.kind === "agent");
|
|
70
|
-
if (displays.length === 1 && displays[0])
|
|
71
|
-
return displays[0];
|
|
72
|
-
if (agents.length === 1 && agents[0])
|
|
73
|
-
return agents[0];
|
|
74
|
-
if (displays.length === 0)
|
|
75
|
-
return error("No display is shared with this Space", NO_DISPLAY_HINT);
|
|
76
|
-
return error("Several displays are shared", `Pass --display with one of: ${displays.map((display) => display.id).join(", ")}`);
|
|
77
|
-
}
|
|
78
|
-
async function target(spacesCmd, opts, launching = false) {
|
|
79
|
-
const spaceId = await resolveSpace(spacesCmd);
|
|
80
|
-
const api = createClient().space(spaceId).displays;
|
|
81
|
-
let { displays, virtual } = await api.list();
|
|
82
|
-
if (launching && !opts.display && !displays.some((display) => display.apps) && virtual === "available")
|
|
83
|
-
({ displays } = await api.startVirtual());
|
|
84
|
-
const launchers = displays.filter((display) => display.apps);
|
|
85
|
-
return { spaceId, api, display: pickDisplay(launching && !opts.display && launchers.length > 0 ? launchers : displays, opts.display) };
|
|
86
|
-
}
|
|
87
|
-
function displayUrl(spaceId, displayId) {
|
|
88
|
-
return webUrl(`/spaces/${spaceId}?window=${encodeURIComponent(`display:${displayId}`)}`);
|
|
89
|
-
}
|
|
90
|
-
function needsHint(display) {
|
|
91
|
-
const needs = display.needs ?? [];
|
|
92
|
-
if (needs.length === 0)
|
|
93
|
-
return null;
|
|
94
|
-
if (needs.includes("phoneControl"))
|
|
95
|
-
return `${display.name || display.id} needs phone control: ask the user to set it up in the Cohub app on the phone.`;
|
|
96
|
-
if (!display.desktop)
|
|
97
|
-
return `${display.name || display.id} needs control: on the phone, enable Cohub in Accessibility settings.`;
|
|
98
|
-
const names = needs.map((need) => (need === "screenRecording" ? "Screen Recording" : "Accessibility")).join(" and ");
|
|
99
|
-
return `${display.name || display.id} needs ${names}: allow it for the Runtime's terminal in System Settings → Privacy & Security, then restart the Runtime.`;
|
|
100
|
-
}
|
|
101
|
-
async function writeOnce(path, content) {
|
|
102
|
-
await writeFile(path, content, { flag: "wx" }).catch((e) => {
|
|
103
|
-
if (e.code !== "EEXIST")
|
|
104
|
-
throw e;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
async function imageDir() {
|
|
108
|
-
const dir = resolve(IMAGE_DIR);
|
|
109
|
-
await mkdir(dir, { recursive: true });
|
|
110
|
-
await Promise.all([writeOnce(join(dir, "..", ".gitignore"), "*\n"), writeOnce(join(dir, ".nomedia"), "")]);
|
|
111
|
-
const images = (await readdir(dir)).filter((name) => name.endsWith(".jpg")).sort();
|
|
112
|
-
await Promise.all(images.slice(0, -(KEPT_IMAGES - 1)).map((name) => rm(join(dir, name), { force: true })));
|
|
113
|
-
return dir;
|
|
114
|
-
}
|
|
115
|
-
async function saveImage(spaceId, display, image, output) {
|
|
116
|
-
const name = `${new Date().toISOString().replace(/[:.]/g, "-")}-${display.id}.jpg`;
|
|
117
|
-
const path = output ? resolve(output) : join(await imageDir().catch(() => join(CACHE_DIR, "displays")), name);
|
|
118
|
-
await mkdir(dirname(path), { recursive: true });
|
|
119
|
-
await writeFile(path, Buffer.from(image.data, "base64"));
|
|
120
|
-
await rememberFrame(spaceId, display, image);
|
|
121
|
-
return { path, width: image.width, height: image.height };
|
|
122
|
-
}
|
|
123
|
-
async function screenshot(api, spaceId, display, maxSize, output) {
|
|
124
|
-
return saveImage(spaceId, display, await api.capture(display.id, { maxSize }), output);
|
|
125
|
-
}
|
|
126
|
-
function formatElement(element, frame, indent = true, box = true) {
|
|
127
|
-
const scaleX = frame.width - 1 || 1;
|
|
128
|
-
const scaleY = frame.height - 1 || 1;
|
|
129
|
-
const [x, y, width, height] = element.bounds;
|
|
130
|
-
const parts = [`${indent ? " ".repeat(element.depth) : ""}${element.ref}`, element.role];
|
|
131
|
-
if (element.name)
|
|
132
|
-
parts.push(JSON.stringify(element.name));
|
|
133
|
-
if (element.value)
|
|
134
|
-
parts.push(`value=${JSON.stringify(element.value)}`);
|
|
135
|
-
if (element.states?.length)
|
|
136
|
-
parts.push(`[${element.states.join(", ")}]`);
|
|
137
|
-
if (box)
|
|
138
|
-
parts.push(`(${Math.round(x * scaleX)},${Math.round(y * scaleY)} ${Math.round(width * scaleX)}x${Math.round(height * scaleY)})`);
|
|
139
|
-
return parts.join(" ");
|
|
140
|
-
}
|
|
141
|
-
function formatTree(tree, frame, compact = false) {
|
|
142
|
-
return tree.elements.map((element) => formatElement(element, frame, true, !compact || Boolean(element.actions?.length))).join("\n");
|
|
143
|
-
}
|
|
144
|
-
const ACTOR = process.env.COHUB_SESSION_ID
|
|
145
|
-
? { sessionId: process.env.COHUB_SESSION_ID, ...(process.env.COHUB_TURN_ID ? { turnId: process.env.COHUB_TURN_ID } : {}) }
|
|
146
|
-
: undefined;
|
|
147
|
-
function untilOf(opts) {
|
|
148
|
-
const until = {
|
|
149
|
-
...(opts.untilText ? { text: opts.untilText } : {}),
|
|
150
|
-
...(opts.untilGone ? { gone: opts.untilGone } : {}),
|
|
151
|
-
...(opts.untilApp ? { app: opts.untilApp } : {}),
|
|
152
|
-
...(opts.untilStable ? { stable: true } : {}),
|
|
153
|
-
};
|
|
154
|
-
if (Object.keys(until).length === 0)
|
|
155
|
-
return undefined;
|
|
156
|
-
return { ...until, ...(opts.timeoutMs ? { timeoutMs: parseNumber("timeout-ms", opts.timeoutMs) } : {}) };
|
|
157
|
-
}
|
|
158
|
-
async function act(spacesCmd, opts, actions) {
|
|
159
|
-
let sent = false;
|
|
160
|
-
try {
|
|
161
|
-
const launching = actions.some((action) => action.type === "launch" || action.type === "open");
|
|
162
|
-
const { spaceId, api, display } = await target(spacesCmd, opts, launching);
|
|
163
|
-
if (!display.input && actions.some((action) => action.type !== "wait"))
|
|
164
|
-
return error("This display is view only", needsHint(display) ?? "Allow control on the device first.");
|
|
165
|
-
const frame = await frameOf(spaceId, display, opts.size);
|
|
166
|
-
const tree = opts.tree ?? "compact";
|
|
167
|
-
if (!TREES.includes(tree))
|
|
168
|
-
return error("Invalid tree", `Use one of: ${TREES.join(", ")}`);
|
|
169
|
-
const last = actions.at(-1);
|
|
170
|
-
if (last) {
|
|
171
|
-
const until = untilOf(opts);
|
|
172
|
-
if (until)
|
|
173
|
-
last.until = until;
|
|
174
|
-
if (opts.label)
|
|
175
|
-
last.label = opts.label;
|
|
176
|
-
}
|
|
177
|
-
const steps = compileDisplayPlan(actions, frame.width, frame.height);
|
|
178
|
-
sent = steps.length > 0;
|
|
179
|
-
const result = await api.act(display.id, {
|
|
180
|
-
steps,
|
|
181
|
-
observe: { tree: tree, image: opts.screenshot ? "always" : "auto", maxSize: DEFAULT_MAX_SIZE },
|
|
182
|
-
...(ACTOR ? { actor: ACTOR } : {}),
|
|
183
|
-
});
|
|
184
|
-
const image = result.screen.image
|
|
185
|
-
? await saveImage(spaceId, display, result.screen.image, typeof opts.screenshot === "string" ? opts.screenshot : undefined)
|
|
186
|
-
: undefined;
|
|
187
|
-
const shown = image ?? frame;
|
|
188
|
-
if (result.stopped)
|
|
189
|
-
process.exitCode = 1;
|
|
190
|
-
if (jsonRequested(opts)) {
|
|
191
|
-
const { image: _, ...screen } = result.screen;
|
|
192
|
-
return outJson({ display: display.id, ...result, screen: { ...screen, ...(image ? { image } : {}) }, frame: { width: shown.width, height: shown.height } });
|
|
193
|
-
}
|
|
194
|
-
printResult(display, actions, result, shown, tree === "compact", image?.path);
|
|
195
|
-
}
|
|
196
|
-
catch (e) {
|
|
197
|
-
if (e instanceof DisplayActionError)
|
|
198
|
-
return error("Invalid action", e.message);
|
|
199
|
-
if (sent && isLostAnswer(e))
|
|
200
|
-
return error("The answer was lost", "The plan may have run, in part or whole: `look` before repeating any step.");
|
|
201
|
-
handleHttp(e);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function isLostAnswer(e) {
|
|
205
|
-
const status = e.status;
|
|
206
|
-
return status === undefined ? e instanceof TypeError : status >= 500 && status !== 501;
|
|
207
|
-
}
|
|
208
|
-
function targetText(target) {
|
|
209
|
-
return target.name ? `${target.role} ${JSON.stringify(target.name)}` : target.role;
|
|
210
|
-
}
|
|
211
|
-
function atPoint(action) {
|
|
212
|
-
return action.x !== undefined && action.ref === undefined && action.name === undefined && action.role === undefined;
|
|
213
|
-
}
|
|
214
|
-
function actionText(action) {
|
|
215
|
-
const point = atPoint(action) ? ` (${action.x},${action.y})` : "";
|
|
216
|
-
switch (action.type) {
|
|
217
|
-
case "tap": return `${action.count === 2 ? "double-tap" : action.count === 3 ? "triple-tap" : "tap"}${point}`;
|
|
218
|
-
case "long_press": return `long press${point}`;
|
|
219
|
-
case "swipe": return `swipe${point} to (${action.to_x},${action.to_y})`;
|
|
220
|
-
case "scroll": return `scroll ${action.direction ?? "down"}`;
|
|
221
|
-
case "type": return `type ${[...(action.text ?? "")].length} characters`; // never echo it: it may be a secret
|
|
222
|
-
case "key": return `key ${action.key}`;
|
|
223
|
-
case "system": return `press ${action.action}`;
|
|
224
|
-
case "launch": return `launch ${action.app}`;
|
|
225
|
-
case "open": return `open ${action.url}`;
|
|
226
|
-
case "wait": return "wait";
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function stepText(action, step) {
|
|
230
|
-
const parts = [action ? actionText(action) : "step"];
|
|
231
|
-
if (step.target)
|
|
232
|
-
parts.push(`${action && atPoint(action) ? "on " : action?.type === "type" ? "into " : ""}${targetText(step.target)}`);
|
|
233
|
-
if (action?.type !== "wait")
|
|
234
|
-
parts.push(`· ${step.effect}`);
|
|
235
|
-
parts.push(`· ${step.findMs + step.actMs + step.waitedMs} ms`);
|
|
236
|
-
return parts.join(" ");
|
|
237
|
-
}
|
|
238
|
-
function printResult(display, actions, result, frame, compact, imageFile) {
|
|
239
|
-
const name = display.name || display.id;
|
|
240
|
-
if (result.steps.length > 0 || result.stopped) {
|
|
241
|
-
const done = result.steps.length;
|
|
242
|
-
const still = result.steps.findIndex((step, index) => step.effect === "none" && actions[index]?.type !== "wait");
|
|
243
|
-
if (!result.stopped) {
|
|
244
|
-
if (still >= 0)
|
|
245
|
-
warn(`Step ${still + 1} changed nothing on ${name}: it may not have landed. Look before repeating it.`);
|
|
246
|
-
else
|
|
247
|
-
ok(`${done} step${done === 1 ? "" : "s"} on ${name}`);
|
|
248
|
-
}
|
|
249
|
-
for (const [index, step] of result.steps.entries())
|
|
250
|
-
console.log(` ${index + 1}. ${stepText(actions[index], step)}`);
|
|
251
|
-
if (result.stopped) {
|
|
252
|
-
console.log(`✗ Stopped (${result.stopped.reason}): ${result.stopped.message}`);
|
|
253
|
-
for (const candidate of result.stopped.candidates ?? [])
|
|
254
|
-
console.log(` ${formatElement(candidate, frame, false)}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const { screen } = result;
|
|
258
|
-
console.log(`\n${[screen.app, screen.quality === "poor" ? "the tree misses much of this screen: read the image" : null].filter(Boolean).join(" · ") || name}`);
|
|
259
|
-
if (screen.unchanged)
|
|
260
|
-
console.log(" The screen is as you last saw it; its refs are gone, so target by name or `look` again.");
|
|
261
|
-
if (screen.tree) {
|
|
262
|
-
console.log(formatTree(screen.tree, frame, compact));
|
|
263
|
-
if (screen.tree.truncated)
|
|
264
|
-
console.log(" More elements exist; pass --tree full or read `tree --max`.");
|
|
265
|
-
}
|
|
266
|
-
if (imageFile)
|
|
267
|
-
console.log(`\n Image ${frame.width}x${frame.height}: ${imageFile} (coordinates are its pixels)`);
|
|
268
|
-
if (screen.tree)
|
|
269
|
-
console.log(`\n Boxes are x,y and size in ${frame.width}x${frame.height} pixels.`);
|
|
270
|
-
if (display.held)
|
|
271
|
-
console.log(" A person at the device has taken it over; wait until they hand it back.");
|
|
272
|
-
else if (display.viewers?.some((viewer) => viewer.control))
|
|
273
|
-
console.log(" A person is watching with control; what you do here pauses while they act.");
|
|
274
|
-
}
|
|
275
|
-
const HANDOVER_ENDS = {
|
|
276
|
-
stopped: () => ["The person stopped this", "Do not go on with this Turn; ask them."],
|
|
277
|
-
gone: () => ["The display went away", "Ask the person what happened before going on."],
|
|
278
|
-
expired: (held) => held
|
|
279
|
-
? ["Timed out while the person is still working", "Tell them to say so in the chat when done; they will not wake you by handing back."]
|
|
280
|
-
: ["Timed out; the person did not take over", "Tell them what is needed, and to say so in the chat when done."],
|
|
281
|
-
};
|
|
282
|
-
async function handover(spacesCmd, opts) {
|
|
283
|
-
try {
|
|
284
|
-
const timeoutMs = opts.timeoutMs ? parseNumber("timeout-ms", opts.timeoutMs) : DISPLAY_HANDOVER_DEFAULT_MS;
|
|
285
|
-
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > DISPLAY_HANDOVER_MAX_MS)
|
|
286
|
-
return error("Invalid timeout", `--timeout-ms must be between 1 and ${DISPLAY_HANDOVER_MAX_MS} milliseconds.`);
|
|
287
|
-
const { api, display } = await target(spacesCmd, opts);
|
|
288
|
-
const params = { id: randomUUID(), reason: opts.reason, timeoutMs, ...(ACTOR ? { actor: ACTOR } : {}) };
|
|
289
|
-
const giveUpAt = Date.now() + timeoutMs + HANDOVER_RETRY_MS;
|
|
290
|
-
let result = await api.handover(display.id, { ...params, waitMs: opts.wait ? DISPLAY_HANDOVER_WAIT_MS : 0 });
|
|
291
|
-
while (opts.wait && result.state === "waiting") {
|
|
292
|
-
try {
|
|
293
|
-
result = await api.handover(display.id, { ...params, waitMs: DISPLAY_HANDOVER_WAIT_MS });
|
|
294
|
-
}
|
|
295
|
-
catch (e) {
|
|
296
|
-
if (!isLostAnswer(e) || Date.now() > giveUpAt)
|
|
297
|
-
throw e;
|
|
298
|
-
await new Promise((done) => setTimeout(done, HANDOVER_RETRY_GAP_MS));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (result.state === "waiting") {
|
|
302
|
-
if (jsonRequested(opts))
|
|
303
|
-
return outJson({ display: display.id, ...result });
|
|
304
|
-
return ok(`Asked the person: ${opts.reason}`);
|
|
305
|
-
}
|
|
306
|
-
if (result.state === "returned")
|
|
307
|
-
return act(spacesCmd, { display: display.id, json: opts.json }, []);
|
|
308
|
-
const [title, hint] = HANDOVER_ENDS[result.state](result.held);
|
|
309
|
-
if (jsonRequested(opts)) {
|
|
310
|
-
process.exitCode = 1;
|
|
311
|
-
return outJson({ display: display.id, ...result });
|
|
312
|
-
}
|
|
313
|
-
return error(title, hint);
|
|
314
|
-
}
|
|
315
|
-
catch (e) {
|
|
316
|
-
handleHttp(e);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
function withAct(command) {
|
|
320
|
-
return command
|
|
321
|
-
.option("-d, --display <id>", "Display id; defaults to the only one, or the agent screen")
|
|
322
|
-
.option("--size <WxH>", "Coordinates are pixels of an image this size (default: the latest image)")
|
|
323
|
-
.option("--until-text <text>", "Wait until this text shows")
|
|
324
|
-
.option("--until-gone <text>", "Wait until this text is gone, e.g. a loading label")
|
|
325
|
-
.option("--until-app <id>", "Wait until this app is in front")
|
|
326
|
-
.option("--until-stable", "Wait until the screen stops changing")
|
|
327
|
-
.option("--timeout-ms <ms>", "How long --until-* waits (default 8000)")
|
|
328
|
-
.option("--label <text>", "What this does, shown to people watching")
|
|
329
|
-
.option("--screenshot [path]", "Attach an image of the screen after (by default only when its tree misses much)")
|
|
330
|
-
.option("--tree <kind>", `The tree after: ${TREES.join(", ")}`)
|
|
331
|
-
.option("--json", "Output as JSON");
|
|
332
|
-
}
|
|
333
|
-
function withTarget(command) {
|
|
334
|
-
return command
|
|
335
|
-
.option("--name <text>", "The element that says this: whole, then start, then part")
|
|
336
|
-
.option("--role <role>", `Its role: ${DISPLAY_ELEMENT_ROLES.join(", ")}`)
|
|
337
|
-
.option("--nth <n>", "The nth match, top to bottom")
|
|
338
|
-
.option("--scroll", "Scroll the list on until it shows");
|
|
339
|
-
}
|
|
340
|
-
function targetOf(x, y, opts, command) {
|
|
341
|
-
if (opts.name !== undefined || opts.role !== undefined) {
|
|
342
|
-
if (opts.role !== undefined && !DISPLAY_ELEMENT_ROLES.includes(opts.role)) {
|
|
343
|
-
return error("Invalid role", `Use one of: ${DISPLAY_ELEMENT_ROLES.join(", ")}`);
|
|
344
|
-
}
|
|
345
|
-
return {
|
|
346
|
-
...(opts.name !== undefined ? { name: opts.name } : {}),
|
|
347
|
-
...(opts.role !== undefined ? { role: opts.role } : {}),
|
|
348
|
-
...(opts.nth !== undefined ? { nth: parseNumber("nth", opts.nth) } : {}),
|
|
349
|
-
...(opts.scroll ? { scroll: true } : {}),
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
if (x === undefined)
|
|
353
|
-
return error("Missing target", `Pass --name, an element ref, or x and y, e.g. ${command} --name Send.`);
|
|
354
|
-
if (y === undefined)
|
|
355
|
-
return isRef(x) ? { ref: x } : error("Invalid target", `Pass x and y, or an element ref from \`cohub spaces displays tree\`, e.g. ${command} e3.12.`);
|
|
356
|
-
return { x: parseNumber("x", x), y: parseNumber("y", y) };
|
|
357
|
-
}
|
|
358
|
-
export function registerSpaceDisplays(spacesCmd) {
|
|
359
|
-
const displays = spacesCmd
|
|
360
|
-
.command("displays")
|
|
361
|
-
.description("Screens shared with a Space: view, read and act on them")
|
|
362
|
-
.hook("preAction", async () => { await resolveSpace(spacesCmd); });
|
|
363
|
-
displays
|
|
364
|
-
.command("ls")
|
|
365
|
-
.alias("list")
|
|
366
|
-
.description("List shared displays, what they can do, and who uses them")
|
|
367
|
-
.option("--json", "Output as JSON")
|
|
368
|
-
.action(async (opts) => {
|
|
369
|
-
try {
|
|
370
|
-
const spaceId = await resolveSpace(spacesCmd);
|
|
371
|
-
const result = await createClient().space(spaceId).displays.list();
|
|
372
|
-
if (jsonRequested(opts))
|
|
373
|
-
return outJson(result);
|
|
374
|
-
if (result.displays.length === 0)
|
|
375
|
-
console.log(` (no shared displays) ${NO_DISPLAY_HINT}`);
|
|
376
|
-
else {
|
|
377
|
-
table(result.displays.map((display) => ({
|
|
378
|
-
...display,
|
|
379
|
-
size: `${display.width}x${display.height}`,
|
|
380
|
-
kind: display.kind ?? "screen",
|
|
381
|
-
abilities: [display.stream && "view", display.capture && "capture", display.input && "control", display.tree && "tree", display.apps && "apps", display.desktop && "desktop"].filter(Boolean).join(", "),
|
|
382
|
-
using: [
|
|
383
|
-
display.held && "a person at the device",
|
|
384
|
-
display.activity && `an agent${display.activity.label ? `: ${display.activity.label}` : ""}`,
|
|
385
|
-
display.viewers?.length && `${display.viewers.length} watching${display.viewers.some((viewer) => viewer.control) ? " (controlling)" : ""}`,
|
|
386
|
-
].filter(Boolean).join("; ") || "—",
|
|
387
|
-
})), [
|
|
388
|
-
{ key: "id", label: "ID" },
|
|
389
|
-
{ key: "name", label: "Name" },
|
|
390
|
-
{ key: "kind", label: "Kind" },
|
|
391
|
-
{ key: "size", label: "Size" },
|
|
392
|
-
{ key: "abilities", label: "Abilities" },
|
|
393
|
-
{ key: "using", label: "In use by" },
|
|
394
|
-
]);
|
|
395
|
-
for (const display of result.displays) {
|
|
396
|
-
const hint = needsHint(display);
|
|
397
|
-
if (hint)
|
|
398
|
-
console.log(` ${hint}`);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
if (result.virtual)
|
|
402
|
-
console.log(` Virtual screen: ${result.virtual === "running" ? "running (cohub spaces displays stop)" : "available (cohub spaces displays start)"}`);
|
|
403
|
-
}
|
|
404
|
-
catch (e) {
|
|
405
|
-
handleHttp(e);
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
displays
|
|
409
|
-
.command("start")
|
|
410
|
-
.description("Start the machine's virtual screen: a phone's agent screen, or a sandbox's")
|
|
411
|
-
.option("--size <WxH>", "Screen size where the machine lets you choose (default 1280x800)")
|
|
412
|
-
.option("--json", "Output as JSON")
|
|
413
|
-
.action(async (opts) => {
|
|
414
|
-
try {
|
|
415
|
-
const spaceId = await resolveSpace(spacesCmd);
|
|
416
|
-
if (opts.size)
|
|
417
|
-
parseSize(opts.size);
|
|
418
|
-
const result = await createClient().space(spaceId).displays.startVirtual(opts.size ? { size: opts.size } : {});
|
|
419
|
-
const started = result.displays.find((display) => display.kind === "agent") ?? result.displays[0];
|
|
420
|
-
const url = started ? displayUrl(spaceId, started.id) : null;
|
|
421
|
-
if (jsonRequested(opts))
|
|
422
|
-
return outJson({ ...result, url });
|
|
423
|
-
ok("Virtual screen running; apps and programs you start from now on run on it");
|
|
424
|
-
if (url)
|
|
425
|
-
console.log(` Watch and take over: ${url}`);
|
|
426
|
-
}
|
|
427
|
-
catch (e) {
|
|
428
|
-
handleHttp(e);
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
displays
|
|
432
|
-
.command("stop")
|
|
433
|
-
.description("Stop the machine's virtual screen")
|
|
434
|
-
.option("--json", "Output as JSON")
|
|
435
|
-
.action(async (opts) => {
|
|
436
|
-
try {
|
|
437
|
-
const spaceId = await resolveSpace(spacesCmd);
|
|
438
|
-
const result = await createClient().space(spaceId).displays.stopVirtual();
|
|
439
|
-
if (jsonRequested(opts))
|
|
440
|
-
return outJson(result);
|
|
441
|
-
ok("Virtual screen stopped");
|
|
442
|
-
}
|
|
443
|
-
catch (e) {
|
|
444
|
-
handleHttp(e);
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
displays
|
|
448
|
-
.command("capture")
|
|
449
|
-
.description("Save a screenshot; later coordinates are its pixels")
|
|
450
|
-
.option("-d, --display <id>", "Display id; defaults to the only one, or the agent screen")
|
|
451
|
-
.option("-o, --output <path>", `Where to write the image (default: ${IMAGE_DIR}/, the latest ${KEPT_IMAGES} kept)`)
|
|
452
|
-
.option("--max-size <px>", `Longest edge in pixels (default ${DEFAULT_MAX_SIZE})`)
|
|
453
|
-
.option("--json", "Output as JSON")
|
|
454
|
-
.action(async (opts) => {
|
|
455
|
-
try {
|
|
456
|
-
const { spaceId, api, display } = await target(spacesCmd, opts);
|
|
457
|
-
const maxSize = opts.maxSize ? parseNumber("max-size", opts.maxSize) : DEFAULT_MAX_SIZE;
|
|
458
|
-
const shot = await screenshot(api, spaceId, display, maxSize, opts.output);
|
|
459
|
-
if (jsonRequested(opts))
|
|
460
|
-
return outJson({ display: display.id, ...shot });
|
|
461
|
-
ok(`Saved ${shot.width}x${shot.height} screenshot to ${shot.path}`);
|
|
462
|
-
}
|
|
463
|
-
catch (e) {
|
|
464
|
-
handleHttp(e);
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
displays
|
|
468
|
-
.command("tree")
|
|
469
|
-
.description("Read the interface as elements: refs to act on, roles, names and boxes")
|
|
470
|
-
.option("-d, --display <id>", "Display id; defaults to the only one, or the agent screen")
|
|
471
|
-
.option("--max <n>", "Most elements to return (default 300)")
|
|
472
|
-
.option("--full", "Every element, nested, instead of what can be acted on or read")
|
|
473
|
-
.addOption(new Option("--compact").hideHelp())
|
|
474
|
-
.option("--json", "Output as JSON")
|
|
475
|
-
.action(async (opts) => {
|
|
476
|
-
try {
|
|
477
|
-
const { spaceId, api, display } = await target(spacesCmd, opts);
|
|
478
|
-
if (!display.tree)
|
|
479
|
-
return error("This display has no element tree", "Use capture and coordinates instead.");
|
|
480
|
-
const tree = await api.tree(display.id, {
|
|
481
|
-
...(opts.max ? { maxElements: parseNumber("max", opts.max) } : {}),
|
|
482
|
-
...(opts.full ? {} : { compact: true }),
|
|
483
|
-
});
|
|
484
|
-
if (jsonRequested(opts))
|
|
485
|
-
return outJson(tree);
|
|
486
|
-
const frame = await frameOf(spaceId, display);
|
|
487
|
-
if (tree.app)
|
|
488
|
-
console.log(tree.app);
|
|
489
|
-
console.log(formatTree(tree, frame, !opts.full));
|
|
490
|
-
console.log(`\n Boxes are x,y and size in ${frame.width}x${frame.height} pixels. Act with: tap --name <text> · type <text> --into <ref> · act < plan.json`);
|
|
491
|
-
if (tree.truncated)
|
|
492
|
-
console.log(" More elements exist; pass --max to read more.");
|
|
493
|
-
}
|
|
494
|
-
catch (e) {
|
|
495
|
-
handleHttp(e);
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
displays
|
|
499
|
-
.command("apps")
|
|
500
|
-
.description("List the apps a display can launch")
|
|
501
|
-
.option("-d, --display <id>", "Display id; defaults to the only one, or the agent screen")
|
|
502
|
-
.option("--json", "Output as JSON")
|
|
503
|
-
.action(async (opts) => {
|
|
504
|
-
try {
|
|
505
|
-
const { api, display } = await target(spacesCmd, opts);
|
|
506
|
-
if (!display.apps)
|
|
507
|
-
return error("This display does not launch apps");
|
|
508
|
-
const { apps } = await api.apps(display.id);
|
|
509
|
-
if (jsonRequested(opts))
|
|
510
|
-
return outJson({ apps });
|
|
511
|
-
table(apps, [{ key: "id", label: "ID" }, { key: "name", label: "Name" }]);
|
|
512
|
-
}
|
|
513
|
-
catch (e) {
|
|
514
|
-
handleHttp(e);
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
withAct(displays.command("look").description("Read the screen as `act` reports it, without acting; --until-* waits first"))
|
|
518
|
-
.action((opts) => act(spacesCmd, opts, untilOf(opts) ? [{ type: "wait" }] : []));
|
|
519
|
-
withAct(displays.command("launch <app>").description("Launch an app by id (see `apps`) and wait until it is in front"))
|
|
520
|
-
.action((app, opts) => act(spacesCmd, { untilApp: app, ...opts }, [{ type: "launch", app }]));
|
|
521
|
-
withAct(displays.command("open <url>").description("Open a link, or a page of the system's settings"))
|
|
522
|
-
.action((url, opts) => act(spacesCmd, opts, [{ type: "open", url }]));
|
|
523
|
-
withAct(withTarget(displays.command("tap [x] [y]").description("Tap an element (--name, or a ref) or a point")))
|
|
524
|
-
.option("--count <n>", "2 to double-tap, 3 to triple-tap")
|
|
525
|
-
.option("--button <button>", `Mouse button on a desktop: ${BUTTONS.join(", ")}`)
|
|
526
|
-
.action((x, y, opts) => {
|
|
527
|
-
const button = BUTTONS.find((candidate) => candidate === (opts.button ?? "primary"));
|
|
528
|
-
if (!button)
|
|
529
|
-
return error("Invalid button", `Use one of: ${BUTTONS.join(", ")}`);
|
|
530
|
-
return act(spacesCmd, opts, [{
|
|
531
|
-
type: "tap", ...targetOf(x, y, opts, "tap"), button,
|
|
532
|
-
...(opts.count ? { count: parseNumber("count", opts.count) } : {}),
|
|
533
|
-
}]);
|
|
534
|
-
});
|
|
535
|
-
withAct(withTarget(displays.command("long-press [x] [y]").description("Touch and hold an element or a point")))
|
|
536
|
-
.option("--duration <ms>", "Hold time in milliseconds", "800")
|
|
537
|
-
.action((x, y, opts) => act(spacesCmd, opts, [{ type: "long_press", ...targetOf(x, y, opts, "long-press"), duration_ms: parseNumber("duration", opts.duration) }]));
|
|
538
|
-
withAct(displays.command("swipe <x1> <y1> <x2> <y2>").description("Swipe from one point to another"))
|
|
539
|
-
.option("--duration <ms>", "Swipe time in milliseconds", "300")
|
|
540
|
-
.action((x1, y1, x2, y2, opts) => act(spacesCmd, opts, [{
|
|
541
|
-
type: "swipe",
|
|
542
|
-
x: parseNumber("x1", x1), y: parseNumber("y1", y1),
|
|
543
|
-
to_x: parseNumber("x2", x2), to_y: parseNumber("y2", y2),
|
|
544
|
-
duration_ms: parseNumber("duration", opts.duration),
|
|
545
|
-
}]));
|
|
546
|
-
withAct(displays.command("scroll <direction>").description("Scroll content up, down, left or right"))
|
|
547
|
-
.option("--amount <fraction>", "Fraction of the display, 0.1–1", "0.5")
|
|
548
|
-
.option("--in <ref>", "Scroll this element of the tree")
|
|
549
|
-
.action((direction, opts) => {
|
|
550
|
-
if (!DIRECTIONS.includes(direction))
|
|
551
|
-
return error("Invalid direction", `Use one of: ${DIRECTIONS.join(", ")}`);
|
|
552
|
-
return act(spacesCmd, opts, [{
|
|
553
|
-
type: "scroll", direction: direction, amount: parseNumber("amount", opts.amount),
|
|
554
|
-
...(opts.in ? { ref: opts.in } : {}),
|
|
555
|
-
}]);
|
|
556
|
-
});
|
|
557
|
-
withAct(withTarget(displays.command("type <text>").description("Type into the focused field, or replace a field's text")))
|
|
558
|
-
.option("--into <ref>", "Replace the text of this element of the tree")
|
|
559
|
-
.action((text, opts) => {
|
|
560
|
-
const field = opts.into ? { ref: opts.into } : opts.name !== undefined || opts.role !== undefined ? targetOf(undefined, undefined, opts, "type") : {};
|
|
561
|
-
return act(spacesCmd, opts, [{ type: "type", text, ...field }]);
|
|
562
|
-
});
|
|
563
|
-
withAct(displays.command("key <key>").description("Press a key or shortcut, e.g. Enter or Control+a"))
|
|
564
|
-
.action((key, opts) => act(spacesCmd, opts, [{ type: "key", key }]));
|
|
565
|
-
withAct(displays.command("press <button>").description(`Press a system button: ${DISPLAY_SYSTEM_ACTIONS.join(", ")}`))
|
|
566
|
-
.action((button, opts) => {
|
|
567
|
-
const action = DISPLAY_SYSTEM_ACTIONS.find((candidate) => candidate === button);
|
|
568
|
-
if (!action)
|
|
569
|
-
return error("Invalid button", `Use one of: ${DISPLAY_SYSTEM_ACTIONS.join(", ")}`);
|
|
570
|
-
return act(spacesCmd, opts, [{ type: "system", action }]);
|
|
571
|
-
});
|
|
572
|
-
withAct(displays.command("wait").description("Wait for --until-* (or a pause) without acting"))
|
|
573
|
-
.option("--ms <ms>", "Pause this long first")
|
|
574
|
-
.action((opts) => act(spacesCmd, opts, [{ type: "wait", ...(opts.ms ? { duration_ms: parseNumber("ms", opts.ms) } : {}) }]));
|
|
575
|
-
displays
|
|
576
|
-
.command("handover")
|
|
577
|
-
.description("Ask the person to do what you must not (sign in, pay), and wait until they hand back")
|
|
578
|
-
.requiredOption("--reason <text>", "What they need to do, in their language; shown on the device")
|
|
579
|
-
.option("-d, --display <id>", "Display id; defaults to the only one, or the agent screen")
|
|
580
|
-
.option("--timeout-ms <ms>", `How long to wait (default: ${DISPLAY_HANDOVER_DEFAULT_MS}; max: ${DISPLAY_HANDOVER_MAX_MS})`)
|
|
581
|
-
.option("--no-wait", "Ask and exit without waiting")
|
|
582
|
-
.option("--json", "Output as JSON")
|
|
583
|
-
.action(async (opts) => {
|
|
584
|
-
await handover(spacesCmd, opts);
|
|
585
|
-
});
|
|
586
|
-
withAct(displays.command("act").description("Run a plan: a JSON array of actions from --actions or stdin"))
|
|
587
|
-
.option("--actions <json>", 'Actions, e.g. \'[{"type":"launch","app":"com.android.settings"},{"type":"tap","name":"Wi-Fi"}]\'')
|
|
588
|
-
.addHelpText("after", `
|
|
589
|
-
Each action is one step; the plan runs on the device and stops at the first
|
|
590
|
-
surprise (a target missing or ambiguous, an until that never came, a dialog,
|
|
591
|
-
another app, a person taking over), then reports the screen.
|
|
592
|
-
|
|
593
|
-
{"type":"launch","app":"<id>"} {"type":"open","url":"<link>"}
|
|
594
|
-
{"type":"tap","name":"Send"} {"type":"tap","name":"Ada","scroll":true} {"type":"tap","ref":"e3.12"} {"type":"tap","x":540,"y":1200}
|
|
595
|
-
{"type":"type","text":"hi","name":"Message","role":"textField"} {"type":"type","text":"hi"}
|
|
596
|
-
{"type":"scroll","direction":"down"} {"type":"swipe",...} {"type":"key","key":"Enter"}
|
|
597
|
-
{"type":"system","action":"back"} {"type":"long_press",...} {"type":"wait","duration_ms":500}
|
|
598
|
-
|
|
599
|
-
Any action takes "until": {"text"|"gone"|"app": …, "stable": true, "timeoutMs": 8000}
|
|
600
|
-
and "label": what it does, shown to people watching; name matches take "role" and "nth".`)
|
|
601
|
-
.action(async (opts) => {
|
|
602
|
-
let raw = opts.actions ?? "";
|
|
603
|
-
if (!raw && !process.stdin.isTTY) {
|
|
604
|
-
const chunks = [];
|
|
605
|
-
for await (const chunk of process.stdin)
|
|
606
|
-
chunks.push(chunk);
|
|
607
|
-
raw = Buffer.concat(chunks).toString();
|
|
608
|
-
}
|
|
609
|
-
let actions;
|
|
610
|
-
try {
|
|
611
|
-
actions = JSON.parse(raw);
|
|
612
|
-
}
|
|
613
|
-
catch {
|
|
614
|
-
return error("Invalid actions", "Pass a JSON array with --actions or on stdin.");
|
|
615
|
-
}
|
|
616
|
-
if (!Array.isArray(actions) || actions.length === 0)
|
|
617
|
-
return error("Invalid actions", "Pass a non-empty JSON array.");
|
|
618
|
-
return act(spacesCmd, opts, actions);
|
|
619
|
-
});
|
|
620
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { SpaceFsCopyResult, SpaceFsCopyStats } from "@neta-art/cohub";
|
|
2
|
-
import { type Command } from "commander";
|
|
3
|
-
export declare function formatBytes(bytes: number): string;
|
|
4
|
-
export declare function formatCopySummary(result: SpaceFsCopyStats & Pick<SpaceFsCopyResult, "overwritten" | "skipped">): string;
|
|
5
|
-
export declare function registerSpaceFileTransfer(filesCmd: Command, spacesCmd: Command): void;
|