@reticlehq/computer 0.0.0-stage → 3.11.1

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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +12 -0
  3. package/README.md +237 -2
  4. package/bin/attach.mjs +333 -0
  5. package/dist/attach.d.ts +105 -0
  6. package/dist/attach.js +234 -0
  7. package/dist/channels.d.ts +42 -0
  8. package/dist/channels.js +46 -0
  9. package/dist/computer-realm.d.ts +54 -0
  10. package/dist/computer-realm.js +487 -0
  11. package/dist/doctor.d.ts +32 -0
  12. package/dist/doctor.js +42 -0
  13. package/dist/driver.d.ts +227 -0
  14. package/dist/driver.js +73 -0
  15. package/dist/effect.d.ts +60 -0
  16. package/dist/effect.js +158 -0
  17. package/dist/files.d.ts +16 -0
  18. package/dist/files.js +40 -0
  19. package/dist/hud/port.d.ts +44 -0
  20. package/dist/hud/port.js +6 -0
  21. package/dist/index.d.ts +34 -0
  22. package/dist/index.js +22 -0
  23. package/dist/lines.d.ts +34 -0
  24. package/dist/lines.js +80 -0
  25. package/dist/mac/from-ax.d.ts +27 -0
  26. package/dist/mac/from-ax.js +275 -0
  27. package/dist/mac/mac-driver.d.ts +42 -0
  28. package/dist/mac/mac-driver.js +355 -0
  29. package/dist/mac/mac-hud.d.ts +10 -0
  30. package/dist/mac/mac-hud.js +142 -0
  31. package/dist/peer/act-effect.d.ts +9 -0
  32. package/dist/peer/act-effect.js +13 -0
  33. package/dist/peer/commands.d.ts +87 -0
  34. package/dist/peer/commands.js +811 -0
  35. package/dist/peer/form.d.ts +62 -0
  36. package/dist/peer/form.js +103 -0
  37. package/dist/peer/link-switch.d.ts +12 -0
  38. package/dist/peer/link-switch.js +38 -0
  39. package/dist/peer/peer.d.ts +43 -0
  40. package/dist/peer/peer.js +216 -0
  41. package/dist/peer/pointer.d.ts +97 -0
  42. package/dist/peer/pointer.js +289 -0
  43. package/dist/peer/scroll.d.ts +12 -0
  44. package/dist/peer/scroll.js +157 -0
  45. package/dist/peer/seen.d.ts +18 -0
  46. package/dist/peer/seen.js +61 -0
  47. package/dist/peer/select.d.ts +27 -0
  48. package/dist/peer/select.js +78 -0
  49. package/dist/peer/window.d.ts +25 -0
  50. package/dist/peer/window.js +111 -0
  51. package/dist/ui-node.d.ts +93 -0
  52. package/dist/ui-node.js +192 -0
  53. package/dist/win/helper-launch.d.ts +16 -0
  54. package/dist/win/helper-launch.js +57 -0
  55. package/native/linux/Dockerfile +22 -0
  56. package/native/linux/reticle-atspi.py +933 -0
  57. package/native/linux/sandbox.mjs +127 -0
  58. package/native/mac/build/reticle-ax +0 -0
  59. package/native/mac/build/reticle-hud +0 -0
  60. package/native/mac/hud.swift +749 -0
  61. package/native/mac/reticle-ax.swift +1786 -0
  62. package/native/win/reticle-uia.ps1 +620 -0
  63. package/package.json +65 -3
@@ -0,0 +1,127 @@
1
+ // `reticle-computer --sandbox linux`: a Linux desktop of its own for the agent, in a container.
2
+ // The application runs on an X screen in memory, and joins the daemon of this machine. The agent
3
+ // works there; the person's screen, pointer and keyboard are not used at all.
4
+ //
5
+ // reticle-computer --sandbox linux --app <name> --open "<command>" [--port <port>]
6
+ // reticle-computer --sandbox stop
7
+ //
8
+ // Needs Docker. The image is built once from native/linux/Dockerfile. The package is mounted into
9
+ // the container read-only, at the same path, so the container runs this same version.
10
+ import { execFileSync, spawnSync } from 'node:child_process';
11
+ import { readFileSync, realpathSync } from 'node:fs';
12
+ import { createRequire } from 'node:module';
13
+ import { homedir } from 'node:os';
14
+ import { dirname, join, sep } from 'node:path';
15
+ import { setTimeout as sleep } from 'node:timers/promises';
16
+ import { fileURLToPath } from 'node:url';
17
+
18
+ const IMAGE = 'reticle-computer-linux:1';
19
+ const LABEL = 'reticle.computer.sandbox';
20
+ const here = fileURLToPath(new URL('.', import.meta.url));
21
+ const pkg = realpathSync(join(here, '..', '..'));
22
+ const say = (line) => process.stdout.write(`${line}\n`);
23
+ const docker = (args, options = {}) =>
24
+ execFileSync('docker', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], ...options });
25
+
26
+ /** The longest folder that holds both paths. */
27
+ function common(a, b) {
28
+ const x = a.split(sep);
29
+ const y = b.split(sep);
30
+ let n = 0;
31
+ while (n < x.length && n < y.length && x[n] === y[n]) n += 1;
32
+ return x.slice(0, n).join(sep) || sep;
33
+ }
34
+
35
+ export async function sandbox(argv) {
36
+ const valueOf = (flag) => {
37
+ const at = argv.indexOf(flag);
38
+ return at < 0 ? undefined : argv[at + 1];
39
+ };
40
+ if (0 !== spawnSync('docker', ['info'], { stdio: 'ignore' }).status) {
41
+ say('The sandbox needs Docker, and Docker is not running. Start Docker, and try again.');
42
+ return 2;
43
+ }
44
+ if ('stop' === valueOf('--sandbox')) {
45
+ const ids = docker(['ps', '-q', '--filter', `label=${LABEL}`])
46
+ .split('\n')
47
+ .filter(Boolean);
48
+ for (const id of ids) docker(['kill', id]);
49
+ say(`Stopped ${String(ids.length)} sandbox(es).`);
50
+ return 0;
51
+ }
52
+ if ('linux' !== valueOf('--sandbox')) {
53
+ say('The sandbox is Linux: --sandbox linux. Or --sandbox stop.');
54
+ return 2;
55
+ }
56
+ const app = valueOf('--app');
57
+ const open = valueOf('--open');
58
+ if (app === undefined || open === undefined) {
59
+ say('Name the application and how to start it: --app <name> --open "<command>".');
60
+ return 2;
61
+ }
62
+ if (0 !== spawnSync('docker', ['image', 'inspect', IMAGE], { stdio: 'ignore' }).status) {
63
+ say(`Building ${IMAGE} once, from ${join(here, 'Dockerfile')}. This takes a few minutes.`);
64
+ docker(['build', '-t', IMAGE, '-f', join(here, 'Dockerfile'), here], { stdio: 'inherit' });
65
+ }
66
+ // The package and its dependencies, at the same paths, read-only.
67
+ const core = realpathSync(createRequire(join(pkg, 'package.json')).resolve('@reticlehq/core'));
68
+ const mount = common(pkg, dirname(core));
69
+ const port = valueOf('--port') ?? process.env['RETICLE_PORT'] ?? '4400';
70
+ let token = process.env['RETICLE_TOKEN'];
71
+ try {
72
+ token ??= readFileSync(join(homedir(), '.reticle', 'pairing-token'), 'utf8').trim();
73
+ } catch {
74
+ // ponytail: no token file; the bridge then refuses the dial, and the command says so.
75
+ }
76
+ // Docker Desktop reaches this machine's localhost as host.docker.internal. Docker on Linux
77
+ // shares the network of the machine instead.
78
+ const linux = 'linux' === process.platform;
79
+ const host = linux ? '127.0.0.1' : 'host.docker.internal';
80
+ const name = `reticle-computer-${app.replace(/[^a-zA-Z0-9_.-]/g, '-')}`;
81
+ const attach = join(pkg, 'bin', 'attach.mjs');
82
+ const inside = `${open} & sleep 3; exec node '${attach}' --app '${app}' --host ${host} --port ${port} --no-hud`;
83
+ docker([
84
+ 'run',
85
+ '-d',
86
+ '--rm',
87
+ '--name',
88
+ name,
89
+ '--label',
90
+ LABEL,
91
+ ...(linux ? ['--network', 'host'] : []),
92
+ ...(token === undefined ? [] : ['-e', `RETICLE_TOKEN=${token}`]),
93
+ '-v',
94
+ `${mount}:${mount}:ro`,
95
+ IMAGE,
96
+ 'dbus-run-session',
97
+ '--',
98
+ 'xvfb-run',
99
+ '-a',
100
+ '-s',
101
+ '-screen 0 1280x800x24',
102
+ 'sh',
103
+ '-c',
104
+ inside,
105
+ ]);
106
+ // The joined line of the command in the container: it has the sessionId to give each call.
107
+ for (let i = 0; i < 60; i += 1) {
108
+ await sleep(1000);
109
+ const logs = spawnSync('docker', ['logs', name], { encoding: 'utf8' });
110
+ const joined = `${logs.stdout}${logs.stderr}`
111
+ .split('\n')
112
+ .find((l) => l.startsWith('{"joined"'));
113
+ if (joined !== undefined) {
114
+ say(joined);
115
+ say(
116
+ `It runs in the container ${name}, on a screen of its own. Stop it: reticle-computer --sandbox stop`,
117
+ );
118
+ return 0;
119
+ }
120
+ if (0 !== spawnSync('docker', ['inspect', name], { stdio: 'ignore' }).status) {
121
+ say(`The sandbox ended before ${app} joined. Its output:\n${logs.stdout}${logs.stderr}`);
122
+ return 1;
123
+ }
124
+ }
125
+ say(`${app} did not join in 60 seconds. See: docker logs ${name}`);
126
+ return 1;
127
+ }
Binary file
Binary file