@clagentic/console 1.9.0 → 1.10.0-beta.2
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/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +9 -3
- package/bin/cli.js +40 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/audit.js +3 -2
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +25 -22
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +57 -0
- package/lib/daemon.js +288 -205
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/memory-shed.js +13 -32
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +37 -22
- package/lib/project-external-trigger.js +166 -105
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +17 -9
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +217 -0
- package/lib/project-sessions.js +192 -355
- package/lib/project-user-message.js +27 -15
- package/lib/project.js +212 -147
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +680 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +80 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +52 -47
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -59
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +170 -20
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +81 -906
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +142 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +348 -284
- package/lib/sdk-message-processor.js +117 -146
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +156 -115
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +61 -30
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +66 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +36 -23
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +34 -0
- package/lib/yoke/adapters/claude-worker.js +57 -87
- package/lib/yoke/adapters/claude.js +182 -88
- package/lib/yoke/adapters/codex-capabilities.js +40 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +462 -211
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +91 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +30 -56
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +84 -174
- package/lib/yoke/install-probe.js +136 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +206 -4
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +377 -0
- package/package.json +12 -9
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed-build.js +59 -17
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
package/lib/project-http.js
CHANGED
|
@@ -5,6 +5,9 @@ var crypto = require("crypto");
|
|
|
5
5
|
var { execFileSync, spawn } = require("child_process");
|
|
6
6
|
var { fsAsUser } = require("./os-users");
|
|
7
7
|
var usersModule = require("./users");
|
|
8
|
+
var { promptsFor } = require("./prompt-registry");
|
|
9
|
+
var { mayAnswerPrompt } = require("./prompt-access");
|
|
10
|
+
var fileScope = require("./project-file-scope");
|
|
8
11
|
|
|
9
12
|
var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".ico"]);
|
|
10
13
|
var MIME_TYPES = {
|
|
@@ -22,6 +25,7 @@ var MIME_TYPES = {
|
|
|
22
25
|
".ico": "image/x-icon",
|
|
23
26
|
};
|
|
24
27
|
var MAX_UPLOAD_BYTES = 50 * 1024 * 1024; // 50 MB
|
|
28
|
+
var HTTP_PERMISSION_DECISIONS = ["allow", "deny"];
|
|
25
29
|
|
|
26
30
|
function parseJsonBody(req) {
|
|
27
31
|
return new Promise(function (resolve, reject) {
|
|
@@ -54,8 +58,8 @@ function parseJsonBody(req) {
|
|
|
54
58
|
* Attach HTTP request handler to a project context.
|
|
55
59
|
*
|
|
56
60
|
* ctx fields:
|
|
57
|
-
* cwd, slug, project, sm, send, sendTo, imagesDir, osUsers, pushModule,
|
|
58
|
-
*
|
|
61
|
+
* cwd, slug, project, sm, send, sendTo, imagesDir, osUsers, pushModule, projectAccess,
|
|
62
|
+
* getOsUserInfoForReq, sendExtensionCommandAny,
|
|
59
63
|
* _extToken, _browserTabList
|
|
60
64
|
*/
|
|
61
65
|
function attachHTTP(ctx) {
|
|
@@ -67,8 +71,7 @@ function attachHTTP(ctx) {
|
|
|
67
71
|
var imagesDir = ctx.imagesDir;
|
|
68
72
|
var osUsers = ctx.osUsers;
|
|
69
73
|
var pushModule = ctx.pushModule;
|
|
70
|
-
var
|
|
71
|
-
var safeAbsPath = ctx.safeAbsPath;
|
|
74
|
+
var projectAccess = ctx.projectAccess;
|
|
72
75
|
var getOsUserInfoForReq = ctx.getOsUserInfoForReq;
|
|
73
76
|
var sendExtensionCommandAny = ctx.sendExtensionCommandAny;
|
|
74
77
|
var _extToken = ctx._extToken;
|
|
@@ -211,36 +214,43 @@ function attachHTTP(ctx) {
|
|
|
211
214
|
return true;
|
|
212
215
|
}
|
|
213
216
|
|
|
214
|
-
// Permission response from push notification
|
|
217
|
+
// Permission response from a push notification. Reached only after the
|
|
218
|
+
// server's auth gate and project-access check (lib/server.js); the
|
|
219
|
+
// answering user must also be able to see the prompt's session, the same
|
|
220
|
+
// rule the WS card path applies. Allow-once and deny only: granting a
|
|
221
|
+
// tool for the rest of a session is reserved for the in-app card. A plan
|
|
222
|
+
// answered here gets the same session side effects as one answered on
|
|
223
|
+
// the card, because the registry runs them inside respond().
|
|
215
224
|
if (req.method === "POST" && urlPath === "/api/permission-response") {
|
|
216
225
|
parseJsonBody(req).then(function (data) {
|
|
217
226
|
var requestId = data.requestId;
|
|
218
227
|
var decision = data.decision;
|
|
219
|
-
if (!requestId || !decision) {
|
|
228
|
+
if (typeof requestId !== "string" || !requestId || !decision) {
|
|
220
229
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
221
230
|
res.end('{"error":"missing requestId or decision"}');
|
|
222
231
|
return;
|
|
223
232
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
decision: decision,
|
|
233
|
+
if (HTTP_PERMISSION_DECISIONS.indexOf(decision) === -1) {
|
|
234
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
235
|
+
res.end('{"error":"decision must be allow or deny"}');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
var prompts = promptsFor(sm);
|
|
239
|
+
var found = prompts.lookup(requestId);
|
|
240
|
+
// An answer from a user who cannot see the session is refused as
|
|
241
|
+
// not found, without touching the prompt or its banner.
|
|
242
|
+
var outcome = (found && !mayAnswerPrompt(req._clagenticUser || null, found.session))
|
|
243
|
+
? { status: "stale" }
|
|
244
|
+
: prompts.respond(requestId, { decision: decision }, {
|
|
245
|
+
kinds: ["permission", "plan"],
|
|
246
|
+
denyMessage: "Denied via push notification",
|
|
239
247
|
});
|
|
240
|
-
|
|
241
|
-
if (found) {
|
|
248
|
+
if (outcome.status === "resolved") {
|
|
242
249
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
243
250
|
res.end('{"ok":true}');
|
|
251
|
+
} else if (outcome.status === "invalid") {
|
|
252
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
253
|
+
res.end('{"error":"answer refused; the request is still pending"}');
|
|
244
254
|
} else {
|
|
245
255
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
246
256
|
res.end('{"error":"permission request not found"}');
|
|
@@ -270,15 +280,21 @@ function attachHTTP(ctx) {
|
|
|
270
280
|
var params = new URLSearchParams(urlPath.substring(qIdx));
|
|
271
281
|
var reqFilePath = params.get("path");
|
|
272
282
|
if (!reqFilePath) { res.writeHead(400); res.end("Missing path"); return true; }
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
283
|
+
// Same file policy as the WebSocket file messages: a caller without the
|
|
284
|
+
// fileBrowser permission, or without an OS identity in os-users mode,
|
|
285
|
+
// is refused rather than served by a read as the daemon user.
|
|
286
|
+
var fileServeUserInfo = getOsUserInfoForReq(req);
|
|
287
|
+
// No user is the single-user owner only for a request the server marked
|
|
288
|
+
// authenticated (or the local MCP bridge), else a stranger.
|
|
289
|
+
var fileAccessError = projectAccess.principalFor(req._clagenticUser, projectAccess.authOf(req))
|
|
290
|
+
? fileScope.checkFileAccess({ user: req._clagenticUser, osUsers: osUsers, osUserInfo: fileServeUserInfo, usersModule: usersModule })
|
|
291
|
+
: "Authentication required";
|
|
292
|
+
if (fileAccessError) { res.writeHead(403); res.end(fileAccessError); return true; }
|
|
293
|
+
var absFile = fileScope.resolveProjectPath(cwd, reqFilePath, fileServeUserInfo);
|
|
277
294
|
if (!absFile) { res.writeHead(403); res.end("Access denied"); return true; }
|
|
278
295
|
var fileExt = path.extname(absFile).toLowerCase();
|
|
279
296
|
if (!IMAGE_EXTS.has(fileExt)) { res.writeHead(403); res.end("Only image files"); return true; }
|
|
280
297
|
try {
|
|
281
|
-
var fileServeUserInfo = getOsUserInfoForReq(req);
|
|
282
298
|
var fileContent;
|
|
283
299
|
if (fileServeUserInfo) {
|
|
284
300
|
var binResult = fsAsUser("read_binary", { file: absFile }, fileServeUserInfo);
|
package/lib/project-loop.js
CHANGED
|
@@ -6,6 +6,8 @@ var { createLoopRegistry } = require("./scheduler");
|
|
|
6
6
|
var store = require("./store");
|
|
7
7
|
var usersModule = require("./users");
|
|
8
8
|
var { writeHandoff, buildHandoffPreamble } = require("./loop-handoff");
|
|
9
|
+
var { authOf } = require("./project-access");
|
|
10
|
+
var { INITIATORS } = require("./turn-initiator");
|
|
9
11
|
|
|
10
12
|
var LOOP_ID_RE = /^loop_[A-Za-z0-9_-]+$/;
|
|
11
13
|
|
|
@@ -35,7 +37,7 @@ function validateLoopId(id) {
|
|
|
35
37
|
*
|
|
36
38
|
* ctx fields:
|
|
37
39
|
* cwd, slug, sm, sdk, send, sendTo, sendToSession, pushModule,
|
|
38
|
-
* getHubSchedules, getAllProjectSessions, getSessionUnread, getStatus,
|
|
40
|
+
* getHubSchedules(userId), broadcastHubSchedules, getAllProjectSessions, getSessionUnread, getStatus,
|
|
39
41
|
* getLinuxUserForSession, onProcessingChanged,
|
|
40
42
|
* hydrateImageRefs
|
|
41
43
|
*/
|
|
@@ -50,6 +52,12 @@ function attachLoop(ctx) {
|
|
|
50
52
|
var pushModule = ctx.pushModule;
|
|
51
53
|
var notificationsModule = ctx.notificationsModule;
|
|
52
54
|
var getHubSchedules = ctx.getHubSchedules;
|
|
55
|
+
// getHubSchedules(userId, proof) is limited to what that user may see; a
|
|
56
|
+
// context without a per-client broadcaster sends the list for no user and no
|
|
57
|
+
// proof of login (empty).
|
|
58
|
+
var broadcastHubSchedules = ctx.broadcastHubSchedules || function () {
|
|
59
|
+
send({ type: "loop_registry_updated", records: getHubSchedules(null) });
|
|
60
|
+
};
|
|
53
61
|
var getAllProjectSessions = ctx.getAllProjectSessions;
|
|
54
62
|
// lr-0aa7b6: per-session unread lookup — (ws, sessionProjectSlug, localId) => count.
|
|
55
63
|
var getSessionUnread = ctx.getSessionUnread || function () { return 0; };
|
|
@@ -372,7 +380,7 @@ function attachLoop(ctx) {
|
|
|
372
380
|
triggerFromQueue(record);
|
|
373
381
|
},
|
|
374
382
|
onChange: function () {
|
|
375
|
-
|
|
383
|
+
broadcastHubSchedules();
|
|
376
384
|
},
|
|
377
385
|
});
|
|
378
386
|
loopRegistry.load();
|
|
@@ -606,7 +614,7 @@ function attachLoop(ctx) {
|
|
|
606
614
|
session.acceptEditsAfterStart = true;
|
|
607
615
|
session.singleTurn = true;
|
|
608
616
|
if (loopState.settings) session.loopSettings = loopState.settings;
|
|
609
|
-
sdk.startQuery(session, _iterationPrompt, undefined, getLinuxUserForSession(session));
|
|
617
|
+
sdk.startQuery(session, _iterationPrompt, undefined, getLinuxUserForSession(session), INITIATORS.LOOP);
|
|
610
618
|
}
|
|
611
619
|
|
|
612
620
|
function runJudge() {
|
|
@@ -729,7 +737,7 @@ function attachLoop(ctx) {
|
|
|
729
737
|
judgeSession.acceptEditsAfterStart = true;
|
|
730
738
|
judgeSession.singleTurn = true;
|
|
731
739
|
if (loopState.settings) judgeSession.loopSettings = loopState.settings;
|
|
732
|
-
sdk.startQuery(judgeSession, judgePrompt, undefined, getLinuxUserForSession(judgeSession));
|
|
740
|
+
sdk.startQuery(judgeSession, judgePrompt, undefined, getLinuxUserForSession(judgeSession), INITIATORS.LOOP);
|
|
733
741
|
}
|
|
734
742
|
|
|
735
743
|
// lr-2ea2a7: forward-accumulates delta/text across the FULL heap array —
|
|
@@ -1155,7 +1163,7 @@ function attachLoop(ctx) {
|
|
|
1155
1163
|
onProcessingChanged();
|
|
1156
1164
|
judgeCraftSession.sentToolResults = {};
|
|
1157
1165
|
sendToSession(judgeCraftSession.localId, { type: "status", status: "processing" });
|
|
1158
|
-
sdk.startQuery(judgeCraftSession, judgeCraftPrompt, undefined, getLinuxUserForSession(judgeCraftSession));
|
|
1166
|
+
sdk.startQuery(judgeCraftSession, judgeCraftPrompt, undefined, getLinuxUserForSession(judgeCraftSession), INITIATORS.LOOP);
|
|
1159
1167
|
|
|
1160
1168
|
send({ type: "ralph_crafting_started", sessionId: judgeCraftSession.localId, taskId: newLoopId, source: recordSource });
|
|
1161
1169
|
send({ type: "ralph_phase", phase: "crafting", wizardData: loopState.wizardData, craftingSessionId: judgeCraftSession.localId });
|
|
@@ -1232,7 +1240,7 @@ function attachLoop(ctx) {
|
|
|
1232
1240
|
onProcessingChanged();
|
|
1233
1241
|
craftingSession.sentToolResults = {};
|
|
1234
1242
|
sendToSession(craftingSession.localId, { type: "status", status: "processing" });
|
|
1235
|
-
sdk.startQuery(craftingSession, craftingPrompt, undefined, getLinuxUserForSession(craftingSession));
|
|
1243
|
+
sdk.startQuery(craftingSession, craftingPrompt, undefined, getLinuxUserForSession(craftingSession), INITIATORS.LOOP);
|
|
1236
1244
|
|
|
1237
1245
|
send({ type: "ralph_crafting_started", sessionId: craftingSession.localId, taskId: newLoopId, source: recordSource });
|
|
1238
1246
|
send({ type: "ralph_phase", phase: "crafting", wizardData: loopState.wizardData, craftingSessionId: craftingSession.localId });
|
|
@@ -1389,7 +1397,7 @@ function attachLoop(ctx) {
|
|
|
1389
1397
|
|
|
1390
1398
|
// --- Hub: cross-project schedule aggregation ---
|
|
1391
1399
|
if (msg.type === "hub_schedules_list") {
|
|
1392
|
-
sendTo(ws, { type: "hub_schedules", schedules: getHubSchedules() });
|
|
1400
|
+
sendTo(ws, { type: "hub_schedules", schedules: getHubSchedules(ws._clagenticUser ? ws._clagenticUser.id : null, authOf(ws)) });
|
|
1393
1401
|
return true;
|
|
1394
1402
|
}
|
|
1395
1403
|
|
|
@@ -1403,7 +1411,7 @@ function attachLoop(ctx) {
|
|
|
1403
1411
|
// recent sessions overall. getAllProjectSessions returns annotated shallow
|
|
1404
1412
|
// copies carrying _projectSlug/_projectTitle/_projectIcon for every project.
|
|
1405
1413
|
var hubUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
|
|
1406
|
-
var allSessions = getAllProjectSessions ? getAllProjectSessions(true, hubUserId) : [];
|
|
1414
|
+
var allSessions = getAllProjectSessions ? getAllProjectSessions(true, hubUserId, authOf(ws)) : [];
|
|
1407
1415
|
// Sort newest-first by lastActivity
|
|
1408
1416
|
allSessions.sort(function (a, b) {
|
|
1409
1417
|
return (b.lastActivity || b.createdAt || 0) - (a.lastActivity || a.createdAt || 0);
|
|
@@ -1445,7 +1453,7 @@ function attachLoop(ctx) {
|
|
|
1445
1453
|
|
|
1446
1454
|
// --- Loop Registry messages ---
|
|
1447
1455
|
if (msg.type === "loop_registry_list") {
|
|
1448
|
-
sendTo(ws, { type: "loop_registry_updated", records: getHubSchedules() });
|
|
1456
|
+
sendTo(ws, { type: "loop_registry_updated", records: getHubSchedules(ws._clagenticUser ? ws._clagenticUser.id : null, authOf(ws)) });
|
|
1449
1457
|
return true;
|
|
1450
1458
|
}
|
|
1451
1459
|
|
package/lib/project-mcp.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var crypto = require("crypto");
|
|
2
|
+
var mcpToolSchema = require("./mcp-tool-schema");
|
|
3
|
+
var { prepareTool } = require("./mcp-tool-input");
|
|
2
4
|
|
|
3
5
|
// MCP Bridge module: manages remote MCP servers reported by the Chrome Extension.
|
|
4
6
|
// Creates proxy MCP server objects that forward tool calls over WebSocket.
|
|
@@ -14,14 +16,18 @@ function attachMcp(ctx) {
|
|
|
14
16
|
var getExtensionId = ctx.getExtensionId || function () { return null; };
|
|
15
17
|
var localMcp = ctx.localMcp || null; // mcp-local instance for localhost clients
|
|
16
18
|
|
|
19
|
+
// The three tables below are keyed by names and ids a client reports, so
|
|
20
|
+
// they have no prototype to answer for "constructor" or "__proto__".
|
|
21
|
+
|
|
17
22
|
// Available servers reported by extension: { name -> { name, transport, tools, enabled } }
|
|
18
|
-
var _availableServers =
|
|
23
|
+
var _availableServers = Object.create(null);
|
|
19
24
|
|
|
20
25
|
// Proxy MCP server objects for the SDK: { name -> sdkMcpServerConfig }
|
|
21
|
-
var _proxyServers =
|
|
26
|
+
var _proxyServers = Object.create(null);
|
|
22
27
|
|
|
23
|
-
// Pending tool calls: { callId -> { resolve, reject, timer } }
|
|
24
|
-
|
|
28
|
+
// Pending tool calls: { callId -> { resolve, reject, timer, ws } }
|
|
29
|
+
// `ws` is the extension socket the call was sent to; only it may answer.
|
|
30
|
+
var _pendingCalls = Object.create(null);
|
|
25
31
|
|
|
26
32
|
var TOOL_TIMEOUT_MS = 30000;
|
|
27
33
|
|
|
@@ -33,11 +39,11 @@ function attachMcp(ctx) {
|
|
|
33
39
|
return true;
|
|
34
40
|
}
|
|
35
41
|
if (msg.type === "mcp_tool_result") {
|
|
36
|
-
handleToolResult(msg);
|
|
42
|
+
handleToolResult(ws, msg);
|
|
37
43
|
return true;
|
|
38
44
|
}
|
|
39
45
|
if (msg.type === "mcp_tool_error") {
|
|
40
|
-
handleToolError(msg);
|
|
46
|
+
handleToolError(ws, msg);
|
|
41
47
|
return true;
|
|
42
48
|
}
|
|
43
49
|
if (msg.type === "mcp_toggle_server") {
|
|
@@ -50,15 +56,16 @@ function attachMcp(ctx) {
|
|
|
50
56
|
var _remoteHostConnected = false;
|
|
51
57
|
|
|
52
58
|
function handleServersAvailable(ws, msg) {
|
|
53
|
-
var servers = msg.servers
|
|
59
|
+
var servers = Array.isArray(msg.servers) ? msg.servers : [];
|
|
54
60
|
_remoteHostConnected = !!msg.hostConnected;
|
|
55
|
-
_availableServers =
|
|
61
|
+
_availableServers = Object.create(null);
|
|
56
62
|
for (var i = 0; i < servers.length; i++) {
|
|
57
63
|
var s = servers[i];
|
|
64
|
+
if (!s || typeof s !== "object" || typeof s.name !== "string") continue;
|
|
58
65
|
_availableServers[s.name] = {
|
|
59
66
|
name: s.name,
|
|
60
67
|
transport: s.transport || "stdio",
|
|
61
|
-
tools: s.tools
|
|
68
|
+
tools: Array.isArray(s.tools) ? s.tools : [],
|
|
62
69
|
enabled: s.enabled !== false,
|
|
63
70
|
};
|
|
64
71
|
}
|
|
@@ -70,28 +77,32 @@ function attachMcp(ctx) {
|
|
|
70
77
|
broadcastMcpState();
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
// The call a result or error answers, if the socket that sent it is the
|
|
81
|
+
// socket the call went to; otherwise null and the pending call is untouched.
|
|
82
|
+
function takePendingCall(ws, callId) {
|
|
83
|
+
if (typeof callId !== "string") return null;
|
|
76
84
|
var pending = _pendingCalls[callId];
|
|
77
|
-
if (!pending) return;
|
|
85
|
+
if (!pending || pending.ws !== ws) return null;
|
|
78
86
|
if (pending.timer) clearTimeout(pending.timer);
|
|
79
87
|
delete _pendingCalls[callId];
|
|
88
|
+
return pending;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function handleToolResult(ws, msg) {
|
|
92
|
+
var pending = takePendingCall(ws, msg.callId);
|
|
93
|
+
if (!pending) return;
|
|
80
94
|
pending.resolve(msg.result || { content: [{ type: "text", text: "(empty result)" }] });
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
function handleToolError(msg) {
|
|
84
|
-
var
|
|
85
|
-
console.log("[mcp-bridge] Tool error received: " + callId + " error=" + (msg.error || "unknown"));
|
|
86
|
-
var pending = _pendingCalls[callId];
|
|
97
|
+
function handleToolError(ws, msg) {
|
|
98
|
+
var pending = takePendingCall(ws, msg.callId);
|
|
87
99
|
if (!pending) return;
|
|
88
|
-
|
|
89
|
-
delete _pendingCalls[callId];
|
|
90
|
-
pending.reject(new Error(msg.error || "MCP tool call failed"));
|
|
100
|
+
pending.reject(new Error(typeof msg.error === "string" && msg.error ? msg.error : "MCP tool call failed"));
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
function handleToggleServer(ws, msg) {
|
|
94
104
|
var name = msg.name;
|
|
105
|
+
if (typeof name !== "string" || !name) return;
|
|
95
106
|
var enabled = !!msg.enabled;
|
|
96
107
|
|
|
97
108
|
var list = getEnabledMcpServers() || [];
|
|
@@ -111,7 +122,7 @@ function attachMcp(ctx) {
|
|
|
111
122
|
// ---------- Proxy Server Builder ----------
|
|
112
123
|
|
|
113
124
|
function rebuildProxyServers() {
|
|
114
|
-
_proxyServers =
|
|
125
|
+
_proxyServers = Object.create(null);
|
|
115
126
|
|
|
116
127
|
var sdk;
|
|
117
128
|
try {
|
|
@@ -154,14 +165,10 @@ function attachMcp(ctx) {
|
|
|
154
165
|
var mcpTool = serverTools[ti];
|
|
155
166
|
var toolName = mcpTool.name;
|
|
156
167
|
var toolDesc = mcpTool.description || toolName;
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
toolDesc,
|
|
162
|
-
shape,
|
|
163
|
-
createToolHandler(serverName, toolName)
|
|
164
|
-
));
|
|
168
|
+
var prepared = prepareOrSkip(z, serverName, toolName, mcpTool.inputSchema, createToolHandler(serverName, toolName));
|
|
169
|
+
if (!prepared) continue;
|
|
170
|
+
|
|
171
|
+
tools.push(tool(toolName, toolDesc, prepared.inputSchema, prepared.handler));
|
|
165
172
|
}
|
|
166
173
|
|
|
167
174
|
if (tools.length > 0) {
|
|
@@ -186,13 +193,9 @@ function attachMcp(ctx) {
|
|
|
186
193
|
var localTools = [];
|
|
187
194
|
for (var lti = 0; lti < ls.tools.length; lti++) {
|
|
188
195
|
var lt = ls.tools[lti];
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
lt.description || lt.name,
|
|
193
|
-
ltShape,
|
|
194
|
-
createLocalToolHandler(ls.name, lt.name)
|
|
195
|
-
));
|
|
196
|
+
var ltPrepared = prepareOrSkip(z, ls.name, lt.name, lt.inputSchema, createLocalToolHandler(ls.name, lt.name));
|
|
197
|
+
if (!ltPrepared) continue;
|
|
198
|
+
localTools.push(tool(lt.name, lt.description || lt.name, ltPrepared.inputSchema, ltPrepared.handler));
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
if (localTools.length > 0) {
|
|
@@ -229,7 +232,7 @@ function attachMcp(ctx) {
|
|
|
229
232
|
reject(new Error("MCP tool call timed out after " + (TOOL_TIMEOUT_MS / 1000) + "s"));
|
|
230
233
|
}, TOOL_TIMEOUT_MS);
|
|
231
234
|
|
|
232
|
-
_pendingCalls[callId] = { resolve: resolve, reject: reject, timer: timer };
|
|
235
|
+
_pendingCalls[callId] = { resolve: resolve, reject: reject, timer: timer, ws: extWs };
|
|
233
236
|
|
|
234
237
|
console.log("[mcp-bridge] Sending tool call: " + callId + " server=" + serverName + " tool=" + toolName);
|
|
235
238
|
sendTo(extWs, {
|
|
@@ -243,38 +246,16 @@ function attachMcp(ctx) {
|
|
|
243
246
|
};
|
|
244
247
|
}
|
|
245
248
|
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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;
|
|
249
|
+
// The zod shape and validating handler for a tool, or null when its JSON
|
|
250
|
+
// input schema cannot be read: the tool is then left out and reported (never
|
|
251
|
+
// registered with a looser schema than it declared).
|
|
252
|
+
function prepareOrSkip(z, serverName, toolName, inputSchema, handler) {
|
|
253
|
+
try {
|
|
254
|
+
return prepareTool(z, inputSchema, handler);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
mcpToolSchema.reportSkippedTool(serverName, toolName, (e && e.message) || String(e), send);
|
|
257
|
+
return null;
|
|
276
258
|
}
|
|
277
|
-
return shape;
|
|
278
259
|
}
|
|
279
260
|
|
|
280
261
|
// ---------- State Broadcasting ----------
|
|
@@ -291,7 +272,7 @@ function attachMcp(ctx) {
|
|
|
291
272
|
function buildMcpState() {
|
|
292
273
|
var enabledList = getEnabledMcpServers() || [];
|
|
293
274
|
var servers = [];
|
|
294
|
-
var seen =
|
|
275
|
+
var seen = Object.create(null);
|
|
295
276
|
|
|
296
277
|
// Remote servers (from Extension)
|
|
297
278
|
var names = Object.keys(_availableServers);
|
|
@@ -347,13 +328,13 @@ function attachMcp(ctx) {
|
|
|
347
328
|
if (pending.timer) clearTimeout(pending.timer);
|
|
348
329
|
pending.reject(new Error("MCP bridge disconnected"));
|
|
349
330
|
}
|
|
350
|
-
_pendingCalls =
|
|
331
|
+
_pendingCalls = Object.create(null);
|
|
351
332
|
}
|
|
352
333
|
|
|
353
334
|
function handleExtensionDisconnect() {
|
|
354
335
|
cancelAllPending();
|
|
355
|
-
_availableServers =
|
|
356
|
-
_proxyServers =
|
|
336
|
+
_availableServers = Object.create(null);
|
|
337
|
+
_proxyServers = Object.create(null);
|
|
357
338
|
broadcastMcpState();
|
|
358
339
|
}
|
|
359
340
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The single access gate at the entry of project message handling.
|
|
2
|
+
//
|
|
3
|
+
// Before any handler sees a message, the gate settles two questions:
|
|
4
|
+
// 1. may this connection's user act on THIS project (access can change
|
|
5
|
+
// after the socket was opened), and
|
|
6
|
+
// 2. if the message names another project (targetSlug), may the user act
|
|
7
|
+
// on that one, and does it exist.
|
|
8
|
+
// A message is either refused here or handed on with the target resolved and
|
|
9
|
+
// the client-supplied slug removed, so handlers only ever act on a slug the
|
|
10
|
+
// gate authorized.
|
|
11
|
+
//
|
|
12
|
+
// deps:
|
|
13
|
+
// slug this project's slug
|
|
14
|
+
// canAccess(userId, slug, proof) -> boolean fail-closed project access
|
|
15
|
+
// check; a null userId is the implicit
|
|
16
|
+
// single-user owner only when `proof`
|
|
17
|
+
// ({ authenticated: true }, from the
|
|
18
|
+
// connection) says the upgrade login
|
|
19
|
+
// check passed, else a stranger
|
|
20
|
+
// (lib/project-access.js). Null for a
|
|
21
|
+
// bare context with no access wiring.
|
|
22
|
+
// getProject(slug) -> project context | null
|
|
23
|
+
|
|
24
|
+
var { authOf } = require("./project-access");
|
|
25
|
+
|
|
26
|
+
var DENIED ="Project not found or access denied";
|
|
27
|
+
|
|
28
|
+
function createMessageGate(deps) {
|
|
29
|
+
var slug = deps.slug;
|
|
30
|
+
var canAccess = deps.canAccess;
|
|
31
|
+
var getProject = deps.getProject;
|
|
32
|
+
|
|
33
|
+
function refuse(error) {
|
|
34
|
+
return { allowed: false, error: error || null, target: null, message: null };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function authorize(ws, msg) {
|
|
38
|
+
// Anything that is not a JSON object cannot be a message.
|
|
39
|
+
if (!msg || typeof msg !== "object" || Array.isArray(msg)) return refuse(null);
|
|
40
|
+
|
|
41
|
+
var user = ws && ws._clagenticUser;
|
|
42
|
+
var userId = user ? user.id : null;
|
|
43
|
+
var wired = typeof canAccess === "function";
|
|
44
|
+
|
|
45
|
+
var proof = authOf(ws);
|
|
46
|
+
|
|
47
|
+
if (wired && !canAccess(userId, slug, proof)) return refuse(DENIED);
|
|
48
|
+
|
|
49
|
+
var named = msg.targetSlug;
|
|
50
|
+
var hasTarget = named !== undefined && named !== null && named !== "";
|
|
51
|
+
if (!hasTarget) return { allowed: true, error: null, target: null, message: msg };
|
|
52
|
+
|
|
53
|
+
if (typeof named !== "string") return refuse(DENIED);
|
|
54
|
+
|
|
55
|
+
var forwarded = Object.assign({}, msg);
|
|
56
|
+
delete forwarded.targetSlug;
|
|
57
|
+
if (named === slug) return { allowed: true, error: null, target: null, message: forwarded };
|
|
58
|
+
|
|
59
|
+
// Another project: both the existence and the right to act must hold.
|
|
60
|
+
if (!wired || typeof getProject !== "function") return refuse(DENIED);
|
|
61
|
+
if (!canAccess(userId, named, proof)) return refuse(DENIED);
|
|
62
|
+
var target = getProject(named);
|
|
63
|
+
if (!target) return refuse(DENIED);
|
|
64
|
+
return { allowed: true, error: null, target: target, message: forwarded };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { authorize: authorize };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { createMessageGate: createMessageGate, DENIED: DENIED };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
var fs = require("fs");
|
|
6
6
|
var path = require("path");
|
|
7
7
|
var config = require("./config");
|
|
8
|
+
var yokeRegistry = require("./yoke").registry;
|
|
8
9
|
|
|
9
10
|
var NOTIF_FILE = path.join(config.CONFIG_DIR, "notifications.json");
|
|
10
11
|
var REMINDER_INTERVAL = 60 * 60 * 1000; // 1 hour
|
|
@@ -20,8 +21,9 @@ function generateId() {
|
|
|
20
21
|
|
|
21
22
|
var formatters = {
|
|
22
23
|
auth_required: function (data) {
|
|
23
|
-
var vendor = data.vendor ||
|
|
24
|
-
var
|
|
24
|
+
var vendor = data.vendor || yokeRegistry.ids()[0];
|
|
25
|
+
var vendorName = yokeRegistry.isKnown(vendor) ? yokeRegistry.displayNameFor(vendor) : vendor;
|
|
26
|
+
var title = data.title || (vendorName + " is not logged in");
|
|
25
27
|
return {
|
|
26
28
|
type: "auth_required",
|
|
27
29
|
title: title,
|
|
@@ -65,7 +67,15 @@ var formatters = {
|
|
|
65
67
|
type: "permission_request",
|
|
66
68
|
title: data.title || "Permission requested",
|
|
67
69
|
body: data.body || "",
|
|
68
|
-
meta: {
|
|
70
|
+
meta: {
|
|
71
|
+
requestId: data.requestId,
|
|
72
|
+
kind: data.kind || "permission",
|
|
73
|
+
toolName: data.toolName,
|
|
74
|
+
toolInput: data.toolInput || null,
|
|
75
|
+
// So the banner offers the answers the card does (see prompt-banner.js).
|
|
76
|
+
suppressAlwaysAllowRule: data.suppressAlwaysAllowRule === true ? true : undefined,
|
|
77
|
+
defaultToNo: data.defaultToNo === true ? true : undefined,
|
|
78
|
+
},
|
|
69
79
|
};
|
|
70
80
|
},
|
|
71
81
|
|
|
@@ -115,11 +125,16 @@ function attachNotifications(ctx) {
|
|
|
115
125
|
var notifications = loadNotifications();
|
|
116
126
|
var reminderTimer = null;
|
|
117
127
|
|
|
128
|
+
// A prompt notification is actionable only while its prompt's resolver
|
|
129
|
+
// lives in this process; none survives a restart, so a persisted one would
|
|
130
|
+
// offer buttons for a prompt nothing can answer.
|
|
118
131
|
function loadNotifications() {
|
|
119
132
|
try {
|
|
120
133
|
var raw = fs.readFileSync(NOTIF_FILE, "utf8");
|
|
121
134
|
var parsed = JSON.parse(raw);
|
|
122
|
-
if (Array.isArray(parsed))
|
|
135
|
+
if (Array.isArray(parsed)) {
|
|
136
|
+
return parsed.filter(function (n) { return !(n && n.type === "permission_request"); });
|
|
137
|
+
}
|
|
123
138
|
} catch (e) {}
|
|
124
139
|
return [];
|
|
125
140
|
}
|
|
@@ -193,6 +208,17 @@ function attachNotifications(ctx) {
|
|
|
193
208
|
}
|
|
194
209
|
}
|
|
195
210
|
|
|
211
|
+
// A prompt notification is only actionable while its prompt is pending; the
|
|
212
|
+
// prompt registry calls this on every transition that ends one, so the
|
|
213
|
+
// banner buttons never outlive it.
|
|
214
|
+
function dismissByRequestId(requestId) {
|
|
215
|
+
if (!requestId) return;
|
|
216
|
+
var ids = notifications.filter(function (n) {
|
|
217
|
+
return n.type === "permission_request" && n.meta && n.meta.requestId === requestId;
|
|
218
|
+
}).map(function (n) { return n.id; });
|
|
219
|
+
if (ids.length) dismiss(ids);
|
|
220
|
+
}
|
|
221
|
+
|
|
196
222
|
function dismissAll() {
|
|
197
223
|
if (notifications.length > 0) {
|
|
198
224
|
notifications = [];
|
|
@@ -242,6 +268,7 @@ function attachNotifications(ctx) {
|
|
|
242
268
|
|
|
243
269
|
return {
|
|
244
270
|
notify: notify,
|
|
271
|
+
dismissByRequestId: dismissByRequestId,
|
|
245
272
|
getUnreadCount: getUnreadCount,
|
|
246
273
|
sendConnectionState: sendConnectionState,
|
|
247
274
|
handleNotificationMessage: handleNotificationMessage,
|