@clagentic/console 1.0.0-beta.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 (221) hide show
  1. package/CREDITS.md +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +250 -0
  4. package/bin/cli.js +2812 -0
  5. package/lib/agents-favorites.js +164 -0
  6. package/lib/agents.js +282 -0
  7. package/lib/ask-user-mcp-server.js +120 -0
  8. package/lib/browser-mcp-server.js +484 -0
  9. package/lib/build-user-env.js +63 -0
  10. package/lib/certs/fullchain.pem +47 -0
  11. package/lib/certs/privkey.pem +5 -0
  12. package/lib/cli-sessions.js +265 -0
  13. package/lib/codex-defaults.js +18 -0
  14. package/lib/config.js +332 -0
  15. package/lib/crisis-safety.js +60 -0
  16. package/lib/daemon-projects.js +164 -0
  17. package/lib/daemon.js +1602 -0
  18. package/lib/dm.js +128 -0
  19. package/lib/ipc.js +125 -0
  20. package/lib/ipv4-only.js +39 -0
  21. package/lib/mcp-local.js +385 -0
  22. package/lib/notes.js +141 -0
  23. package/lib/os-users.js +529 -0
  24. package/lib/pages.js +1325 -0
  25. package/lib/project-connection.js +302 -0
  26. package/lib/project-external-trigger.js +236 -0
  27. package/lib/project-file-watch.js +120 -0
  28. package/lib/project-filesystem.js +528 -0
  29. package/lib/project-http.js +753 -0
  30. package/lib/project-image.js +95 -0
  31. package/lib/project-knowledge.js +88 -0
  32. package/lib/project-loop.js +1304 -0
  33. package/lib/project-mcp.js +374 -0
  34. package/lib/project-memory.js +39 -0
  35. package/lib/project-notifications.js +262 -0
  36. package/lib/project-sessions.js +1581 -0
  37. package/lib/project-user-mention.js +193 -0
  38. package/lib/project-user-message.js +628 -0
  39. package/lib/project.js +1303 -0
  40. package/lib/public/app.js +1031 -0
  41. package/lib/public/apple-touch-icon.png +0 -0
  42. package/lib/public/claude-code-avatar.png +0 -0
  43. package/lib/public/codex-avatar.png +0 -0
  44. package/lib/public/console-icon.png +0 -0
  45. package/lib/public/css/admin.css +736 -0
  46. package/lib/public/css/agent-picker.css +119 -0
  47. package/lib/public/css/base.css +235 -0
  48. package/lib/public/css/channel-layout.css +441 -0
  49. package/lib/public/css/command-palette.css +559 -0
  50. package/lib/public/css/debate.css +1609 -0
  51. package/lib/public/css/diff.css +139 -0
  52. package/lib/public/css/filebrowser.css +1976 -0
  53. package/lib/public/css/highlight.css +144 -0
  54. package/lib/public/css/home-hub.css +545 -0
  55. package/lib/public/css/icon-strip.css +1856 -0
  56. package/lib/public/css/input.css +1349 -0
  57. package/lib/public/css/loop.css +1248 -0
  58. package/lib/public/css/mention.css +317 -0
  59. package/lib/public/css/menus.css +857 -0
  60. package/lib/public/css/messages.css +1833 -0
  61. package/lib/public/css/mobile-nav.css +1332 -0
  62. package/lib/public/css/notifications-center.css +296 -0
  63. package/lib/public/css/overlays.css +1273 -0
  64. package/lib/public/css/playbook.css +264 -0
  65. package/lib/public/css/profile.css +397 -0
  66. package/lib/public/css/rewind.css +671 -0
  67. package/lib/public/css/scheduler-modal.css +1495 -0
  68. package/lib/public/css/scheduler.css +1420 -0
  69. package/lib/public/css/server-settings.css +909 -0
  70. package/lib/public/css/session-search.css +159 -0
  71. package/lib/public/css/sidebar.css +2012 -0
  72. package/lib/public/css/skills.css +789 -0
  73. package/lib/public/css/sticky-notes.css +854 -0
  74. package/lib/public/css/stt.css +155 -0
  75. package/lib/public/css/title-bar.css +674 -0
  76. package/lib/public/css/tooltip.css +67 -0
  77. package/lib/public/css/user-settings.css +702 -0
  78. package/lib/public/emoji-data.json +1 -0
  79. package/lib/public/favicon-banded-32.png +0 -0
  80. package/lib/public/favicon-banded.png +0 -0
  81. package/lib/public/favicon-dark.svg +32 -0
  82. package/lib/public/favicon.svg +32 -0
  83. package/lib/public/icon-192.png +0 -0
  84. package/lib/public/icon-512.png +0 -0
  85. package/lib/public/icon-banded-76.png +0 -0
  86. package/lib/public/icon-banded-96.png +0 -0
  87. package/lib/public/icon-mono.svg +25 -0
  88. package/lib/public/icons/email/gmail.svg +7 -0
  89. package/lib/public/icons/email/outlook.svg +35 -0
  90. package/lib/public/icons/email/yahoo.svg +1 -0
  91. package/lib/public/index.html +1946 -0
  92. package/lib/public/manifest.json +27 -0
  93. package/lib/public/markdown-worker.js +43 -0
  94. package/lib/public/marked.min.js +6 -0
  95. package/lib/public/modules/admin.js +954 -0
  96. package/lib/public/modules/agent-picker.js +429 -0
  97. package/lib/public/modules/app-connection.js +216 -0
  98. package/lib/public/modules/app-cursors.js +492 -0
  99. package/lib/public/modules/app-dm.js +265 -0
  100. package/lib/public/modules/app-favicon.js +231 -0
  101. package/lib/public/modules/app-header.js +242 -0
  102. package/lib/public/modules/app-home-hub.js +432 -0
  103. package/lib/public/modules/app-loop-ui.js +691 -0
  104. package/lib/public/modules/app-loop-wizard.js +439 -0
  105. package/lib/public/modules/app-messages.js +1415 -0
  106. package/lib/public/modules/app-misc.js +463 -0
  107. package/lib/public/modules/app-notifications.js +651 -0
  108. package/lib/public/modules/app-panels.js +1061 -0
  109. package/lib/public/modules/app-projects.js +875 -0
  110. package/lib/public/modules/app-rate-limit.js +529 -0
  111. package/lib/public/modules/app-rendering.js +739 -0
  112. package/lib/public/modules/app-skills-install.js +285 -0
  113. package/lib/public/modules/avatar.js +36 -0
  114. package/lib/public/modules/command-palette.js +491 -0
  115. package/lib/public/modules/console-logo.js +162 -0
  116. package/lib/public/modules/context-sources.js +365 -0
  117. package/lib/public/modules/diff.js +412 -0
  118. package/lib/public/modules/dom-refs.js +21 -0
  119. package/lib/public/modules/emoji-picker.js +222 -0
  120. package/lib/public/modules/events.js +21 -0
  121. package/lib/public/modules/filebrowser.js +1966 -0
  122. package/lib/public/modules/fileicons.js +172 -0
  123. package/lib/public/modules/icons.js +80 -0
  124. package/lib/public/modules/input.js +1102 -0
  125. package/lib/public/modules/longpress.js +74 -0
  126. package/lib/public/modules/markdown.js +486 -0
  127. package/lib/public/modules/mcp-ui.js +295 -0
  128. package/lib/public/modules/mention.js +1093 -0
  129. package/lib/public/modules/notifications.js +613 -0
  130. package/lib/public/modules/playbook.js +578 -0
  131. package/lib/public/modules/profile.js +594 -0
  132. package/lib/public/modules/project-settings.js +849 -0
  133. package/lib/public/modules/project-switcher.js +375 -0
  134. package/lib/public/modules/qrcode.js +87 -0
  135. package/lib/public/modules/rewind.js +381 -0
  136. package/lib/public/modules/scheduler-config.js +1611 -0
  137. package/lib/public/modules/scheduler-history.js +131 -0
  138. package/lib/public/modules/scheduler.js +1689 -0
  139. package/lib/public/modules/server-settings.js +842 -0
  140. package/lib/public/modules/session-search.js +456 -0
  141. package/lib/public/modules/settings-defaults.js +253 -0
  142. package/lib/public/modules/sidebar-mobile.js +1425 -0
  143. package/lib/public/modules/sidebar-projects.js +2022 -0
  144. package/lib/public/modules/sidebar-sessions.js +1548 -0
  145. package/lib/public/modules/sidebar-users.js +449 -0
  146. package/lib/public/modules/sidebar.js +348 -0
  147. package/lib/public/modules/skills.js +793 -0
  148. package/lib/public/modules/state.js +3 -0
  149. package/lib/public/modules/sticky-notes.js +1221 -0
  150. package/lib/public/modules/store.js +34 -0
  151. package/lib/public/modules/stt.js +266 -0
  152. package/lib/public/modules/terminal.js +987 -0
  153. package/lib/public/modules/theme.js +812 -0
  154. package/lib/public/modules/tool-palette.js +562 -0
  155. package/lib/public/modules/tools.js +2285 -0
  156. package/lib/public/modules/tooltip.js +150 -0
  157. package/lib/public/modules/user-settings.js +544 -0
  158. package/lib/public/modules/utils.js +56 -0
  159. package/lib/public/modules/ws-ref.js +26 -0
  160. package/lib/public/style.css +34 -0
  161. package/lib/public/sw.js +159 -0
  162. package/lib/push.js +149 -0
  163. package/lib/scheduler.js +471 -0
  164. package/lib/sdk-bridge.js +1792 -0
  165. package/lib/sdk-message-processor.js +740 -0
  166. package/lib/sdk-message-queue.js +42 -0
  167. package/lib/sdk-skill-discovery.js +131 -0
  168. package/lib/sdk-worker.js +677 -0
  169. package/lib/server-admin.js +712 -0
  170. package/lib/server-auth.js +737 -0
  171. package/lib/server-dm.js +170 -0
  172. package/lib/server-palette.js +104 -0
  173. package/lib/server-settings.js +553 -0
  174. package/lib/server-skills.js +280 -0
  175. package/lib/server.js +1390 -0
  176. package/lib/session-search.js +693 -0
  177. package/lib/sessions.js +946 -0
  178. package/lib/smtp.js +221 -0
  179. package/lib/terminal-manager.js +219 -0
  180. package/lib/terminal.js +39 -0
  181. package/lib/themes/ayu-light.json +9 -0
  182. package/lib/themes/catppuccin-latte.json +9 -0
  183. package/lib/themes/catppuccin-mocha.json +9 -0
  184. package/lib/themes/clagentic-dark.json +10 -0
  185. package/lib/themes/clagentic-light.json +10 -0
  186. package/lib/themes/dracula.json +9 -0
  187. package/lib/themes/everforest-light.json +9 -0
  188. package/lib/themes/everforest.json +9 -0
  189. package/lib/themes/github-light.json +9 -0
  190. package/lib/themes/gruvbox-dark.json +9 -0
  191. package/lib/themes/gruvbox-light.json +9 -0
  192. package/lib/themes/monokai.json +9 -0
  193. package/lib/themes/nord-light.json +9 -0
  194. package/lib/themes/nord.json +9 -0
  195. package/lib/themes/one-dark.json +9 -0
  196. package/lib/themes/one-light.json +9 -0
  197. package/lib/themes/rose-pine-dawn.json +9 -0
  198. package/lib/themes/rose-pine.json +9 -0
  199. package/lib/themes/solarized-dark.json +9 -0
  200. package/lib/themes/solarized-light.json +9 -0
  201. package/lib/themes/tokyo-night-light.json +9 -0
  202. package/lib/themes/tokyo-night.json +9 -0
  203. package/lib/updater.js +124 -0
  204. package/lib/user-presence.js +92 -0
  205. package/lib/users-auth.js +146 -0
  206. package/lib/users-permissions.js +118 -0
  207. package/lib/users-preferences.js +254 -0
  208. package/lib/users.js +465 -0
  209. package/lib/utils.js +64 -0
  210. package/lib/worktree.js +134 -0
  211. package/lib/ws-schema.js +464 -0
  212. package/lib/yoke/adapters/claude-worker.js +759 -0
  213. package/lib/yoke/adapters/claude.js +1599 -0
  214. package/lib/yoke/adapters/codex.js +1559 -0
  215. package/lib/yoke/codex-app-server.js +352 -0
  216. package/lib/yoke/index.js +319 -0
  217. package/lib/yoke/instructions.js +61 -0
  218. package/lib/yoke/interface.js +98 -0
  219. package/lib/yoke/mcp-bridge-server.js +302 -0
  220. package/lib/yoke/package.json +7 -0
  221. package/package.json +72 -0
@@ -0,0 +1,484 @@
1
+ // Browser MCP Server for Clay
2
+ // Provides browser automation tool definitions.
3
+ // SDK-free: returns runtime-agnostic tool definitions for YOKE adapter.
4
+ //
5
+ // Usage:
6
+ // var browserMcp = require("./browser-mcp-server");
7
+ // var toolDefs = browserMcp.getToolDefs(sendExtensionCommandAny, getTabList, contextOps);
8
+ // var mcpConfig = adapter.createToolServer({ name: "clay-browser", version: "1.0.0", tools: toolDefs });
9
+
10
+ var z;
11
+ try { z = require("zod"); } catch (e) { z = null; }
12
+
13
+ // Build a Zod shape from simple property descriptors
14
+ function buildShape(props, required) {
15
+ if (!z) return {};
16
+ var shape = {};
17
+ var keys = Object.keys(props);
18
+ for (var i = 0; i < keys.length; i++) {
19
+ var k = keys[i];
20
+ var p = props[k];
21
+ var field;
22
+ if (p.type === "number") field = z.number();
23
+ else if (p.type === "boolean") field = z.boolean();
24
+ else if (p.enum) field = z.enum(p.enum);
25
+ else field = z.string();
26
+ if (p.description) field = field.describe(p.description);
27
+ if (!required || required.indexOf(k) === -1) field = field.optional();
28
+ shape[k] = field;
29
+ }
30
+ return shape;
31
+ }
32
+
33
+ // Helper: convert positional args (name, desc, schema, handler) to tool definition object
34
+ function def(name, description, inputSchema, handler) {
35
+ return { name: name, description: description, inputSchema: inputSchema, handler: handler };
36
+ }
37
+
38
+ function getToolDefs(sendCommand, getTabList, contextOps) {
39
+ // sendCommand(command, args, timeout) -> Promise<result>
40
+ // getTabList() -> array of { id, url, title, favIconUrl }
41
+
42
+ // Helper: ensure inject.js loaded (best-effort)
43
+ function ensureInjected(tabId) {
44
+ return sendCommand("tab_inject", { tabId: tabId }).catch(function () {});
45
+ }
46
+
47
+ var tools = [];
48
+
49
+ // --- browser_list_tabs ---
50
+ tools.push(def(
51
+ "browser_list_tabs",
52
+ "List all open browser tabs with their IDs, URLs, and titles",
53
+ buildShape({}, []),
54
+ function () {
55
+ var tabs = getTabList ? getTabList() : [];
56
+ return Promise.resolve({ content: [{ type: "text", text: JSON.stringify(tabs, null, 2) }] });
57
+ }
58
+ ));
59
+
60
+ // --- browser_open ---
61
+ tools.push(def(
62
+ "browser_open",
63
+ "Open a new browser tab and return its tab ID",
64
+ buildShape({
65
+ url: { type: "string", description: "URL to open" },
66
+ active: { type: "boolean", description: "Activate the tab (default true)" },
67
+ }, ["url"]),
68
+ function (args) {
69
+ return sendCommand("tab_open", { url: args.url, active: args.active !== false }).then(function (result) {
70
+ return { content: [{ type: "text", text: "Opened tab " + (result.id || "unknown") + ": " + args.url }] };
71
+ });
72
+ }
73
+ ));
74
+
75
+ // --- browser_close ---
76
+ tools.push(def(
77
+ "browser_close",
78
+ "Close a browser tab",
79
+ buildShape({
80
+ tabId: { type: "number", description: "Tab ID to close" },
81
+ }, ["tabId"]),
82
+ function (args) {
83
+ return sendCommand("tab_close", { tabId: args.tabId }).then(function () {
84
+ return { content: [{ type: "text", text: "Closed tab " + args.tabId }] };
85
+ });
86
+ }
87
+ ));
88
+
89
+ // --- browser_navigate ---
90
+ tools.push(def(
91
+ "browser_navigate",
92
+ "Navigate a tab to a new URL",
93
+ buildShape({
94
+ tabId: { type: "number", description: "Tab ID" },
95
+ url: { type: "string", description: "URL to navigate to" },
96
+ }, ["tabId", "url"]),
97
+ function (args) {
98
+ return sendCommand("tab_navigate", { tabId: args.tabId, url: args.url }).then(function () {
99
+ return { content: [{ type: "text", text: "Navigated tab " + args.tabId + " to " + args.url }] };
100
+ });
101
+ }
102
+ ));
103
+
104
+ // --- browser_screenshot ---
105
+ tools.push(def(
106
+ "browser_screenshot",
107
+ "Capture a screenshot of a browser tab. Skip if the tab is already attached as a context source (data is auto-injected).",
108
+ buildShape({
109
+ tabId: { type: "number", description: "Tab ID" },
110
+ selector: { type: "string", description: "CSS selector to capture a specific element (optional)" },
111
+ }, ["tabId"]),
112
+ function (args) {
113
+ var extArgs = { tabId: args.tabId };
114
+ if (args.selector) extArgs.selector = args.selector;
115
+ return sendCommand("tab_screenshot", extArgs, 10000).then(function (result) {
116
+ if (!result || !result.image) throw new Error("Screenshot failed");
117
+ return {
118
+ content: [
119
+ { type: "image", data: result.image, mimeType: "image/png" },
120
+ { type: "text", text: "Screenshot captured" + (args.selector ? " (selector: " + args.selector + ")" : " (full viewport)") },
121
+ ],
122
+ };
123
+ });
124
+ }
125
+ ));
126
+
127
+ // --- browser_console ---
128
+ tools.push(def(
129
+ "browser_console",
130
+ "Read captured console logs from a tab. Skip if the tab is already a context source (data is auto-injected).",
131
+ buildShape({
132
+ tabId: { type: "number", description: "Tab ID" },
133
+ }, ["tabId"]),
134
+ function (args) {
135
+ return ensureInjected(args.tabId).then(function () {
136
+ return sendCommand("tab_console", { tabId: args.tabId });
137
+ }).then(function (result) {
138
+ var logs = [];
139
+ try { logs = typeof result.logs === "string" ? JSON.parse(result.logs) : (result.logs || []); } catch (e) {}
140
+ if (logs.length === 0) return { content: [{ type: "text", text: "No console output captured" }] };
141
+ var lines = logs.map(function (entry) {
142
+ var ts = entry.ts ? new Date(entry.ts).toTimeString().slice(0, 8) : "";
143
+ return "[" + ts + " " + (entry.level || "log").toUpperCase() + "] " + (entry.text || "");
144
+ });
145
+ return { content: [{ type: "text", text: lines.join("\n") }] };
146
+ });
147
+ }
148
+ ));
149
+
150
+ // --- browser_network ---
151
+ tools.push(def(
152
+ "browser_network",
153
+ "Read captured network requests (fetch/XHR) from a tab. Skip if the tab is already a context source.",
154
+ buildShape({
155
+ tabId: { type: "number", description: "Tab ID" },
156
+ }, ["tabId"]),
157
+ function (args) {
158
+ return ensureInjected(args.tabId).then(function () {
159
+ return sendCommand("tab_network", { tabId: args.tabId });
160
+ }).then(function (result) {
161
+ var reqs = [];
162
+ try { reqs = typeof result.network === "string" ? JSON.parse(result.network) : (result.network || []); } catch (e) {}
163
+ if (reqs.length === 0) return { content: [{ type: "text", text: "No network requests captured" }] };
164
+ var lines = reqs.map(function (r) {
165
+ var line = (r.method || "GET") + " " + (r.url || "") + " " + (r.status || 0) + " " + (r.duration || 0) + "ms";
166
+ if (r.error) line += " [" + r.error + "]";
167
+ return line;
168
+ });
169
+ return { content: [{ type: "text", text: lines.join("\n") }] };
170
+ });
171
+ }
172
+ ));
173
+
174
+ // --- browser_read_page ---
175
+ tools.push(def(
176
+ "browser_read_page",
177
+ "Read page text content (innerText). Skip if the tab is already a context source (text is auto-injected). Use for tabs NOT in context sources, or to read a specific element via selector.",
178
+ buildShape({
179
+ tabId: { type: "number", description: "Tab ID" },
180
+ selector: { type: "string", description: "CSS selector to read specific element (optional)" },
181
+ }, ["tabId"]),
182
+ function (args) {
183
+ if (args.selector) {
184
+ var script = "(function() { var el = document.querySelector(" + JSON.stringify(args.selector) + "); if (!el) return ''; var t = el.innerText; return t.length > 32768 ? t.substring(0, 32768) : t; })()";
185
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
186
+ var text = result.value || "";
187
+ if (!text) return { content: [{ type: "text", text: "Element not found or empty: " + args.selector }] };
188
+ return { content: [{ type: "text", text: text }] };
189
+ });
190
+ }
191
+ return sendCommand("tab_page_text", { tabId: args.tabId }).then(function (result) {
192
+ var text = result.text || "";
193
+ if (!text) return { content: [{ type: "text", text: "Page has no text content" }] };
194
+ return { content: [{ type: "text", text: text }] };
195
+ });
196
+ }
197
+ ));
198
+
199
+ // --- browser_dom ---
200
+ tools.push(def(
201
+ "browser_dom",
202
+ "Get a simplified DOM tree (tag, id, class, children) for structural analysis",
203
+ buildShape({
204
+ tabId: { type: "number", description: "Tab ID" },
205
+ selector: { type: "string", description: "CSS selector for root element (default body)" },
206
+ depth: { type: "number", description: "Max tree depth (default 3)" },
207
+ }, ["tabId"]),
208
+ function (args) {
209
+ var selector = args.selector ? JSON.stringify(args.selector) : '"body"';
210
+ var depth = args.depth || 3;
211
+ var script = "(function() {" +
212
+ "function walk(el, d, max) {" +
213
+ " if (!el || d > max) return null;" +
214
+ " var n = { tag: el.tagName.toLowerCase() };" +
215
+ " if (el.id) n.id = el.id;" +
216
+ " if (el.className && typeof el.className === 'string') { var c = el.className.trim(); if (c) n.class = c; }" +
217
+ " if (el.children.length > 0 && d < max) {" +
218
+ " n.children = [];" +
219
+ " for (var i = 0; i < el.children.length; i++) {" +
220
+ " var child = walk(el.children[i], d + 1, max);" +
221
+ " if (child) n.children.push(child);" +
222
+ " }" +
223
+ " } else if (el.children.length > 0) {" +
224
+ " n.childCount = el.children.length;" +
225
+ " }" +
226
+ " if (el.children.length === 0 && el.textContent) {" +
227
+ " var t = el.textContent.trim();" +
228
+ " if (t.length > 100) t = t.substring(0, 100) + '...';" +
229
+ " if (t) n.text = t;" +
230
+ " }" +
231
+ " return n;" +
232
+ "}" +
233
+ "var root = document.querySelector(" + selector + ") || document.body;" +
234
+ "return JSON.stringify(walk(root, 0, " + depth + "), null, 2);" +
235
+ "})()";
236
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
237
+ return { content: [{ type: "text", text: result.value || "null" }] };
238
+ });
239
+ }
240
+ ));
241
+
242
+ // --- browser_styles ---
243
+ tools.push(def(
244
+ "browser_styles",
245
+ "Get computed styles of an element (display, position, size, colors, etc.)",
246
+ buildShape({
247
+ tabId: { type: "number", description: "Tab ID" },
248
+ selector: { type: "string", description: "CSS selector" },
249
+ }, ["tabId", "selector"]),
250
+ function (args) {
251
+ var script = "(function() {" +
252
+ "var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
253
+ "if (!el) return JSON.stringify({ error: 'Element not found' });" +
254
+ "var cs = window.getComputedStyle(el);" +
255
+ "var props = ['display','visibility','opacity','position','top','right','bottom','left'," +
256
+ "'width','height','minWidth','minHeight','maxWidth','maxHeight'," +
257
+ "'margin','padding','border','borderRadius'," +
258
+ "'color','backgroundColor','fontSize','fontFamily','fontWeight'," +
259
+ "'overflow','zIndex','transform','transition','boxShadow','cursor'];" +
260
+ "var result = {};" +
261
+ "for (var i = 0; i < props.length; i++) { result[props[i]] = cs[props[i]]; }" +
262
+ "result.boundingRect = el.getBoundingClientRect().toJSON();" +
263
+ "return JSON.stringify(result, null, 2);" +
264
+ "})()";
265
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
266
+ return { content: [{ type: "text", text: result.value || "null" }] };
267
+ });
268
+ }
269
+ ));
270
+
271
+ // --- browser_storage ---
272
+ tools.push(def(
273
+ "browser_storage",
274
+ "Read browser storage (localStorage, sessionStorage, or cookies)",
275
+ buildShape({
276
+ tabId: { type: "number", description: "Tab ID" },
277
+ type: { type: "string", enum: ["local", "session", "cookie"], description: "Storage type (default local)" },
278
+ }, ["tabId"]),
279
+ function (args) {
280
+ var storageType = args.type || "local";
281
+ var script;
282
+ if (storageType === "cookie") {
283
+ script = "JSON.stringify(document.cookie.split('; ').reduce(function(o, c) { var p = c.split('='); o[p[0]] = decodeURIComponent(p.slice(1).join('=')); return o; }, {}), null, 2)";
284
+ } else if (storageType === "session") {
285
+ script = "(function() { var o = {}; for (var i = 0; i < sessionStorage.length; i++) { var k = sessionStorage.key(i); o[k] = sessionStorage.getItem(k); } return JSON.stringify(o, null, 2); })()";
286
+ } else {
287
+ script = "(function() { var o = {}; for (var i = 0; i < localStorage.length; i++) { var k = localStorage.key(i); o[k] = localStorage.getItem(k); } return JSON.stringify(o, null, 2); })()";
288
+ }
289
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
290
+ return { content: [{ type: "text", text: result.value || "{}" }] };
291
+ });
292
+ }
293
+ ));
294
+
295
+ // --- browser_evaluate ---
296
+ tools.push(def(
297
+ "browser_evaluate",
298
+ "Execute arbitrary JavaScript in the page context and return the result",
299
+ buildShape({
300
+ tabId: { type: "number", description: "Tab ID" },
301
+ script: { type: "string", description: "JavaScript expression or IIFE to evaluate" },
302
+ }, ["tabId", "script"]),
303
+ function (args) {
304
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: args.script }).then(function (result) {
305
+ if (result.error) throw new Error(result.error);
306
+ var text = typeof result.value === "string" ? result.value : JSON.stringify(result.value, null, 2);
307
+ return { content: [{ type: "text", text: text || "(undefined)" }] };
308
+ });
309
+ }
310
+ ));
311
+
312
+ // --- browser_click ---
313
+ tools.push(def(
314
+ "browser_click",
315
+ "Click an element on the page",
316
+ buildShape({
317
+ tabId: { type: "number", description: "Tab ID" },
318
+ selector: { type: "string", description: "CSS selector of the element to click" },
319
+ }, ["tabId", "selector"]),
320
+ function (args) {
321
+ var script = "(function() {" +
322
+ "var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
323
+ "if (!el) return 'Element not found: " + args.selector.replace(/'/g, "\\'") + "';" +
324
+ "el.scrollIntoView({ block: 'center', behavior: 'instant' });" +
325
+ "el.click();" +
326
+ "return 'Clicked: " + args.selector.replace(/'/g, "\\'") + "';" +
327
+ "})()";
328
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
329
+ return { content: [{ type: "text", text: result.value || "Click executed" }] };
330
+ });
331
+ }
332
+ ));
333
+
334
+ // --- browser_type ---
335
+ tools.push(def(
336
+ "browser_type",
337
+ "Type text into an input element (sets value and dispatches input/change events)",
338
+ buildShape({
339
+ tabId: { type: "number", description: "Tab ID" },
340
+ selector: { type: "string", description: "CSS selector of the input element" },
341
+ text: { type: "string", description: "Text to type" },
342
+ }, ["tabId", "selector", "text"]),
343
+ function (args) {
344
+ var script = "(function() {" +
345
+ "var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
346
+ "if (!el) return 'Element not found: " + args.selector.replace(/'/g, "\\'") + "';" +
347
+ "el.focus();" +
348
+ "var nativeSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value') || Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value');" +
349
+ "if (nativeSetter && nativeSetter.set) { nativeSetter.set.call(el, " + JSON.stringify(args.text) + "); }" +
350
+ "else { el.value = " + JSON.stringify(args.text) + "; }" +
351
+ "el.dispatchEvent(new Event('input', { bubbles: true }));" +
352
+ "el.dispatchEvent(new Event('change', { bubbles: true }));" +
353
+ "return 'Typed into: " + args.selector.replace(/'/g, "\\'") + "';" +
354
+ "})()";
355
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
356
+ return { content: [{ type: "text", text: result.value || "Type executed" }] };
357
+ });
358
+ }
359
+ ));
360
+
361
+ // --- browser_scroll ---
362
+ tools.push(def(
363
+ "browser_scroll",
364
+ "Scroll the page or scroll a specific element into view",
365
+ buildShape({
366
+ tabId: { type: "number", description: "Tab ID" },
367
+ selector: { type: "string", description: "CSS selector to scroll into view (optional)" },
368
+ x: { type: "number", description: "Horizontal scroll position (optional)" },
369
+ y: { type: "number", description: "Vertical scroll position (optional)" },
370
+ }, ["tabId"]),
371
+ function (args) {
372
+ var script;
373
+ if (args.selector) {
374
+ script = "(function() {" +
375
+ "var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
376
+ "if (!el) return 'Element not found';" +
377
+ "el.scrollIntoView({ block: 'center', behavior: 'smooth' });" +
378
+ "return 'Scrolled to: " + args.selector.replace(/'/g, "\\'") + "';" +
379
+ "})()";
380
+ } else {
381
+ var x = args.x || 0;
382
+ var y = args.y || 0;
383
+ script = "(function() { window.scrollTo(" + x + ", " + y + "); return 'Scrolled to (" + x + ", " + y + ")'; })()";
384
+ }
385
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
386
+ return { content: [{ type: "text", text: result.value || "Scroll executed" }] };
387
+ });
388
+ }
389
+ ));
390
+
391
+ // --- browser_wait ---
392
+ tools.push(def(
393
+ "browser_wait",
394
+ "Wait for an element matching a CSS selector to appear in the DOM",
395
+ buildShape({
396
+ tabId: { type: "number", description: "Tab ID" },
397
+ selector: { type: "string", description: "CSS selector to wait for" },
398
+ timeout: { type: "number", description: "Timeout in ms (default 5000)" },
399
+ }, ["tabId", "selector"]),
400
+ function (args) {
401
+ var timeout = args.timeout || 5000;
402
+ var script = "(function() {" +
403
+ "var el = document.querySelector(" + JSON.stringify(args.selector) + ");" +
404
+ "if (el) return JSON.stringify({ found: true, tag: el.tagName.toLowerCase() });" +
405
+ "return JSON.stringify({ found: false });" +
406
+ "})()";
407
+ var startTime = Date.now();
408
+ function poll() {
409
+ return sendCommand("tab_evaluate", { tabId: args.tabId, script: script }).then(function (result) {
410
+ var parsed = {};
411
+ try { parsed = JSON.parse(result.value || "{}"); } catch (e) {}
412
+ if (parsed.found) {
413
+ return { content: [{ type: "text", text: "Element found: " + args.selector + " (" + parsed.tag + ")" }] };
414
+ }
415
+ if (Date.now() - startTime >= timeout) {
416
+ throw new Error("Timeout waiting for element: " + args.selector + " (" + timeout + "ms)");
417
+ }
418
+ return new Promise(function (resolve) {
419
+ setTimeout(function () { resolve(poll()); }, 300);
420
+ });
421
+ });
422
+ }
423
+ return poll();
424
+ }
425
+ ));
426
+
427
+ // --- browser_wait_navigation ---
428
+ tools.push(def(
429
+ "browser_wait_navigation",
430
+ "Wait for page navigation to complete (URL change + load event)",
431
+ buildShape({
432
+ tabId: { type: "number", description: "Tab ID" },
433
+ timeout: { type: "number", description: "Timeout in ms (default 10000)" },
434
+ }, ["tabId"]),
435
+ function (args) {
436
+ var timeout = args.timeout || 10000;
437
+ return sendCommand("tab_wait_navigation", { tabId: args.tabId, timeout: timeout }, timeout + 3000).then(function (result) {
438
+ if (result.error) throw new Error(result.error);
439
+ return { content: [{ type: "text", text: "Navigation complete: " + (result.url || "unknown URL") }] };
440
+ });
441
+ }
442
+ ));
443
+
444
+ // --- browser_watch_tab ---
445
+ if (contextOps && contextOps.watchTab) {
446
+ tools.push(def(
447
+ "browser_watch_tab",
448
+ "Add a browser tab as a persistent context source. Its screenshot and text will be automatically included in every subsequent message.",
449
+ buildShape({
450
+ tabId: { type: "number", description: "Tab ID to watch" },
451
+ }, ["tabId"]),
452
+ function (args) {
453
+ var tabs = getTabList ? getTabList() : [];
454
+ var found = null;
455
+ for (var i = 0; i < tabs.length; i++) {
456
+ if (tabs[i].id === args.tabId) { found = tabs[i]; break; }
457
+ }
458
+ if (!found) throw new Error("Tab " + args.tabId + " not found in open tabs");
459
+ var active = contextOps.watchTab(args.tabId);
460
+ return Promise.resolve({
461
+ content: [{ type: "text", text: "Now watching tab " + args.tabId + " (" + (found.title || found.url) + "). Its content will be included as context in every message. Active sources: " + active.join(", ") }],
462
+ });
463
+ }
464
+ ));
465
+
466
+ tools.push(def(
467
+ "browser_unwatch_tab",
468
+ "Remove a browser tab from persistent context sources. Stops auto-including its content.",
469
+ buildShape({
470
+ tabId: { type: "number", description: "Tab ID to stop watching" },
471
+ }, ["tabId"]),
472
+ function (args) {
473
+ var active = contextOps.unwatchTab(args.tabId);
474
+ return Promise.resolve({
475
+ content: [{ type: "text", text: "Stopped watching tab " + args.tabId + ". Active sources: " + (active.length > 0 ? active.join(", ") : "none") }],
476
+ });
477
+ }
478
+ ));
479
+ }
480
+
481
+ return tools;
482
+ }
483
+
484
+ module.exports = { getToolDefs: getToolDefs };
@@ -0,0 +1,63 @@
1
+ // build-user-env.js — Build a minimal, safe environment for user subprocesses.
2
+ // Prevents leaking the root daemon's full process.env to user sessions.
3
+
4
+ var os = require("os");
5
+
6
+ // Only these vars are forwarded from the daemon's environment.
7
+ var ALLOWED_KEYS = ["PATH", "LANG", "NODE_ENV"];
8
+
9
+ /**
10
+ * Build a clean env object for spawning a user process.
11
+ * osUserInfo: { uid, gid, home, user, shell } or null for same-user fallback.
12
+ */
13
+ function buildUserEnv(osUserInfo) {
14
+ var env = {};
15
+
16
+ // Copy only allowlisted keys from daemon env
17
+ for (var i = 0; i < ALLOWED_KEYS.length; i++) {
18
+ var key = ALLOWED_KEYS[i];
19
+ if (process.env[key]) env[key] = process.env[key];
20
+ }
21
+
22
+ // Copy all LC_* locale vars
23
+ var keys = Object.keys(process.env);
24
+ for (var j = 0; j < keys.length; j++) {
25
+ if (keys[j].indexOf("LC_") === 0) {
26
+ env[keys[j]] = process.env[keys[j]];
27
+ }
28
+ }
29
+
30
+ // Terminal settings
31
+ env.TERM = "xterm-256color";
32
+ env.COLORFGBG = "15;0"; // Suppress OSC 11 background-color queries
33
+
34
+ // User identity
35
+ if (osUserInfo) {
36
+ env.HOME = osUserInfo.home;
37
+ env.USER = osUserInfo.user;
38
+ env.LOGNAME = osUserInfo.user;
39
+ if (osUserInfo.shell) env.SHELL = osUserInfo.shell;
40
+ } else {
41
+ env.HOME = process.env.HOME || os.homedir();
42
+ env.USER = process.env.USER || "";
43
+ env.LOGNAME = process.env.LOGNAME || process.env.USER || "";
44
+ env.SHELL = process.env.SHELL || "/bin/bash";
45
+ }
46
+
47
+ // XDG runtime dir (needed for dbus, systemd user services, etc.)
48
+ if (osUserInfo) {
49
+ env.XDG_RUNTIME_DIR = "/run/user/" + osUserInfo.uid;
50
+ } else if (process.env.XDG_RUNTIME_DIR) {
51
+ env.XDG_RUNTIME_DIR = process.env.XDG_RUNTIME_DIR;
52
+ }
53
+
54
+ // Force Node.js to prefer IPv4. Without this, the SDK CLI subprocess
55
+ // tries IPv6 first (happy eyeballs), times out on servers without IPv6
56
+ // outbound, then falls back to IPv4. This causes multi-second delays
57
+ // on cold start (compounded by exponential backoff retries).
58
+ env.NODE_OPTIONS = (env.NODE_OPTIONS ? env.NODE_OPTIONS + " " : "") + "--dns-result-order=ipv4first";
59
+
60
+ return env;
61
+ }
62
+
63
+ module.exports = { buildUserEnv: buildUserEnv };
@@ -0,0 +1,47 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDgjCCAwigAwIBAgISBmtBLGUclrEfhwU9evzgyDCQMAoGCCqGSM49BAMDMDIx
3
+ CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJF
4
+ ODAeFw0yNjAzMjMwOTQ0MDJaFw0yNjA2MjEwOTQ0MDFaMBoxGDAWBgNVBAMMDyou
5
+ ZC5jbGF5LnN0dWRpb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