clay-server 5.2.0-beta.4 → 5.2.0-beta.6
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/lib/account-auth-socket.js +1 -0
- package/lib/builtin-mates.js +17 -14
- package/lib/canonical-clay-record-authority.js +15 -0
- package/lib/canonical-clay-scheduling-authority.js +19 -0
- package/lib/claude-hook-installer.js +1 -239
- package/lib/claude-jsonl-watcher.js +1 -204
- package/lib/clay-mate-chat-receipts.js +26 -0
- package/lib/clay-mate-chat.js +87 -0
- package/lib/clay-mate-knowledge-input.js +26 -0
- package/lib/clay-mate-knowledge.js +95 -0
- package/lib/clay-mate-lifecycle.js +95 -0
- package/lib/clay-product-control-input.js +33 -0
- package/lib/clay-product-control-tools.js +51 -0
- package/lib/clay-product-control.js +237 -0
- package/lib/clay-project-lifecycle.js +154 -0
- package/lib/clay-project-record-input.js +44 -0
- package/lib/clay-project-records.js +83 -0
- package/lib/clay-scheduling-input.js +21 -0
- package/lib/clay-scheduling-receipts.js +26 -0
- package/lib/clay-scheduling.js +119 -0
- package/lib/clay-screen-controls.js +96 -0
- package/lib/clay-skill-install.js +1 -33
- package/lib/clay-workspace-controls.js +83 -0
- package/lib/clay-workspace-input.js +17 -0
- package/lib/clay-workspace-receipts.js +26 -0
- package/lib/cli-sessions.js +1 -300
- package/lib/codex-defaults.js +1 -28
- package/lib/context-usage.js +3 -2
- package/lib/daemon-project-access.js +11 -0
- package/lib/daemon-project-lifecycle-callbacks.js +15 -0
- package/lib/daemon-project-lifecycle.js +262 -0
- package/lib/daemon-projects.js +1 -1
- package/lib/daemon.js +78 -276
- package/lib/default-ai-runtime.js +4 -8
- package/lib/email-mcp-server.js +1 -1
- package/lib/issues-service.js +29 -15
- package/lib/kiro-defaults.js +1 -22
- package/lib/knowledge-db-import.js +5 -4
- package/lib/knowledge-db-service.js +9 -6
- package/lib/knowledge-document-index.js +2 -1
- package/lib/knowledge-product-operations.js +46 -0
- package/lib/mate-creation-mcp-server.js +2 -0
- package/lib/mate-knowledge-canonical-access.js +10 -0
- package/lib/mate-knowledge-service.js +7 -4
- package/lib/mate-lifecycle-service.js +94 -0
- package/lib/mate-message-delivery.js +43 -0
- package/lib/mate-ready-creation.js +9 -1
- package/lib/mate-schedule-input.js +29 -0
- package/lib/mate-schedule-lifecycle.js +151 -0
- package/lib/mate-scheduling.js +103 -0
- package/lib/mates.js +4 -3
- package/lib/mcp-proxy.js +2 -32
- package/lib/mcp-query-bridge.js +1 -1
- package/lib/mcp-source-adapters.js +1 -91
- package/lib/mcp-source-context.js +1 -42
- package/lib/mcp-source-discovery.js +1 -169
- package/lib/mcp-source-plugins.js +1 -68
- package/lib/mcp-source-restrictions.js +1 -47
- package/lib/mcp-tool-policy.js +1 -26
- package/lib/notes-checklist.js +50 -0
- package/lib/notes.js +49 -3
- package/lib/os-user-diagnostics.js +2 -4
- package/lib/os-users.js +24 -70
- package/lib/project-admin-overview.js +51 -0
- package/lib/project-ask-user.js +4 -2
- package/lib/project-connection.js +8 -7
- package/lib/project-delegated-follow-up.js +2 -1
- package/lib/project-directory-claim.js +65 -0
- package/lib/project-file-operations.js +61 -0
- package/lib/project-filesystem.js +13 -87
- package/lib/project-full-access.js +23 -2
- package/lib/project-http.js +4 -4
- package/lib/project-knowledge.js +32 -18
- package/lib/project-lifecycle-operations.js +98 -0
- package/lib/project-lifecycle-process-witness.js +32 -0
- package/lib/project-lifecycle-runtime.js +50 -0
- package/lib/project-linux-access.js +22 -0
- package/lib/project-logs-canonical-clay.js +27 -0
- package/lib/project-logs-clay-query.js +16 -0
- package/lib/project-logs-schema.js +4 -2
- package/lib/project-logs-service.js +8 -7
- package/lib/project-logs.js +1 -0
- package/lib/project-loop.js +1 -0
- package/lib/project-mate-chat-control.js +55 -0
- package/lib/project-mate-creation-proposal.js +18 -3
- package/lib/project-mcp.js +2 -2
- package/lib/project-models.js +14 -31
- package/lib/project-notifications.js +74 -16
- package/lib/project-ownership.js +77 -0
- package/lib/project-pair-result-delivery.js +14 -3
- package/lib/project-pair-usage.js +12 -13
- package/lib/project-pending-message-queue.js +4 -1
- package/lib/project-product-control.js +87 -0
- package/lib/project-product-session-queue.js +46 -0
- package/lib/project-push-access.js +28 -0
- package/lib/project-scheduled-message-queue.js +30 -0
- package/lib/project-scheduled-messages.js +63 -64
- package/lib/project-scheduled-task-control.js +83 -0
- package/lib/project-scheduled-tasks.js +13 -2
- package/lib/project-scheduling-access.js +10 -0
- package/lib/project-session-actions.js +65 -0
- package/lib/project-session-delete.js +8 -1
- package/lib/project-session-github.js +47 -12
- package/lib/project-session-history-actions.js +167 -0
- package/lib/project-session-pair.js +1 -1
- package/lib/project-session-runtime-actions.js +64 -0
- package/lib/project-session-spawn.js +2 -3
- package/lib/project-session-vendor.js +55 -0
- package/lib/project-sessions.js +82 -267
- package/lib/project-user-message.js +31 -1
- package/lib/project-vendor-login.js +6 -36
- package/lib/project-workspace-operations.js +126 -0
- package/lib/project-workspace-query.js +9 -2
- package/lib/project.js +95 -3
- package/lib/public/app.js +1 -0
- package/lib/public/css/clay-tool-activity.css +51 -0
- package/lib/public/css/home-mate-creation.css +5 -0
- package/lib/public/css/messages.css +6 -2
- package/lib/public/css/overlays.css +4 -2
- package/lib/public/css/project-admin-overview.css +13 -0
- package/lib/public/css/session-folders.css +11 -0
- package/lib/public/css/session-github.css +3 -0
- package/lib/public/css/sticky-notes.css +61 -1
- package/lib/public/index.html +1 -1
- package/lib/public/modules/admin-settings-projects.js +6 -2
- package/lib/public/modules/app-connection.js +8 -1
- package/lib/public/modules/app-favicon.js +11 -2
- package/lib/public/modules/app-header.js +4 -2
- package/lib/public/modules/app-loop-ui.js +2 -0
- package/lib/public/modules/app-message-router.js +1 -1
- package/lib/public/modules/app-messages.js +54 -8
- package/lib/public/modules/app-notifications.js +1 -2
- package/lib/public/modules/app-panels.js +61 -123
- package/lib/public/modules/app-projects.js +5 -0
- package/lib/public/modules/app-rate-limit.js +7 -27
- package/lib/public/modules/chat-render-runtime.js +3 -0
- package/lib/public/modules/clay-owner-navigation.js +27 -0
- package/lib/public/modules/clay-tool-activity.js +140 -0
- package/lib/public/modules/clay-tool-presentation.js +338 -0
- package/lib/public/modules/command-palette.js +1 -1
- package/lib/public/modules/default-ai.js +11 -3
- package/lib/public/modules/home-debate-planning.js +5 -5
- package/lib/public/modules/home-mate-chat.js +8 -6
- package/lib/public/modules/home-mate-creation.js +73 -1
- package/lib/public/modules/mcp-connection-view.js +1 -1
- package/lib/public/modules/permission-control.js +5 -4
- package/lib/public/modules/personal-settings-dialog.js +7 -1
- package/lib/public/modules/project-access-recovery.js +17 -0
- package/lib/public/modules/project-admin-overview.js +21 -0
- package/lib/public/modules/scheduler.js +2 -0
- package/lib/public/modules/session-create-form.js +10 -10
- package/lib/public/modules/session-folder-layout.js +1 -1
- package/lib/public/modules/session-folder-view-menu.js +9 -0
- package/lib/public/modules/session-github.js +65 -8
- package/lib/public/modules/settings-defaults.js +27 -28
- package/lib/public/modules/sidebar-session-folders-ui.js +1 -1
- package/lib/public/modules/sticky-note-markdown.js +72 -6
- package/lib/public/modules/sticky-notes-actions.js +30 -0
- package/lib/public/modules/sticky-notes-browser.js +9 -2
- package/lib/public/modules/sticky-notes-card.js +23 -7
- package/lib/public/modules/sticky-notes-checklist.js +71 -0
- package/lib/public/modules/sticky-notes-editor.js +108 -44
- package/lib/public/modules/sticky-notes-shared.js +50 -2
- package/lib/public/modules/sticky-notes-state.js +66 -0
- package/lib/public/modules/sticky-notes.js +34 -51
- package/lib/public/modules/thinking-lifecycle.js +33 -3
- package/lib/public/modules/thinking-view.js +23 -1
- package/lib/public/modules/tools.js +36 -7
- package/lib/public/modules/tui-grab.js +1 -2
- package/lib/public/modules/user-settings-appearance.js +10 -3
- package/lib/public/modules/user-settings-editors.js +1 -1
- package/lib/public/modules/user-settings-layout.js +11 -2
- package/lib/public/modules/user-settings-preferences.js +6 -2
- package/lib/public/modules/user-settings-profile.js +12 -2
- package/lib/public/modules/user-settings.js +3 -2
- package/lib/public/modules/vendor-login-browser.js +5 -3
- package/lib/public/modules/vendor-login.js +2 -2
- package/lib/public/modules/vendor-priority.js +15 -1
- package/lib/public/muse-avatar.svg +4 -0
- package/lib/public/style.css +2 -0
- package/lib/safe-bash-commands.js +3 -45
- package/lib/scheduled-task-records.js +3 -1
- package/lib/scheduler.js +2 -0
- package/lib/sdk-bridge.js +334 -403
- package/lib/sdk-foreground-admission.js +16 -0
- package/lib/sdk-mcp-descriptors.js +2 -37
- package/lib/sdk-message-processor.js +52 -17
- package/lib/sdk-quota-snapshot.js +1 -1
- package/lib/sdk-response-recovery.js +1 -0
- package/lib/sdk-worker.js +2 -677
- package/lib/server-admin.js +63 -16
- package/lib/server-dm.js +1 -1
- package/lib/server-global-ws.js +10 -20
- package/lib/server-home-chat-events.js +7 -3
- package/lib/server-home-chat.js +4 -16
- package/lib/server-home-mate-creation.js +1 -0
- package/lib/server-home-mcp-consent.js +3 -3
- package/lib/server-mates.js +25 -67
- package/lib/server-owner-ui.js +77 -0
- package/lib/server-path-access.js +38 -0
- package/lib/server-project-removal.js +22 -0
- package/lib/server.js +100 -30
- package/lib/session-config-transition.js +45 -0
- package/lib/session-folders.js +7 -2
- package/lib/session-fork-history.js +21 -0
- package/lib/session-github.js +9 -2
- package/lib/session-hygiene.js +3 -35
- package/lib/session-permission-mode.js +4 -3
- package/lib/session-skill-scope.js +11 -0
- package/lib/session-visibility.js +5 -2
- package/lib/sessions.js +27 -89
- package/lib/terminal-manager.js +52 -0
- package/lib/tool-llm.js +1 -1
- package/lib/tui-transcript-index.js +1 -132
- package/lib/users-permissions.js +2 -8
- package/lib/users.js +4 -0
- package/lib/vendor-login-browser.js +1 -11
- package/lib/workspace-query-access.js +4 -1
- package/lib/ws-schema.js +8 -2
- package/lib/yoke/acp-agent-profiles.js +5 -3
- package/lib/yoke/adapters/antigravity.js +3 -14
- package/lib/yoke/adapters/claude-query-contract.js +9 -0
- package/lib/yoke/adapters/claude.js +54 -50
- package/lib/yoke/adapters/codex-query-contract.js +24 -0
- package/lib/yoke/adapters/codex.js +53 -111
- package/lib/yoke/adapters/kiro.js +3 -1
- package/lib/yoke/adapters/muse-query-contract.js +7 -0
- package/lib/yoke/adapters/muse.js +122 -0
- package/lib/yoke/auth-events.js +17 -0
- package/lib/yoke/claude-hook-installer.js +267 -0
- package/lib/yoke/claude-jsonl-watcher.js +204 -0
- package/lib/yoke/claude-maintenance.js +55 -0
- package/lib/yoke/claude-permission-patterns.js +53 -0
- package/lib/yoke/claude-response-recovery.js +155 -0
- package/lib/yoke/claude-transcript-hygiene.js +34 -0
- package/lib/yoke/claude-worker-startup.js +28 -0
- package/lib/yoke/clay-skill-install.js +33 -0
- package/lib/yoke/cli-sessions.js +300 -0
- package/lib/yoke/codex-app-server.js +7 -12
- package/lib/yoke/codex-idle-recovery.js +81 -1
- package/lib/yoke/codex-recovery-admission.js +164 -0
- package/lib/yoke/configuration.js +13 -0
- package/lib/yoke/discovery.js +70 -0
- package/lib/yoke/errors.js +8 -0
- package/lib/yoke/host-environment.js +7 -0
- package/lib/yoke/index.js +9 -51
- package/lib/yoke/interface.js +116 -0
- package/lib/yoke/kiro-acp-server.js +5 -5
- package/lib/yoke/legacy-sessions.js +89 -0
- package/lib/yoke/login-protocol.js +25 -0
- package/lib/yoke/maintenance.js +12 -0
- package/lib/yoke/mcp-proxy.js +32 -0
- package/lib/yoke/mcp-source-adapters.js +91 -0
- package/lib/yoke/mcp-source-context.js +42 -0
- package/lib/yoke/mcp-source-discovery.js +169 -0
- package/lib/yoke/mcp-source-plugins.js +68 -0
- package/lib/yoke/mcp-source-restrictions.js +47 -0
- package/lib/yoke/mcp-tool-policy-normalize.js +28 -0
- package/lib/yoke/model-preferences.js +6 -0
- package/lib/yoke/muse-artifacts.js +36 -0
- package/lib/yoke/muse-controls.js +50 -0
- package/lib/yoke/muse-input.js +64 -0
- package/lib/yoke/muse-items.js +157 -0
- package/lib/yoke/muse-policy.js +52 -0
- package/lib/yoke/muse-query.js +428 -0
- package/lib/yoke/muse-runtime.js +211 -0
- package/lib/yoke/muse-services.js +79 -0
- package/lib/yoke/muse-skills.js +79 -0
- package/lib/yoke/muse-turns.js +71 -0
- package/lib/yoke/options/acp.js +2 -0
- package/lib/yoke/options/antigravity.js +2 -0
- package/lib/yoke/options/claude.js +21 -0
- package/lib/yoke/options/codex-defaults.js +29 -0
- package/lib/yoke/options/codex-settings.js +21 -0
- package/lib/yoke/options/codex.js +6 -0
- package/lib/yoke/options/kiro-defaults.js +22 -0
- package/lib/yoke/options/kiro.js +5 -0
- package/lib/yoke/options/muse.js +5 -0
- package/lib/yoke/provider-contract.js +5 -0
- package/lib/yoke/providers/antigravity-executable.js +8 -0
- package/lib/yoke/providers/claude-executable.js +40 -0
- package/lib/yoke/providers/claude-model-descriptions.js +14 -0
- package/lib/yoke/providers/claude-process.js +97 -0
- package/lib/yoke/providers/claude-provision.js +75 -0
- package/lib/yoke/providers/codex-errors.js +8 -0
- package/lib/yoke/providers/muse-executable.js +17 -0
- package/lib/yoke/provisioning.js +6 -0
- package/lib/yoke/query-options.js +10 -0
- package/lib/yoke/response-recovery.js +41 -0
- package/lib/yoke/sdk-mcp-descriptors.js +37 -0
- package/lib/yoke/sdk-server-factory.js +7 -0
- package/lib/yoke/session-history.js +8 -0
- package/lib/yoke/session-tool-transport.js +34 -13
- package/lib/yoke/settings.js +23 -0
- package/lib/yoke/source-locations.js +4 -0
- package/lib/yoke/title-query.js +18 -7
- package/lib/yoke/tui-transcript-index.js +132 -0
- package/lib/yoke/usage.js +48 -0
- package/lib/yoke/user-input.js +13 -0
- package/lib/yoke/vendor-registry.js +81 -1
- package/package.json +3 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var userInput = require("./user-input");
|
|
2
|
+
function createRouter(runtime, queryOpts, signal) {
|
|
3
|
+
var pending = new Map();
|
|
4
|
+
function route(request) {
|
|
5
|
+
if (pending.has(request.userInputId)) return pending.get(request.userInputId).operation;
|
|
6
|
+
if (pending.size >= 1000) return Promise.reject(new Error("Muse input request capacity exceeded"));
|
|
7
|
+
var controller = new AbortController();
|
|
8
|
+
var entry = { controller: controller, retired: false };
|
|
9
|
+
function abort() { controller.abort(); }
|
|
10
|
+
if (signal.aborted) abort(); else signal.addEventListener("abort", abort, { once: true });
|
|
11
|
+
var operation = Promise.resolve().then(async function() {
|
|
12
|
+
runtime.check();
|
|
13
|
+
var input = { id: request.userInputId, questions: (request.questions || []).map(function(question) {
|
|
14
|
+
return { id: question.id, header: question.header, question: question.question,
|
|
15
|
+
options: question.options, multiSelect: question.selection && question.selection.mode === "multiple", allowOther: true };
|
|
16
|
+
}) };
|
|
17
|
+
if (typeof queryOpts.validateUserInputRequest === "function") {
|
|
18
|
+
var reason = queryOpts.validateUserInputRequest(input);
|
|
19
|
+
if (reason) throw new Error(reason);
|
|
20
|
+
}
|
|
21
|
+
var result = await runtime.wait(userInput.dispatchUserInput(queryOpts.onUserInputRequest, input,
|
|
22
|
+
{ source: "muse", native: true, provider: "muse", signal: controller.signal }));
|
|
23
|
+
runtime.check();
|
|
24
|
+
if (entry.retired) return;
|
|
25
|
+
if (result.status !== "submitted") return runtime.waitRequest(runtime.connection.command("userInput/cancel", {
|
|
26
|
+
sessionId: request.sessionId, userInputId: request.userInputId,
|
|
27
|
+
}));
|
|
28
|
+
var answers = request.questions.map(function(question) {
|
|
29
|
+
var values = result.answers[question.id] || [];
|
|
30
|
+
var selection = question.selection || {};
|
|
31
|
+
if (values.length < (selection.minSelections || 1) || selection.maxSelections != null && values.length > selection.maxSelections) throw new Error("Muse answer violates selection bounds");
|
|
32
|
+
var known = values.every(function(value) { return (question.options || []).some(function(option) { return option.label === value; }); });
|
|
33
|
+
var answer = { questionId: question.id };
|
|
34
|
+
if (!known || !question.options.length) {
|
|
35
|
+
var text = values.join(", ");
|
|
36
|
+
if (text.length > 500) throw new Error("Muse free-text answer exceeds 500 characters");
|
|
37
|
+
answer.freeText = text;
|
|
38
|
+
} else if (selection.mode === "multiple") answer.selectedLabels = values;
|
|
39
|
+
else answer.selectedLabel = values[0];
|
|
40
|
+
return answer;
|
|
41
|
+
});
|
|
42
|
+
return runtime.waitRequest(runtime.connection.command("userInput/answer", {
|
|
43
|
+
sessionId: request.sessionId, userInputId: request.userInputId, answers: answers,
|
|
44
|
+
}));
|
|
45
|
+
});
|
|
46
|
+
entry.operation = operation.finally(function() { signal.removeEventListener("abort", abort); });
|
|
47
|
+
pending.set(request.userInputId, entry);
|
|
48
|
+
return entry.operation;
|
|
49
|
+
}
|
|
50
|
+
route.settle = function(id) {
|
|
51
|
+
var entry = pending.get(id);
|
|
52
|
+
if (entry) { entry.retired = true; entry.controller.abort(); }
|
|
53
|
+
};
|
|
54
|
+
return route;
|
|
55
|
+
}
|
|
56
|
+
function inputParts(text, images) {
|
|
57
|
+
var parts = [{ type: "text", text: text }];
|
|
58
|
+
(images || []).forEach(function(image) {
|
|
59
|
+
if (!image || typeof image.data !== "string" || !image.data || !/^image\/[a-z0-9.+-]+$/i.test(image.mediaType || "") || !/^[A-Za-z0-9+/]+={0,2}$/.test(image.data)) throw new Error("Invalid Muse image attachment");
|
|
60
|
+
parts.push({ type: "image", mediaType: image.mediaType, base64Data: image.data });
|
|
61
|
+
});
|
|
62
|
+
return parts;
|
|
63
|
+
}
|
|
64
|
+
module.exports = { createRouter: createRouter, inputParts: inputParts };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
function itemInput(item) {
|
|
2
|
+
if (!item || typeof item.args !== "string") return {};
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(item.args);
|
|
5
|
+
} catch (e) {
|
|
6
|
+
return {
|
|
7
|
+
rawArgs: item.args
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toolName(item) {
|
|
13
|
+
var name = String(item && (item.tool || item.toolName) || "Tool").toLowerCase();
|
|
14
|
+
if (name.indexOf("shell") !== -1 || name.indexOf("command") !== -1) return "Bash";
|
|
15
|
+
if (name.indexOf("read") !== -1) return "Read";
|
|
16
|
+
if (name.indexOf("write") !== -1 || name.indexOf("create") !== -1) return "Write";
|
|
17
|
+
if (name.indexOf("edit") !== -1 || name.indexOf("delete") !== -1) return "Edit";
|
|
18
|
+
if (name.indexOf("search") !== -1 || name.indexOf("grep") !== -1) return "Grep";
|
|
19
|
+
return item && (item.tool || item.toolName) || "Tool";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function createRenderer(state, push) {
|
|
23
|
+
var streamedItems = {};
|
|
24
|
+
var openBlocks = {};
|
|
25
|
+
var notices = {};
|
|
26
|
+
function closeBlocks(turnId) {
|
|
27
|
+
Object.keys(openBlocks).forEach(function(id) {
|
|
28
|
+
if (turnId && openBlocks[id] !== turnId) return;
|
|
29
|
+
push({
|
|
30
|
+
yokeType: "block_stop",
|
|
31
|
+
blockId: id
|
|
32
|
+
});
|
|
33
|
+
delete openBlocks[id];
|
|
34
|
+
});
|
|
35
|
+
if (!turnId) { state.thinkingBlocks = {}; state.textBlocks = {}; state.toolBlocks = {}; }
|
|
36
|
+
}
|
|
37
|
+
function emitNotice(item, id) {
|
|
38
|
+
if (item.status === "inProgress" || item.kind === "userMessage") return;
|
|
39
|
+
var failed = ["failed", "rejected", "timedOut"].includes(item.status)
|
|
40
|
+
|| (item.kind === "compaction" && item.outcome === "failed")
|
|
41
|
+
|| (item.kind === "hookRun" && ["failed", "blocked", "timedOut"].includes(item.runStatus))
|
|
42
|
+
|| (item.kind === "subagent" && item.result && item.result.errorKind);
|
|
43
|
+
var text = "";
|
|
44
|
+
if (failed) {
|
|
45
|
+
var labels = { reminderChild: "A background task", hookRun: "A hook", compaction: "Context maintenance", sideChat: "A side conversation", subagent: "A task", workflow: "A workflow", userShell: "A command", webSearch: "A search" };
|
|
46
|
+
var label = labels[item.kind] || "A Muse operation";
|
|
47
|
+
// Unknown kinds have no established human-facing fields. Do not dump them.
|
|
48
|
+
var detail = labels[item.kind] ? (item.failureReason || item.reason || item.message || "") : "";
|
|
49
|
+
if (item.kind === "subagent" && !detail && item.result) detail = item.result.summary || "";
|
|
50
|
+
text = label + " failed" + (detail ? ": " + detail : ".");
|
|
51
|
+
} else if (item.status === "completed") {
|
|
52
|
+
// Only documented action results belong in chat. Reminder/hook/compaction/
|
|
53
|
+
// side-chat bookkeeping and unknown protocol fallback text stay silent.
|
|
54
|
+
if (item.kind === "subagent" && item.result) text = item.result.text || item.result.summary || "";
|
|
55
|
+
else if (item.kind === "workflow") text = item.finalSummary || item.message || "";
|
|
56
|
+
else if (item.kind === "userShell") text = item.visibleOutput || "";
|
|
57
|
+
else if (item.kind === "webSearch") text = item.fallbackText || "";
|
|
58
|
+
}
|
|
59
|
+
var key = id + (failed ? ":failure" : ":summary");
|
|
60
|
+
if (typeof text !== "string" || !text.trim() || notices[key]) return;
|
|
61
|
+
notices[key] = true;
|
|
62
|
+
push({ yokeType: "informational", level: failed ? "warning" : "info", content: text });
|
|
63
|
+
}
|
|
64
|
+
function emitItem(item) {
|
|
65
|
+
if (!item || state.stopped) return;
|
|
66
|
+
var id = item.itemId || "muse-item";
|
|
67
|
+
if (item.kind === "agentMessage" || item.kind === "reasoning") {
|
|
68
|
+
var previous = state.textBlocks[id] || "";
|
|
69
|
+
var value = item.kind === "reasoning" && Array.isArray(item.summary) ? item.summary.join("\n") : item.text || "";
|
|
70
|
+
var blockId = state.thinkingBlocks[id] || id;
|
|
71
|
+
if (item.kind === "reasoning") state.thinkingBlocks[id] = blockId;
|
|
72
|
+
if (!previous && value) {
|
|
73
|
+
openBlocks[blockId] = item.turnId;
|
|
74
|
+
push({
|
|
75
|
+
yokeType: item.kind === "reasoning" ? "thinking_start" : "text_start",
|
|
76
|
+
blockId: blockId
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (value.length > previous.length) push({
|
|
80
|
+
yokeType: item.kind === "reasoning" ? "thinking_delta" : "text_delta",
|
|
81
|
+
blockId: blockId,
|
|
82
|
+
text: value.substring(previous.length)
|
|
83
|
+
});
|
|
84
|
+
if (value.length >= previous.length) state.textBlocks[id] = value;
|
|
85
|
+
if (item.status !== "inProgress" && openBlocks[blockId]) {
|
|
86
|
+
push({
|
|
87
|
+
yokeType: "block_stop",
|
|
88
|
+
blockId: blockId
|
|
89
|
+
});
|
|
90
|
+
delete openBlocks[blockId];
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (item.kind === "toolCall") {
|
|
95
|
+
if (!state.toolBlocks[id]) {
|
|
96
|
+
state.toolBlocks[id] = true;
|
|
97
|
+
push({
|
|
98
|
+
yokeType: "tool_start",
|
|
99
|
+
blockId: id,
|
|
100
|
+
toolId: id,
|
|
101
|
+
toolName: toolName(item)
|
|
102
|
+
});
|
|
103
|
+
push({
|
|
104
|
+
yokeType: "tool_executing",
|
|
105
|
+
blockId: id,
|
|
106
|
+
toolId: id,
|
|
107
|
+
toolName: toolName(item),
|
|
108
|
+
input: itemInput(item)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (item.status && item.status !== "inProgress" && state.toolBlocks[id] !== "completed") {
|
|
112
|
+
state.toolBlocks[id] = "completed";
|
|
113
|
+
push({
|
|
114
|
+
yokeType: "tool_result",
|
|
115
|
+
blockId: id,
|
|
116
|
+
toolId: id,
|
|
117
|
+
content: item.visibleOutput || item.message || item.failureReason || "",
|
|
118
|
+
isError: item.status !== "completed"
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
emitNotice(item, id);
|
|
124
|
+
}
|
|
125
|
+
function renderFrame(frame) {
|
|
126
|
+
var params = frame.params || {};
|
|
127
|
+
var item = params.item;
|
|
128
|
+
var owner = item && item.turnId || streamedItems[params.itemId] && streamedItems[params.itemId].turnId;
|
|
129
|
+
if (!(state.liveTurnIds && state.liveTurnIds.has(owner) || state.activeTurn && owner === state.activeTurn.turnId)) return false;
|
|
130
|
+
if (item) streamedItems[item.itemId] = Object.assign({}, item); else if (frame.method === "item/delta") {
|
|
131
|
+
item = streamedItems[params.itemId];
|
|
132
|
+
if (item) {
|
|
133
|
+
var field = params.field || "text";
|
|
134
|
+
if (field.indexOf("summary.") === 0) {
|
|
135
|
+
var index = Number(field.split(".")[1]);
|
|
136
|
+
item.summary = (item.summary || []).slice();
|
|
137
|
+
item.summary[index] = (item.summary[index] || "") + params.delta;
|
|
138
|
+
} else if (field === "text") item.text = (item.text || "") + params.delta; else if (field === "output") item.visibleOutput = (item.visibleOutput || "") + params.delta;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (item) emitItem(item);
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
emitItem: emitItem,
|
|
146
|
+
renderFrame: renderFrame,
|
|
147
|
+
closeBlocks: closeBlocks,
|
|
148
|
+
hasItem: function(id) {
|
|
149
|
+
return !!streamedItems[id];
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports = {
|
|
155
|
+
createRenderer: createRenderer,
|
|
156
|
+
itemInput: itemInput
|
|
157
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var itemInput = require("./muse-items").itemInput;
|
|
2
|
+
|
|
3
|
+
function normalizeMcpServers(servers) {
|
|
4
|
+
var config = {};
|
|
5
|
+
if (servers == null) return config;
|
|
6
|
+
if (!Array.isArray(servers)) throw new Error("Invalid Muse session MCP servers");
|
|
7
|
+
for (var i = 0; i < servers.length; i++) {
|
|
8
|
+
var server = servers[i] || {};
|
|
9
|
+
if (!server.name || !server.command || typeof server.name !== "string" || typeof server.command !== "string" || !Array.isArray(server.args || [])) throw new Error("Invalid Muse session MCP server");
|
|
10
|
+
if (["__proto__", "constructor", "prototype"].includes(server.name) || Object.prototype.hasOwnProperty.call(config, server.name)) throw new Error("Invalid or duplicate Muse MCP server name");
|
|
11
|
+
var env = {};
|
|
12
|
+
var entries = Array.isArray(server.env) ? server.env : [];
|
|
13
|
+
for (var j = 0; j < entries.length; j++) if (entries[j] && entries[j].name) env[entries[j].name] = String(entries[j].value == null ? "" : entries[j].value);
|
|
14
|
+
config[server.name] = {
|
|
15
|
+
transport: "stdio",
|
|
16
|
+
command: server.command,
|
|
17
|
+
args: server.args || [],
|
|
18
|
+
env: env,
|
|
19
|
+
mode: "required"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function chooseApprovalDecision(request, canUseTool, signal) {
|
|
26
|
+
var choices = Array.isArray(request && request.availableChoices) ? request.availableChoices : [];
|
|
27
|
+
if (!choices.length || typeof canUseTool !== "function") return Promise.reject(new Error("Muse approval cannot be decided safely"));
|
|
28
|
+
if (signal && signal.aborted) return Promise.reject(new Error("Muse approval cancelled"));
|
|
29
|
+
return Promise.resolve(canUseTool(request.toolName || "Tool", itemInput({
|
|
30
|
+
args: request.rawArgs
|
|
31
|
+
}), {
|
|
32
|
+
request: request,
|
|
33
|
+
signal: signal
|
|
34
|
+
})).then(function(result) {
|
|
35
|
+
if (signal && signal.aborted) throw new Error("Muse approval cancelled");
|
|
36
|
+
var allowed = result && result.behavior === "allow";
|
|
37
|
+
if (!allowed && !(result && result.behavior === "deny")) throw new Error("Muse approval returned an unsupported decision");
|
|
38
|
+
for (var i = 0; i < choices.length; i++) if (choices[i].scope === "once" && (choices[i].decision === (allowed ? "approved" : "denied") || !allowed && choices[i].decision === "abort")) {
|
|
39
|
+
var decision = {
|
|
40
|
+
choiceId: choices[i].choiceId
|
|
41
|
+
};
|
|
42
|
+
if (choices[i].acceptsFeedback && result.message) decision.feedback = result.message;
|
|
43
|
+
return decision;
|
|
44
|
+
}
|
|
45
|
+
throw new Error("Muse approval has no matching safe choice");
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
normalizeMcpServers: normalizeMcpServers,
|
|
51
|
+
chooseApprovalDecision: chooseApprovalDecision
|
|
52
|
+
};
|