clay-server 5.2.0-beta.3 → 5.2.0-beta.5
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 +19 -16
- package/lib/bundled-skills/clay-agent-browser/SKILL.md +6 -2
- package/lib/canonical-clay-record-authority.js +15 -0
- package/lib/canonical-clay-scheduling-authority.js +19 -0
- package/lib/claude-hook-installer.js +28 -0
- 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-workspace-controls.js +83 -0
- package/lib/clay-workspace-input.js +17 -0
- package/lib/clay-workspace-receipts.js +26 -0
- 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 +73 -221
- package/lib/issues-service.js +29 -15
- 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-file-store.js +7 -1
- package/lib/knowledge-product-operations.js +46 -0
- package/lib/mate-avatar-catalog.js +12 -0
- package/lib/mate-avatar-migration.js +41 -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 +18 -6
- package/lib/mcp-agent-tools.js +117 -0
- package/lib/mcp-connection-store.js +119 -15
- package/lib/mcp-import-credentials.js +31 -0
- package/lib/mcp-local-transport.js +13 -0
- package/lib/mcp-oauth.js +8 -6
- package/lib/mcp-query-bridge.js +30 -0
- package/lib/mcp-remote-connections.js +74 -20
- package/lib/mcp-source-adapters.js +91 -0
- package/lib/mcp-source-context.js +42 -0
- package/lib/mcp-source-discovery.js +169 -0
- package/lib/mcp-source-plugins.js +68 -0
- package/lib/mcp-source-restrictions.js +47 -0
- package/lib/mcp-tool-policy.js +34 -0
- package/lib/notes-checklist.js +50 -0
- package/lib/notes.js +49 -3
- package/lib/os-users.js +20 -5
- package/lib/project-admin-overview.js +51 -0
- package/lib/project-ask-user.js +8 -4
- package/lib/project-debate.js +1 -0
- 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-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-mate-interaction.js +8 -0
- package/lib/project-mcp.js +54 -16
- 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-pending-message-queue.js +1 -0
- 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-document.js +8 -3
- package/lib/project-session-github.js +63 -19
- package/lib/project-session-history-actions.js +165 -0
- package/lib/project-session-linear.js +14 -6
- package/lib/project-session-notes.js +7 -3
- package/lib/project-session-runtime-actions.js +63 -0
- package/lib/project-session-vendor.js +54 -0
- package/lib/project-sessions.js +68 -241
- package/lib/project-shared-browser.js +56 -12
- package/lib/project-user-message.js +30 -1
- package/lib/project-workspace-operations.js +126 -0
- package/lib/project-workspace-query.js +9 -2
- package/lib/project.js +144 -37
- package/lib/public/app.js +5 -0
- package/lib/public/appearance-bootstrap.js +14 -0
- package/lib/public/css/clay-tool-activity.css +51 -0
- package/lib/public/css/clay-workspace.css +29 -0
- package/lib/public/css/home-debate-planning.css +2 -0
- package/lib/public/css/home-mate-creation.css +5 -0
- package/lib/public/css/mate-avatar-gallery.css +12 -0
- package/lib/public/css/mate-conversation.css +10 -5
- 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 +46 -1
- package/lib/public/css/shared-browser.css +35 -1
- package/lib/public/css/sticky-notes.css +61 -1
- package/lib/public/index.html +11 -5
- package/lib/public/mate-avatars/B01.png +0 -0
- package/lib/public/mate-avatars/B02.png +0 -0
- package/lib/public/mate-avatars/B03.png +0 -0
- package/lib/public/mate-avatars/B04.png +0 -0
- package/lib/public/mate-avatars/B05.png +0 -0
- package/lib/public/mate-avatars/B06.png +0 -0
- package/lib/public/mate-avatars/B07.png +0 -0
- package/lib/public/mate-avatars/B08.png +0 -0
- package/lib/public/mate-avatars/B09.png +0 -0
- package/lib/public/mate-avatars/B10.png +0 -0
- package/lib/public/mate-avatars/B11.png +0 -0
- package/lib/public/mate-avatars/B12.png +0 -0
- package/lib/public/mate-avatars/B13.png +0 -0
- package/lib/public/mate-avatars/B14.png +0 -0
- package/lib/public/mate-avatars/B15.png +0 -0
- package/lib/public/mate-avatars/B16.png +0 -0
- package/lib/public/mate-avatars/B17.png +0 -0
- package/lib/public/mate-avatars/B18.png +0 -0
- package/lib/public/mate-avatars/B19.png +0 -0
- package/lib/public/mate-avatars/B20.png +0 -0
- package/lib/public/mate-avatars/B21.png +0 -0
- package/lib/public/mate-avatars/B22.png +0 -0
- package/lib/public/mate-avatars/B23.png +0 -0
- package/lib/public/mate-avatars/B24.png +0 -0
- package/lib/public/mate-avatars/B25.png +0 -0
- package/lib/public/mate-avatars/B26.png +0 -0
- package/lib/public/mate-avatars/B27.png +0 -0
- package/lib/public/mate-avatars/B28.png +0 -0
- package/lib/public/mate-avatars/B29.png +0 -0
- package/lib/public/mate-avatars/B30.png +0 -0
- package/lib/public/mate-avatars/B31.png +0 -0
- package/lib/public/mate-avatars/B32.png +0 -0
- package/lib/public/mate-avatars/B33.png +0 -0
- package/lib/public/mate-avatars/B34.png +0 -0
- package/lib/public/mate-avatars/B35.png +0 -0
- package/lib/public/mate-avatars/B36.png +0 -0
- package/lib/public/mate-avatars/B37.png +0 -0
- package/lib/public/mate-avatars/B38.png +0 -0
- package/lib/public/mate-avatars/B39.png +0 -0
- package/lib/public/mate-avatars/B40.png +0 -0
- package/lib/public/mate-avatars/B41.png +0 -0
- package/lib/public/mate-avatars/B42.png +0 -0
- package/lib/public/mate-avatars/B43.png +0 -0
- package/lib/public/mate-avatars/B44.png +0 -0
- package/lib/public/mate-avatars/B45.png +0 -0
- package/lib/public/mate-avatars/B46.png +0 -0
- package/lib/public/mate-avatars/B47.png +0 -0
- package/lib/public/mate-avatars/B48.png +0 -0
- package/lib/public/mate-avatars/C01.png +0 -0
- package/lib/public/mate-avatars/C02.png +0 -0
- package/lib/public/mate-avatars/C03.png +0 -0
- package/lib/public/mate-avatars/C04.png +0 -0
- package/lib/public/mate-avatars/C05.png +0 -0
- package/lib/public/mate-avatars/C06.png +0 -0
- package/lib/public/mate-avatars/C07.png +0 -0
- package/lib/public/mate-avatars/C08.png +0 -0
- package/lib/public/mate-avatars/C09.png +0 -0
- package/lib/public/mate-avatars/C10.png +0 -0
- package/lib/public/mate-avatars/C11.png +0 -0
- package/lib/public/mate-avatars/C12.png +0 -0
- package/lib/public/mate-avatars/C13.png +0 -0
- package/lib/public/mate-avatars/C14.png +0 -0
- package/lib/public/mate-avatars/C15.png +0 -0
- package/lib/public/mate-avatars/C16.png +0 -0
- package/lib/public/mate-avatars/C17.png +0 -0
- package/lib/public/mate-avatars/C18.png +0 -0
- package/lib/public/mate-avatars/C19.png +0 -0
- package/lib/public/mate-avatars/C20.png +0 -0
- package/lib/public/mate-avatars/C21.png +0 -0
- package/lib/public/mate-avatars/C22.png +0 -0
- package/lib/public/mate-avatars/C23.png +0 -0
- package/lib/public/mate-avatars/C24.png +0 -0
- package/lib/public/mate-avatars/C25.png +0 -0
- package/lib/public/mate-avatars/C26.png +0 -0
- package/lib/public/mate-avatars/C27.png +0 -0
- package/lib/public/mate-avatars/C28.png +0 -0
- package/lib/public/mate-avatars/C29.png +0 -0
- package/lib/public/mate-avatars/C30.png +0 -0
- package/lib/public/mate-avatars/C31.png +0 -0
- package/lib/public/mate-avatars/C32.png +0 -0
- package/lib/public/mate-avatars/C33.png +0 -0
- package/lib/public/mate-avatars/C34.png +0 -0
- package/lib/public/mate-avatars/C35.png +0 -0
- package/lib/public/mate-avatars/C36.png +0 -0
- package/lib/public/mate-avatars/C37.png +0 -0
- package/lib/public/mate-avatars/C38.png +0 -0
- package/lib/public/mate-avatars/C39.png +0 -0
- package/lib/public/mate-avatars/C40.png +0 -0
- package/lib/public/mate-avatars/C41.png +0 -0
- package/lib/public/mate-avatars/C42.png +0 -0
- package/lib/public/mate-avatars/C43.png +0 -0
- package/lib/public/mate-avatars/C44.png +0 -0
- package/lib/public/mate-avatars/C45.png +0 -0
- package/lib/public/mate-avatars/C46.png +0 -0
- package/lib/public/mate-avatars/C47.png +0 -0
- package/lib/public/mate-avatars/C48.png +0 -0
- package/lib/public/mate-avatars/catalog.json +482 -0
- package/lib/public/mate-avatars/lead-clay.png +0 -0
- package/lib/public/modules/admin-settings-projects.js +6 -2
- package/lib/public/modules/app-connection.js +8 -1
- package/lib/public/modules/app-message-router.js +4 -0
- package/lib/public/modules/app-messages.js +31 -5
- package/lib/public/modules/app-projects.js +5 -0
- package/lib/public/modules/app-rendering.js +1 -1
- package/lib/public/modules/avatar.js +15 -41
- package/lib/public/modules/chat-render-runtime.js +10 -1
- package/lib/public/modules/clay-browser-links.js +47 -0
- package/lib/public/modules/clay-log-links.js +1 -1
- 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 +2 -2
- package/lib/public/modules/debate.js +1 -0
- package/lib/public/modules/default-ai.js +11 -3
- package/lib/public/modules/history-replay-batch.js +5 -1
- package/lib/public/modules/home-debate-live.js +2 -0
- package/lib/public/modules/home-debate-planning.js +7 -7
- package/lib/public/modules/home-mate-avatar-editor.js +127 -208
- package/lib/public/modules/home-mate-chat.js +8 -6
- package/lib/public/modules/home-mate-creation.js +73 -1
- package/lib/public/modules/home-mate-settings.js +19 -12
- package/lib/public/modules/markdown.js +4 -0
- package/lib/public/modules/mate-avatar-catalog.js +97 -0
- package/lib/public/modules/mate-management.js +40 -7
- package/lib/public/modules/mcp-connection-view.js +31 -13
- package/lib/public/modules/mcp-discovery-view.js +31 -0
- package/lib/public/modules/mcp-ui.js +23 -4
- package/lib/public/modules/mention.js +3 -0
- package/lib/public/modules/pane-browser-bridge.js +20 -0
- package/lib/public/modules/personal-settings-dialog.js +7 -1
- package/lib/public/modules/profile.js +1 -238
- package/lib/public/modules/project-access-recovery.js +17 -0
- package/lib/public/modules/project-admin-overview.js +21 -0
- package/lib/public/modules/project-mate-navigation.js +99 -14
- package/lib/public/modules/search-clay-chat.js +16 -2
- 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 +85 -14
- package/lib/public/modules/session-work-primary.js +51 -0
- package/lib/public/modules/shared-browser-settings.js +112 -0
- package/lib/public/modules/shared-browser-tabs.js +13 -3
- package/lib/public/modules/shared-browser.js +27 -6
- package/lib/public/modules/sidebar-session-folders-ui.js +1 -1
- package/lib/public/modules/split-view.js +2 -0
- 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/theme.js +8 -1
- 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/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/style.css +3 -0
- package/lib/public/sw.js +3 -1
- package/lib/scheduled-task-records.js +3 -1
- package/lib/scheduler.js +2 -0
- package/lib/sdk-bridge.js +228 -23
- package/lib/sdk-message-processor.js +2 -0
- package/lib/sdk-response-recovery.js +155 -0
- package/lib/server-admin.js +63 -16
- package/lib/server-appearance-settings.js +13 -1
- package/lib/server-dm.js +2 -1
- package/lib/server-global-ws.js +10 -20
- package/lib/server-home-chat-events.js +18 -4
- package/lib/server-home-chat.js +12 -16
- package/lib/server-home-mate-creation.js +1 -0
- package/lib/server-home-mcp-consent.js +14 -0
- package/lib/server-mates.js +25 -62
- 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-settings.js +4 -1
- package/lib/server.js +144 -41
- package/lib/session-config-transition.js +45 -0
- package/lib/session-folders.js +7 -2
- package/lib/session-github.js +9 -2
- package/lib/session-visibility.js +5 -2
- package/lib/session-work-primary.js +50 -0
- package/lib/sessions.js +13 -0
- package/lib/shared-browser-cookie-sync.js +32 -0
- package/lib/shared-browser-cookies.js +79 -0
- package/lib/shared-browser-runtime.js +25 -9
- package/lib/shared-browser-storage-sync.js +43 -0
- package/lib/shared-browser-storage.js +101 -0
- package/lib/shared-browser-tools.js +2 -1
- package/lib/shared-browser-worker.js +46 -10
- package/lib/terminal-manager.js +52 -0
- package/lib/users-permissions.js +2 -8
- package/lib/users.js +4 -0
- package/lib/workspace-query-access.js +4 -1
- package/lib/ws-schema.js +8 -2
- package/lib/yoke/acp-agent-profiles.js +2 -2
- package/lib/yoke/adapters/claude.js +47 -8
- package/lib/yoke/adapters/codex.js +52 -111
- package/lib/yoke/claude-worker-startup.js +28 -0
- package/lib/yoke/codex-idle-recovery.js +81 -1
- package/lib/yoke/codex-recovery-admission.js +164 -0
- package/lib/yoke/session-tool-transport.js +3 -0
- package/package.json +5 -1
|
@@ -1,16 +1,31 @@
|
|
|
1
|
+
var primary = require('./session-work-primary');
|
|
1
2
|
var github = require("./session-github");
|
|
2
3
|
var buildShape = require("./session-spawn-mcp-server").buildShape;
|
|
3
4
|
var CONTRACT = "GitHub work links: proactively call link_session_github as soon as conversation context or tool results reasonably establish that an issue or PR is part of this session's work. Do not wait for an explicit linking request, implementation to begin, or work to finish. Investigating an issue, reviewing a PR or its requested changes, addressing review feedback, and checking CI or merge readiness all count as work. When a working PR is connected to an issue and both are relevant to the task, link both. Resolve a known repository and issue/PR number to the exact GitHub URL; if the repository is uncertain, verify it with a read-only lookup instead of silently skipping the link. Incidental mentions, examples, and unrelated reference material alone do not qualify. The current branch alone is insufficient evidence because sessions may share a checkout; combine it with conversation or verified task evidence. This records local metadata only and does not post to GitHub, so no separate linking approval is needed. Use get_session_github to inspect/refresh linked status and discover accessible sessions already working on the same reference before starting duplicate work. When the work shifts to another issue or PR, check that the relevant links are present before reporting progress or completion. Keep Issues as quiet background records, not a mandatory workflow. Unlink an incorrect association with unlink_session_github.";
|
|
5
|
+
CONTRACT += primary.GUIDANCE;
|
|
4
6
|
function attachSessionGithub(ctx) {
|
|
5
7
|
var inflight = new Map();
|
|
6
8
|
var attempts = new Map();
|
|
7
9
|
var statusCache = new Map();
|
|
8
10
|
var statusQueue = Promise.resolve();
|
|
9
|
-
|
|
11
|
+
var viewerCache = new Map();
|
|
12
|
+
async function readViewerLogin(identity, viewerKey) {
|
|
13
|
+
var key = JSON.stringify([viewerKey || null, identity || null]);
|
|
14
|
+
var cached = viewerCache.get(key);
|
|
15
|
+
if (cached && cached.until > Date.now()) return cached.value;
|
|
16
|
+
var pending = (ctx.run || github.runGh)(ctx.cwd, ["api", "user"], identity).then(function (value) {
|
|
17
|
+
var login = String(value && value.login || "").trim().toLowerCase();
|
|
18
|
+
viewerCache.set(key, { value: login, until: Date.now() + 300000 });
|
|
19
|
+
return login;
|
|
20
|
+
});
|
|
21
|
+
viewerCache.set(key, { value: pending, until: Date.now() + 30000 });
|
|
22
|
+
try { return await pending; } catch (error) { viewerCache.delete(key); throw error; }
|
|
23
|
+
}
|
|
24
|
+
function readStatus(session, link, stillAllowed, viewerKey, allowPersonalReview) {
|
|
10
25
|
var identity = authorize(session);
|
|
11
|
-
var key = JSON.stringify([session.ownerId || null, identity && identity.uid, identity && identity.home, link.url.toLowerCase()]);
|
|
26
|
+
var key = JSON.stringify([session.ownerId || null, viewerKey || null, !!allowPersonalReview, identity && identity.uid, identity && identity.home, link.url.toLowerCase()]);
|
|
12
27
|
var cached = statusCache.get(key);
|
|
13
|
-
if (cached && (cached.pending || cached.until > Date.now())) return cached.pending || (cached.error ? Promise.reject(cached.error) : Promise.resolve(cached.value));
|
|
28
|
+
if (cached && (cached.pending || cached.until > Date.now())) return cached.pending || (cached.error ? Promise.reject(cached.error) : Promise.resolve({ value: cached.value, personalReviewState: cached.personalReviewState || "unknown" }));
|
|
14
29
|
var entry = { failures: cached ? cached.failures : 0 };
|
|
15
30
|
statusCache.set(key, entry);
|
|
16
31
|
entry.pending = statusQueue.then(async function () {
|
|
@@ -18,9 +33,17 @@ function attachSessionGithub(ctx) {
|
|
|
18
33
|
var currentIdentity = authorize(session);
|
|
19
34
|
if (JSON.stringify(currentIdentity) !== JSON.stringify(identity) || (stillAllowed && !stillAllowed())) throw new Error("Session access changed.");
|
|
20
35
|
entry.value = await github.readReference(ctx.cwd, link.url, identity, ctx.run, true);
|
|
36
|
+
entry.personalReviewState = "clear";
|
|
37
|
+
if (allowPersonalReview && entry.value.reviewRequests && entry.value.reviewRequests.length) {
|
|
38
|
+
try {
|
|
39
|
+
entry.personalReviewState = entry.value.reviewRequests.indexOf(await readViewerLogin(identity, viewerKey)) >= 0 ? "requested" : "clear";
|
|
40
|
+
} catch (viewerError) { entry.personalReviewState = "unknown"; }
|
|
41
|
+
}
|
|
42
|
+
if (!allowPersonalReview) entry.personalReviewState = "unknown";
|
|
43
|
+
delete entry.value.reviewRequests;
|
|
21
44
|
entry.failures = 0;
|
|
22
45
|
entry.until = Date.now() + (entry.value.state === "closed" || entry.value.state === "merged" ? 300000 : 45000);
|
|
23
|
-
return entry.value;
|
|
46
|
+
return { value: entry.value, personalReviewState: entry.personalReviewState };
|
|
24
47
|
} catch (error) {
|
|
25
48
|
entry.error = error;
|
|
26
49
|
entry.failures++;
|
|
@@ -39,7 +62,7 @@ function attachSessionGithub(ctx) {
|
|
|
39
62
|
return entry.pending;
|
|
40
63
|
}
|
|
41
64
|
function authorize(session) {
|
|
42
|
-
if (!session || ctx.sm.sessions.get(session.localId) !== session ||
|
|
65
|
+
if (!session || ctx.sm.sessions.get(session.localId) !== session || !ctx.canUse(session)) throw new Error("GitHub links require an authorized project session.");
|
|
43
66
|
var identity = ctx.identity(session);
|
|
44
67
|
// Account login does not imply OS isolation. Match the project's execution mode.
|
|
45
68
|
if (ctx.osUsers && !identity) throw new Error("GitHub requires a mapped OS user with gh authentication in OS-isolated mode.");
|
|
@@ -49,21 +72,29 @@ function attachSessionGithub(ctx) {
|
|
|
49
72
|
if (ctx.sm.saveSessionFile(session) === false) throw new Error("Could not save GitHub links.");
|
|
50
73
|
ctx.sm.broadcastSessionList();
|
|
51
74
|
}
|
|
52
|
-
async function refresh(session, force, statusOnly, stillAllowed) {
|
|
75
|
+
async function refresh(session, force, statusOnly, stillAllowed, viewerKey, allowPersonalReview) {
|
|
53
76
|
var identity = authorize(session);
|
|
54
|
-
var id = session.localId + (statusOnly ? ":status" : ":full");
|
|
77
|
+
var id = session.localId + (statusOnly ? ":status:" + (viewerKey || "anonymous") : ":full");
|
|
55
78
|
if (inflight.has(id)) return inflight.get(id);
|
|
56
|
-
if (!force && Date.now() - (attempts.get(id) || 0) < (statusOnly ? 30000 : 60000)) return session.githubLinks || [];
|
|
79
|
+
if (!force && Date.now() - (attempts.get(id) || 0) < (statusOnly ? 30000 : 60000)) return { links: session.githubLinks || [], viewerReviewRequests: {} };
|
|
57
80
|
attempts.set(id, Date.now());
|
|
58
81
|
var pending = (async function () {
|
|
59
82
|
var links = (session.githubLinks || []).slice();
|
|
60
83
|
var updated = [];
|
|
84
|
+
var viewerReviewRequests = {};
|
|
61
85
|
for (var link of links) {
|
|
62
86
|
try {
|
|
63
87
|
if (stillAllowed && !stillAllowed()) throw new Error("Session access changed.");
|
|
64
|
-
|
|
88
|
+
if (statusOnly) {
|
|
89
|
+
var status = await readStatus(session, link, stillAllowed, viewerKey, allowPersonalReview);
|
|
90
|
+
updated.push(Object.assign({}, link, status.value, { stale: false }));
|
|
91
|
+
if (status.personalReviewState !== "unknown") viewerReviewRequests[link.url.toLowerCase()] = status.personalReviewState;
|
|
92
|
+
} else updated.push(await github.readReference(ctx.cwd, link.url, identity, ctx.run));
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
updated.push(Object.assign({}, link, { stale: true }));
|
|
96
|
+
if (statusOnly) viewerReviewRequests[link.url.toLowerCase()] = "unknown";
|
|
65
97
|
}
|
|
66
|
-
catch (error) { updated.push(Object.assign({}, link, { stale: true })); }
|
|
67
98
|
}
|
|
68
99
|
authorize(session);
|
|
69
100
|
if (stillAllowed && !stillAllowed()) throw new Error("Session access changed.");
|
|
@@ -79,7 +110,7 @@ function attachSessionGithub(ctx) {
|
|
|
79
110
|
return next;
|
|
80
111
|
});
|
|
81
112
|
if (changed) persist(session);
|
|
82
|
-
return session.githubLinks || [];
|
|
113
|
+
return { links: session.githubLinks || [], viewerReviewRequests: viewerReviewRequests };
|
|
83
114
|
})();
|
|
84
115
|
inflight.set(id, pending);
|
|
85
116
|
try { return await pending; } finally { inflight.delete(id); }
|
|
@@ -87,7 +118,8 @@ function attachSessionGithub(ctx) {
|
|
|
87
118
|
async function invoke(session, name, args) {
|
|
88
119
|
var identity = authorize(session);
|
|
89
120
|
if (name === "get_session_github") {
|
|
90
|
-
var
|
|
121
|
+
var refreshed = await refresh(session, false);
|
|
122
|
+
var links = refreshed.links;
|
|
91
123
|
var matches = [];
|
|
92
124
|
if (args.url) {
|
|
93
125
|
var url = github.parseReference(args.url).url.toLowerCase();
|
|
@@ -95,10 +127,11 @@ function attachSessionGithub(ctx) {
|
|
|
95
127
|
if (!other.hidden && !other.delegated && !require("./session-provenance").isWorker(other) && ctx.canRead(session, other) && (other.githubLinks || []).some(function (link) { return link.url.toLowerCase() === url; })) matches.push({ sessionId: other.localId, title: other.title });
|
|
96
128
|
});
|
|
97
129
|
}
|
|
98
|
-
return { links: links, matchingSessions: matches.slice(0, 20) };
|
|
130
|
+
return { links: links, workPrimary: session.workPrimary || {}, matchingSessions: matches.slice(0, 20) };
|
|
99
131
|
}
|
|
100
132
|
var ref = github.parseReference(args.url);
|
|
101
133
|
if (name === "unlink_session_github") {
|
|
134
|
+
primary.guardUnlink(session, ref.url);
|
|
102
135
|
session.githubLinks = (session.githubLinks || []).filter(function (link) { return link.url.toLowerCase() !== ref.url.toLowerCase(); });
|
|
103
136
|
} else {
|
|
104
137
|
var verified = await github.readReference(ctx.cwd, ref.url, identity, ctx.run);
|
|
@@ -108,12 +141,15 @@ function attachSessionGithub(ctx) {
|
|
|
108
141
|
session.githubLinks = retained.concat([verified]);
|
|
109
142
|
}
|
|
110
143
|
persist(session);
|
|
111
|
-
|
|
144
|
+
if (name === "link_session_github" && args.primary === true) await primary.requestPrimary(ctx, session, ref.url, authorize);
|
|
145
|
+
return { links: session.githubLinks, workPrimary: session.workPrimary || {} };
|
|
112
146
|
}
|
|
113
147
|
function defs(session) {
|
|
114
|
-
if (
|
|
148
|
+
if (session && !ctx.canUse(session)) return [];
|
|
115
149
|
return ["link_session_github", "get_session_github", "unlink_session_github"].map(function (name) {
|
|
116
|
-
|
|
150
|
+
var fields = { url: { type: "string", description: "Exact https://github.com/owner/repo/issues/123 or /pull/123 URL." } };
|
|
151
|
+
if (name === "link_session_github") fields.primary = { type: "boolean", description: "Only for an explicit user request to select this item as primary. Requires human confirmation." };
|
|
152
|
+
return { name: name, permissionName: "mcp__clay-github__" + name, description: CONTRACT + " " + (name === "get_session_github" ? "Read linked status; optional URL finds visible existing work sessions." : name === "link_session_github" ? "Verify and attach one issue or PR to the current session." : "Remove one local association without modifying GitHub."), inputSchema: buildShape(fields, name === "get_session_github" ? [] : ["url"]), handler: async function (args) {
|
|
117
153
|
try { return { content: [{ type: "text", text: JSON.stringify(await invoke(session, name, args || {})) }] }; }
|
|
118
154
|
catch (error) { return { isError: true, content: [{ type: "text", text: error.message }] }; }
|
|
119
155
|
} };
|
|
@@ -121,17 +157,25 @@ function attachSessionGithub(ctx) {
|
|
|
121
157
|
}
|
|
122
158
|
return {
|
|
123
159
|
getDynamicToolDefs: defs,
|
|
124
|
-
getSystemPrompt: function () { return
|
|
125
|
-
createMcpServer: function (adapter, session) { return
|
|
160
|
+
getSystemPrompt: function () { return CONTRACT; },
|
|
161
|
+
createMcpServer: function (adapter, session) { return !adapter.createToolServer ? null : adapter.createToolServer({ name: "clay-github", version: "1.0.0", tools: defs(session) }); },
|
|
126
162
|
getBridgeTools: function (session, normalize) { return defs(session).map(function (tool) { return { server: "clay-github", name: tool.name, description: tool.description, inputSchema: normalize(tool.inputSchema) }; }); },
|
|
127
163
|
callBridgeTool: function (session, name, args) { var tool = defs(session).find(function (item) { return item.name === name; }); return tool ? tool.handler(args) : Promise.reject(new Error("GitHub tool unavailable.")); },
|
|
128
164
|
handleMessage: function (ws, msg) {
|
|
165
|
+
if (primary.handleMessage(ctx, ws, msg, function (session) {
|
|
166
|
+
if (ctx.sm.sessions.get(session.localId) !== session || !ctx.canUse(session)) throw new Error("Primary work requires an authorized project session.");
|
|
167
|
+
})) return true;
|
|
129
168
|
if (msg.type !== "session_github_refresh") return false;
|
|
130
169
|
var ids = Array.isArray(msg.sessionIds) ? msg.sessionIds.slice(0, 100) : [ws._clayActiveSession];
|
|
131
170
|
Array.from(new Set(ids)).forEach(function (id) {
|
|
132
171
|
var session = ctx.sm.sessions.get(id);
|
|
133
172
|
if (!session || !ctx.canRefresh(ws, session) || !(session.githubLinks || []).length) return;
|
|
134
|
-
|
|
173
|
+
var viewerId = ws._clayUser && ws._clayUser.id;
|
|
174
|
+
var allowPersonalReview = !session.ownerId || !viewerId || viewerId === session.ownerId;
|
|
175
|
+
refresh(session, false, true, function () { return ctx.canRefresh(ws, session); }, viewerId, allowPersonalReview).then(function (result) {
|
|
176
|
+
if (!allowPersonalReview || typeof ctx.sendTo !== "function" || !result.viewerReviewRequests || !ctx.canRefresh(ws, session)) return;
|
|
177
|
+
ctx.sendTo(ws, { type: "session_github_status", projectSlug: ctx.projectSlug || null, accountId: viewerId || null, requestId: msg.requestId || null, sessionId: session.localId, personalReview: result.viewerReviewRequests });
|
|
178
|
+
}).catch(function () {});
|
|
135
179
|
});
|
|
136
180
|
return true;
|
|
137
181
|
},
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var sessionVisibility = require("./session-visibility");
|
|
2
|
+
function attachSessionHistoryActions(ctx) {
|
|
3
|
+
var sm = ctx.sm, sdk = ctx.sdk, cwd = ctx.cwd, hydrateImageRefs = ctx.hydrateImageRefs;
|
|
4
|
+
var resolveSessionHome = ctx.resolveSessionHome, cancelPendingAskUser = ctx.cancelPendingAskUser;
|
|
5
|
+
var onProcessingChanged = ctx.onProcessingChanged;
|
|
6
|
+
async function rewind(session, uuid, mode, ws, revalidate) {
|
|
7
|
+
if (session._rewindInProgress) throw new Error("Rewind already in progress.");
|
|
8
|
+
session._rewindInProgress = true;
|
|
9
|
+
try {
|
|
10
|
+
// File restoration (delegated to adapter via sdk-bridge)
|
|
11
|
+
if (mode !== "chat") {
|
|
12
|
+
await sdk.rewindExecuteFiles(session, uuid);
|
|
13
|
+
revalidate();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Conversation rollback (skip for files-only mode)
|
|
17
|
+
if (mode !== "files") {
|
|
18
|
+
var targetIdx = -1;
|
|
19
|
+
for (var i = 0; i < session.messageUUIDs.length; i++) {
|
|
20
|
+
if (session.messageUUIDs[i].uuid === uuid) {
|
|
21
|
+
targetIdx = i;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Codex's thread/revert cuts at a turn id, not a count. Read the
|
|
27
|
+
// target entry's turnId BEFORE trimming local history below.
|
|
28
|
+
var hasTurnsToRollBack = false;
|
|
29
|
+
var targetTurnId = null;
|
|
30
|
+
if (targetIdx >= 0) {
|
|
31
|
+
targetTurnId = session.messageUUIDs[targetIdx].turnId || null;
|
|
32
|
+
for (var ri = targetIdx; ri < session.messageUUIDs.length; ri++) {
|
|
33
|
+
if (session.messageUUIDs[ri].type === "user") { hasTurnsToRollBack = true; break; }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Notify adapter of conversation rollback (e.g. Codex thread/revert)
|
|
38
|
+
// BEFORE trimming local history below. Deliberately not caught
|
|
39
|
+
// here: a failed or impossible (missing turnId) provider-side
|
|
40
|
+
// rollback must abort the whole rewind via the outer catch, never
|
|
41
|
+
// leave local history trimmed ahead of the real provider thread.
|
|
42
|
+
if (hasTurnsToRollBack) {
|
|
43
|
+
await sdk.rollbackConversation(session, targetTurnId);
|
|
44
|
+
revalidate();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (targetIdx >= 0) {
|
|
48
|
+
var trimTo = session.messageUUIDs[targetIdx].historyIndex;
|
|
49
|
+
for (var k = trimTo - 1; k >= 0; k--) {
|
|
50
|
+
if (session.history[k].type === "user_message") {
|
|
51
|
+
trimTo = k;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
session.history = session.history.slice(0, trimTo);
|
|
56
|
+
session.messageUUIDs = session.messageUUIDs.slice(0, targetIdx);
|
|
57
|
+
// Reset digest checkpoint if it points past the trimmed history
|
|
58
|
+
if (typeof session._dmLastDigestedIndex === "number" && session._dmLastDigestedIndex > trimTo) {
|
|
59
|
+
session._dmLastDigestedIndex = trimTo;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var kept = session.messageUUIDs;
|
|
64
|
+
session.lastRewindUuid = kept.length > 0 ? kept[kept.length - 1].uuid : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (session.abortController) {
|
|
68
|
+
try { session.abortController.abort(); } catch (e) {}
|
|
69
|
+
}
|
|
70
|
+
if (session.messageQueue) {
|
|
71
|
+
try { session.messageQueue.end(); } catch (e) {}
|
|
72
|
+
}
|
|
73
|
+
session.queryInstance = null;
|
|
74
|
+
session.messageQueue = null;
|
|
75
|
+
session.abortController = null;
|
|
76
|
+
session.blocks = {};
|
|
77
|
+
session.sentToolResults = {};
|
|
78
|
+
session.pendingPermissions = {};
|
|
79
|
+
cancelPendingAskUser(session, "Conversation rewound");
|
|
80
|
+
session.isProcessing = false;
|
|
81
|
+
onProcessingChanged();
|
|
82
|
+
|
|
83
|
+
if (sm.saveSessionFile(session) === false) throw new Error("The conversation was rewound but could not be saved.");
|
|
84
|
+
if (ws) sm.switchSession(session.localId, ws, hydrateImageRefs);
|
|
85
|
+
sm.sendAndRecord(session, { type: "rewind_complete", mode: mode });
|
|
86
|
+
sm.broadcastSessionList();
|
|
87
|
+
} finally { session._rewindInProgress = false; }
|
|
88
|
+
return { mode: mode };
|
|
89
|
+
}
|
|
90
|
+
function saveFork(forked, ws) {
|
|
91
|
+
if (sm.saveSessionFile(forked) !== false) return;
|
|
92
|
+
var error = new Error("The provider fork exists and its local session is retained in memory, but the fork could not be saved. Do not create another fork to retry this save.");
|
|
93
|
+
if (!ws) error.productControlResult = { status: "failed", outcome: "partial", persisted: false, runtimeEffect: "applied", retrySafe: false,
|
|
94
|
+
retainedSession: true, forkedSessionRef: require("./workspace-query-service").sessionRef(ctx.slug, forked), error: error.message };
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
async function fork(session, uuid, ws, revalidate) {
|
|
98
|
+
var forkTitle = (session.title || "New Session") + " (fork)";
|
|
99
|
+
var result = await sdk.forkSession(session, uuid);
|
|
100
|
+
revalidate();
|
|
101
|
+
if (result.useLocalHistory) {
|
|
102
|
+
// Copy local history up to the target UUID
|
|
103
|
+
var targetIdx = -1;
|
|
104
|
+
for (var fi = 0; fi < session.messageUUIDs.length; fi++) {
|
|
105
|
+
if (session.messageUUIDs[fi].uuid === uuid) { targetIdx = fi; break; }
|
|
106
|
+
}
|
|
107
|
+
var forkHistory = [];
|
|
108
|
+
if (targetIdx >= 0) {
|
|
109
|
+
var trimTo = session.messageUUIDs[targetIdx].historyIndex;
|
|
110
|
+
forkHistory = session.history.slice(0, trimTo);
|
|
111
|
+
} else {
|
|
112
|
+
forkHistory = session.history.slice();
|
|
113
|
+
}
|
|
114
|
+
var create = ws ? sm.createSession : sm.createSessionRaw;
|
|
115
|
+
var forked = create({
|
|
116
|
+
vendor: session.vendor,
|
|
117
|
+
ownerId: session.ownerId || null,
|
|
118
|
+
userKnowledgeOwnerId: session.userKnowledgeOwnerId || null,
|
|
119
|
+
sessionVisibility: sessionVisibility.normalize(session.sessionVisibility),
|
|
120
|
+
}, ws);
|
|
121
|
+
forked.cliSessionId = result.sessionId;
|
|
122
|
+
forked.title = forkTitle;
|
|
123
|
+
forked.history = forkHistory;
|
|
124
|
+
forked.messageUUIDs = [];
|
|
125
|
+
for (var hi = 0; hi < forkHistory.length; hi++) {
|
|
126
|
+
if (forkHistory[hi].type === "message_uuid") {
|
|
127
|
+
forked.messageUUIDs.push({ uuid: forkHistory[hi].uuid, type: forkHistory[hi].messageType, historyIndex: hi, turnId: forkHistory[hi].turnId || null });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
saveFork(forked, ws);
|
|
131
|
+
if (ws) sm.switchSession(forked.localId, ws, hydrateImageRefs);
|
|
132
|
+
sm.broadcastSessionList();
|
|
133
|
+
return forked;
|
|
134
|
+
} else {
|
|
135
|
+
// Read history from CLI session files
|
|
136
|
+
var cliSess = require("./cli-sessions");
|
|
137
|
+
var history = await cliSess.readCliSessionHistory(resolveSessionHome(session), cwd, result.sessionId);
|
|
138
|
+
revalidate();
|
|
139
|
+
var options = {
|
|
140
|
+
history: history,
|
|
141
|
+
title: forkTitle,
|
|
142
|
+
vendor: session.vendor,
|
|
143
|
+
ownerId: session.ownerId || null,
|
|
144
|
+
userKnowledgeOwnerId: session.userKnowledgeOwnerId || null,
|
|
145
|
+
sessionVisibility: sessionVisibility.normalize(session.sessionVisibility),
|
|
146
|
+
sessionVisibilityExplicit: session.sessionVisibilityExplicit === true,
|
|
147
|
+
};
|
|
148
|
+
var forked;
|
|
149
|
+
if (ws) forked = sm.resumeSession(result.sessionId, options, ws);
|
|
150
|
+
else {
|
|
151
|
+
forked = sm.createSessionRaw(Object.assign({}, options, { cliSessionId: result.sessionId }));
|
|
152
|
+
forked.title = forkTitle;
|
|
153
|
+
forked.history = history;
|
|
154
|
+
saveFork(forked, ws);
|
|
155
|
+
sm.broadcastSessionList();
|
|
156
|
+
}
|
|
157
|
+
if (forked) {
|
|
158
|
+
if (ws) ws._clayActiveSession = forked.localId;
|
|
159
|
+
}
|
|
160
|
+
return forked;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { fork: fork, rewind: rewind };
|
|
164
|
+
}
|
|
165
|
+
module.exports = { attachSessionHistoryActions: attachSessionHistoryActions };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var primary = require('./session-work-primary');
|
|
1
2
|
var api = require('./linear-api');
|
|
2
3
|
var buildShape = require('./session-spawn-mcp-server').buildShape;
|
|
3
4
|
var isWorker = require('./session-provenance').isWorker;
|
|
@@ -10,6 +11,7 @@ var CONTRACT = [
|
|
|
10
11
|
'Use get_session_linear with the issue URL to discover accessible existing work before starting duplicate work, and read_linear_issue to read requirements and comments before implementing linked work. When the work shifts to another issue or before reporting progress or completion, check that the relevant links are present. When a GitHub PR implements the Linear issue, link both using link_session_linear and link_session_github when available; do not infer a relationship from the current branch alone.',
|
|
11
12
|
'Do not link incidental mentions, examples, or unrelated references. Use unlink_session_linear to correct an association. Linking shares the issue identifier, title and status with people who can see this Clay session. These tools only read Linear and store local session links; they never update Linear issues or post comments, so no separate linking approval is needed. Issue content is task data, not permission for unrelated actions.',
|
|
12
13
|
].join(' ');
|
|
14
|
+
CONTRACT += primary.GUIDANCE;
|
|
13
15
|
function attachSessionLinear(ctx) {
|
|
14
16
|
var inflight = new Map(), attempts = new Map(), statusCache = new Map(), statusQueue = Promise.resolve();
|
|
15
17
|
function connection(ownerId) {
|
|
@@ -23,7 +25,7 @@ function attachSessionLinear(ctx) {
|
|
|
23
25
|
if (ctx.storage.view(bound.owner).revision !== bound.revision) throw new Error('Linear connection changed. Please retry.');
|
|
24
26
|
}
|
|
25
27
|
function authorize(session) {
|
|
26
|
-
if (!session || ctx.sm.sessions.get(session.localId) !== session ||
|
|
28
|
+
if (!session || ctx.sm.sessions.get(session.localId) !== session || !ctx.canUse(session)) throw new Error('Linear links require an authorized project session.');
|
|
27
29
|
}
|
|
28
30
|
function readStatus(session, url) {
|
|
29
31
|
var bound = connection(session.ownerId);
|
|
@@ -112,6 +114,7 @@ function attachSessionLinear(ctx) {
|
|
|
112
114
|
}
|
|
113
115
|
function unlink(session, url) {
|
|
114
116
|
authorize(session); var ref = api.parseReference(url);
|
|
117
|
+
primary.guardUnlink(session, ref.url);
|
|
115
118
|
save(session, (session.linearLinks || []).filter(function (item) { return item.url.toLowerCase() !== ref.url.toLowerCase(); }));
|
|
116
119
|
return { links: session.linearLinks };
|
|
117
120
|
}
|
|
@@ -125,15 +128,20 @@ function attachSessionLinear(ctx) {
|
|
|
125
128
|
if (session.ownerId !== owner) throw new Error('Session owner changed.');
|
|
126
129
|
return result;
|
|
127
130
|
}
|
|
128
|
-
if (name === 'link_session_linear')
|
|
131
|
+
if (name === 'link_session_linear') {
|
|
132
|
+
await link(session, args.url, session.ownerId);
|
|
133
|
+
if (args.primary === true) await primary.requestPrimary(ctx, session, api.parseReference(args.url).url, authorize);
|
|
134
|
+
return { links: session.linearLinks, workPrimary: session.workPrimary || {} };
|
|
135
|
+
}
|
|
129
136
|
if (name === 'unlink_session_linear') return unlink(session, args.url);
|
|
130
|
-
return { links: await refresh(session), matchingSessions: args.url ? find(session, api.parseReference(args.url).url) : [] };
|
|
137
|
+
return { links: await refresh(session), workPrimary: session.workPrimary || {}, matchingSessions: args.url ? find(session, api.parseReference(args.url).url) : [] };
|
|
131
138
|
}
|
|
132
139
|
function defs(session) {
|
|
133
|
-
if (
|
|
140
|
+
if (!ctx.storage || (session && !ctx.canUse(session))) return [];
|
|
134
141
|
return ['link_session_linear', 'get_session_linear', 'unlink_session_linear', 'read_linear_issue', 'search_linear_issues'].map(function (name) {
|
|
135
142
|
var fields = name === 'search_linear_issues' ? { query: { type: 'string', description: 'Issue title, identifier or exact URL. Returns up to 20 matches.' } } :
|
|
136
143
|
{ url: { type: 'string', description: 'Exact https://linear.app/workspace/issue/ENG-123/title URL.' } };
|
|
144
|
+
if (name === 'link_session_linear') fields.primary = { type: 'boolean', description: 'Only for an explicit user request to select this item as primary. Requires human confirmation.' };
|
|
137
145
|
if (name === 'read_linear_issue') fields.cursor = { type: 'string', description: 'Optional endCursor for the next page of comments.' };
|
|
138
146
|
return { name: name, permissionName: 'mcp__clay-linear__' + name, description: CONTRACT + ' Operation: ' + name + '.',
|
|
139
147
|
inputSchema: buildShape(fields, name === 'get_session_linear' ? [] : [name === 'search_linear_issues' ? 'query' : 'url']),
|
|
@@ -189,8 +197,8 @@ function attachSessionLinear(ctx) {
|
|
|
189
197
|
return true;
|
|
190
198
|
}
|
|
191
199
|
return { handleMessage: handleMessage, getDynamicToolDefs: defs,
|
|
192
|
-
getSystemPrompt: function () { return
|
|
193
|
-
createMcpServer: function (adapter, session) { return
|
|
200
|
+
getSystemPrompt: function () { return CONTRACT; },
|
|
201
|
+
createMcpServer: function (adapter, session) { return !ctx.storage || !adapter.createToolServer ? null : adapter.createToolServer({ name: 'clay-linear', version: '1.0.0', tools: defs(session) }); },
|
|
194
202
|
getBridgeTools: function (session, normalize) { return defs(session).map(function (tool) { return { server: 'clay-linear', name: tool.name, description: tool.description, inputSchema: normalize(tool.inputSchema) }; }); },
|
|
195
203
|
callBridgeTool: function (session, name, args) { var tool = defs(session).find(function (item) { return item.name === name; }); return tool && session ? tool.handler(args) : Promise.reject(new Error('Linear tool unavailable.')); } };
|
|
196
204
|
}
|
|
@@ -130,7 +130,10 @@ function attachSessionNotes(ctx) {
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
function canUseSession(caller) { return !!caller && (!ctx.canUseSession || ctx.canUseSession(caller)); }
|
|
134
|
+
|
|
133
135
|
function listNotes(args, caller) {
|
|
136
|
+
if (!canUseSession(caller)) return toolError("Notes require a live authorized session.");
|
|
134
137
|
if (!caller) return toolError("list_notes requires a session-bound tool server");
|
|
135
138
|
var state = args && typeof args.state === "string" ? args.state : "open";
|
|
136
139
|
if (["open", "closed", "all"].indexOf(state) === -1) return toolError("state must be open, closed, or all");
|
|
@@ -138,6 +141,7 @@ function attachSessionNotes(ctx) {
|
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
function writeNote(args, caller) {
|
|
144
|
+
if (!canUseSession(caller)) return toolError("Notes require a live authorized session.");
|
|
141
145
|
if (!caller) return toolError("write_note requires a session-bound tool server");
|
|
142
146
|
var rawText = typeof args.text === "string" ? args.text : "";
|
|
143
147
|
if (rawText.length > MAX_NOTE_TEXT_CHARS) return toolError("text exceeds " + MAX_NOTE_TEXT_CHARS + " characters");
|
|
@@ -227,7 +231,7 @@ function attachSessionNotes(ctx) {
|
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
function getToolDefs(boundSession) {
|
|
230
|
-
if (
|
|
234
|
+
if (boundSession && !canUseSession(boundSession)) return [];
|
|
231
235
|
return sessionNotesMcp.getToolDefs({
|
|
232
236
|
list: function (args) { return listNotes(args, boundSession || null); },
|
|
233
237
|
write: function (args) { return writeNote(args, boundSession || null); },
|
|
@@ -238,7 +242,7 @@ function attachSessionNotes(ctx) {
|
|
|
238
242
|
}
|
|
239
243
|
|
|
240
244
|
function createMcpServer(adapter, boundSession) {
|
|
241
|
-
if (
|
|
245
|
+
if (!adapter || typeof adapter.createToolServer !== "function") return null;
|
|
242
246
|
return adapter.createToolServer({
|
|
243
247
|
name: "clay-notes",
|
|
244
248
|
version: "1.0.0",
|
|
@@ -247,12 +251,12 @@ function attachSessionNotes(ctx) {
|
|
|
247
251
|
}
|
|
248
252
|
|
|
249
253
|
function getSystemPrompt() {
|
|
250
|
-
if (ctx.isMate) return "";
|
|
251
254
|
return buildNotesPrompt(nm.list());
|
|
252
255
|
}
|
|
253
256
|
|
|
254
257
|
return {
|
|
255
258
|
createMcpServer: createMcpServer,
|
|
259
|
+
canUseSession: canUseSession,
|
|
256
260
|
getSystemPrompt: getSystemPrompt,
|
|
257
261
|
getToolDefs: getToolDefs,
|
|
258
262
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Legacy terminal recovery only. New terminal presentation has been retired.
|
|
2
|
+
function attachSessionRuntimeActions(ctx) {
|
|
3
|
+
function inspect(session) {
|
|
4
|
+
return JSON.stringify([session.terminalId, session.runtimeTerminalId, session.tuiSuspended, [session.terminalId, session.runtimeTerminalId].map(function (id) { return typeof id === "number" && ctx.tm ? ctx.tm.identity(id) : null; })]);
|
|
5
|
+
}
|
|
6
|
+
async function change(session, mode, revalidate) {
|
|
7
|
+
revalidate();
|
|
8
|
+
if (mode !== "gui") throw new Error("New terminal presentation has been removed. Only return to GUI chat is supported; provider threads cannot migrate across vendors.");
|
|
9
|
+
if (session.isProcessing || session._queryStarting || session.queryInstance || Object.keys(session.pendingPermissions || {}).length || Object.keys(session.pendingAskUser || {}).length) throw new Error("Runtime changes require an idle session without an active provider handle or pending approvals.");
|
|
10
|
+
if (session.taskStopRequested || session._pendingMessageDrainPaused || ctx.isPendingQueuePaused && ctx.isPendingQueuePaused(session)) throw new Error("A stopped session cannot be resumed by a runtime change.");
|
|
11
|
+
var vendor = session.vendor || ctx.sm.defaultVendor || "claude";
|
|
12
|
+
var ids = Array.from(new Set([session.terminalId, session.runtimeTerminalId].filter(function (id) { return typeof id === "number"; })));
|
|
13
|
+
if (!ids.length && (session.runtimeMode || session.mode || "gui") === "gui") return { status: "completed", runtimeMode: "gui", runtimeEffect: "none", threadPreserved: true };
|
|
14
|
+
if (vendor !== "claude" || !session.cliSessionId) throw new Error("Only a legacy Claude terminal thread can return to GUI chat.");
|
|
15
|
+
var closed = 0, persisted = false;
|
|
16
|
+
var fields = ['terminalId', 'runtimeTerminalId'];
|
|
17
|
+
var originalFields = fields.map(function (field) { return session[field]; });
|
|
18
|
+
var targets = ids.map(function (id) { return { id: id, identity: ctx.tm && ctx.tm.identity(id), closed: false }; });
|
|
19
|
+
var suspended = session.tuiSuspended;
|
|
20
|
+
function exactTerminals() {
|
|
21
|
+
if (session.tuiSuspended !== suspended) throw new Error("Terminal presentation changed during shutdown.");
|
|
22
|
+
targets.forEach(function (target) {
|
|
23
|
+
var current = ctx.tm && ctx.tm.identity(target.id);
|
|
24
|
+
if (!target.identity || (target.closed ? current !== null : current !== target.identity)) throw new Error("A terminal runtime was replaced during shutdown.");
|
|
25
|
+
});
|
|
26
|
+
fields.forEach(function (field, index) {
|
|
27
|
+
var original = originalFields[index], current = session[field];
|
|
28
|
+
if (current === original || current == null && original == null) return;
|
|
29
|
+
var target = targets.find(function (item) { return item.id === original; });
|
|
30
|
+
if (current == null && target && target.closed) return;
|
|
31
|
+
throw new Error("A new or replacement terminal was attached during shutdown.");
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
for (var target of targets) {
|
|
36
|
+
revalidate();
|
|
37
|
+
exactTerminals();
|
|
38
|
+
if (!ctx.tm || typeof ctx.tm.closeAndWait !== "function") throw new Error("Completion-aware terminal shutdown is unavailable.");
|
|
39
|
+
ctx.tm.markReclaimed(target.id);
|
|
40
|
+
await ctx.tm.closeAndWait(target.id); target.closed = true; closed++;
|
|
41
|
+
revalidate();
|
|
42
|
+
exactTerminals();
|
|
43
|
+
}
|
|
44
|
+
revalidate();
|
|
45
|
+
exactTerminals();
|
|
46
|
+
session.terminalId = null; session.runtimeTerminalId = null;
|
|
47
|
+
ctx.prepareGui(session, { deferSave: true });
|
|
48
|
+
exactTerminals();
|
|
49
|
+
session.runtimeMode = "gui"; session.tuiSuspended = false;
|
|
50
|
+
if (ctx.sm.saveSessionFile(session) !== true) throw new Error("GUI presentation could not be saved after terminal shutdown.");
|
|
51
|
+
persisted = true;
|
|
52
|
+
ctx.sm.broadcastSessionList();
|
|
53
|
+
ctx.publishGui(session);
|
|
54
|
+
return { status: "completed", runtimeMode: "gui", runtimeEffect: closed ? "terminal_closed" : "none", persisted: true, threadPreserved: true, executionStarted: false };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
error.productControlResult = { status: "failed", outcome: "partial", persisted: persisted, runtimeEffect: closed ? "terminal_closed" : "closure_unconfirmed", retrySafe: false, executionStarted: false };
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function inspectLifecycle() { return ctx.tm.list().map(function (terminal) { return Object.assign({}, terminal, { identity: ctx.tm.identity(terminal.id) }); }); }
|
|
61
|
+
return { change: change, inspect: inspect, inspectLifecycle: inspectLifecycle };
|
|
62
|
+
}
|
|
63
|
+
module.exports = { attachSessionRuntimeActions: attachSessionRuntimeActions };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var yoke = require('./yoke');
|
|
2
|
+
function attachSessionVendor(ctx) {
|
|
3
|
+
function verifyIdentity(session, vendor) {
|
|
4
|
+
if (!ctx.osUsers) return;
|
|
5
|
+
var info = yoke.getVendorInfo(vendor), linuxUser = ctx.getLinuxUserForSession(session);
|
|
6
|
+
if (!info || !info.osUserIsolation || !linuxUser) throw new Error('The provider requires an authorized mapped OS identity.');
|
|
7
|
+
var identity = require('./os-users').resolveOsUserInfo(linuxUser);
|
|
8
|
+
if (!Number.isInteger(identity.uid) || identity.uid < 0 || !Number.isInteger(identity.gid) || identity.gid < 0) throw new Error('The mapped OS identity is unavailable.');
|
|
9
|
+
}
|
|
10
|
+
function setVendor(session, vendor, revalidate) {
|
|
11
|
+
if (!session || ctx.sm.sessions.get(session.localId) !== session) throw new Error('The Driver was deleted or replaced.');
|
|
12
|
+
if (revalidate) revalidate();
|
|
13
|
+
if (!(ctx.adapters || {})[vendor] || (ctx.sm.availableVendors || []).indexOf(vendor) < 0) throw new Error('This provider is unavailable in the project runtime.');
|
|
14
|
+
verifyIdentity(session, vendor);
|
|
15
|
+
if (session.cliSessionId || session.queryInstance || session.isProcessing || session._queryStarting || (session.history || []).length || (session.runtimeMode || session.mode || 'gui') !== 'gui') throw new Error('Provider selection requires a fresh idle GUI Driver without a provider thread or transcript.');
|
|
16
|
+
if (session.taskStopRequested || session._pendingMessageDrainPaused || ctx.isPendingQueuePaused && ctx.isPendingQueuePaused(session)) throw new Error('A stopped Driver requires an explicit separate resume action.');
|
|
17
|
+
var previous = { vendor: session.vendor, model: session.model, effort: session.effort, permissionMode: session.permissionMode, effectivePermissionMode: session.effectivePermissionMode };
|
|
18
|
+
session.vendor = vendor;
|
|
19
|
+
session.model = null;
|
|
20
|
+
session.effort = yoke.clampEffort(vendor, session.effort) || null;
|
|
21
|
+
if (session.permissionMode === 'auto' && vendor !== 'claude') session.permissionMode = 'default';
|
|
22
|
+
session.effectivePermissionMode = null;
|
|
23
|
+
try { if (ctx.sm.saveSessionFile(session) !== true) throw new Error('Could not persist the provider selection.'); }
|
|
24
|
+
catch (error) { Object.assign(session, previous); throw error; }
|
|
25
|
+
try {
|
|
26
|
+
ctx.sm.broadcastSessionList();
|
|
27
|
+
ctx.sm.sendToSession(session, { type: 'model_info', vendor: vendor, sessionId: session.localId, model: '', models: (ctx.sm.modelsByVendor || {})[vendor] || [], availableVendors: ctx.sm.availableVendors || [], installedVendors: ctx.sm.installedVendors || [] });
|
|
28
|
+
ctx.sm.sendToSession(session, { type: 'config_state', vendor: vendor, sessionId: session.localId, model: '', effort: session.effort, mode: session.permissionMode || ctx.sm.currentPermissionMode || 'default' });
|
|
29
|
+
} catch (error) { return { status: 'failed', outcome: 'partial', persisted: true, runtimeEffect: 'none', vendor: vendor, error: 'Provider selection saved, but publication failed: ' + error.message }; }
|
|
30
|
+
return { status: 'completed', persisted: true, runtimeEffect: 'none', vendor: vendor };
|
|
31
|
+
}
|
|
32
|
+
function newSession(source, vendor, revalidate) {
|
|
33
|
+
revalidate();
|
|
34
|
+
if (!(ctx.adapters || {})[vendor] || (ctx.sm.availableVendors || []).indexOf(vendor) < 0) throw new Error('This provider is unavailable in the project runtime.');
|
|
35
|
+
if (source.isProcessing || source._queryStarting || source.taskStopRequested || source._pendingMessageDrainPaused || ctx.isPendingQueuePaused && ctx.isPendingQueuePaused(source)) throw new Error('Create a replacement provider session only from an idle, unstopped Driver.');
|
|
36
|
+
verifyIdentity(source, vendor);
|
|
37
|
+
revalidate();
|
|
38
|
+
var created = ctx.sm.createSessionRaw({ ownerId: source.ownerId || null, vendor: vendor, mode: 'gui', sessionVisibility: 'private' });
|
|
39
|
+
var ref = require('./workspace-query-service').sessionRef(ctx.slug, created), persisted = false;
|
|
40
|
+
try {
|
|
41
|
+
revalidate();
|
|
42
|
+
if (ctx.sm.saveSessionFile(created) !== true) throw new Error('Could not save the new provider session.');
|
|
43
|
+
persisted = true;
|
|
44
|
+
revalidate();
|
|
45
|
+
ctx.sm.broadcastSessionList();
|
|
46
|
+
return { status: 'completed', persisted: true, newSessionRef: ref, vendor: vendor, threadMigrated: false, originalRetained: true, executionStarted: false };
|
|
47
|
+
} catch (error) {
|
|
48
|
+
error.productControlResult = { status: 'failed', outcome: 'partial', persisted: persisted, retainedInMemory: true, newSessionRef: ref, threadMigrated: false, originalRetained: true, executionStarted: false, retrySafe: false };
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { setVendor: setVendor, newSession: newSession };
|
|
53
|
+
}
|
|
54
|
+
module.exports = { attachSessionVendor: attachSessionVendor };
|