@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.
- package/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
var crypto = require("crypto");
|
|
2
|
+
|
|
3
|
+
// MCP Bridge module: manages remote MCP servers reported by the Chrome Extension.
|
|
4
|
+
// Creates proxy MCP server objects that forward tool calls over WebSocket.
|
|
5
|
+
// Follows the attachXxx(ctx) pattern per MODULE_MAP.md.
|
|
6
|
+
|
|
7
|
+
function attachMcp(ctx) {
|
|
8
|
+
var send = ctx.send;
|
|
9
|
+
var sendTo = ctx.sendTo;
|
|
10
|
+
var slug = ctx.slug;
|
|
11
|
+
var getEnabledMcpServers = ctx.getEnabledMcpServers;
|
|
12
|
+
var setEnabledMcpServers = ctx.setEnabledMcpServers;
|
|
13
|
+
var getExtensionWs = ctx.getExtensionWs;
|
|
14
|
+
var getExtensionId = ctx.getExtensionId || function () { return null; };
|
|
15
|
+
var localMcp = ctx.localMcp || null; // mcp-local instance for localhost clients
|
|
16
|
+
|
|
17
|
+
// Available servers reported by extension: { name -> { name, transport, tools, enabled } }
|
|
18
|
+
var _availableServers = {};
|
|
19
|
+
|
|
20
|
+
// Proxy MCP server objects for the SDK: { name -> sdkMcpServerConfig }
|
|
21
|
+
var _proxyServers = {};
|
|
22
|
+
|
|
23
|
+
// Pending tool calls: { callId -> { resolve, reject, timer } }
|
|
24
|
+
var _pendingCalls = {};
|
|
25
|
+
|
|
26
|
+
var TOOL_TIMEOUT_MS = 30000;
|
|
27
|
+
|
|
28
|
+
// ---------- Message Handler ----------
|
|
29
|
+
|
|
30
|
+
function handleMcpMessage(ws, msg) {
|
|
31
|
+
if (msg.type === "mcp_servers_available") {
|
|
32
|
+
handleServersAvailable(ws, msg);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (msg.type === "mcp_tool_result") {
|
|
36
|
+
handleToolResult(msg);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (msg.type === "mcp_tool_error") {
|
|
40
|
+
handleToolError(msg);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (msg.type === "mcp_toggle_server") {
|
|
44
|
+
handleToggleServer(ws, msg);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var _remoteHostConnected = false;
|
|
51
|
+
|
|
52
|
+
function handleServersAvailable(ws, msg) {
|
|
53
|
+
var servers = msg.servers || [];
|
|
54
|
+
_remoteHostConnected = !!msg.hostConnected;
|
|
55
|
+
_availableServers = {};
|
|
56
|
+
for (var i = 0; i < servers.length; i++) {
|
|
57
|
+
var s = servers[i];
|
|
58
|
+
_availableServers[s.name] = {
|
|
59
|
+
name: s.name,
|
|
60
|
+
transport: s.transport || "stdio",
|
|
61
|
+
tools: s.tools || [],
|
|
62
|
+
enabled: s.enabled !== false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Rebuild proxy servers based on project-level enabled list
|
|
67
|
+
rebuildProxyServers();
|
|
68
|
+
|
|
69
|
+
// Broadcast updated state to all clients
|
|
70
|
+
broadcastMcpState();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleToolResult(msg) {
|
|
74
|
+
var callId = msg.callId;
|
|
75
|
+
console.log("[mcp-bridge] Tool result received: " + callId);
|
|
76
|
+
var pending = _pendingCalls[callId];
|
|
77
|
+
if (!pending) return;
|
|
78
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
79
|
+
delete _pendingCalls[callId];
|
|
80
|
+
pending.resolve(msg.result || { content: [{ type: "text", text: "(empty result)" }] });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function handleToolError(msg) {
|
|
84
|
+
var callId = msg.callId;
|
|
85
|
+
console.log("[mcp-bridge] Tool error received: " + callId + " error=" + (msg.error || "unknown"));
|
|
86
|
+
var pending = _pendingCalls[callId];
|
|
87
|
+
if (!pending) return;
|
|
88
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
89
|
+
delete _pendingCalls[callId];
|
|
90
|
+
pending.reject(new Error(msg.error || "MCP tool call failed"));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function handleToggleServer(ws, msg) {
|
|
94
|
+
var name = msg.name;
|
|
95
|
+
var enabled = !!msg.enabled;
|
|
96
|
+
|
|
97
|
+
var list = getEnabledMcpServers() || [];
|
|
98
|
+
var idx = list.indexOf(name);
|
|
99
|
+
|
|
100
|
+
if (enabled && idx === -1) {
|
|
101
|
+
list.push(name);
|
|
102
|
+
} else if (!enabled && idx !== -1) {
|
|
103
|
+
list.splice(idx, 1);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setEnabledMcpServers(list);
|
|
107
|
+
rebuildProxyServers();
|
|
108
|
+
broadcastMcpState();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ---------- Proxy Server Builder ----------
|
|
112
|
+
|
|
113
|
+
function rebuildProxyServers() {
|
|
114
|
+
_proxyServers = {};
|
|
115
|
+
|
|
116
|
+
var sdk;
|
|
117
|
+
try {
|
|
118
|
+
sdk = require("@anthropic-ai/claude-agent-sdk");
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error("[mcp-bridge] Failed to load SDK:", e.message);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var createSdkMcpServer = sdk.createSdkMcpServer;
|
|
125
|
+
var tool = sdk.tool;
|
|
126
|
+
if (!createSdkMcpServer || !tool) {
|
|
127
|
+
console.error("[mcp-bridge] SDK missing createSdkMcpServer or tool helper");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var z;
|
|
132
|
+
try { z = require("zod").z; } catch (e) {
|
|
133
|
+
try { z = require("zod"); } catch (e2) {
|
|
134
|
+
console.error("[mcp-bridge] Failed to load zod:", e2.message);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var enabledList = getEnabledMcpServers() || [];
|
|
140
|
+
|
|
141
|
+
// --- Remote servers (via Extension) ---
|
|
142
|
+
var serverNames = Object.keys(_availableServers);
|
|
143
|
+
for (var si = 0; si < serverNames.length; si++) {
|
|
144
|
+
var serverName = serverNames[si];
|
|
145
|
+
var serverInfo = _availableServers[serverName];
|
|
146
|
+
|
|
147
|
+
if (!serverInfo.enabled) continue;
|
|
148
|
+
if (enabledList.indexOf(serverName) === -1) continue;
|
|
149
|
+
|
|
150
|
+
var tools = [];
|
|
151
|
+
var serverTools = serverInfo.tools || [];
|
|
152
|
+
|
|
153
|
+
for (var ti = 0; ti < serverTools.length; ti++) {
|
|
154
|
+
var mcpTool = serverTools[ti];
|
|
155
|
+
var toolName = mcpTool.name;
|
|
156
|
+
var toolDesc = mcpTool.description || toolName;
|
|
157
|
+
var shape = buildZodShape(z, mcpTool.inputSchema);
|
|
158
|
+
|
|
159
|
+
tools.push(tool(
|
|
160
|
+
toolName,
|
|
161
|
+
toolDesc,
|
|
162
|
+
shape,
|
|
163
|
+
createToolHandler(serverName, toolName)
|
|
164
|
+
));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (tools.length > 0) {
|
|
168
|
+
var mcpServer = createSdkMcpServer({
|
|
169
|
+
name: serverName,
|
|
170
|
+
version: "1.0.0",
|
|
171
|
+
tools: tools,
|
|
172
|
+
});
|
|
173
|
+
_proxyServers[serverName] = mcpServer;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// --- Local servers (direct process, localhost only) ---
|
|
178
|
+
if (localMcp && localMcp.isReady()) {
|
|
179
|
+
var localServers = localMcp.getAvailableServers();
|
|
180
|
+
for (var li = 0; li < localServers.length; li++) {
|
|
181
|
+
var ls = localServers[li];
|
|
182
|
+
if (!ls.ready) continue;
|
|
183
|
+
if (_proxyServers[ls.name]) continue; // remote takes precedence if same name
|
|
184
|
+
if (enabledList.indexOf(ls.name) === -1) continue;
|
|
185
|
+
|
|
186
|
+
var localTools = [];
|
|
187
|
+
for (var lti = 0; lti < ls.tools.length; lti++) {
|
|
188
|
+
var lt = ls.tools[lti];
|
|
189
|
+
var ltShape = buildZodShape(z, lt.inputSchema);
|
|
190
|
+
localTools.push(tool(
|
|
191
|
+
lt.name,
|
|
192
|
+
lt.description || lt.name,
|
|
193
|
+
ltShape,
|
|
194
|
+
createLocalToolHandler(ls.name, lt.name)
|
|
195
|
+
));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (localTools.length > 0) {
|
|
199
|
+
_proxyServers[ls.name] = createSdkMcpServer({
|
|
200
|
+
name: ls.name,
|
|
201
|
+
version: "1.0.0",
|
|
202
|
+
tools: localTools,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function createLocalToolHandler(serverName, toolName) {
|
|
210
|
+
return function (args) {
|
|
211
|
+
return localMcp.callTool(serverName, toolName, args);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function createToolHandler(serverName, toolName) {
|
|
216
|
+
return function (args) {
|
|
217
|
+
return new Promise(function (resolve, reject) {
|
|
218
|
+
var extWs = getExtensionWs();
|
|
219
|
+
if (!extWs || extWs.readyState !== 1) {
|
|
220
|
+
reject(new Error("Browser extension not connected. Cannot reach MCP server: " + serverName));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
var callId = "mc_" + Date.now() + "_" + crypto.randomUUID().slice(0, 8);
|
|
225
|
+
|
|
226
|
+
var timer = setTimeout(function () {
|
|
227
|
+
console.log("[mcp-bridge] Tool call TIMEOUT: " + callId + " server=" + serverName + " tool=" + toolName);
|
|
228
|
+
delete _pendingCalls[callId];
|
|
229
|
+
reject(new Error("MCP tool call timed out after " + (TOOL_TIMEOUT_MS / 1000) + "s"));
|
|
230
|
+
}, TOOL_TIMEOUT_MS);
|
|
231
|
+
|
|
232
|
+
_pendingCalls[callId] = { resolve: resolve, reject: reject, timer: timer };
|
|
233
|
+
|
|
234
|
+
console.log("[mcp-bridge] Sending tool call: " + callId + " server=" + serverName + " tool=" + toolName);
|
|
235
|
+
sendTo(extWs, {
|
|
236
|
+
type: "mcp_tool_call",
|
|
237
|
+
callId: callId,
|
|
238
|
+
server: serverName,
|
|
239
|
+
method: "tools/call",
|
|
240
|
+
params: { name: toolName, arguments: args },
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Build a Zod shape from MCP JSON Schema inputSchema
|
|
247
|
+
function buildZodShape(z, inputSchema) {
|
|
248
|
+
if (!inputSchema || !inputSchema.properties) return {};
|
|
249
|
+
var shape = {};
|
|
250
|
+
var props = inputSchema.properties;
|
|
251
|
+
var required = inputSchema.required || [];
|
|
252
|
+
var keys = Object.keys(props);
|
|
253
|
+
|
|
254
|
+
for (var i = 0; i < keys.length; i++) {
|
|
255
|
+
var k = keys[i];
|
|
256
|
+
var p = props[k];
|
|
257
|
+
var field;
|
|
258
|
+
|
|
259
|
+
if (p.type === "number" || p.type === "integer") {
|
|
260
|
+
field = z.number();
|
|
261
|
+
} else if (p.type === "boolean") {
|
|
262
|
+
field = z.boolean();
|
|
263
|
+
} else if (p.type === "array") {
|
|
264
|
+
field = z.array(z.any());
|
|
265
|
+
} else if (p.type === "object") {
|
|
266
|
+
field = z.record(z.any());
|
|
267
|
+
} else if (p.enum) {
|
|
268
|
+
field = z.enum(p.enum);
|
|
269
|
+
} else {
|
|
270
|
+
field = z.string();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (p.description) field = field.describe(p.description);
|
|
274
|
+
if (required.indexOf(k) === -1) field = field.optional();
|
|
275
|
+
shape[k] = field;
|
|
276
|
+
}
|
|
277
|
+
return shape;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ---------- State Broadcasting ----------
|
|
281
|
+
|
|
282
|
+
function broadcastMcpState() {
|
|
283
|
+
var state = buildMcpState();
|
|
284
|
+
send(state);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function sendConnectionState(ws) {
|
|
288
|
+
sendTo(ws, buildMcpState());
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function buildMcpState() {
|
|
292
|
+
var enabledList = getEnabledMcpServers() || [];
|
|
293
|
+
var servers = [];
|
|
294
|
+
var seen = {};
|
|
295
|
+
|
|
296
|
+
// Remote servers (from Extension)
|
|
297
|
+
var names = Object.keys(_availableServers);
|
|
298
|
+
for (var i = 0; i < names.length; i++) {
|
|
299
|
+
var name = names[i];
|
|
300
|
+
var info = _availableServers[name];
|
|
301
|
+
seen[name] = true;
|
|
302
|
+
servers.push({
|
|
303
|
+
name: name,
|
|
304
|
+
transport: info.transport,
|
|
305
|
+
toolCount: (info.tools || []).length,
|
|
306
|
+
extensionEnabled: info.enabled,
|
|
307
|
+
projectEnabled: enabledList.indexOf(name) !== -1,
|
|
308
|
+
source: "remote",
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Local servers
|
|
313
|
+
if (localMcp && localMcp.isReady()) {
|
|
314
|
+
var localServers = localMcp.getAvailableServers();
|
|
315
|
+
for (var j = 0; j < localServers.length; j++) {
|
|
316
|
+
var ls = localServers[j];
|
|
317
|
+
if (seen[ls.name]) continue;
|
|
318
|
+
servers.push({
|
|
319
|
+
name: ls.name,
|
|
320
|
+
transport: ls.transport || "stdio",
|
|
321
|
+
toolCount: ls.toolCount || 0,
|
|
322
|
+
extensionEnabled: true,
|
|
323
|
+
projectEnabled: enabledList.indexOf(ls.name) !== -1,
|
|
324
|
+
source: "local",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
type: "mcp_servers_state",
|
|
331
|
+
servers: servers,
|
|
332
|
+
hostConnected: _remoteHostConnected || !!(localMcp && localMcp.isReady()),
|
|
333
|
+
extensionId: getExtensionId() || null,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ---------- Public API ----------
|
|
338
|
+
|
|
339
|
+
function getMcpServers() {
|
|
340
|
+
return _proxyServers;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function cancelAllPending() {
|
|
344
|
+
var ids = Object.keys(_pendingCalls);
|
|
345
|
+
for (var i = 0; i < ids.length; i++) {
|
|
346
|
+
var pending = _pendingCalls[ids[i]];
|
|
347
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
348
|
+
pending.reject(new Error("MCP bridge disconnected"));
|
|
349
|
+
}
|
|
350
|
+
_pendingCalls = {};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function handleExtensionDisconnect() {
|
|
354
|
+
cancelAllPending();
|
|
355
|
+
_availableServers = {};
|
|
356
|
+
_proxyServers = {};
|
|
357
|
+
broadcastMcpState();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function rebuildAndBroadcast() {
|
|
361
|
+
rebuildProxyServers();
|
|
362
|
+
broadcastMcpState();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return {
|
|
366
|
+
handleMcpMessage: handleMcpMessage,
|
|
367
|
+
getMcpServers: getMcpServers,
|
|
368
|
+
sendConnectionState: sendConnectionState,
|
|
369
|
+
handleExtensionDisconnect: handleExtensionDisconnect,
|
|
370
|
+
rebuildAndBroadcast: rebuildAndBroadcast,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
module.exports = { attachMcp: attachMcp };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory engine stub — memory was a Clay Mates feature.
|
|
3
|
+
* Mates have been removed (lr-316f). This stub satisfies the
|
|
4
|
+
* project.js interface so existing call sites compile cleanly.
|
|
5
|
+
*
|
|
6
|
+
* handleMemoryList / handleMemorySearch / handleMemoryDelete are
|
|
7
|
+
* kept as no-ops; the WS message types (memory_list etc.) still
|
|
8
|
+
* exist in ws-schema.js and project.js routes them here.
|
|
9
|
+
*/
|
|
10
|
+
function attachMemory(ctx) {
|
|
11
|
+
var sendTo = ctx.sendTo;
|
|
12
|
+
|
|
13
|
+
function gateMemory() {}
|
|
14
|
+
function updateMemorySummary() {}
|
|
15
|
+
function initMemorySummary() {}
|
|
16
|
+
|
|
17
|
+
function handleMemoryList(ws) {
|
|
18
|
+
sendTo(ws, { type: "memory_list", digests: [] });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function handleMemorySearch(ws) {
|
|
22
|
+
sendTo(ws, { type: "memory_search_results", results: [] });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function handleMemoryDelete(ws) {
|
|
26
|
+
sendTo(ws, { type: "memory_deleted" });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
gateMemory: gateMemory,
|
|
31
|
+
updateMemorySummary: updateMemorySummary,
|
|
32
|
+
initMemorySummary: initMemorySummary,
|
|
33
|
+
handleMemoryList: handleMemoryList,
|
|
34
|
+
handleMemorySearch: handleMemorySearch,
|
|
35
|
+
handleMemoryDelete: handleMemoryDelete,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = { attachMemory };
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// project-notifications.js - Global notification queue, event-based creation
|
|
2
|
+
// Single instance shared by all projects. All formatting logic lives here.
|
|
3
|
+
// Follows attachXxx(ctx) pattern per MODULE_MAP.md
|
|
4
|
+
|
|
5
|
+
var fs = require("fs");
|
|
6
|
+
var path = require("path");
|
|
7
|
+
var config = require("./config");
|
|
8
|
+
|
|
9
|
+
var NOTIF_FILE = path.join(config.CONFIG_DIR, "notifications.json");
|
|
10
|
+
var REMINDER_INTERVAL = 60 * 60 * 1000; // 1 hour
|
|
11
|
+
|
|
12
|
+
function generateId() {
|
|
13
|
+
var rand = Math.random().toString(36).substring(2, 8);
|
|
14
|
+
return "n_" + Date.now() + "_" + rand;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ========================================================
|
|
18
|
+
// Event -> notification formatters
|
|
19
|
+
// ========================================================
|
|
20
|
+
|
|
21
|
+
var formatters = {
|
|
22
|
+
auth_required: function (data) {
|
|
23
|
+
var vendor = data.vendor || "claude";
|
|
24
|
+
var title = data.title || ((vendor === "codex" ? "Codex" : "Claude Code") + " is not logged in");
|
|
25
|
+
return {
|
|
26
|
+
type: "auth_required",
|
|
27
|
+
title: title,
|
|
28
|
+
body: data.body || "Open a terminal, then click the URL and follow the instructions.",
|
|
29
|
+
meta: {
|
|
30
|
+
vendor: vendor,
|
|
31
|
+
loginCommand: data.loginCommand || "",
|
|
32
|
+
linuxUser: data.linuxUser || null,
|
|
33
|
+
canAutoLogin: !!data.canAutoLogin,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
loop_complete: function (data) {
|
|
39
|
+
var reason = data.reason || "complete";
|
|
40
|
+
var body = (reason === "pass" || reason === "complete")
|
|
41
|
+
? "Completed after " + (data.iterations || 0) + " iteration(s)"
|
|
42
|
+
: reason === "max_iterations"
|
|
43
|
+
? "Reached max iterations (" + (data.maxIterations || "?") + ")"
|
|
44
|
+
: reason === "stopped"
|
|
45
|
+
? "Stopped by user"
|
|
46
|
+
: "Ended due to error";
|
|
47
|
+
return {
|
|
48
|
+
type: reason === "error" ? "loop_error" : "loop_complete",
|
|
49
|
+
title: (data.name || "Loop") + " " + (reason === "error" ? "failed" : "complete"),
|
|
50
|
+
body: body,
|
|
51
|
+
meta: { reason: reason, iterations: data.iterations },
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
response_done: function (data) {
|
|
56
|
+
return {
|
|
57
|
+
type: "response_done",
|
|
58
|
+
title: data.title || "Response ready",
|
|
59
|
+
body: data.preview || "",
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
permission_request: function (data) {
|
|
64
|
+
return {
|
|
65
|
+
type: "permission_request",
|
|
66
|
+
title: data.title || "Permission requested",
|
|
67
|
+
body: data.body || "",
|
|
68
|
+
meta: { requestId: data.requestId, toolName: data.toolName, toolInput: data.toolInput || null },
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
mate_dm: function (data) {
|
|
73
|
+
return {
|
|
74
|
+
type: "mate_dm",
|
|
75
|
+
title: data.senderName || "Message",
|
|
76
|
+
body: data.preview || "Sent you a message",
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
mention_response: function (data) {
|
|
81
|
+
return {
|
|
82
|
+
type: "mention_response",
|
|
83
|
+
title: data.title || "Mention response ready",
|
|
84
|
+
body: data.preview || "",
|
|
85
|
+
meta: { avatarMateId: data.avatarMateId || null },
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
user_mention: function (data) {
|
|
90
|
+
return {
|
|
91
|
+
type: "user_mention",
|
|
92
|
+
title: "@" + (data.fromName || "Someone"),
|
|
93
|
+
body: data.preview || "Mentioned you",
|
|
94
|
+
meta: {
|
|
95
|
+
fromUserId: data.fromUserId || null,
|
|
96
|
+
fromName: data.fromName || "",
|
|
97
|
+
fromAvatarStyle: data.fromAvatarStyle || null,
|
|
98
|
+
fromAvatarSeed: data.fromAvatarSeed || null,
|
|
99
|
+
fromAvatarColor: data.fromAvatarColor || null,
|
|
100
|
+
fromAvatarCustom: data.fromAvatarCustom || "",
|
|
101
|
+
persistent: true,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// ========================================================
|
|
108
|
+
// Module (global singleton)
|
|
109
|
+
// ========================================================
|
|
110
|
+
|
|
111
|
+
function attachNotifications(ctx) {
|
|
112
|
+
var broadcastAll = ctx.broadcastAll;
|
|
113
|
+
var sendToUser = ctx.sendToUser || null; // (userId, msg) -> void; iterates all project clients
|
|
114
|
+
var pushModule = ctx.pushModule;
|
|
115
|
+
|
|
116
|
+
var notifications = loadNotifications();
|
|
117
|
+
var reminderTimer = null;
|
|
118
|
+
|
|
119
|
+
function loadNotifications() {
|
|
120
|
+
try {
|
|
121
|
+
var raw = fs.readFileSync(NOTIF_FILE, "utf8");
|
|
122
|
+
var parsed = JSON.parse(raw);
|
|
123
|
+
if (Array.isArray(parsed)) return parsed;
|
|
124
|
+
} catch (e) {}
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function saveNotifications() {
|
|
129
|
+
var tmp = NOTIF_FILE + ".tmp";
|
|
130
|
+
try {
|
|
131
|
+
fs.writeFileSync(tmp, JSON.stringify(notifications, null, 2));
|
|
132
|
+
fs.renameSync(tmp, NOTIF_FILE);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.error("[notifications] Failed to save:", e.message);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getUnreadCount() {
|
|
139
|
+
return notifications.length;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// --- Core API ---
|
|
143
|
+
|
|
144
|
+
function notify(event, data) {
|
|
145
|
+
data = data || {};
|
|
146
|
+
var formatter = formatters[event];
|
|
147
|
+
if (!formatter) {
|
|
148
|
+
console.warn("[notifications] Unknown event: " + event);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
var formatted = formatter(data || {});
|
|
152
|
+
if (!formatted) return null;
|
|
153
|
+
|
|
154
|
+
var notif = {
|
|
155
|
+
id: generateId(),
|
|
156
|
+
type: formatted.type || event,
|
|
157
|
+
title: formatted.title || "",
|
|
158
|
+
body: formatted.body || "",
|
|
159
|
+
slug: data.slug || "",
|
|
160
|
+
sessionId: data.sessionId || null,
|
|
161
|
+
mateId: data.mateId || null,
|
|
162
|
+
ownerId: data.ownerId || null,
|
|
163
|
+
targetUserId: data.targetUserId || null,
|
|
164
|
+
createdAt: Date.now(),
|
|
165
|
+
meta: formatted.meta || {},
|
|
166
|
+
};
|
|
167
|
+
notifications.unshift(notif);
|
|
168
|
+
saveNotifications();
|
|
169
|
+
var payload = {
|
|
170
|
+
type: "notification_created",
|
|
171
|
+
notification: notif,
|
|
172
|
+
unreadCount: getUnreadCount(),
|
|
173
|
+
};
|
|
174
|
+
// If targeted at a specific user, deliver only to that user's connections.
|
|
175
|
+
// Otherwise broadcast to everyone (existing behavior).
|
|
176
|
+
if (notif.targetUserId && typeof sendToUser === "function") {
|
|
177
|
+
sendToUser(notif.targetUserId, payload);
|
|
178
|
+
} else {
|
|
179
|
+
broadcastAll(payload);
|
|
180
|
+
}
|
|
181
|
+
return notif;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function dismiss(ids) {
|
|
185
|
+
var before = notifications.length;
|
|
186
|
+
notifications = notifications.filter(function(n) { return ids.indexOf(n.id) === -1; });
|
|
187
|
+
if (notifications.length !== before) {
|
|
188
|
+
saveNotifications();
|
|
189
|
+
broadcastAll({
|
|
190
|
+
type: "notification_dismissed",
|
|
191
|
+
ids: ids,
|
|
192
|
+
unreadCount: getUnreadCount(),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function dismissAll() {
|
|
198
|
+
if (notifications.length > 0) {
|
|
199
|
+
notifications = [];
|
|
200
|
+
saveNotifications();
|
|
201
|
+
broadcastAll({ type: "notification_dismissed_all", unreadCount: 0 });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// --- Periodic reminder ---
|
|
206
|
+
|
|
207
|
+
function startReminder() {
|
|
208
|
+
if (reminderTimer) return;
|
|
209
|
+
reminderTimer = setInterval(function () {
|
|
210
|
+
var count = getUnreadCount();
|
|
211
|
+
if (count > 0 && pushModule) {
|
|
212
|
+
pushModule.sendPush({
|
|
213
|
+
type: "reminder",
|
|
214
|
+
title: "Clagentic:Console",
|
|
215
|
+
body: count + " unread notification" + (count > 1 ? "s" : ""),
|
|
216
|
+
tag: "clay-notif-reminder",
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}, REMINDER_INTERVAL);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function stopReminder() {
|
|
223
|
+
if (reminderTimer) { clearInterval(reminderTimer); reminderTimer = null; }
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
startReminder();
|
|
227
|
+
|
|
228
|
+
// --- Connection state (called per-client with sendTo) ---
|
|
229
|
+
|
|
230
|
+
function sendConnectionState(ws, sendTo) {
|
|
231
|
+
if (!sendTo) return;
|
|
232
|
+
sendTo(ws, {
|
|
233
|
+
type: "notifications_state",
|
|
234
|
+
notifications: notifications,
|
|
235
|
+
unreadCount: getUnreadCount(),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// --- Message handler ---
|
|
240
|
+
|
|
241
|
+
function handleNotificationMessage(ws, msg) {
|
|
242
|
+
if (msg.type === "notification_dismiss") {
|
|
243
|
+
dismiss(msg.ids || []);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
if (msg.type === "notification_dismiss_all") {
|
|
247
|
+
dismissAll();
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
notify: notify,
|
|
255
|
+
getUnreadCount: getUnreadCount,
|
|
256
|
+
sendConnectionState: sendConnectionState,
|
|
257
|
+
handleNotificationMessage: handleNotificationMessage,
|
|
258
|
+
stopReminder: stopReminder,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = { attachNotifications: attachNotifications };
|