@1outres/dsh-bot-connector-desktop 0.0.0-stage → 0.3.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.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -2
  3. package/cordis.patch.yml +6 -0
  4. package/debian-packages.txt +34 -0
  5. package/icon.svg +10 -0
  6. package/lib/client.js +14592 -0
  7. package/lib/index.js +2472 -0
  8. package/locale/en.json +6 -0
  9. package/locale/ja.json +6 -0
  10. package/package.json +68 -3
  11. package/src/client/DesktopPanel.tsx +160 -0
  12. package/src/client/base64.ts +14 -0
  13. package/src/client/channel.ts +73 -0
  14. package/src/client/dsh.ts +17 -0
  15. package/src/client/i18n.ts +42 -0
  16. package/src/client/index.tsx +28 -0
  17. package/src/client/novnc.d.ts +17 -0
  18. package/src/client/screen-session.ts +171 -0
  19. package/src/client/styles.ts +62 -0
  20. package/src/host/agent/check.ts +147 -0
  21. package/src/host/agent/client.ts +32 -0
  22. package/src/host/agent/connect.ts +45 -0
  23. package/src/host/agent/protocol.ts +249 -0
  24. package/src/host/agent/rpc.ts +161 -0
  25. package/src/host/connector.ts +59 -0
  26. package/src/host/control.ts +180 -0
  27. package/src/host/frame.ts +97 -0
  28. package/src/host/image.ts +96 -0
  29. package/src/host/screen/relay.ts +128 -0
  30. package/src/host/screen/rfb-filter.ts +229 -0
  31. package/src/host/screen/stream.ts +35 -0
  32. package/src/host/session.ts +39 -0
  33. package/src/host/settings.ts +37 -0
  34. package/src/host/sheet.ts +177 -0
  35. package/src/host/tools/arguments.ts +71 -0
  36. package/src/host/tools/clipboard.ts +55 -0
  37. package/src/host/tools/define.ts +131 -0
  38. package/src/host/tools/elements.ts +209 -0
  39. package/src/host/tools/handoff.ts +138 -0
  40. package/src/host/tools/index.ts +28 -0
  41. package/src/host/tools/keyboard.ts +101 -0
  42. package/src/host/tools/pointer.ts +173 -0
  43. package/src/host/tools/screen.ts +142 -0
  44. package/src/host/tools/sheet.ts +98 -0
  45. package/src/host/tools/windows.ts +104 -0
  46. package/src/host/vm/commands.ts +71 -0
  47. package/src/host/vm/files.ts +93 -0
  48. package/src/host/vm/layout.ts +63 -0
  49. package/src/host/vm/packages.ts +26 -0
  50. package/src/host/vm/preparation.ts +249 -0
  51. package/src/index.ts +62 -0
  52. package/src/shared/connector.ts +2 -0
  53. package/src/shared/screen.ts +103 -0
  54. package/src/text-files.d.ts +4 -0
  55. package/vm/agent/dsh_desktop_agent/__init__.py +0 -0
  56. package/vm/agent/dsh_desktop_agent/__main__.py +35 -0
  57. package/vm/agent/dsh_desktop_agent/actions.py +96 -0
  58. package/vm/agent/dsh_desktop_agent/atspi_access.py +160 -0
  59. package/vm/agent/dsh_desktop_agent/errors.py +17 -0
  60. package/vm/agent/dsh_desktop_agent/inputs.py +128 -0
  61. package/vm/agent/dsh_desktop_agent/launcher.py +27 -0
  62. package/vm/agent/dsh_desktop_agent/limits.py +22 -0
  63. package/vm/agent/dsh_desktop_agent/loop.py +13 -0
  64. package/vm/agent/dsh_desktop_agent/model.py +44 -0
  65. package/vm/agent/dsh_desktop_agent/observer.py +113 -0
  66. package/vm/agent/dsh_desktop_agent/params.py +71 -0
  67. package/vm/agent/dsh_desktop_agent/render.py +76 -0
  68. package/vm/agent/dsh_desktop_agent/screen.py +29 -0
  69. package/vm/agent/dsh_desktop_agent/server.py +82 -0
  70. package/vm/agent/dsh_desktop_agent/service.py +342 -0
  71. package/vm/agent/dsh_desktop_agent/sheet.py +68 -0
  72. package/vm/agent/dsh_desktop_agent/snapshots.py +40 -0
  73. package/vm/agent/dsh_desktop_agent/tables.py +111 -0
  74. package/vm/agent/dsh_desktop_agent/walker.py +177 -0
  75. package/vm/agent/run.py +3 -0
  76. package/vm/apt/google-chrome.asc +305 -0
  77. package/vm/apt/google-chrome.sources +6 -0
  78. package/vm/bin/chrome-ready +8 -0
  79. package/vm/bin/chrome-run +6 -0
  80. package/vm/bin/google-chrome-stable +7 -0
  81. package/vm/bin/xvnc-start +20 -0
  82. package/vm/config/fcitx5-profile +15 -0
  83. package/vm/config/libreoffice.xcd +42 -0
  84. package/vm/systemd/dsh-desktop-agent.service +17 -0
  85. package/vm/systemd/dsh-desktop-chrome.service +19 -0
  86. package/vm/systemd/dsh-desktop-im.service +14 -0
  87. package/vm/systemd/dsh-desktop-session.service +25 -0
  88. package/vm/systemd/dsh-desktop-xvnc.service +12 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 1outres
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,67 @@
1
- # Temporary Holding Version
1
+ # @1outres/dsh-bot-connector-desktop
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A bot-core connector (`desktop`) that gives each bot a desktop in its own VM — XFCE on Xvnc with LibreOffice, Google Chrome, a terminal and a file manager — which the bot reads through the accessibility tree (AT-SPI) and operates with keyboard and mouse, and which a person watches and takes over in the bot's window (the **Desktop** panel). Row id `bot-connector-desktop`. A Host part and a Client part; it needs `@1outres/dsh-bot-core` and a bot environment (`@1outres/dsh-bot-vm`).
4
+
5
+ It is off for every bot until a person enables it (`bot.configureConnector(botId, "desktop", { enabled: true, values: { resolution } })`, Remote `botConnectors.configure`). It needs a bot whose VM spec has 4 GiB of memory or more (`minimumSpec`; bot-core refuses the switch otherwise, and new bots get 6 GiB); then bot-core runs the preparation, shown as `preparing` steps.
6
+
7
+ ## What runs where
8
+
9
+ - **Host**: the connector definition and a thin client. It reaches the VM only through bot-core's environment access (`exec`, `spawn`, `writeFile` as the bot user, `sudo -n` where root is needed); it never calls Incus or opens SSH itself.
10
+ - **VM** (bot user's systemd user services, linger): `dsh-desktop-xvnc` (Xvnc :1, RFB only on `$XDG_RUNTIME_DIR/dsh-desktop/vnc.sock` 0600, a fresh X cookie in `…/Xauthority` each start), `dsh-desktop-session` (XFCE), `dsh-desktop-agent` (`vm/agent/`: Python + pyatspi, newline-delimited JSON-RPC on `$XDG_RUNTIME_DIR/dsh-desktop-agent/agent.sock` 0600), `dsh-desktop-im` (fcitx5-mozc, for people typing Japanese on the screen later) and `dsh-desktop-chrome` (the screen's browser, below).
11
+
12
+ ## Google Chrome
13
+
14
+ The desktop's browser is Google Chrome from Google's apt source (`vm/apt/`: the key, primary fingerprint `EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796`, and a source of its own, `dsh-google-chrome.sources` on `dl.google.com/linux/chrome/deb`; the package then keeps its own `google-chrome.sources` on `chrome-stable/deb` with its own key, and the two never write the same file). There is **one Chrome per VM**: the user service `dsh-desktop-chrome` (`vm/bin/chrome-run`: its own profile `~/.local/share/dsh-desktop/chrome`, DevTools on `127.0.0.1:9222` — Chrome binds it to loopback and refuses it on the default profile since 136 —, `--force-renderer-accessibility` so the page content is in `desktop_tree`), enabled with the session, `Restart=always`, ready once DevTools answers (`vm/bin/chrome-ready`). `/usr/bin/google-chrome-stable` is replaced (`dpkg-divert`, the package's file kept as `.dsh-real`) by `vm/bin/google-chrome-stable`, which starts that service and opens its arguments in it, so the menu, `xdg-open`, `x-www-browser`, exo and `desktop_launch chrome` all open in the same Chrome. The browser connector (`@1outres/dsh-bot-connector-browser`) drives this Chrome over DevTools; it requires this connector.
15
+
16
+ The agent runs where the bot is root, so the Host treats every answer as untrusted: each method's result is checked against its shape and limits (`src/host/agent/protocol.ts`), screenshots are checked for format, size and length before `images.admit`.
17
+
18
+ ## Preparation
19
+
20
+ One idempotent path (`src/host/vm/preparation.ts`): read the account → write `vm/` to its places (`src/host/vm/files.ts`, Google's source among them, after diverting `/usr/bin/google-chrome-stable`) and `/etc/dsh-desktop/display.env` → install the package list (`debian-packages.txt`, one name per line) when any is missing → enable linger, `daemon-reload`, enable the units → restart Xvnc if it runs at another size or `xvnc-start` changed → start the session, restart the agent → restart Chrome if `chrome-run` or its unit changed, start it → check `xdpyinfo` and the agent's `status`. Turning the connector off disables and stops the units; packages and data stay.
21
+
22
+ The bot base image (`infra/vm/build-base-image.sh`) installs the same `debian-packages.txt`, so on a VM made from a current image the package step finds everything installed and downloads nothing; the step still runs, and installs whatever an older image or a changed list lacks. `test/base-image.test.ts` checks that the image build reads this file. After changing the list, rebuild the image.
23
+
24
+ ## Settings
25
+
26
+ | Key | Kind | Default | Options |
27
+ | ------------ | ------ | ----------- | ----------------------- |
28
+ | `resolution` | choice | `1280x1024` | `1280x1024`, `1280x800` |
29
+
30
+ Changing it restarts the desktop session (open applications close).
31
+
32
+ ## Tools
33
+
34
+ All `allow`, every session of the bot; all but `desktop_request_handoff` are `exclusive: "display"` (one call at a time per bot, from any session).
35
+
36
+ | Tool | What it does |
37
+ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
38
+ | `desktop_tree` | The active window (or a window/element) as lines `[id] role "name" text=… states`; start here |
39
+ | `desktop_find` | Elements by role, name, text, states |
40
+ | `desktop_act` | press, focus, set_text, set_value, select, click, activate, scroll_into_view; answers the changes |
41
+ | `desktop_text` | The whole text of an element |
42
+ | `desktop_sheet` | LibreOffice Calc: read the non-empty cells, write a block of values |
43
+ | `desktop_windows` / `desktop_focus_window` / `desktop_launch` | Windows with ids; raise one; start writer, calc, impress, chrome, terminal, files |
44
+ | `desktop_type` / `desktop_key` / `desktop_hold_key` | Keyboard; non-ASCII text is pasted through the clipboard |
45
+ | `desktop_click` / `move` / `drag` / `mouse_down` / `mouse_up` / `scroll` | Mouse at the latest screenshot's coordinates or an element's centre |
46
+ | `desktop_cursor_position`, `desktop_clipboard_get` / `_set` | |
47
+ | `desktop_screenshot` | The screen, the active window, an element, or a zoomed region; the last resort |
48
+ | `desktop_request_handoff` | Ask the person to take over (log in, a password, a code) and wait until they hand it back |
49
+
50
+ Coordinates refer to the latest screenshot's image as the model received it; before one, after a reconnection or a screen size change, pointer calls fail with `SCREENSHOT_REQUIRED`. Where accessibility cannot do something (Chrome's fields have no editable text, XFCE panel menus do not open with press, Calc cells must not be selected), the error says what to do instead; there is no silent substitute.
51
+
52
+ ## Who operates the desktop
53
+
54
+ `DesktopControl` (`src/host/control.ts`, state only) holds per bot whether the agent or one viewer of the screen (one panel stream) has the input, and the bot's open request that a person take over. While a person does, tools that change the screen fail with `USER_IN_CONTROL`; reading tools still work. The first result after the agent gets it back (and after a reconnection) starts with a note to look again. When the viewer holding the input goes away (its tab closes, its connection drops, the connector leaves ready) the agent has it back; a reconnected viewer takes it again. The control is the connector's `status` for bot-core: a note and `operatedBy: "person"` while a person operates (bot-core then runs only the reading tools of connectors that require the desktop, such as the browser's), and the request.
55
+
56
+ `desktop_request_handoff(reason, wait_minutes?)` (default 10, at most 30) puts the request up and waits: it answers once the person took over and handed back (or their viewer closed), turned it down, or the wait ran out; a stopped turn ends the wait; the request goes in every case. One request per bot at a time (`HANDOFF_PENDING`). People see it in the bot's window only (a band above the conversation of every session of the bot, a dot on the Desktop button, Take over / Decline in the panel); channels do not get it.
57
+
58
+ ## The screen and the Desktop panel
59
+
60
+ - **Relay** (`src/host/screen/`): the panel's `screen` stream (bot-core's `botConnectorStreams`, owner only, while the desktop is ready) starts `socat -b65536 - UNIX-CONNECT:$XDG_RUNTIME_DIR/dsh-desktop/vnc.sock` in the VM through bot-core's environment and relays RFB as base64 items (`src/shared/screen.ts`): down `rfb` and `control` (who holds the input, the request), up `rfb` (at most 192 KiB of base64), `take`, `release`, `decline`. The screen is read only when the Gateway asks for the next item, so a slow browser holds Xvnc back.
61
+ - **RFB filter** (`src/host/screen/rfb-filter.ts`): frames the viewer's RFB 3.8 messages; picture requests always pass, input (keys, pointer, clipboard, desktop size, xvp, QEMU keys) only from the viewer in control; another version, a security type other than None, an unknown message or clipboard text over 128 KiB fails the stream. ClientInit is made shared and ExtendedMouseButtons is taken out of SetEncodings. Keys and buttons a viewer held are released when it loses control.
62
+ - **Panel** (`src/client/`): noVNC 1.7 in bot-core's `bot-core.connector.panel` Slot (key `desktop`), view only until **Take over**; **Hand back**, **Send Ctrl+Alt+Del**, **Reconnect**. While you operate, it says that what you type (passwords included) reaches the bot's VM. A broken stream reopens after 2 s, doubling to 30 s; while the page is hidden and you do not hold the input, it closes the stream. The build defers noVNC's top-level H.264 probe (`scripts/build-options.mjs`) and fails if that line changes.
63
+ - Xvnc runs at `-FrameRate 24`; the preparation restarts it when `xvnc-start` changed.
64
+
65
+ ## Development
66
+
67
+ `vm/` is installed as it is; `test/files.test.ts` checks every file there has a place. Tests run without a VM (`pnpm test`).
@@ -0,0 +1,6 @@
1
+ # Installs this plugin on its own (dsh plugin add @1outres/dsh-bot-connector-desktop).
2
+ # The @1outres/dsh-bots bundle inserts the same "bot-connector-desktop" row, so select
3
+ # one bundle or the other, never both.
4
+ - insert:
5
+ - id: bot-connector-desktop
6
+ name: "@1outres/dsh-bot-connector-desktop"
@@ -0,0 +1,34 @@
1
+ tigervnc-standalone-server
2
+ xauth
3
+ x11-utils
4
+ x11-xserver-utils
5
+ dbus-user-session
6
+ dbus-x11
7
+ xfce4-session
8
+ xfwm4
9
+ xfce4-panel
10
+ xfdesktop4
11
+ xfce4-settings
12
+ xfce4-terminal
13
+ xfconf
14
+ thunar
15
+ adwaita-icon-theme
16
+ librsvg2-common
17
+ at-spi2-core
18
+ python3-pyatspi
19
+ gir1.2-atspi-2.0
20
+ python3-gi
21
+ python3-pil
22
+ libreoffice-writer
23
+ libreoffice-calc
24
+ libreoffice-gtk3
25
+ google-chrome-stable
26
+ curl
27
+ fonts-noto-cjk
28
+ fonts-noto-core
29
+ fcitx5
30
+ fcitx5-mozc
31
+ fcitx5-frontend-gtk3
32
+ xdotool
33
+ xclip
34
+ socat
package/icon.svg ADDED
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" fill="none" role="img" aria-labelledby="title">
2
+ <title id="title">Bot desktop connector</title>
3
+ <rect x="2" y="2" width="60" height="60" rx="14" fill="#0E7490"/>
4
+ <rect x="13" y="16" width="38" height="25" rx="3" fill="#FFFFFF" fill-opacity="0.95"/>
5
+ <rect x="17" y="20" width="14" height="10" rx="1.5" fill="#0E7490" fill-opacity="0.55"/>
6
+ <rect x="34" y="20" width="13" height="3" rx="1.5" fill="#0E7490" fill-opacity="0.4"/>
7
+ <rect x="34" y="26" width="9" height="3" rx="1.5" fill="#0E7490" fill-opacity="0.4"/>
8
+ <rect x="28" y="41" width="8" height="5" fill="#FFFFFF" fill-opacity="0.95"/>
9
+ <rect x="21" y="46" width="22" height="3" rx="1.5" fill="#FFFFFF" fill-opacity="0.95"/>
10
+ </svg>