dsh-plugin-linux-computer-use 0.0.0-stage → 0.1.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.
package/index.js ADDED
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Host half of the Linux Computer Use bundle.
3
+ *
4
+ * The bundle's real work is done by the stdio MCP server under ./server (see
5
+ * cordis.patch.yml, entry "linux-computer-use-mcp"). This module adds the one
6
+ * thing an MCP server cannot do for itself: a diagnostic tool that still works
7
+ * while that server is disabled or failing to start.
8
+ *
9
+ * Deliberately dependency-free (node builtins only): a bundle that imports
10
+ * DSH internals breaks on upgrade, and the doctor is exactly what you need
11
+ * when something else is broken.
12
+ */
13
+ import { execFile } from 'node:child_process'
14
+ import {
15
+ accessSync,
16
+ constants as fsConstants,
17
+ copyFileSync,
18
+ existsSync,
19
+ mkdirSync,
20
+ readdirSync,
21
+ readFileSync,
22
+ } from 'node:fs'
23
+ import { homedir } from 'node:os'
24
+ import { dirname, join } from 'node:path'
25
+ import { fileURLToPath } from 'node:url'
26
+
27
+ const HERE = dirname(fileURLToPath(import.meta.url))
28
+ const PACKAGE_SERVER_SCRIPT = join(HERE, 'server', 'linux_desktop_mcp.py')
29
+
30
+ /**
31
+ * Where this bundle keeps its own copy of the Python server.
32
+ *
33
+ * cordis.patch.yml cannot know where a published package lands, so the patch
34
+ * runs a fixed launcher path instead; the launcher execs whatever is in this
35
+ * directory. Keeping the copy under the user's home means a package update
36
+ * refreshes the server without root.
37
+ */
38
+ const INSTALL_DIR = join(homedir(), '.local', 'share', 'dsh-linux-computer-use')
39
+ const LAUNCHER = '/usr/local/bin/dsh-linux-desktop-mcp'
40
+ const SELFTEST_TIMEOUT_MS = 45000
41
+
42
+ /** Copy ./server/*.py into INSTALL_DIR, overwriting only files that changed. */
43
+ function syncServerFiles() {
44
+ const source = join(HERE, 'server')
45
+ if (!existsSync(source)) return { ok: false, dir: INSTALL_DIR, detail: `missing package directory ${source}` }
46
+ const copied = []
47
+ try {
48
+ mkdirSync(INSTALL_DIR, { recursive: true, mode: 0o700 })
49
+ for (const name of readdirSync(source)) {
50
+ if (!name.endsWith('.py')) continue
51
+ const from = join(source, name)
52
+ const to = join(INSTALL_DIR, name)
53
+ const wanted = readFileSync(from)
54
+ if (existsSync(to)) {
55
+ const current = readFileSync(to)
56
+ if (current.length === wanted.length && current.equals(wanted)) continue
57
+ }
58
+ copyFileSync(from, to)
59
+ copied.push(name)
60
+ }
61
+ return { ok: true, dir: INSTALL_DIR, copied }
62
+ } catch (error) {
63
+ return { ok: false, dir: INSTALL_DIR, detail: error?.message ?? String(error), copied }
64
+ }
65
+ }
66
+
67
+ /** The server script the MCP bridge actually runs: the synced copy when present. */
68
+ function resolveServerScript() {
69
+ const installed = join(INSTALL_DIR, 'linux_desktop_mcp.py')
70
+ return existsSync(installed) ? installed : PACKAGE_SERVER_SCRIPT
71
+ }
72
+
73
+ function check(list, id, status, title, detail, fix) {
74
+ const entry = { id, status, title }
75
+ if (detail) entry.detail = detail
76
+ if (fix) entry.fix = fix
77
+ list.push(entry)
78
+ }
79
+
80
+ /**
81
+ * Is this account listed in the `input` group, per /etc/group?
82
+ *
83
+ * Reading the group database instead of process credentials is deliberate:
84
+ * a long running host keeps the group list it was started with, so the two can
85
+ * disagree for as long as the host stays up. That mismatch is only used to give
86
+ * a better explanation - the real signal stays "can this process open the device".
87
+ */
88
+ function inInputGroup() {
89
+ try {
90
+ const user = process.env.USER || process.env.LOGNAME || ''
91
+ for (const line of readFileSync('/etc/group', 'utf8').split('\n')) {
92
+ const fields = line.split(':')
93
+ if (fields[0] !== 'input') continue
94
+ const members = (fields[3] || '').split(',').map((name) => name.trim())
95
+ return user && members.includes(user) ? user : false
96
+ }
97
+ } catch {
98
+ /* /etc/group unreadable: fall through to the plain path */
99
+ }
100
+ return false
101
+ }
102
+
103
+ /** Run the server's own --selftest and parse its JSON report. */
104
+ function runSelftest(python, script) {
105
+ return new Promise((resolve) => {
106
+ execFile(
107
+ python,
108
+ ['-u', script, '--selftest'],
109
+ { timeout: SELFTEST_TIMEOUT_MS, maxBuffer: 4 * 1024 * 1024, env: process.env },
110
+ (error, stdout, stderr) => {
111
+ if (error) {
112
+ resolve({ error: `${error.message}${stderr ? `\n${String(stderr).trim().slice(-600)}` : ''}` })
113
+ return
114
+ }
115
+ try {
116
+ resolve({ report: JSON.parse(String(stdout)) })
117
+ } catch (parseError) {
118
+ resolve({ error: `could not parse the self-test output: ${parseError.message}` })
119
+ }
120
+ },
121
+ )
122
+ })
123
+ }
124
+
125
+ /** Names of the MCP tools this bundle publishes, if the bridge is live. */
126
+ function bridgedTools(tools) {
127
+ try {
128
+ const definitions = typeof tools?.definitions === 'function' ? tools.definitions() : []
129
+ return [...definitions]
130
+ .map((definition) => definition?.name)
131
+ .filter((name) => typeof name === 'string' && name.startsWith('mcp__linux__'))
132
+ } catch {
133
+ return []
134
+ }
135
+ }
136
+
137
+ function renderReport(_args, value) {
138
+ const icon = { ok: 'ok ', warn: 'warn', fail: 'FAIL' }
139
+ const lines = []
140
+ const failures = value.checks.filter((entry) => entry.status === 'fail').length
141
+ const warnings = value.checks.filter((entry) => entry.status === 'warn').length
142
+ lines.push(
143
+ failures === 0
144
+ ? `Linux Computer Use: ready${warnings > 0 ? ` (${warnings} warning${warnings === 1 ? '' : 's'})` : ''}`
145
+ : `Linux Computer Use: ${failures} blocking problem${failures === 1 ? '' : 's'}, ${warnings} warning${warnings === 1 ? '' : 's'}`,
146
+ )
147
+ for (const entry of value.checks) {
148
+ const head = `- [${icon[entry.status] ?? entry.status}] ${entry.title}`
149
+ lines.push(entry.detail ? `${head}\n ${entry.detail}` : head)
150
+ if (entry.fix) lines.push(` fix: ${entry.fix}`)
151
+ }
152
+ if (value.server?.log) lines.push(`\nserver log: ${value.server.log}`)
153
+ if (value.summary) lines.push(`\n${value.summary}`)
154
+ return [{ type: 'text', text: lines.join('\n') }]
155
+ }
156
+
157
+ const CHECK_SCHEMA = {
158
+ type: 'object',
159
+ properties: {
160
+ id: { type: 'string' },
161
+ status: { type: 'string', enum: ['ok', 'warn', 'fail'] },
162
+ title: { type: 'string' },
163
+ detail: { type: 'string' },
164
+ fix: { type: 'string' },
165
+ },
166
+ required: ['id', 'status', 'title'],
167
+ }
168
+
169
+ /** Build the linux_mcp_doctor tool definition for one configured python. */
170
+ function createDoctor(tools, python, sync) {
171
+ return {
172
+ name: 'linux_mcp_doctor',
173
+ description: [
174
+ 'Diagnose the Linux Computer Use bundle: whether the MCP bridge is live (mcp__linux__* tools registered),',
175
+ 'whether /dev/uinput is writable so pointer and keyboard injection can work, and whether screenshots,',
176
+ 'AT-SPI, the portal and the clipboard helpers are available.',
177
+ 'Run it first whenever a desktop action fails, or before asking the user to install something.',
178
+ ].join(' '),
179
+ parameters: {
180
+ type: 'object',
181
+ properties: {
182
+ verbose: {
183
+ type: 'boolean',
184
+ default: false,
185
+ description: 'Include raw paths and the full environment block in the report.',
186
+ },
187
+ },
188
+ additionalProperties: false,
189
+ },
190
+ timeoutMs: SELFTEST_TIMEOUT_MS + 15000,
191
+ output: {
192
+ schema: {
193
+ type: 'object',
194
+ properties: {
195
+ ok: { type: 'boolean' },
196
+ summary: { type: 'string' },
197
+ bridge: {
198
+ type: 'object',
199
+ properties: {
200
+ tools_registered: { type: 'number' },
201
+ names: { type: 'array', items: { type: 'string' } },
202
+ },
203
+ },
204
+ checks: { type: 'array', items: CHECK_SCHEMA },
205
+ server: {
206
+ type: 'object',
207
+ properties: {
208
+ name: { type: 'string' },
209
+ version: { type: 'string' },
210
+ log: { type: 'string' },
211
+ script: { type: 'string' },
212
+ },
213
+ },
214
+ },
215
+ required: ['ok', 'checks'],
216
+ },
217
+ render: renderReport,
218
+ },
219
+ async execute(args) {
220
+ const checks = []
221
+ const script = resolveServerScript()
222
+ const report = { ok: false, checks, bridge: { tools_registered: 0, names: [] }, server: { script } }
223
+
224
+ if (sync && sync.ok === false) {
225
+ check(
226
+ checks,
227
+ 'install-sync',
228
+ 'warn',
229
+ 'could not refresh the installed server copy',
230
+ sync.detail,
231
+ 'check that ~/.local/share is writable, then reload this plugin',
232
+ )
233
+ }
234
+
235
+ const bridged = bridgedTools(tools)
236
+ report.bridge = { tools_registered: bridged.length, names: bridged }
237
+ if (bridged.length > 0) {
238
+ check(checks, 'bridge', 'ok', `MCP bridge is live (${bridged.length} tools as mcp__linux__*)`)
239
+ } else {
240
+ check(
241
+ checks,
242
+ 'bridge',
243
+ 'warn',
244
+ 'MCP bridge is not running (no mcp__linux__* tools registered)',
245
+ 'Computer Use ships disabled, so this is expected until you switch it on.',
246
+ 'Settings -> Plugins -> Linux Computer Use: enable it, then reload the page',
247
+ )
248
+ }
249
+
250
+ if (!existsSync(script)) {
251
+ check(checks, 'server-script', 'fail', 'the MCP server script is missing', script, 'reinstall the bundle from the plugins page')
252
+ report.summary = 'The bundle looks incomplete; reinstall it before anything else.'
253
+ return report
254
+ }
255
+ check(checks, 'server-script', 'ok', 'MCP server script present', script)
256
+
257
+ if (existsSync(LAUNCHER)) {
258
+ check(checks, 'launcher', 'ok', 'MCP launcher installed', LAUNCHER)
259
+ } else {
260
+ check(
261
+ checks,
262
+ 'launcher',
263
+ 'fail',
264
+ 'the MCP launcher is missing, so the bridge cannot start',
265
+ LAUNCHER,
266
+ 'sudo ./linux-computer-use-prep.sh installs it (it execs the copy under ~/.local/share)',
267
+ )
268
+ }
269
+
270
+ try {
271
+ accessSync('/dev/uinput', fsConstants.R_OK | fsConstants.W_OK)
272
+ check(checks, 'uinput', 'ok', '/dev/uinput is writable by this account')
273
+ } catch (error) {
274
+ const member = inInputGroup()
275
+ const detail =
276
+ error?.code === 'ENOENT'
277
+ ? '/dev/uinput does not exist on this machine (kernel built without CONFIG_INPUT_UINPUT?)'
278
+ : member
279
+ ? `/dev/uinput is not writable from this process. ${member} is in the "input" group, but a running process never picks up group changes - the uaccess ACL from the prep script is what makes this work`
280
+ : '/dev/uinput exists but this account cannot open it for writing'
281
+ check(
282
+ checks,
283
+ 'uinput',
284
+ 'fail',
285
+ 'pointer and keyboard injection cannot work',
286
+ detail,
287
+ 'sudo ./linux-computer-use-prep.sh (adds a uaccess ACL on /dev/uinput), then restart dsh web',
288
+ )
289
+ }
290
+
291
+ const selftest = await runSelftest(python, script)
292
+ if (selftest.error) {
293
+ check(
294
+ checks,
295
+ 'selftest',
296
+ 'fail',
297
+ 'the desktop server self-test crashed',
298
+ selftest.error,
299
+ 'check python3-gi and gir1.2-atspi-2.0 are installed, then run: python3 server/linux_desktop_mcp.py --selftest',
300
+ )
301
+ } else {
302
+ report.server = { ...(selftest.report.server ?? {}), script }
303
+ for (const entry of selftest.report.checks ?? []) checks.push(entry)
304
+ }
305
+
306
+ report.ok = !checks.some((entry) => entry.status === 'fail')
307
+ const failures = checks.filter((entry) => entry.status === 'fail').length
308
+ const warnings = checks.filter((entry) => entry.status === 'warn').length
309
+ report.summary = report.ok
310
+ ? `All blocking checks passed${warnings > 0 ? ` (${warnings} warning${warnings === 1 ? '' : 's'})` : ''}.`
311
+ : `${failures} blocking problem${failures === 1 ? '' : 's'} must be fixed first.`
312
+ if (args?.verbose === true) {
313
+ report.environment = { session: process.env.XDG_SESSION_TYPE, desktop: process.env.XDG_CURRENT_DESKTOP, python }
314
+ }
315
+ return report
316
+ },
317
+ }
318
+ }
319
+
320
+ export const inject = ['tools']
321
+
322
+ export const name = 'linux-computer-use-doctor'
323
+
324
+ export function apply(context, config = {}) {
325
+ const configured = typeof config?.python === 'string' && config.python ? config.python : undefined
326
+ const python = configured ?? process.env.DSH_LINUX_CU_PYTHON ?? 'python3'
327
+ // Keep the launcher's copy of the server in step with the installed package,
328
+ // so updating the bundle updates the MCP server with it.
329
+ const sync = syncServerFiles()
330
+ const tool = createDoctor(context.tools, python, sync)
331
+ context.effect(() => context.tools.register(tool))
332
+ }
@@ -0,0 +1,281 @@
1
+ #!/usr/bin/env bash
2
+ # linux-computer-use-prep.sh
3
+ # Host preparation for the DSH "Linux Computer Use" bundle on Ubuntu 24.04 / Wayland.
4
+ # Idempotent: safe to run more than once.
5
+ #
6
+ # Why each step is needed:
7
+ # 1. /dev/uinput is what lets the plugin inject real kernel input events on
8
+ # Wayland (there is no SendInput equivalent). It ships as a built-in misc
9
+ # device, owned root:root mode 0600, so a normal user cannot open it.
10
+ # 2. A udev rule makes it group "input", mode 0660, permanently, and the user
11
+ # is added to that group so the desk server can open it.
12
+ # 3. wl-clipboard provides wl-copy / wl-paste for clipboard read/write.
13
+ # 4. ydotool (+ ydotoold) is the fallback injection path used when /dev/uinput
14
+ # is unavailable; harmless if unused.
15
+ #
16
+ # Usage:
17
+ # chmod +x linux-computer-use-prep.sh
18
+ # sudo ./linux-computer-use-prep.sh
19
+ # # then LOG OUT and LOG BACK IN (group membership needs a fresh session)
20
+ # ./linux-computer-use-prep.sh --verify # no sudo needed
21
+ #
22
+ # Undo: sudo ./linux-computer-use-prep.sh --uninstall
23
+
24
+ set -uo pipefail
25
+
26
+ TARGET_USER="${SUDO_USER:-$(id -un)}"
27
+ TARGET_UID="$(id -u "$TARGET_USER")"
28
+ TARGET_GROUP="$(id -gn "$TARGET_USER")"
29
+ TARGET_HOME="$(getent passwd "$TARGET_USER" | cut -d: -f6)"
30
+ SOCKET_PATH="/run/ydotoold.socket"
31
+ UNIT_PATH="/etc/systemd/system/ydotoold.service"
32
+ UDEV_RULE="/etc/udev/rules.d/60-uinput.rules"
33
+ LAUNCHER="/usr/local/bin/dsh-linux-desktop-mcp"
34
+ SHARE_DIR="$TARGET_HOME/.local/share/dsh-linux-computer-use"
35
+
36
+ c_ok() { printf ' \033[32mOK\033[0m %s\n' "$*"; }
37
+ c_warn() { printf ' \033[33mWARN\033[0m %s\n' "$*"; }
38
+ c_bad() { printf ' \033[31mMISS\033[0m %s\n' "$*"; }
39
+ c_note() { printf ' \033[2mnote\033[0m %s\n' "$*"; }
40
+ say() { printf '\n\033[1m== %s ==\033[0m\n' "$*"; }
41
+
42
+ require_root() {
43
+ if [ "$(id -u)" -ne 0 ]; then
44
+ echo "This mode needs root. Re-run with: sudo $0 ${1:-}" >&2
45
+ exit 1
46
+ fi
47
+ }
48
+
49
+ # ---------------------------------------------------------------- verify mode
50
+ if [ "${1:-}" = "--verify" ]; then
51
+ say "Verification (user: $TARGET_USER)"
52
+ printf 'session: %s / %s\n' "${XDG_SESSION_TYPE:-unknown}" "${XDG_CURRENT_DESKTOP:-unknown}"
53
+
54
+ if [ -c /dev/uinput ]; then
55
+ c_ok "/dev/uinput is present"
56
+ ls -l /dev/uinput | sed 's/^/ /'
57
+ if [ -w /dev/uinput ] && [ -r /dev/uinput ]; then
58
+ c_ok "/dev/uinput readable+writable by you (input injection ready)"
59
+ elif command -v getfacl >/dev/null && getfacl -p /dev/uinput 2>/dev/null | grep -q "^user:${TARGET_USER}:rw"; then
60
+ c_warn "/dev/uinput has an ACL for $TARGET_USER but this shell is not using it"
61
+ c_warn " -> start the plugin from the desktop session (or re-run this script)"
62
+ else
63
+ c_warn "/dev/uinput NOT accessible to you yet"
64
+ c_warn " -> re-run this script (it adds a uaccess ACL), then restart 'dsh web'"
65
+ fi
66
+ else
67
+ c_bad "/dev/uinput missing (kernel built without CONFIG_INPUT_UINPUT?)"
68
+ fi
69
+
70
+ if id -nG "$TARGET_USER" | tr ' ' '\n' | grep -qx input; then
71
+ c_ok "user $TARGET_USER is in group 'input'"
72
+ else
73
+ c_bad "user $TARGET_USER is NOT in group 'input'"
74
+ fi
75
+
76
+ command -v wl-copy >/dev/null && c_ok "wl-copy: $(command -v wl-copy)" || c_bad "wl-copy missing (apt install wl-clipboard)"
77
+ command -v wl-paste >/dev/null && c_ok "wl-paste: $(command -v wl-paste)" || c_bad "wl-paste missing (apt install wl-clipboard)"
78
+ command -v notify-send >/dev/null && c_ok "notify-send: $(command -v notify-send)" || c_warn "notify-send missing (apt install libnotify-bin)"
79
+
80
+ if command -v ydotool >/dev/null && command -v ydotoold >/dev/null; then
81
+ c_ok "ydotool fallback installed ($(command -v ydotool))"
82
+ if systemctl is-active --quiet ydotoold; then
83
+ c_ok "ydotoold service active"
84
+ else
85
+ c_warn "ydotoold service not active (fallback only, not required)"
86
+ fi
87
+ if [ -S "$SOCKET_PATH" ]; then
88
+ ls -l "$SOCKET_PATH" | sed 's/^/ /'
89
+ case "$(stat -c '%A' "$SOCKET_PATH")" in
90
+ srw-------*) c_ok "socket mode is 0600 (private to you)" ;;
91
+ *) c_warn "socket mode is not 0600 — other local users could inject input" ;;
92
+ esac
93
+ fi
94
+ else
95
+ c_warn "ydotool not installed (optional fallback; /dev/uinput is the primary path)"
96
+ fi
97
+
98
+ if [ -x "$LAUNCHER" ]; then
99
+ c_ok "MCP launcher installed: $LAUNCHER"
100
+ if [ -f "$SHARE_DIR/linux_desktop_mcp.py" ]; then
101
+ c_ok "server copy present: $SHARE_DIR"
102
+ else
103
+ c_warn "server copy missing: $SHARE_DIR (it syncs when the plugin loads once)"
104
+ fi
105
+ else
106
+ c_bad "MCP launcher missing: $LAUNCHER"
107
+ fi
108
+
109
+ say "Summary"
110
+ if [ -r /dev/uinput ] && [ -w /dev/uinput ]; then
111
+ c_ok "input injection: READY"
112
+ else
113
+ c_bad "input injection: not ready yet (see above)"
114
+ fi
115
+ exit 0
116
+ fi
117
+
118
+ # ------------------------------------------------------------- uninstall mode
119
+ if [ "${1:-}" = "--uninstall" ]; then
120
+ require_root --uninstall
121
+ say "Removing ydotoold unit and udev rule"
122
+ systemctl disable --now ydotoold 2>/dev/null || true
123
+ rm -f "$UNIT_PATH" "$UDEV_RULE" "$LAUNCHER"
124
+ systemctl daemon-reload
125
+ udevadm control --reload-rules 2>/dev/null || true
126
+ echo "Kept installed packages and group membership."
127
+ echo "Remove manually if wanted: apt-get remove ydotool wl-clipboard; gpasswd -d $TARGET_USER input"
128
+ exit 0
129
+ fi
130
+
131
+ require_root ""
132
+
133
+ say "Target user: $TARGET_USER (uid $TARGET_UID)"
134
+
135
+ # 1. packages ---------------------------------------------------------------
136
+ say "Installing wl-clipboard (required) and ydotool (optional fallback)"
137
+ export DEBIAN_FRONTEND=noninteractive
138
+ apt-get update -qq || c_warn "apt-get update failed; trying install anyway"
139
+ if apt-get install -y --no-install-recommends wl-clipboard; then
140
+ c_ok "wl-clipboard $(dpkg-query -W -f='${Version}' wl-clipboard 2>/dev/null)"
141
+ else
142
+ c_bad "could not install wl-clipboard — clipboard tools will be unavailable"
143
+ fi
144
+ if apt-get install -y --no-install-recommends ydotool; then
145
+ c_ok "ydotool $(dpkg-query -W -f='${Version}' ydotool 2>/dev/null)"
146
+ else
147
+ c_warn "could not install ydotool — continuing, /dev/uinput is the primary path"
148
+ fi
149
+ apt-get install -y --no-install-recommends libnotify-bin >/dev/null 2>&1 && c_ok "libnotify-bin present" || c_warn "libnotify-bin not installed (notifications optional)"
150
+
151
+ # 2. uinput device ----------------------------------------------------------
152
+ say "Preparing /dev/uinput"
153
+ # On Ubuntu 24.04 uinput is built into the kernel, so there is no module to
154
+ # load; try anyway for kernels that build it as a module, but never fail here.
155
+ modprobe uinput 2>/dev/null && c_ok "uinput module loaded" || c_ok "uinput is built into this kernel (no module needed)"
156
+ if [ -c /dev/uinput ]; then
157
+ c_ok "/dev/uinput exists"
158
+ else
159
+ c_bad "/dev/uinput does not exist; input injection cannot work on this kernel"
160
+ fi
161
+
162
+ # 3. udev rule --------------------------------------------------------------
163
+ say "Installing udev rule for /dev/uinput"
164
+ cat > "$UDEV_RULE" <<'EOF'
165
+ # Give the logged-in desktop user access to /dev/uinput (DSH Linux Computer Use).
166
+ # TAG+="uaccess" makes systemd-logind grant the *active session user* an ACL. That
167
+ # is the important part: the process keeps its normal gid, so tools that inspect
168
+ # the caller through /proc/<pid>/root (xdg-desktop-portal screen capture) still
169
+ # work. GROUP="input" is only a secondary path for setups without logind.
170
+ KERNEL=="uinput", SUBSYSTEM=="misc", GROUP="input", MODE="0660", TAG+="uaccess", OPTIONS+="watch"
171
+ EOF
172
+ udevadm control --reload-rules || c_warn "udevadm control failed"
173
+ udevadm trigger --name-match=uinput 2>/dev/null || c_warn "udevadm trigger failed"
174
+ # The device already exists, so the rule may not re-apply until reboot:
175
+ # fix permissions now as well, which makes the plugin usable in this boot.
176
+ if [ -c /dev/uinput ]; then
177
+ chgrp input /dev/uinput && chmod 0660 /dev/uinput
178
+ if command -v setfacl >/dev/null; then
179
+ setfacl -m "u:${TARGET_USER}:rw" /dev/uinput \
180
+ && c_ok "ACL: u:${TARGET_USER}:rw on /dev/uinput" \
181
+ || c_warn "setfacl on /dev/uinput failed"
182
+ else
183
+ c_warn "setfacl missing (apt install acl) — falling back to the input group"
184
+ fi
185
+ c_ok "$UDEV_RULE installed; current permissions applied"
186
+ ls -l /dev/uinput | sed 's/^/ /'
187
+ fi
188
+
189
+ # 4. group membership -------------------------------------------------------
190
+ say "Adding $TARGET_USER to the 'input' group"
191
+ getent group input >/dev/null || groupadd --system input
192
+ if id -nG "$TARGET_USER" | tr ' ' '\n' | grep -qx input; then
193
+ c_ok "already a member"
194
+ else
195
+ usermod -aG input "$TARGET_USER" && c_ok "added — takes effect after the next login"
196
+ fi
197
+
198
+ # 5. ydotoold unit (fallback path) ------------------------------------------
199
+ if command -v ydotoold >/dev/null; then
200
+ say "Installing the ydotoold fallback unit"
201
+ cat > "$UNIT_PATH" <<EOF
202
+ [Unit]
203
+ Description=ydotool input injection daemon (DSH Linux Computer Use fallback)
204
+ Documentation=https://github.com/ReimuNotMoe/ydotool
205
+ After=systemd-user-sessions.service
206
+
207
+ [Service]
208
+ Type=simple
209
+ User=$TARGET_USER
210
+ Group=input
211
+ UMask=0077
212
+ ExecStart=/usr/bin/ydotoold --socket-path $SOCKET_PATH --socket-perm 0600
213
+ Restart=on-failure
214
+ RestartSec=2s
215
+
216
+ [Install]
217
+ WantedBy=multi-user.target
218
+ EOF
219
+ systemctl daemon-reload
220
+ if systemctl enable --now ydotoold 2>/dev/null; then
221
+ c_ok "ydotoold running"
222
+ else
223
+ c_warn "ydotoold did not start (fallback only); journal:"
224
+ journalctl -u ydotoold -n 15 --no-pager 2>/dev/null | sed 's/^/ /' || true
225
+ fi
226
+ if [ -S "$SOCKET_PATH" ]; then
227
+ chown "$TARGET_USER:$TARGET_USER" "$SOCKET_PATH" 2>/dev/null || true
228
+ chmod 0600 "$SOCKET_PATH" 2>/dev/null || true
229
+ ls -l "$SOCKET_PATH" | sed 's/^/ /'
230
+ fi
231
+ else
232
+ c_note "no ydotoold binary in this distro's ydotool package - skipping the"
233
+ c_note "fallback unit. The primary path (/dev/uinput) does not need it."
234
+ fi
235
+
236
+ # 6. MCP launcher (fixed path the cordis patch can reference) ---------------
237
+ say "Installing the MCP launcher"
238
+ install -d -m 0755 /usr/local/bin
239
+ cat > "$LAUNCHER" <<'LAUNCH'
240
+ #!/bin/sh
241
+ # Installed by dsh-plugin-linux-computer-use.
242
+ # Launches the bundle's stdio MCP server from the copy it syncs under the
243
+ # user's home, so the cordis patch never has to hard-code a package path.
244
+ #
245
+ # If the process that spawned us predates the 'input' group change (a long
246
+ # running DSH host, or a lingering systemd --user manager), our own group list
247
+ # is stale and /dev/uinput stays out of reach. The udev uaccess ACL is the
248
+ # normal fix and needs no credentials at all. `sg input` is only an explicit
249
+ # opt-in escape hatch: it swaps the process gid, which makes xdg-desktop-portal
250
+ # refuse to identify us (/proc/<pid>/root) and therefore breaks screen capture.
251
+ DIR="${DSH_LINUX_CU_DIR:-$HOME/.local/share/dsh-linux-computer-use}"
252
+ SELF="/usr/local/bin/dsh-linux-desktop-mcp"
253
+ if [ ! -f "$DIR/linux_desktop_mcp.py" ]; then
254
+ echo "dsh-linux-desktop-mcp: no server copy in $DIR" >&2
255
+ echo "enable the plugin once (it syncs the server there), then retry" >&2
256
+ exit 1
257
+ fi
258
+ if [ "${DSH_LINUX_CU_FORCE_SG:-}" = 1 ] && [ "$#" -eq 0 ]; then
259
+ exec sg input -c "exec \"$SELF\""
260
+ fi
261
+ exec /usr/bin/python3 -u "$DIR/linux_desktop_mcp.py" "$@"
262
+ LAUNCH
263
+ chmod 0755 "$LAUNCHER"
264
+ c_ok "launcher: $LAUNCHER"
265
+
266
+ install -d -m 0700 -o "$TARGET_USER" -g "$TARGET_GROUP" "$SHARE_DIR" 2>/dev/null \
267
+ || install -d -m 0700 -o "$TARGET_USER" "$SHARE_DIR"
268
+ c_ok "server home: $SHARE_DIR"
269
+
270
+ # 7. summary ----------------------------------------------------------------
271
+ say "Done"
272
+ cat <<EOF
273
+ Next steps:
274
+ 1. Run: $0 --verify
275
+ 2. Tell the DSH agent it is done; it will restart the plugin and check again.
276
+
277
+ Note: any process running as $TARGET_USER can now inject keyboard/mouse input.
278
+ That is the point of the feature. Access goes through a uaccess ACL on
279
+ /dev/uinput (plus the 'input' group as a fallback), and the ydotoold socket,
280
+ when present, stays 0600.
281
+ EOF
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Ubuntu Desktop Automation (Computer Use)",
4
+ "description": "Screenshot, read the UI tree, click, type, use the clipboard, inspect processes and change settings on an Ubuntu / GNOME Wayland desktop - 28 tools, off by default.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Ubuntu 桌面自动化 (Computer Use)",
4
+ "description": "在 Ubuntu / GNOME Wayland 桌面上截屏、读 UI 树、点鼠标、敲键盘、读写剪贴板、看进程、改系统设置——28 个工具,默认关闭。",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }