dsh-browser-cdp 0.0.1 → 0.16.24

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 (62) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +285 -9
  3. package/THIRD_PARTY_NOTICES.md +62 -0
  4. package/bin/cdp-cast-worker.mjs +7012 -0
  5. package/bin/cdp-chrome-wrapper.sh +53 -0
  6. package/bin/cdp-render-worker.mjs +610 -0
  7. package/bin/record-normalize.d.mts +32 -0
  8. package/bin/record-normalize.mjs +156 -0
  9. package/cordis.patch.yml +17 -0
  10. package/dsh-plugin.json +148 -0
  11. package/lib/client.js +5985 -0
  12. package/lib/index.js +8923 -0
  13. package/lib/launcher-CQyI8-By.js +3 -0
  14. package/lib/launcher-DBaxfIsF.js +269 -0
  15. package/locale/de.json +6 -0
  16. package/locale/en.json +6 -0
  17. package/locale/es.json +6 -0
  18. package/locale/fr.json +6 -0
  19. package/locale/it.json +6 -0
  20. package/locale/ja.json +6 -0
  21. package/locale/ko.json +6 -0
  22. package/locale/ru.json +6 -0
  23. package/locale/zh.json +6 -0
  24. package/package.json +94 -14
  25. package/runtime/PATCHES.md +30 -0
  26. package/runtime/ego-browser/dist/out/index.js +7206 -0
  27. package/runtime/ego-browser/screenshot-clip.d.mts +22 -0
  28. package/runtime/ego-browser/screenshot-clip.mjs +45 -0
  29. package/runtime/ego-linux/bin/ego-browser.mjs +399 -0
  30. package/runtime/ego-linux/src/agent-identity.mjs +65 -0
  31. package/runtime/ego-linux/src/chrome.mjs +867 -0
  32. package/runtime/ego-linux/src/cursor.mjs +1292 -0
  33. package/runtime/ego-linux/src/desktop.mjs +73 -0
  34. package/runtime/ego-linux/src/paths.mjs +35 -0
  35. package/runtime/ego-linux/src/session.mjs +37 -0
  36. package/runtime/ego-linux/src/shim.mjs +145 -0
  37. package/runtime/ego-linux/src/snapshot.mjs +424 -0
  38. package/runtime/ego-linux/src/spaces-server.mjs +355 -0
  39. package/runtime/ego-linux/src/spaces-ui.mjs +456 -0
  40. package/runtime/ego-linux/src/tabs.mjs +109 -0
  41. package/runtime/ego-linux/src/task-spaces.mjs +671 -0
  42. package/runtime/ego-linux/src/transport.mjs +321 -0
  43. package/runtime/ego-linux/src/window-fit.mjs +107 -0
  44. package/runtime/skills/ego-browser/SKILL.md +209 -0
  45. package/runtime/skills/ego-browser/agents/openai.yaml +7 -0
  46. package/runtime/skills/ego-browser/assets/composer-icon.png +0 -0
  47. package/runtime/skills/ego-browser/assets/logo.png +0 -0
  48. package/runtime/skills/ego-browser/learnings/google/browser-tools/autocomplete.js +11 -0
  49. package/runtime/skills/ego-browser/learnings/google/manifest.json +40 -0
  50. package/runtime/skills/ego-browser/learnings/google/notes/overview.md +23 -0
  51. package/runtime/skills/ego-browser/learnings/google/tools/search-extract.js +35 -0
  52. package/runtime/skills/ego-browser/learnings/x-com/browser-tools/extract-post.js +9 -0
  53. package/runtime/skills/ego-browser/learnings/x-com/manifest.json +51 -0
  54. package/runtime/skills/ego-browser/learnings/x-com/notes/overview.md +18 -0
  55. package/runtime/skills/ego-browser/learnings/x-com/notes/timeline.md +19 -0
  56. package/runtime/skills/ego-browser/learnings/x-com/tools/search-users.js +33 -0
  57. package/runtime/skills/ego-browser/learnings/x-com/tools/timeline.js +32 -0
  58. package/runtime/skills/ego-browser/references/install.md +131 -0
  59. package/runtime/skills/ego-browser/references/task-spaces.md +122 -0
  60. package/runtime/skills/ego-browser/references/video.md +17 -0
  61. package/runtime/skills/ego-browser/scripts/install.sh +309 -0
  62. package/index.js +0 -11
@@ -0,0 +1,73 @@
1
+ import { spawn } from "node:child_process";
2
+ import { copyFile, mkdir, writeFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ import { WM_CLASS } from "./chrome.mjs";
8
+
9
+ /**
10
+ * Desktop integration.
11
+ *
12
+ * The macOS build installs as an app: an icon in the launcher you click to open
13
+ * the browser your agents share. There is no Linux app to install, but the same
14
+ * affordance is just an XDG desktop entry plus an icon, so this provides one.
15
+ */
16
+
17
+ const DATA_HOME = process.env.XDG_DATA_HOME || join(homedir(), ".local", "share");
18
+ const APP_ID = "ego-lite-linux";
19
+ const ICON_SOURCE = new URL("../assets/ego-lite-linux.svg", import.meta.url);
20
+ const LAUNCHER = new URL("../bin/ego-browser.mjs", import.meta.url);
21
+
22
+ /**
23
+ * The desktop session's PATH is not your shell's. A node installed by nvm, fnm
24
+ * or asdf lives outside it, so a `#!/usr/bin/env node` shebang resolves to
25
+ * nothing and clicking the icon fails silently. Pin the interpreter that is
26
+ * running this installer — re-run --install-desktop-entry after switching node
27
+ * versions.
28
+ */
29
+ function desktopEntry(execPath) {
30
+ return `[Desktop Entry]
31
+ Type=Application
32
+ Name=ego lite (Linux port)
33
+ GenericName=Agent Browser
34
+ Comment=The browser you and your AI agents share
35
+ Exec=${process.execPath} ${execPath} --open
36
+ Icon=${APP_ID}
37
+ Terminal=false
38
+ # Ties the browser window (launched with --class=ego-lite-linux) to this entry,
39
+ # so the desktop shows it as its own running app under this icon instead of
40
+ # folding it into the ordinary Chrome window group.
41
+ StartupWMClass=${WM_CLASS}
42
+ Categories=Network;WebBrowser;
43
+ Keywords=agent;automation;browser;ego;
44
+ StartupNotify=true
45
+ `;
46
+ }
47
+
48
+ /** Best-effort cache refresh; the entry works without it on most desktops. */
49
+ function refresh(command, args) {
50
+ return new Promise((resolve) => {
51
+ const child = spawn(command, args, { stdio: "ignore" });
52
+ child.on("error", () => resolve(false));
53
+ child.on("close", (code) => resolve(code === 0));
54
+ });
55
+ }
56
+
57
+ export async function installDesktopEntry() {
58
+ const applications = join(DATA_HOME, "applications");
59
+ const icons = join(DATA_HOME, "icons", "hicolor", "scalable", "apps");
60
+ await mkdir(applications, { recursive: true });
61
+ await mkdir(icons, { recursive: true });
62
+
63
+ const iconPath = join(icons, `${APP_ID}.svg`);
64
+ await copyFile(fileURLToPath(ICON_SOURCE), iconPath);
65
+
66
+ const entryPath = join(applications, `${APP_ID}.desktop`);
67
+ await writeFile(entryPath, desktopEntry(fileURLToPath(LAUNCHER)), { mode: 0o755 });
68
+
69
+ await refresh("update-desktop-database", [applications]);
70
+ await refresh("gtk-update-icon-cache", ["-f", "-t", join(DATA_HOME, "icons", "hicolor")]);
71
+
72
+ return { entryPath, iconPath };
73
+ }
@@ -0,0 +1,35 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+
4
+ const HOME = homedir();
5
+ const IS_WIN = process.platform === "win32";
6
+
7
+ /** Persistent browser profile — the Linux stand-in for the ego lite app's profile. */
8
+ export const DATA_DIR = IS_WIN
9
+ ? join(process.env.LOCALAPPDATA || join(HOME, "AppData", "Local"), "ego-lite-linux")
10
+ : join(process.env.XDG_DATA_HOME || join(HOME, ".local", "share"), "ego-lite-linux");
11
+
12
+ /** Runtime state shared across heredoc invocations (each run is its own process). */
13
+ export const STATE_DIR = IS_WIN
14
+ ? join(process.env.LOCALAPPDATA || join(HOME, "AppData", "Local"), "ego-lite-linux")
15
+ : join(process.env.XDG_STATE_HOME || join(HOME, ".local", "state"), "ego-lite-linux");
16
+
17
+ export const PROFILE_DIR = process.env.EGO_LINUX_PROFILE || join(DATA_DIR, "profile");
18
+ export const BROWSER_STATE_FILE = join(STATE_DIR, "browser.json");
19
+ export const SPACES_STATE_FILE = join(STATE_DIR, "spaces-server.json");
20
+ export const TASK_SPACE_FILE = join(STATE_DIR, "task-spaces.json");
21
+
22
+ /** Where a stock Chrome keeps the profile we can import logins from. */
23
+ export const CHROME_CONFIG_CANDIDATES = IS_WIN
24
+ ? [
25
+ join(process.env.LOCALAPPDATA || join(HOME, "AppData", "Local"), "Google", "Chrome", "User Data"),
26
+ join(process.env.ProgramFiles || "C:\\Program Files", "Google", "Chrome", "User Data"),
27
+ join(process.env["ProgramFiles(x86)"] || "C:\\Program Files (x86)", "Google", "Chrome", "User Data"),
28
+ join(process.env.LOCALAPPDATA || join(HOME, "AppData", "Local"), "Microsoft", "Edge", "User Data"),
29
+ ]
30
+ : [
31
+ join(HOME, ".config", "google-chrome"),
32
+ join(HOME, ".config", "chromium"),
33
+ join(HOME, ".config", "microsoft-edge"),
34
+ join(HOME, ".config", "BraveSoftware", "Brave-Browser"),
35
+ ];
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Which page the shim's own CDP calls should act on.
3
+ *
4
+ * The harness picks its own target (state.preferredTargetId, then the active
5
+ * tab) and attaches a session to it. That choice is invisible from here, so the
6
+ * transport records the target of the harness's Target.attachToTarget calls.
7
+ * Using it keeps every shim-side read and overlay on the page the harness is
8
+ * driving — computing "the active tab" independently lets the two drift, which
9
+ * reads as an empty snapshot, or as a cursor drawn on the wrong tab.
10
+ *
11
+ * The resolver caches its session per target, so a run of calls on one page
12
+ * costs a single attach.
13
+ */
14
+ export function createSessionResolver(cdp, { listTabs, op }) {
15
+ let session = { targetId: null, sessionId: null };
16
+
17
+ return async function sessionForActiveTab() {
18
+ let targetId = cdp.attachedHint?.();
19
+
20
+ if (!targetId) {
21
+ const { tabs } = await listTabs();
22
+ const active = tabs.find((tab) => tab.active) || tabs[tabs.length - 1];
23
+ if (!active) throw new Error(`${op}: no page tab to attach to`);
24
+ targetId = active.targetId;
25
+ }
26
+
27
+ if (session.targetId === targetId && session.sessionId) {
28
+ return session.sessionId;
29
+ }
30
+ const { sessionId } = await cdp.call("Target.attachToTarget", {
31
+ targetId,
32
+ flatten: true,
33
+ });
34
+ session = { targetId, sessionId };
35
+ return sessionId;
36
+ };
37
+ }
@@ -0,0 +1,145 @@
1
+ import { ensureBrowser } from "./chrome.mjs";
2
+ import { connectCdp } from "./transport.mjs";
3
+ import { createTabsApi } from "./tabs.mjs";
4
+ import { createSnapshotApi } from "./snapshot.mjs";
5
+ import { createTaskSpacesApi } from "./task-spaces.mjs";
6
+ import { createCursorApi } from "./cursor.mjs";
7
+ import { createWindowFit } from "./window-fit.mjs";
8
+
9
+ /**
10
+ * Build the `globalThis.ego` object the ego-browser harness expects, backed by a
11
+ * plain Chromium over CDP instead of the macOS-only ego lite app.
12
+ *
13
+ * The full native surface the harness uses is 15 methods plus 2 callbacks; every
14
+ * one of them is implemented or explicitly degraded here. See README.md for the
15
+ * per-method fidelity table.
16
+ */
17
+ export async function createEgoShim({ headless = false } = {}) {
18
+ const { wsUrl, port } = await ensureBrowser({ headless });
19
+ const cdp = await connectCdp(wsUrl);
20
+
21
+ const taskSpaces = createTaskSpacesApi(cdp);
22
+ // Downloads are armed per browser context, and a space owns one — so the
23
+ // harness's context-less setDownloadBehavior has to be aimed at the space the
24
+ // agent is actually in. See aimDownloadsAtCurrentSpace in transport.mjs.
25
+ cdp.setDownloadContext(() => taskSpaces.selectedContextId());
26
+ const tabs = createTabsApi(cdp, {
27
+ port,
28
+ getScope: () => taskSpaces.selectedScope(),
29
+ });
30
+ const snapshot = createSnapshotApi(cdp, { listTabs: tabs.listTabs });
31
+ const cursor = createCursorApi(cdp, { listTabs: tabs.listTabs });
32
+
33
+ // Every pointer event the harness sends moves the overlay, and a press ripples
34
+ // where it landed — so a user watching the window sees the agent work.
35
+ cdp.watchMouse((params) => {
36
+ // A wheel does not move the pointer, and page.wheel() defaults its
37
+ // coordinates to (0, 0) — following those would snap the cursor into the
38
+ // corner on every scroll.
39
+ if (params.type === "mouseWheel") return;
40
+ if (params.type === "mousePressed") cursor.press(params.x, params.y);
41
+ else if (params.type === "mouseReleased") cursor.release(params.x, params.y);
42
+ else cursor.moveTo(params.x, params.y);
43
+ });
44
+
45
+ // Typing is the one action with nothing to watch: fill() dispatches no pointer
46
+ // event at all, so without this a whole form fills itself with no explanation.
47
+ cdp.watchKeys(() => cursor.typed());
48
+
49
+ // A space that has ever loaded a real page is never "opened and never used",
50
+ // however blank its tab looks between navigations.
51
+ // A phone-width emulation in a desktop-width window shows a strip of site
52
+ // beside a band of empty chrome; the window follows the viewport instead.
53
+ const windowFit = createWindowFit(cdp);
54
+ cdp.watchViewport((metrics) => {
55
+ void windowFit.follow(metrics, cdp.attachedHint()).catch(() => {});
56
+ });
57
+
58
+ cdp.watchNavigation(() => {
59
+ void taskSpaces.noteContent().catch(() => {});
60
+ // A navigation destroys the overlay with the document it lives in. This is
61
+ // the earliest point the shim hears about one, and arming here is what lets
62
+ // the cursor come back on the load that follows.
63
+ void cursor.watchPage().catch(() => {});
64
+ });
65
+
66
+ const ego = {
67
+ // --- CDP transport: exact passthrough -----------------------------------
68
+ sendCDPMessage: (payload) => cdp.sendRaw(payload),
69
+ onCDPMessage: null,
70
+ onSendCDPMessageError: null,
71
+
72
+ // --- Tabs ---------------------------------------------------------------
73
+ listTabs: tabs.listTabs,
74
+ createTab: (url) => taskSpaces.createTabInSelectedSpace(tabs, url),
75
+
76
+ // --- Observation --------------------------------------------------------
77
+ // Reading is most of what an agent does, and none of it dispatches pointer
78
+ // events — so a session that only opened pages and snapshotted them drew no
79
+ // cursor at all, and looked idle. Showing the read is what makes the window
80
+ // legible while the agent is thinking rather than clicking.
81
+ // The label is deliberately left up afterwards: a snapshot returns in
82
+ // milliseconds, so clearing it on completion made "reading" flash for less
83
+ // than a frame. moveTo and pulseAt take it down when real input arrives.
84
+ async snapshot(options) {
85
+ cursor.reading();
86
+ return snapshot.snapshot(options);
87
+ },
88
+
89
+ // --- Task spaces --------------------------------------------------------
90
+ listTaskSpaces: taskSpaces.listTaskSpaces,
91
+ // Arming on Page.navigate is too late for that same navigation — the claim
92
+ // and Page.enable race the load and usually lose. Selecting a space is the
93
+ // first moment a tab is guaranteed to exist, and it always precedes the
94
+ // goto, so this is where a process's very first load gets covered.
95
+ async createTaskSpace(name) {
96
+ const result = await taskSpaces.createTaskSpace(name);
97
+ void cursor.watchPage().catch(() => {});
98
+ return result;
99
+ },
100
+ async useTaskSpace(id) {
101
+ const result = await taskSpaces.useTaskSpace(id);
102
+ void cursor.watchPage().catch(() => {});
103
+ return result;
104
+ },
105
+ claimTaskSpace: taskSpaces.claimTaskSpace,
106
+ // Handing a space back to the user drops the agent overlay, and taking it
107
+ // over brings it back — the same signal the native app's Space overlay gives.
108
+ async handOffTaskSpace(id) {
109
+ const result = await taskSpaces.handOffTaskSpace(id);
110
+ cursor.hide();
111
+ return result;
112
+ },
113
+ async takeOverTaskSpace(id) {
114
+ const result = await taskSpaces.takeOverTaskSpace(id);
115
+ cursor.show();
116
+ return result;
117
+ },
118
+ completeTaskSpace: taskSpaces.completeTaskSpace,
119
+ closeTaskSpace: taskSpaces.closeTaskSpace,
120
+
121
+ // --- The agent's cursor -------------------------------------------------
122
+ animationHighlightMouseToPosition: (x, y) => cursor.moveTo(x, y),
123
+ setAgentTaskState: (taskState) => cursor.setTaskState(taskState),
124
+
125
+ // Not upstream surface: a Linux-port extension an agent calls directly to
126
+ // show a human what it is talking about. `ego` is a global in the heredoc,
127
+ // so this reads as `await ego.highlight("free shipping")`.
128
+ highlight: (target, options) => cursor.highlight(target, options),
129
+ clearHighlight: () => cursor.clearHighlight(),
130
+
131
+ // --- App-lifecycle: no-ops on Linux -------------------------------------
132
+ async getBrowserVersion() {
133
+ const version = await cdp.call("Browser.getVersion");
134
+ return { version: version.product, revision: version.revision, linuxPort: true };
135
+ },
136
+ async upgradeBrowser() {
137
+ // The Linux port has no bundled app to upgrade; the user's Chrome updates
138
+ // itself. Reporting "done" keeps the harness's upgrade path a no-op.
139
+ return { done: false, reason: "not applicable on the Linux port" };
140
+ },
141
+ };
142
+
143
+ cdp.bind(ego);
144
+ return { ego, cdp, close: () => cdp.close(), port, wsUrl };
145
+ }