pi-web-ui 0.113.1 → 0.114.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/CHANGELOG.md +71 -1
- package/README.md +187 -316
- package/README.zh-CN.md +227 -299
- package/README.zh-TW.md +227 -299
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +4081 -4041
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2419 -1174
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +69 -13
- package/dist/server/canvas/canvas-agent-tool.js +68 -18
- package/dist/server/canvas/canvas-cards.js +1 -1
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +519 -202
- package/dist/server/canvas/canvas-scheduled-task.js +45 -0
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +110 -24
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +351 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +830 -0
- package/dist/server/device-center/local-hub.js +92 -0
- package/dist/server/device-center/local.js +529 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +996 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +84 -27
- package/dist/server/dsh/dsh-agent-service.js +282 -159
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +38 -26
- package/dist/server/global-loader.js +40 -2
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +285 -255
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/patch-bash-process.js +125 -0
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +288 -94
- package/dist/server/preset-fields.js +56 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +113 -72
- package/dist/server/prompt-templates.js +106 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +199 -106
- package/dist/server/request-context.js +164 -0
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/schedule-agent-tool.js +39 -21
- package/dist/server/scheduler-tasks.js +106 -55
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +273 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/setup-page.js +620 -620
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/text-quote.js +9 -0
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +48 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/drivers/claude-code.js +5 -0
- package/dist/server/universal/drivers/codex.js +336 -0
- package/dist/server/universal/index.js +1 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-attachments.js +24 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +357 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/vision-bridge.js +18 -18
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/docs/device-center.md +148 -0
- package/docs/device-desktop.md +48 -0
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +5 -2
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -676
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +11 -1
- package/themes/aetheris.css +501 -607
- package/themes/ayu-light.css +116 -140
- package/themes/bases/flow-base.css +1357 -1363
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +688 -687
- package/themes/bases/zhupi-base.css +660 -659
- package/themes/catppuccin-latte.css +119 -142
- package/themes/catppuccin.css +116 -147
- package/themes/claude-code-dark.css +147 -146
- package/themes/codex.css +114 -138
- package/themes/cyberpunk.css +50 -108
- package/themes/dark-teal.css +264 -265
- package/themes/dazzle.css +38 -108
- package/themes/everforest-light.css +115 -138
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -138
- package/themes/gruvbox-light.css +115 -138
- package/themes/kanagawa-lotus.css +115 -138
- package/themes/md-preview.css +24 -234
- package/themes/mist.css +166 -186
- package/themes/nord.css +107 -138
- package/themes/one-dark.css +106 -139
- package/themes/paper.css +174 -186
- package/themes/rose-pine-dawn.css +114 -138
- package/themes/sakura.css +166 -186
- package/themes/solarized-light.css +114 -137
- package/themes/tokyo-night.css +115 -146
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -186
- package/themes/zhujian-dark.css +115 -114
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -114
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
- package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
- package/web/dist/assets/CanvasStudio-PI9pid0Y.js +1579 -0
- package/web/dist/assets/CanvasStudio-nf5-HxLM.js +1579 -0
- package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
- package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
- package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
- package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
- package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
- package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
- package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
- package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
- package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
- package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
- package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
- package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
- package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
- package/web/dist/assets/TerminalPanel-BBuM_Sez.js +3 -0
- package/web/dist/assets/TerminalPanel-D6x6xz8Q.js +3 -0
- package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
- package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
- package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
- package/web/dist/assets/desktop-YguLbrX1.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
- package/web/dist/assets/index-BPvpea8t.js +85 -0
- package/web/dist/assets/index-D6u8xH0o.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-BRBg6zmQ.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +42 -35
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
- package/web/dist/assets/index-ByiO9f-N.js +0 -2008
- package/web/dist/assets/index-ycGLh4a4.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
2
|
+
import { delimiter, join } from "node:path";
|
|
3
|
+
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
4
|
+
const MAX_FRAME = 4 * 1024 * 1024;
|
|
5
|
+
const MAX_QUEUE = 128;
|
|
6
|
+
const PROBE_OPTIONS = { encoding: "utf8", timeout: 2000, maxBuffer: 256 * 1024, shell: false };
|
|
7
|
+
function executable(name) {
|
|
8
|
+
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
9
|
+
if (!directory)
|
|
10
|
+
continue;
|
|
11
|
+
const candidate = join(directory, name);
|
|
12
|
+
try {
|
|
13
|
+
accessSync(candidate, constants.X_OK);
|
|
14
|
+
if (statSync(candidate).isFile())
|
|
15
|
+
return candidate;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
/* Missing or inaccessible PATH entry. */
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function linuxDesktopStatus() {
|
|
24
|
+
const unsupported = (reason) => ({ supported: false, backend: "x11", reason });
|
|
25
|
+
if (process.platform !== "linux")
|
|
26
|
+
return unsupported("Linux X11 desktop capture requires Linux.");
|
|
27
|
+
// XWayland only captures X11 windows, not the full Wayland desktop.
|
|
28
|
+
if (process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland" || process.env.WAYLAND_DISPLAY)
|
|
29
|
+
return unsupported("Wayland desktop capture requires Portal/PipeWire and is not supported yet.");
|
|
30
|
+
if (!process.env.DISPLAY)
|
|
31
|
+
return unsupported("No X11 DISPLAY is available; Wayland requires Portal/PipeWire.");
|
|
32
|
+
if (!executable("ffmpeg"))
|
|
33
|
+
return unsupported("X11 desktop capture requires ffmpeg (x11grab).");
|
|
34
|
+
return {
|
|
35
|
+
supported: true,
|
|
36
|
+
backend: "x11",
|
|
37
|
+
...(!executable("xdotool") ? { reason: "View only: install xdotool to enable desktop control." } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function screenSize() {
|
|
41
|
+
const display = process.env.DISPLAY;
|
|
42
|
+
const info = executable("xdpyinfo");
|
|
43
|
+
if (info) {
|
|
44
|
+
try {
|
|
45
|
+
const output = execFileSync(info, ["-display", display], PROBE_OPTIONS);
|
|
46
|
+
const defaultScreen = output.match(/default screen number:\s*(\d+)/)?.[1];
|
|
47
|
+
const section = defaultScreen
|
|
48
|
+
? output.split(new RegExp(`screen #${defaultScreen}:`))[1]?.split(/screen #\d+:/)[0]
|
|
49
|
+
: output;
|
|
50
|
+
const match = section?.match(/dimensions:\s*(\d+)x(\d+)\s+pixels/);
|
|
51
|
+
if (match && +match[1] > 0 && +match[2] > 0)
|
|
52
|
+
return [+match[1], +match[2]];
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
/* Try xrandr when xdpyinfo cannot query this display. */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const randr = executable("xrandr");
|
|
59
|
+
if (randr) {
|
|
60
|
+
try {
|
|
61
|
+
const output = execFileSync(randr, ["--display", display, "--current"], PROBE_OPTIONS);
|
|
62
|
+
const match = output.match(/current\s+(\d+)\s+x\s+(\d+)/);
|
|
63
|
+
if (match && +match[1] > 0 && +match[2] > 0)
|
|
64
|
+
return [+match[1], +match[2]];
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* Report a useful dependency/display error below. */
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error("Cannot determine X11 screen dimensions; install xdpyinfo or xrandr and check DISPLAY/XAUTHORITY.");
|
|
71
|
+
}
|
|
72
|
+
function keySymbol(code) {
|
|
73
|
+
if (/^Key[A-Z]$/.test(code))
|
|
74
|
+
return code.slice(3).toLowerCase();
|
|
75
|
+
if (/^Digit[0-9]$/.test(code))
|
|
76
|
+
return code.slice(5);
|
|
77
|
+
if (/^F([1-9]|1[0-9]|2[0-4])$/.test(code))
|
|
78
|
+
return code;
|
|
79
|
+
return {
|
|
80
|
+
Enter: "Return",
|
|
81
|
+
NumpadEnter: "KP_Enter",
|
|
82
|
+
Escape: "Escape",
|
|
83
|
+
Backspace: "BackSpace",
|
|
84
|
+
Tab: "Tab",
|
|
85
|
+
Space: "space",
|
|
86
|
+
ShiftLeft: "Shift_L",
|
|
87
|
+
ShiftRight: "Shift_R",
|
|
88
|
+
ControlLeft: "Control_L",
|
|
89
|
+
ControlRight: "Control_R",
|
|
90
|
+
AltLeft: "Alt_L",
|
|
91
|
+
AltRight: "Alt_R",
|
|
92
|
+
MetaLeft: "Super_L",
|
|
93
|
+
MetaRight: "Super_R",
|
|
94
|
+
ArrowLeft: "Left",
|
|
95
|
+
ArrowRight: "Right",
|
|
96
|
+
ArrowUp: "Up",
|
|
97
|
+
ArrowDown: "Down",
|
|
98
|
+
Home: "Home",
|
|
99
|
+
End: "End",
|
|
100
|
+
PageUp: "Prior",
|
|
101
|
+
PageDown: "Next",
|
|
102
|
+
Delete: "Delete",
|
|
103
|
+
Insert: "Insert",
|
|
104
|
+
CapsLock: "Caps_Lock",
|
|
105
|
+
Minus: "minus",
|
|
106
|
+
Equal: "equal",
|
|
107
|
+
BracketLeft: "bracketleft",
|
|
108
|
+
BracketRight: "bracketright",
|
|
109
|
+
Backslash: "backslash",
|
|
110
|
+
Semicolon: "semicolon",
|
|
111
|
+
Quote: "apostrophe",
|
|
112
|
+
Backquote: "grave",
|
|
113
|
+
Comma: "comma",
|
|
114
|
+
Period: "period",
|
|
115
|
+
Slash: "slash",
|
|
116
|
+
}[code];
|
|
117
|
+
}
|
|
118
|
+
export function startLinuxDesktop(options) {
|
|
119
|
+
let closed = false;
|
|
120
|
+
let capture;
|
|
121
|
+
let command;
|
|
122
|
+
let killTimer;
|
|
123
|
+
let pending = Buffer.alloc(0);
|
|
124
|
+
let stderr = "";
|
|
125
|
+
let queue = [];
|
|
126
|
+
const keys = new Set();
|
|
127
|
+
const buttons = new Set();
|
|
128
|
+
let control;
|
|
129
|
+
let missingControlReported = false;
|
|
130
|
+
let width = 0, height = 0;
|
|
131
|
+
const report = (message) => {
|
|
132
|
+
options.onError(message);
|
|
133
|
+
};
|
|
134
|
+
const releaseArgs = () => {
|
|
135
|
+
const args = [];
|
|
136
|
+
for (const key of keys)
|
|
137
|
+
args.push("keyup", key);
|
|
138
|
+
for (const button of buttons)
|
|
139
|
+
args.push("mouseup", button);
|
|
140
|
+
return args;
|
|
141
|
+
};
|
|
142
|
+
const releaseAfterStop = () => {
|
|
143
|
+
const args = releaseArgs();
|
|
144
|
+
keys.clear();
|
|
145
|
+
buttons.clear();
|
|
146
|
+
if (!control || !args.length)
|
|
147
|
+
return;
|
|
148
|
+
// One bounded, directly spawned cleanup command; never starts a shell.
|
|
149
|
+
execFile(control, args, { timeout: 2000, killSignal: "SIGKILL", maxBuffer: 16384, shell: false }, () => { });
|
|
150
|
+
};
|
|
151
|
+
const close = () => {
|
|
152
|
+
if (closed)
|
|
153
|
+
return;
|
|
154
|
+
closed = true;
|
|
155
|
+
pending = Buffer.alloc(0);
|
|
156
|
+
queue = [];
|
|
157
|
+
if (capture && capture.exitCode === null && capture.signalCode === null) {
|
|
158
|
+
capture.kill("SIGTERM");
|
|
159
|
+
killTimer = setTimeout(() => capture?.kill("SIGKILL"), 1000);
|
|
160
|
+
killTimer.unref();
|
|
161
|
+
}
|
|
162
|
+
// Wait for the active command's callback before releasing, avoiding a late keydown.
|
|
163
|
+
if (command)
|
|
164
|
+
command.kill("SIGKILL");
|
|
165
|
+
else
|
|
166
|
+
releaseAfterStop();
|
|
167
|
+
options.onClose();
|
|
168
|
+
};
|
|
169
|
+
const fail = (message) => {
|
|
170
|
+
if (closed)
|
|
171
|
+
return;
|
|
172
|
+
try {
|
|
173
|
+
report(message);
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
close();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const drain = () => {
|
|
180
|
+
if (closed || command || !queue.length || !control)
|
|
181
|
+
return;
|
|
182
|
+
const args = queue.shift();
|
|
183
|
+
// Track attempted downs too: an interrupted xdotool can already have injected them.
|
|
184
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
185
|
+
if (args[i] === "keydown")
|
|
186
|
+
keys.add(args[i + 1]);
|
|
187
|
+
if (args[i] === "mousedown")
|
|
188
|
+
buttons.add(args[i + 1]);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
command = execFile(control, args, { timeout: 2000, killSignal: "SIGKILL", maxBuffer: 16384, shell: false }, (error) => {
|
|
192
|
+
command = undefined;
|
|
193
|
+
if (closed) {
|
|
194
|
+
releaseAfterStop();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (error) {
|
|
198
|
+
fail(`xdotool input failed: ${error.message}`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
202
|
+
if (args[i] === "keyup")
|
|
203
|
+
keys.delete(args[i + 1]);
|
|
204
|
+
if (args[i] === "mouseup")
|
|
205
|
+
buttons.delete(args[i + 1]);
|
|
206
|
+
}
|
|
207
|
+
drain();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
command = undefined;
|
|
212
|
+
fail(`xdotool input failed: ${String(error)}`);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const input = (event) => {
|
|
216
|
+
if (closed || options.readOnly !== false)
|
|
217
|
+
return;
|
|
218
|
+
if (!control) {
|
|
219
|
+
if (!missingControlReported) {
|
|
220
|
+
missingControlReported = true;
|
|
221
|
+
report("Desktop control requires xdotool; viewing remains available.");
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let args = [];
|
|
226
|
+
switch (event.type) {
|
|
227
|
+
case "pointer": {
|
|
228
|
+
if (!Number.isFinite(event.x) || !Number.isFinite(event.y))
|
|
229
|
+
return;
|
|
230
|
+
args = [
|
|
231
|
+
"mousemove",
|
|
232
|
+
"--sync",
|
|
233
|
+
String(Math.round(Math.max(0, Math.min(1, event.x)) * (width - 1))),
|
|
234
|
+
String(Math.round(Math.max(0, Math.min(1, event.y)) * (height - 1))),
|
|
235
|
+
];
|
|
236
|
+
if (event.action === "down" || event.action === "up") {
|
|
237
|
+
if (![0, 1, 2].includes(event.button))
|
|
238
|
+
return;
|
|
239
|
+
args.push(event.action === "down" ? "mousedown" : "mouseup", String([1, 2, 3][event.button]));
|
|
240
|
+
}
|
|
241
|
+
else if (event.action !== "move")
|
|
242
|
+
return;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "wheel":
|
|
246
|
+
if (!Number.isFinite(event.deltaY) || event.deltaY === 0)
|
|
247
|
+
return;
|
|
248
|
+
args = [
|
|
249
|
+
"click",
|
|
250
|
+
"--repeat",
|
|
251
|
+
String(Math.min(10, Math.max(1, Math.ceil(Math.abs(event.deltaY) / 100)))),
|
|
252
|
+
"--delay",
|
|
253
|
+
"0",
|
|
254
|
+
event.deltaY > 0 ? "5" : "4",
|
|
255
|
+
];
|
|
256
|
+
break;
|
|
257
|
+
case "key": {
|
|
258
|
+
const key = keySymbol(event.code);
|
|
259
|
+
if (!key || (event.action !== "down" && event.action !== "up"))
|
|
260
|
+
return;
|
|
261
|
+
args = [event.action === "down" ? "keydown" : "keyup", key];
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case "text":
|
|
265
|
+
if (typeof event.text !== "string" ||
|
|
266
|
+
!event.text ||
|
|
267
|
+
Buffer.byteLength(event.text) > 4096 ||
|
|
268
|
+
event.text.includes("\0"))
|
|
269
|
+
return;
|
|
270
|
+
args = ["type", "--clearmodifiers", "--delay", "0", "--", event.text];
|
|
271
|
+
break;
|
|
272
|
+
case "release":
|
|
273
|
+
queue = [];
|
|
274
|
+
args = releaseArgs();
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (!args.length)
|
|
280
|
+
return;
|
|
281
|
+
if (queue.length >= MAX_QUEUE) {
|
|
282
|
+
fail("Desktop input queue exceeded its limit.");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
queue.push(args);
|
|
286
|
+
drain();
|
|
287
|
+
};
|
|
288
|
+
try {
|
|
289
|
+
const status = linuxDesktopStatus();
|
|
290
|
+
if (!status.supported)
|
|
291
|
+
throw new Error(status.reason);
|
|
292
|
+
control = executable("xdotool");
|
|
293
|
+
[width, height] = screenSize();
|
|
294
|
+
capture = spawn(executable("ffmpeg"), [
|
|
295
|
+
"-nostdin",
|
|
296
|
+
"-hide_banner",
|
|
297
|
+
"-loglevel",
|
|
298
|
+
"error",
|
|
299
|
+
"-f",
|
|
300
|
+
"x11grab",
|
|
301
|
+
"-framerate",
|
|
302
|
+
"8",
|
|
303
|
+
"-video_size",
|
|
304
|
+
`${width}x${height}`,
|
|
305
|
+
"-i",
|
|
306
|
+
process.env.DISPLAY,
|
|
307
|
+
"-an",
|
|
308
|
+
"-vf",
|
|
309
|
+
"scale=w='min(1600,iw)':h='min(1600,ih)':force_original_aspect_ratio=decrease",
|
|
310
|
+
"-c:v",
|
|
311
|
+
"mjpeg",
|
|
312
|
+
"-q:v",
|
|
313
|
+
"5",
|
|
314
|
+
"-f",
|
|
315
|
+
"image2pipe",
|
|
316
|
+
"pipe:1",
|
|
317
|
+
], { shell: false, stdio: ["ignore", "pipe", "pipe"], env: process.env });
|
|
318
|
+
capture.stdout.on("data", (chunk) => {
|
|
319
|
+
if (closed)
|
|
320
|
+
return;
|
|
321
|
+
// Slice large writes so a single producer chunk cannot grow retained memory unboundedly.
|
|
322
|
+
for (let offset = 0; offset < chunk.length && !closed; offset += 65536) {
|
|
323
|
+
pending = Buffer.concat([pending, chunk.subarray(offset, offset + 65536)]);
|
|
324
|
+
while (pending.length && !closed) {
|
|
325
|
+
const start = pending.indexOf(Buffer.from([0xff, 0xd8]));
|
|
326
|
+
if (start < 0) {
|
|
327
|
+
pending = Buffer.from(pending.subarray(-1));
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
if (start)
|
|
331
|
+
pending = pending.subarray(start);
|
|
332
|
+
const end = pending.indexOf(Buffer.from([0xff, 0xd9]), 2);
|
|
333
|
+
if (end < 0) {
|
|
334
|
+
if (pending.length > MAX_FRAME)
|
|
335
|
+
fail("ffmpeg JPEG frame exceeded 4 MiB.");
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
if (end + 2 > MAX_FRAME) {
|
|
339
|
+
fail("ffmpeg JPEG frame exceeded 4 MiB.");
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
const frame = Buffer.from(pending.subarray(0, end + 2));
|
|
343
|
+
pending = pending.subarray(end + 2);
|
|
344
|
+
try {
|
|
345
|
+
options.onFrame(frame);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
fail(`Desktop frame callback failed: ${String(error)}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
capture.stderr.on("data", (chunk) => {
|
|
354
|
+
if (!closed)
|
|
355
|
+
stderr = (stderr + chunk.toString()).slice(-4096);
|
|
356
|
+
});
|
|
357
|
+
capture.on("error", (error) => fail(`ffmpeg capture failed: ${error.message}`));
|
|
358
|
+
capture.stdout.on("error", (error) => fail(`ffmpeg output failed: ${error.message}`));
|
|
359
|
+
capture.stderr.on("error", (error) => fail(`ffmpeg stderr failed: ${error.message}`));
|
|
360
|
+
capture.on("close", (code, signal) => {
|
|
361
|
+
if (killTimer)
|
|
362
|
+
clearTimeout(killTimer);
|
|
363
|
+
if (!closed)
|
|
364
|
+
fail(`ffmpeg capture stopped (${signal ?? code}): ${stderr || "check X11 permissions and ffmpeg x11grab support"}`);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
// Defer setup failures so callers can store the returned handle before onClose.
|
|
369
|
+
queueMicrotask(() => fail(String(error)));
|
|
370
|
+
}
|
|
371
|
+
return { input, close };
|
|
372
|
+
}
|