clay-server 4.1.0-beta.9 → 4.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/lib/context-usage.js +47 -0
  2. package/lib/daemon-project-access.js +14 -0
  3. package/lib/daemon.js +7 -0
  4. package/lib/issues-mcp-server.js +1 -1
  5. package/lib/issues-service.js +3 -1
  6. package/lib/loop-registry-occurrence.js +1 -0
  7. package/lib/notes.js +20 -3
  8. package/lib/os-users.js +6 -0
  9. package/lib/project-connection.js +14 -3
  10. package/lib/project-file-path.js +13 -0
  11. package/lib/project-file-watch.js +19 -8
  12. package/lib/project-filesystem.js +10 -16
  13. package/lib/project-http.js +53 -48
  14. package/lib/project-issue-launch.js +3 -1
  15. package/lib/project-logs-mcp-server.js +8 -8
  16. package/lib/project-logs-schema.js +1 -1
  17. package/lib/project-logs-service.js +46 -13
  18. package/lib/project-logs-store.js +17 -15
  19. package/lib/project-logs.js +70 -0
  20. package/lib/project-loop.js +1 -0
  21. package/lib/project-notifications.js +1 -1
  22. package/lib/project-scheduled-result-store.js +131 -0
  23. package/lib/project-scheduled-task-execution.js +35 -2
  24. package/lib/project-session-notes.js +11 -4
  25. package/lib/project-sessions.js +39 -6
  26. package/lib/project-user-message.js +47 -0
  27. package/lib/project.js +57 -3
  28. package/lib/public/app.js +27 -9
  29. package/lib/public/css/avatar-imprints.css +1 -1
  30. package/lib/public/css/command-palette.css +57 -19
  31. package/lib/public/css/git-panel.css +13 -12
  32. package/lib/public/css/git-placard.css +4 -4
  33. package/lib/public/css/issues.css +79 -32
  34. package/lib/public/css/mobile-nav.css +7 -0
  35. package/lib/public/css/notifications-center.css +3 -3
  36. package/lib/public/css/project-logs.css +15 -0
  37. package/lib/public/css/sidebar.css +7 -0
  38. package/lib/public/css/sticky-notes.css +29 -0
  39. package/lib/public/index.html +10 -0
  40. package/lib/public/modules/app-connection.js +9 -1
  41. package/lib/public/modules/app-favicon.js +10 -0
  42. package/lib/public/modules/app-messages.js +50 -12
  43. package/lib/public/modules/app-notifications.js +2 -0
  44. package/lib/public/modules/app-panels.js +77 -23
  45. package/lib/public/modules/app-projects.js +2 -0
  46. package/lib/public/modules/app-rate-limit.js +148 -61
  47. package/lib/public/modules/avatar-imprint.js +25 -70
  48. package/lib/public/modules/avatar.js +12 -4
  49. package/lib/public/modules/chat-render-runtime.js +20 -0
  50. package/lib/public/modules/clay-issue-links.js +24 -2
  51. package/lib/public/modules/clay-log-links.js +12 -1
  52. package/lib/public/modules/context-view-preference.js +143 -0
  53. package/lib/public/modules/default-vendor.js +116 -0
  54. package/lib/public/modules/filebrowser-tabs.js +1 -0
  55. package/lib/public/modules/filebrowser.js +45 -18
  56. package/lib/public/modules/issues-render.js +36 -10
  57. package/lib/public/modules/issues.js +95 -13
  58. package/lib/public/modules/markdown.js +3 -1
  59. package/lib/public/modules/pane-bridge.js +14 -8
  60. package/lib/public/modules/pane-issue-bridge.js +27 -0
  61. package/lib/public/modules/permission-hints.js +13 -0
  62. package/lib/public/modules/profile.js +9 -9
  63. package/lib/public/modules/project-activation.js +49 -0
  64. package/lib/public/modules/project-logs-render.js +13 -3
  65. package/lib/public/modules/project-logs.js +45 -15
  66. package/lib/public/modules/project-session-visibility-settings.js +138 -0
  67. package/lib/public/modules/project-settings.js +5 -0
  68. package/lib/public/modules/right-workbench.js +44 -0
  69. package/lib/public/modules/scheduled-result-client.js +33 -0
  70. package/lib/public/modules/scheduled-result-display.js +50 -0
  71. package/lib/public/modules/scheduled-result-notification.js +31 -0
  72. package/lib/public/modules/scheduled-task-presentation.js +15 -0
  73. package/lib/public/modules/scheduled-tasks.js +9 -21
  74. package/lib/public/modules/sidebar-mobile.js +51 -3
  75. package/lib/public/modules/sidebar-projects.js +14 -3
  76. package/lib/public/modules/sidebar-sessions.js +65 -5
  77. package/lib/public/modules/split-session-boundary.js +28 -0
  78. package/lib/public/modules/split-view.js +42 -7
  79. package/lib/public/modules/sticky-notes-browser.js +130 -18
  80. package/lib/public/modules/sticky-notes.js +2 -3
  81. package/lib/public/modules/terminal.js +4 -4
  82. package/lib/public/modules/thinking-lifecycle.js +4 -1
  83. package/lib/public/modules/tools.js +5 -1
  84. package/lib/scheduled-run-state.js +10 -2
  85. package/lib/scheduler.js +1 -0
  86. package/lib/sdk-bridge.js +97 -61
  87. package/lib/sdk-message-processor.js +44 -13
  88. package/lib/sdk-skill-discovery.js +6 -28
  89. package/lib/sdk-turn-queue.js +14 -0
  90. package/lib/server-context-view.js +53 -0
  91. package/lib/server-default-vendor.js +60 -0
  92. package/lib/server.js +31 -7
  93. package/lib/session-notes-mcp-server.js +3 -5
  94. package/lib/session-pair-factory.js +2 -2
  95. package/lib/session-title-generator.js +89 -0
  96. package/lib/session-title-policy.js +8 -2
  97. package/lib/session-visibility.js +62 -1
  98. package/lib/sessions.js +28 -1
  99. package/lib/user-presence.js +6 -0
  100. package/lib/users-context-view-preferences.js +65 -0
  101. package/lib/users-default-vendor-preferences.js +80 -0
  102. package/lib/users.js +12 -0
  103. package/lib/ws-schema.js +13 -0
  104. package/lib/yoke/acp-agent-profiles.js +15 -2
  105. package/lib/yoke/adapters/acp.js +3 -2
  106. package/lib/yoke/adapters/antigravity.js +2 -2
  107. package/lib/yoke/adapters/claude-worker.js +11 -12
  108. package/lib/yoke/adapters/claude.js +75 -22
  109. package/lib/yoke/adapters/codex.js +216 -29
  110. package/lib/yoke/adapters/kiro.js +6 -5
  111. package/lib/yoke/claude-context-usage.js +57 -0
  112. package/lib/yoke/claude-message-correlation.js +31 -0
  113. package/lib/yoke/claude-model-switch.js +15 -0
  114. package/lib/yoke/index.js +5 -1
  115. package/lib/yoke/mcp-bridge-server.js +18 -5
  116. package/lib/yoke/session-skill-catalog.js +45 -0
  117. package/lib/yoke/skill-discovery.js +60 -20
  118. package/lib/yoke/vendor-registry.js +1 -1
  119. package/package.json +5 -7
@@ -0,0 +1,143 @@
1
+ import { store } from './store.js';
2
+ import { getWs } from './ws-ref.js';
3
+
4
+ var MODES = ["off", "mini", "panel"];
5
+ var sequence = 0;
6
+
7
+ function validMode(mode) { return MODES.indexOf(mode) !== -1; }
8
+ function nextRequestId(prefix) { sequence += 1; return prefix + Date.now() + "-" + sequence; }
9
+ function accountId() { return store.get("myUserId") || "default"; }
10
+ function initialState() {
11
+ return { mode: "off", canonicalMode: "off", preferencePresent: false, loading: false, saving: false, requestId: null, saveRequestId: null, pendingSaves: [], accountId: null, serverEpoch: null, rejectedEpoch: null, canonicalRevision: 0, error: "" };
12
+ }
13
+
14
+ function send(message) {
15
+ var ws = getWs();
16
+ if (!ws || ws.readyState !== 1) return false;
17
+ ws.send(JSON.stringify(message));
18
+ return true;
19
+ }
20
+
21
+ export function getContextView() {
22
+ var state = store.get("contextViewPreferenceState") || initialState();
23
+ return validMode(state.mode) ? state.mode : "off";
24
+ }
25
+
26
+ export function getEffectiveContextView() {
27
+ if (store.get("paneMode") !== true) return getContextView();
28
+ var override = store.get("contextViewOverride");
29
+ return override === null || override === undefined ? getContextView() : (validMode(override) ? override : getContextView());
30
+ }
31
+
32
+ export function beginContextViewConnection() {
33
+ var state = store.get("contextViewPreferenceState") || initialState();
34
+ store.set({ contextViewPreferenceState: Object.assign({}, state, {
35
+ mode: validMode(state.canonicalMode) ? state.canonicalMode : "off",
36
+ loading: false,
37
+ saving: false,
38
+ requestId: null,
39
+ saveRequestId: null,
40
+ pendingSaves: [],
41
+ rejectedEpoch: state.serverEpoch || null,
42
+ serverEpoch: null,
43
+ canonicalRevision: 0,
44
+ error: "",
45
+ }) });
46
+ }
47
+
48
+ export function requestContextView() {
49
+ var id = nextRequestId("context-view-");
50
+ var state = store.get("contextViewPreferenceState") || initialState();
51
+ store.set({ contextViewPreferenceState: Object.assign({}, state, { loading: true, requestId: id, error: "" }) });
52
+ if (!send({ type: "context_view_get", requestId: id })) {
53
+ store.set({ contextViewPreferenceState: Object.assign({}, store.get("contextViewPreferenceState") || initialState(), { loading: false, requestId: null, error: "Clay is offline. Reconnect and try again." }) });
54
+ return false;
55
+ }
56
+ return true;
57
+ }
58
+
59
+ export function setContextView(mode) {
60
+ if (!validMode(mode)) return false;
61
+ var id = nextRequestId("context-view-save-");
62
+ var state = store.get("contextViewPreferenceState") || initialState();
63
+ var pendingSaves = (state.pendingSaves || []).concat([{ requestId: id, mode: mode }]);
64
+ store.set({ contextViewPreferenceState: Object.assign({}, state, { mode: mode, saving: true, saveRequestId: id, pendingSaves: pendingSaves, error: "" }) });
65
+ if (!send({ type: "context_view_set", requestId: id, mode: mode })) {
66
+ var reverted = store.get("contextViewPreferenceState") || initialState();
67
+ pendingSaves = (reverted.pendingSaves || []).filter(function (item) { return item.requestId !== id; });
68
+ var pendingMode = pendingSaves.length ? pendingSaves[pendingSaves.length - 1].mode : (reverted.canonicalMode || "off");
69
+ store.set({ contextViewPreferenceState: Object.assign({}, reverted, { mode: pendingMode, saving: pendingSaves.length > 0, saveRequestId: pendingSaves.length ? pendingSaves[pendingSaves.length - 1].requestId : null, pendingSaves: pendingSaves, error: "Clay is offline. Reconnect and try again." }) });
70
+ return false;
71
+ }
72
+ return true;
73
+ }
74
+
75
+ export function handleContextViewMessage(msg) {
76
+ if (!msg || msg.type !== "context_view_state") return false;
77
+ var state = store.get("contextViewPreferenceState") || initialState();
78
+ var currentAccount = accountId();
79
+ var isGetReply = !!msg.requestId && msg.requestId === state.requestId;
80
+ var pendingSaves = state.pendingSaves || [];
81
+ var saveIndex = -1;
82
+ for (var i = 0; i < pendingSaves.length; i++) if (pendingSaves[i].requestId === msg.requestId) saveIndex = i;
83
+ var isSaveReply = !!msg.requestId && saveIndex !== -1;
84
+ var isOlderSaveRevision = isSaveReply && typeof msg.canonicalRevision === "number" && msg.canonicalRevision < (state.canonicalRevision || 0);
85
+ var isCorrelatedAccountFailure = (isGetReply || isSaveReply) && msg.accountId === null && msg.accountAvailable === false;
86
+ if ((!isCorrelatedAccountFailure && msg.accountId !== currentAccount) || (msg.accountId === null && !isCorrelatedAccountFailure)) return true;
87
+ if (msg.serverEpoch && state.serverEpoch && msg.serverEpoch !== state.serverEpoch && (!msg.requestId || (!isGetReply && !isSaveReply))) return true;
88
+ if (msg.serverEpoch && state.rejectedEpoch && msg.serverEpoch === state.rejectedEpoch && (!isGetReply && !isSaveReply)) return true;
89
+ if (msg.canonicalRevision !== undefined && msg.canonicalRevision < (state.canonicalRevision || 0) && msg.serverEpoch === state.serverEpoch && !isSaveReply) return true;
90
+ if (msg.requestId && !isGetReply && !isSaveReply) return true;
91
+ if (msg.requestId && !isSaveReply && msg.ready === false && state.saving) return true;
92
+ var next = Object.assign({}, state, {
93
+ accountId: msg.accountId || currentAccount,
94
+ serverEpoch: msg.serverEpoch || state.serverEpoch || null,
95
+ rejectedEpoch: isGetReply || isSaveReply ? null : state.rejectedEpoch || null,
96
+ canonicalRevision: isOlderSaveRevision ? (state.canonicalRevision || 0) : (typeof msg.canonicalRevision === "number" ? msg.canonicalRevision : state.canonicalRevision || 0),
97
+ loading: isGetReply ? false : state.loading,
98
+ saving: state.saving,
99
+ requestId: isGetReply ? null : state.requestId,
100
+ saveRequestId: state.saveRequestId,
101
+ error: msg.error || "",
102
+ });
103
+ if (Object.prototype.hasOwnProperty.call(msg, "mode") && validMode(msg.mode) && msg.ready !== false && !isCorrelatedAccountFailure) {
104
+ if (isSaveReply) {
105
+ if (!isOlderSaveRevision && msg.ready !== false) {
106
+ pendingSaves = pendingSaves.slice(saveIndex + 1);
107
+ } else {
108
+ pendingSaves = pendingSaves.filter(function (item) { return item.requestId !== msg.requestId; });
109
+ }
110
+ }
111
+ if (!isOlderSaveRevision) {
112
+ next.canonicalMode = msg.mode;
113
+ next.preferencePresent = msg.preferencePresent === true;
114
+ }
115
+ if (pendingSaves.length) {
116
+ next.mode = pendingSaves[pendingSaves.length - 1].mode;
117
+ next.saving = true;
118
+ next.saveRequestId = pendingSaves[pendingSaves.length - 1].requestId;
119
+ } else {
120
+ next.mode = next.canonicalMode;
121
+ next.saving = false;
122
+ next.saveRequestId = null;
123
+ }
124
+ next.pendingSaves = pendingSaves;
125
+ } else if (isSaveReply && (msg.ready === false || isCorrelatedAccountFailure)) {
126
+ pendingSaves = pendingSaves.filter(function (item) { return item.requestId !== msg.requestId; });
127
+ next.pendingSaves = pendingSaves;
128
+ next.mode = pendingSaves.length ? pendingSaves[pendingSaves.length - 1].mode : (state.canonicalMode || "off");
129
+ next.saving = pendingSaves.length > 0;
130
+ next.saveRequestId = pendingSaves.length ? pendingSaves[pendingSaves.length - 1].requestId : null;
131
+ }
132
+ store.set({ contextViewPreferenceState: next });
133
+ return true;
134
+ }
135
+
136
+ store.subscribe(function (state, previous) {
137
+ if (state.myUserId !== previous.myUserId || state.currentSlug !== previous.currentSlug) {
138
+ store.set({ contextViewPreferenceState: Object.assign({}, initialState(), { accountId: accountId() }), contextViewOverride: null });
139
+ if (state.connected) requestContextView();
140
+ }
141
+ });
142
+
143
+ export { validMode };
@@ -0,0 +1,116 @@
1
+ import { store } from './store.js';
2
+ import { getWs } from './ws-ref.js';
3
+ import { firstInstalledVendor } from './vendor-priority.js';
4
+
5
+ function send(message) {
6
+ var ws = getWs();
7
+ if (!ws || ws.readyState !== 1) return false;
8
+ ws.send(JSON.stringify(message));
9
+ return true;
10
+ }
11
+
12
+ var sequence = 0;
13
+
14
+ function nextRequestId(prefix) {
15
+ sequence += 1;
16
+ return prefix + Date.now() + "-" + sequence;
17
+ }
18
+
19
+ function emptyState(accountId, projectSlug) {
20
+ return { loading: false, saving: false, getRequestId: null, saveRequestId: null, preference: null, preferencePresent: false, installedVendors: [], accountId: accountId || null, projectSlug: projectSlug || null, serverEpoch: null, canonicalRevision: 0, error: "" };
21
+ }
22
+
23
+ export function requestDefaultVendor() {
24
+ var id = nextRequestId("default-vendor-");
25
+ var state = store.get("defaultVendorState") || {};
26
+ store.set({ defaultVendorState: Object.assign({}, state, { loading: true, getRequestId: id, error: "" }) });
27
+ if (!send({ type: "default_vendor_get", requestId: id })) {
28
+ store.set({ defaultVendorState: Object.assign({}, store.get("defaultVendorState") || {}, { loading: false, getRequestId: null, error: "Clay is offline. Reconnect and try again." }) });
29
+ return false;
30
+ }
31
+ return true;
32
+ }
33
+
34
+ export function beginDefaultVendorConnection() {
35
+ var state = store.get("defaultVendorState") || {};
36
+ store.set({ defaultVendorState: Object.assign({}, state, {
37
+ loading: false,
38
+ saving: false,
39
+ getRequestId: null,
40
+ saveRequestId: null,
41
+ preference: null,
42
+ preferencePresent: false,
43
+ installedVendors: [],
44
+ accountId: store.get("myUserId") || "default",
45
+ projectSlug: store.get("currentSlug") || null,
46
+ serverEpoch: null,
47
+ canonicalRevision: 0,
48
+ error: "",
49
+ }) });
50
+ }
51
+
52
+ export function saveDefaultVendor(vendor) {
53
+ var state = store.get("defaultVendorState") || {};
54
+ if (vendor !== "" && (state.installedVendors || []).indexOf(vendor) === -1) return false;
55
+ var id = nextRequestId("default-vendor-save-");
56
+ store.set({ defaultVendorState: Object.assign({}, state, { saving: true, saveRequestId: id, error: "" }) });
57
+ if (!send({ type: "default_vendor_set", requestId: id, vendor: vendor })) {
58
+ store.set({ defaultVendorState: Object.assign({}, store.get("defaultVendorState") || {}, { saving: false, saveRequestId: null, error: "Clay is offline. Reconnect and try again." }) });
59
+ return false;
60
+ }
61
+ return true;
62
+ }
63
+
64
+ export function handleDefaultVendorMessage(msg) {
65
+ if (!msg || msg.type !== "default_vendor_state") return false;
66
+ var state = store.get("defaultVendorState") || {};
67
+ var accountId = store.get("myUserId") || "default";
68
+ var projectSlug = store.get("currentSlug") || null;
69
+ var isGetReply = !!msg.requestId && msg.requestId === state.getRequestId;
70
+ var isSaveReply = !!msg.requestId && msg.requestId === state.saveRequestId;
71
+ var isCorrelatedAccountFailure = (isGetReply || isSaveReply) && msg.accountId === null && msg.accountAvailable === false;
72
+ if ((!isCorrelatedAccountFailure && msg.accountId !== accountId) || (msg.accountId === null && !isCorrelatedAccountFailure)) return true;
73
+ if (Object.prototype.hasOwnProperty.call(msg, "projectSlug") && msg.projectSlug !== projectSlug) return true;
74
+ if (msg.serverEpoch && state.serverEpoch && msg.serverEpoch !== state.serverEpoch && (!msg.requestId || (msg.requestId !== state.getRequestId && msg.requestId !== state.saveRequestId))) return true;
75
+ if (msg.canonicalRevision !== undefined && msg.canonicalRevision < (state.canonicalRevision || 0) && msg.serverEpoch === state.serverEpoch) return true;
76
+ if (msg.requestId && !isGetReply && !isSaveReply) return true;
77
+ if (msg.requestId && !isSaveReply && msg.ready === false && state.saving) return true;
78
+ var next = Object.assign({}, state, {
79
+ accountId: msg.accountId || accountId,
80
+ projectSlug: projectSlug,
81
+ serverEpoch: msg.serverEpoch || state.serverEpoch || null,
82
+ canonicalRevision: typeof msg.canonicalRevision === "number" ? msg.canonicalRevision : state.canonicalRevision || 0,
83
+ installedVendors: Array.isArray(msg.installedVendors) ? msg.installedVendors : state.installedVendors || [],
84
+ loading: isGetReply ? false : state.loading,
85
+ saving: isSaveReply ? false : state.saving,
86
+ getRequestId: isGetReply ? null : state.getRequestId,
87
+ saveRequestId: isSaveReply ? null : state.saveRequestId,
88
+ error: msg.error || ""
89
+ });
90
+ if (Object.prototype.hasOwnProperty.call(msg, "preference")) {
91
+ next.preference = msg.preference || null;
92
+ next.preferencePresent = msg.preferencePresent === true;
93
+ }
94
+ store.set({ defaultVendorState: next });
95
+ return true;
96
+ }
97
+
98
+ store.subscribe(function (state, previous) {
99
+ if (state.myUserId !== previous.myUserId || state.currentSlug !== previous.currentSlug) {
100
+ var accountId = state.myUserId || "default";
101
+ store.set({ defaultVendorState: emptyState(accountId, state.currentSlug || null) });
102
+ if (state.connected) requestDefaultVendor();
103
+ }
104
+ });
105
+
106
+ export function resolvePreferredVendor(installedVendors) {
107
+ var installed = Array.isArray(installedVendors) ? installedVendors : [];
108
+ var state = store.get("defaultVendorState") || {};
109
+ if (state.preference && installed.indexOf(state.preference) !== -1) return state.preference;
110
+ return firstInstalledVendor(installed);
111
+ }
112
+
113
+ export function defaultVendorUnavailable(installedVendors) {
114
+ var state = store.get("defaultVendorState") || {};
115
+ return !!state.preference && (installedVendors || []).indexOf(state.preference) === -1;
116
+ }
@@ -101,4 +101,5 @@ export function closeFileViewerTab(path) {
101
101
  }
102
102
 
103
103
  export function focusedFileViewerTab() { return focusedPath; }
104
+ export function focusedFileViewerTabData() { return focusedPath && tabs.has(focusedPath) ? tabs.get(focusedPath) : null; }
104
105
  export function clearFileViewerTabs() { tabs.clear(); focusedPath = null; previewPath = null; render(); }
@@ -2,15 +2,14 @@ import { iconHtml, refreshIcons } from './icons.js';
2
2
  import { escapeHtml, copyToClipboard } from './utils.js';
3
3
  import { renderMarkdown, highlightCodeBlocks, renderMermaidBlocks, exportMarkdownAsPdf } from './markdown.js';
4
4
  import { closeSidebar } from './sidebar.js';
5
- import { closeTerminal } from './terminal.js';
5
+ import { claimRightWorkbench, registerRightWorkbench, releaseRightWorkbench, isRightWorkbenchCurrent } from './right-workbench.js';
6
6
  import { renderUnifiedDiff, renderSplitDiff } from './diff.js';
7
7
  import { initFileIcons, getFileIconSvg, getFolderIconSvg } from './fileicons.js';
8
8
  import { copyMarkdownFormatting } from './rich-clipboard.js';
9
9
  import { animateMarkdownChange, beginMarkdownPresentation, cancelMarkdownFollow, isFollowingMarkdown } from './markdown-live-edit.js';
10
10
  import { store } from './store.js';
11
11
  import { enterMarkdownSlides, exitMarkdownSlides, handleMarkdownSlideKey, syncMarkdownSlidesButton, toggleMarkdownSlideLevelMenu } from './markdown-slides.js';
12
- import { initFileViewerTabs, openFileViewerTab, previewFileViewerTab, updateFileViewerTab, closeFileViewerTab, focusedFileViewerTab, clearFileViewerTabs } from './filebrowser-tabs.js';
13
- import { closeIssues } from './issues.js';
12
+ import { initFileViewerTabs, openFileViewerTab, previewFileViewerTab, updateFileViewerTab, closeFileViewerTab, focusedFileViewerTab, focusedFileViewerTabData, clearFileViewerTabs } from './filebrowser-tabs.js';
14
13
  import { initFileBrowserContextMenu, downloadProjectFile } from './filebrowser-context-menu.js';
15
14
  import { registerClayFileLinkOpener } from './clay-file-links.js';
16
15
 
@@ -41,10 +40,13 @@ export function initFileBrowser(_ctx) {
41
40
  if (mainPanels && ctx.fileViewerEl) mainPanels.appendChild(ctx.fileViewerEl);
42
41
  initFileViewerTabs({
43
42
  onFocus: function(path) {
43
+ claimRightWorkbench("file-viewer");
44
+ ctx.fileViewerEl.classList.remove("hidden");
44
45
  if (path !== currentFilePath) requestFileContent(path);
45
46
  },
46
47
  onEmpty: function() { teardownFileViewer(); },
47
48
  });
49
+ registerRightWorkbench("file-viewer", teardownFileViewer);
48
50
 
49
51
  // Load material file icons in background
50
52
  initFileIcons().then(function () {
@@ -149,7 +151,7 @@ export function initFileBrowser(_ctx) {
149
151
 
150
152
  // Close button
151
153
  document.getElementById("file-viewer-close").addEventListener("click", function () {
152
- closeFileViewerTab(focusedFileViewerTab());
154
+ closeFileViewer();
153
155
  });
154
156
 
155
157
  // Full-viewport presentation toggle
@@ -395,6 +397,7 @@ function kbCollapseOrAscend() {
395
397
  function kbActivate() {
396
398
  if (!_kbFocused) return;
397
399
  if (!isDirRow(_kbFocused) && _kbFocused.dataset.path) {
400
+ claimRightWorkbench("file-viewer");
398
401
  openFileViewerTab(_kbFocused.dataset.path);
399
402
  }
400
403
  _kbFocused.click();
@@ -477,10 +480,7 @@ function ensureRenderedMarkdown() {
477
480
  }
478
481
 
479
482
  export function closeFileViewer() {
480
- if (focusedFileViewerTab()) {
481
- closeFileViewerTab(focusedFileViewerTab());
482
- return;
483
- }
483
+ releaseRightWorkbench("file-viewer");
484
484
  teardownFileViewer();
485
485
  }
486
486
 
@@ -512,6 +512,7 @@ export function setFileViewerFullscreen(enabled) {
512
512
  }
513
513
 
514
514
  export function resetFileBrowser() {
515
+ releaseRightWorkbench("file-viewer");
515
516
  clearFileViewerTabs();
516
517
  teardownFileViewer();
517
518
  // Clear all cached state
@@ -552,12 +553,13 @@ export function openFile(filePath, opts) {
552
553
  if (!state.connected) return false;
553
554
  if (opts && opts.projectSlug && opts.projectSlug !== state.currentSlug) return false;
554
555
  if (opts && opts.sessionId && String(opts.sessionId) !== String(state.activeSessionId)) return false;
555
- closeIssues();
556
+ var workbenchRevision = claimRightWorkbench("file-viewer");
556
557
  if (followedFileChanged(filePath) || (opts && opts.diff && isFollowingMarkdown(filePath))) {
557
558
  cancelMarkdownFollow();
558
559
  }
559
560
  pendingRenderedOpen = !!(opts && opts.rendered);
560
561
  store.set({ pendingFileNavigation: opts && opts.line ? { path: filePath, line: opts.line, column: opts.column || null, requestId: null } : null });
562
+ store.set({ fileViewerOpenRevision: workbenchRevision });
561
563
  openFileViewerTab(filePath);
562
564
  if (opts && opts.diff) {
563
565
  pendingOpenMode = { type: "diff", oldStr: opts.diff.oldStr, newStr: opts.diff.newStr };
@@ -567,9 +569,28 @@ export function openFile(filePath, opts) {
567
569
  requestFileContent(filePath);
568
570
  }
569
571
 
572
+ export function reopenFileViewer() {
573
+ var workbenchRevision = claimRightWorkbench("file-viewer");
574
+ store.set({ fileViewerOpenRevision: workbenchRevision });
575
+ if (!focusedFileViewerTab()) return false;
576
+ ctx.fileViewerEl.classList.remove("hidden");
577
+ var tab = focusedFileViewerTabData();
578
+ if (currentFilePath === focusedFileViewerTab() && currentContent != null) {
579
+ sendWatch(currentFilePath);
580
+ return true;
581
+ }
582
+ if (tab && tab.content != null) {
583
+ showFileContent({ path: focusedFileViewerTab(), content: tab.content, size: tab.content.length });
584
+ return true;
585
+ }
586
+ requestFileContent(focusedFileViewerTab());
587
+ return true;
588
+ }
589
+
570
590
  export function openWorkingTreeDiff(diff) {
571
591
  if (!diff || !diff.path) return;
572
- closeIssues();
592
+ var workbenchRevision = claimRightWorkbench("file-viewer");
593
+ store.set({ fileViewerOpenRevision: workbenchRevision });
573
594
  openFileViewerTab(diff.path);
574
595
  pendingRenderedOpen = false;
575
596
  pendingOpenMode = diff.binary ? null : {
@@ -588,6 +609,8 @@ export function openWorkingTreeDiff(diff) {
588
609
 
589
610
  export function presentMarkdownEdit(msg) {
590
611
  if (!msg || !beginMarkdownPresentation(msg.path)) return;
612
+ var workbenchRevision = claimRightWorkbench("file-viewer");
613
+ store.set({ fileViewerOpenRevision: workbenchRevision });
591
614
  openFileViewerTab(msg.path, { content: msg.content });
592
615
  pendingOpenMode = null;
593
616
  pendingRenderedOpen = true;
@@ -687,7 +710,7 @@ function requestDirectory(dirPath) {
687
710
  function requestFileContent(filePath) {
688
711
  var requestId = "file-read-" + Date.now() + "-" + Math.random().toString(36).slice(2);
689
712
  var state = store.snap();
690
- store.set({ fileReadRequest: { requestId: requestId, path: filePath, projectSlug: state.currentSlug || null, sessionId: state.activeSessionId != null ? String(state.activeSessionId) : null, accountId: state.myUserId || null } });
713
+ store.set({ fileReadRequest: { requestId: requestId, path: filePath, projectSlug: state.currentSlug || null, sessionId: state.activeSessionId != null ? String(state.activeSessionId) : null, accountId: state.myUserId || null, workbenchRevision: store.get('rightWorkbenchRevision') || 0 } });
691
714
  var pending = store.get('pendingFileNavigation');
692
715
  if (pending && pending.path === filePath) store.set({ pendingFileNavigation: Object.assign({}, pending, { requestId: requestId }) });
693
716
  if (ctx.ws && ctx.connected) {
@@ -811,6 +834,7 @@ function renderFilteredTree(container, tree, depth, query) {
811
834
  (function (rowEl, childEl, folderName) {
812
835
  rowEl.addEventListener("click", function (e) {
813
836
  e.stopPropagation();
837
+ claimRightWorkbench("file-viewer");
814
838
  var isExpanded = rowEl.classList.contains("expanded");
815
839
  rowEl.classList.toggle("expanded");
816
840
  childEl.classList.toggle("hidden", isExpanded);
@@ -833,6 +857,7 @@ function renderFilteredTree(container, tree, depth, query) {
833
857
  (function (filePath, rowEl) {
834
858
  rowEl.addEventListener("click", function (e) {
835
859
  e.stopPropagation();
860
+ claimRightWorkbench("file-viewer");
836
861
  if (followedFileChanged(filePath)) cancelMarkdownFollow();
837
862
  var prev = ctx.fileTreeEl.querySelector(".file-tree-item.active");
838
863
  if (prev) prev.classList.remove("active");
@@ -843,7 +868,7 @@ function renderFilteredTree(container, tree, depth, query) {
843
868
  });
844
869
  rowEl.addEventListener("dblclick", function (e) {
845
870
  e.stopPropagation();
846
- openFileViewerTab(filePath);
871
+ openFile(filePath);
847
872
  });
848
873
  })(entry.path, row);
849
874
 
@@ -973,7 +998,7 @@ export function handleFsRead(msg) {
973
998
  if ((request.projectSlug || null) !== (msg.projectSlug || null)) return;
974
999
  if ((request.sessionId || null) !== (msg.sessionId == null ? null : String(msg.sessionId))) return;
975
1000
  if ((request.accountId || null) !== (msg.accountId || null)) return;
976
- showFileContent(msg);
1001
+ showFileContent(msg, request.workbenchRevision);
977
1002
  }
978
1003
 
979
1004
  // --- Tree rendering ---
@@ -1040,6 +1065,7 @@ function renderEntries(container, entries, depth) {
1040
1065
  (function (dirPath, childEl, rowEl, folderName) {
1041
1066
  rowEl.addEventListener("click", function (e) {
1042
1067
  e.stopPropagation();
1068
+ claimRightWorkbench("file-viewer");
1043
1069
  var isExpanded = rowEl.classList.contains("expanded");
1044
1070
  if (isExpanded) {
1045
1071
  rowEl.classList.remove("expanded");
@@ -1079,6 +1105,7 @@ function renderEntries(container, entries, depth) {
1079
1105
  (function (filePath, rowEl) {
1080
1106
  rowEl.addEventListener("click", function (e) {
1081
1107
  e.stopPropagation();
1108
+ claimRightWorkbench("file-viewer");
1082
1109
  if (followedFileChanged(filePath)) cancelMarkdownFollow();
1083
1110
  // Mark active
1084
1111
  var prev = ctx.fileTreeEl.querySelector(".file-tree-item.active");
@@ -1093,7 +1120,7 @@ function renderEntries(container, entries, depth) {
1093
1120
  });
1094
1121
  rowEl.addEventListener("dblclick", function (e) {
1095
1122
  e.stopPropagation();
1096
- openFileViewerTab(filePath);
1123
+ openFile(filePath);
1097
1124
  });
1098
1125
  })(entry.path, row);
1099
1126
 
@@ -1105,8 +1132,9 @@ function renderEntries(container, entries, depth) {
1105
1132
 
1106
1133
  // --- File viewer ---
1107
1134
 
1108
- function showFileContent(msg) {
1135
+ function showFileContent(msg, expectedRevision) {
1109
1136
  if (!updateFileViewerTab(msg.path, { content: msg.content })) return;
1137
+ if (expectedRevision != null && !isRightWorkbenchCurrent("file-viewer", expectedRevision)) return;
1110
1138
  var pathEl = document.getElementById("file-viewer-path");
1111
1139
  var bodyEl = document.getElementById("file-viewer-body");
1112
1140
  var renderBtn = document.getElementById("file-viewer-render");
@@ -1183,7 +1211,6 @@ function showFileContent(msg) {
1183
1211
  }
1184
1212
  }
1185
1213
 
1186
- closeTerminal();
1187
1214
  ctx.fileViewerEl.classList.remove("hidden");
1188
1215
  sendWatch(msg.path);
1189
1216
  refreshIcons();
@@ -1291,7 +1318,7 @@ function pathsReferToSameFile(left, right) {
1291
1318
  }
1292
1319
 
1293
1320
  export function handleFileChanged(msg) {
1294
- if (!msg.path || msg.path !== currentFilePath) return;
1321
+ if (!msg.path || !pathsReferToSameFile(msg.path, currentFilePath)) return;
1295
1322
  if (ctx.fileViewerEl.classList.contains("hidden")) return;
1296
1323
  if (historyVisible || inlineDiffActive) return;
1297
1324
  if (msg.content === currentContent) return;
@@ -1299,7 +1326,7 @@ export function handleFileChanged(msg) {
1299
1326
  var bodyEl = document.getElementById("file-viewer-body");
1300
1327
  var scrollPos = bodyEl ? bodyEl.scrollTop : 0;
1301
1328
  pendingRefresh = true;
1302
- showFileContent(msg);
1329
+ showFileContent(msg.path === currentFilePath ? msg : Object.assign({}, msg, { path: currentFilePath }));
1303
1330
  if (bodyEl) bodyEl.scrollTop = scrollPos;
1304
1331
  }
1305
1332
 
@@ -1,24 +1,50 @@
1
1
  import { escapeHtml } from './utils.js';
2
2
  import { renderMarkdown } from './markdown.js';
3
+ import { authorLine, relativeTime } from './project-logs-render.js';
3
4
  export function statusLabel(status) { return { open: 'Open', in_progress: 'In progress', resolved: 'Resolved', closed: 'Closed' }[status] || 'Issue'; }
4
5
  function esc(value) { return escapeHtml(String(value || '')); }
5
6
  function options(values, selected) { return values.map(function (value) { return '<option value="' + value + '"' + (value === selected ? ' selected' : '') + '>' + esc(statusLabel(value) === 'Issue' ? value.replace(/_/g, ' ') : statusLabel(value)) + '</option>'; }).join(''); }
7
+ function label(value) { return value ? value.charAt(0).toUpperCase() + value.slice(1).replace(/_/g, ' ') : ''; }
8
+ function statusChip(status) { return '<span class="issue-status" data-status="' + esc(status) + '">' + statusLabel(status) + '</span>'; }
9
+ function priorityChip(priority) { return priority && priority !== 'normal' ? '<span class="project-log-priority" data-priority="' + esc(priority) + '">' + esc(label(priority)) + '</span>' : ''; }
10
+ function action(attribute, icon, text, extra) { return '<button type="button" ' + attribute + (extra || '') + '><i data-lucide="' + icon + '"></i>' + text + '</button>'; }
11
+ function prose(text, className) { return '<div class="markdown-body ' + (className || '') + '">' + renderMarkdown(text || '') + '</div>'; }
6
12
  export function renderIssueList(result) {
7
13
  var filtered = !!(result.query || result.status || result.type);
8
14
  if (!result.issues.length) return '<div class="issues-empty"><i data-lucide="circle-dot"></i><h2>' + (filtered ? 'No matching issues' : 'No issues yet') + '</h2><p>' + (filtered ? 'Try a different search or filter.' : 'Manage issues through Driver chat.') + '</p></div>';
9
15
  return result.issues.map(function (entry) {
10
- return '<button class="issue-row" data-open-issue="' + esc(entry.ref) + '"><div class="issue-row-head"><span class="issue-type">' + esc(entry.type) + '</span><span class="issue-status" data-status="' + entry.status + '">' + statusLabel(entry.status) + '</span></div><strong>' + esc(entry.title) + '</strong><p>' + esc(entry.summary) + '</p><small>' + esc(entry.priority) + ' · revision ' + entry.revision + '</small></button>';
11
- }).join('') + (result.nextCursor ? '<button data-issues-more="' + esc(result.nextCursor) + '">Load more</button>' : '');
16
+ var meta = [authorLine(entry), relativeTime(entry.updatedAt || entry.createdAt)];
17
+ if (entry.revision > 1) meta.push('v' + entry.revision);
18
+ if (entry.commentCount) meta.push(entry.commentCount + (entry.commentCount === 1 ? ' comment' : ' comments'));
19
+ return '<button type="button" class="issue-row" data-open-issue="' + esc(entry.ref) + '">' +
20
+ '<div class="issue-row-head"><span class="issue-type">' + esc(entry.type) + '</span>' + priorityChip(entry.priority) + '<strong>' + esc(entry.title) + '</strong></div>' +
21
+ (entry.summary ? '<p>' + esc(entry.summary) + '</p>' : '') +
22
+ '<div class="issue-row-meta">' + statusChip(entry.status) + '<span>' + esc(meta.filter(Boolean).join(' · ')) + '</span></div></button>';
23
+ }).join('') + (result.nextCursor ? '<div class="issues-load-more"><button data-issues-more="' + esc(result.nextCursor) + '">Load more</button></div>' : '');
24
+ }
25
+ function renderComment(comment) {
26
+ var actor = comment.author || {};
27
+ var review = comment.review;
28
+ return '<article class="issue-comment"><div class="issue-comment-meta">' + esc(actor.displayName || actor.userId || 'Project member') + ' · ' + esc(new Date(comment.at).toLocaleString()) + '</div>' +
29
+ prose(comment.body, 'issue-comment-body') + (review ? '<div class="issue-comment-review"><span>' + esc(label(review.action)) + '</span>' + prose(review.response) + '</div>' : '') + '</article>';
12
30
  }
13
31
  export function renderIssueDetail(entry) {
14
- var author = entry.updatedBy || entry.author || {};
15
- var comments = (entry.comments || []).map(function (comment) { var commentAuthor = comment.author || {}; var review = comment.review; return '<article class="issue-comment"><div class="issue-comment-meta">' + esc(commentAuthor.displayName || commentAuthor.userId || 'Project member') + ' · ' + esc(new Date(comment.at).toLocaleString()) + '</div><p>' + esc(comment.body) + '</p>' + (review ? '<small>' + esc(review.action) + ' · ' + esc(review.response) + '</small>' : '') + '</article>'; }).join('');
16
- return '<div class="issue-detail"><span class="issue-status" data-status="' + entry.status + '">' + statusLabel(entry.status) + '</span><h2>' + esc(entry.title) + '</h2><p>' + esc(entry.summary) + '</p><small>' + esc(entry.type) + ' · ' + esc(entry.priority) + ' · revision ' + entry.revision + ' · ' + esc(author.displayName || author.userId || 'Local user') + '</small><div class="markdown-body">' + renderMarkdown(entry.body || '') + '</div>' +
17
- (entry.verifiedCommit ? '<section><h3>Resolution</h3><p>' + esc(entry.resolutionSummary) + '</p><code>' + esc(entry.verifiedCommit.sha) + '</code><p>' + esc(entry.verifiedCommit.subject) + '</p></section>' : '') +
18
- (entry.closeReason ? '<section class="issue-evidence"><h3>Closure</h3><p>' + esc(entry.closeReason.replace(/_/g, ' ')) + '</p></section>' : '') +
19
- '<div class="issue-actions"><button data-issue-edit>Edit</button><button data-issue-work' + (entry.status === 'resolved' || entry.status === 'closed' ? ' disabled title="Reopen this issue to start work"' : '') + '>Start work</button><button data-issue-history>History</button><button data-issue-copy>Copy reference</button>' + (entry.canDelete ? '<button data-issue-delete>Delete issue</button>' : '') + '</div>' +
20
- ((entry.linkedWorkSessions || []).length ? '<section><h3>Linked work sessions</h3>' + entry.linkedWorkSessions.map(function (link) { return '<button data-issue-session="' + esc(link.sessionId) + '">Open Driver session</button>'; }).join('') + '</section>' : '') +
21
- ((entry.resolutionHistory || []).length ? '<section class="issue-evidence"><h3>Resolution history</h3>' + entry.resolutionHistory.map(function (item) { return '<p>' + esc(item.resolutionSummary) + ' <code>' + esc(item.verifiedCommit && item.verifiedCommit.sha) + '</code></p>'; }).join('') + '</section>' : '') + '<section class="issue-discussion"><h3>Discussion' + (comments ? ' (' + entry.comments.length + ')' : '') + '</h3>' + (comments || '<p class="issue-discussion-empty">No comments yet.</p>') + '<form id="issue-comment-form"><label for="issue-comment-input">Add a comment</label><textarea id="issue-comment-input" rows="3" required placeholder="Add context, a correction, or a question."></textarea><p class="issue-comment-status" role="status"></p><button type="submit">Comment</button></form></section></div>';
32
+ var comments = (entry.comments || []).map(renderComment).join('');
33
+ var closed = entry.status === 'resolved' || entry.status === 'closed';
34
+ var time = entry.updatedAt || entry.createdAt;
35
+ var byline = [authorLine(entry), time ? new Date(time).toLocaleString() : '', 'v' + entry.revision].filter(Boolean).join(' · ');
36
+ return '<article class="issue-detail"><div class="issue-doc-chips"><span class="issue-type">' + esc(entry.type) + '</span>' + priorityChip(entry.priority) + statusChip(entry.status) + '</div>' +
37
+ '<h2 class="issue-doc-title">' + esc(entry.title) + '</h2>' + prose(entry.summary, 'issue-doc-summary') + '<div class="issue-byline">' + esc(byline) + '</div>' +
38
+ '<div class="issue-actions">' + action('data-issue-work', 'play', 'Start work', ' class="issue-primary"' + (closed ? ' disabled title="Reopen this issue to start work"' : '')) +
39
+ action('data-issue-edit', 'pencil', 'Edit') + action('data-issue-history', 'history', 'History') + action('data-issue-copy', 'link', 'Copy reference') +
40
+ (entry.canDelete ? action('data-issue-delete', 'trash-2', 'Delete', ' class="issue-danger"') : '') + '</div>' +
41
+ prose(entry.body, 'issue-doc-body') +
42
+ (entry.verifiedCommit ? '<section class="issue-evidence"><h3>Resolution</h3>' + prose(entry.resolutionSummary) + '<code>' + esc(entry.verifiedCommit.sha) + '</code><p>' + esc(entry.verifiedCommit.subject) + '</p></section>' : '') +
43
+ (entry.closeReason ? '<section class="issue-evidence"><h3>Closure</h3><p>' + esc(label(entry.closeReason)) + '</p></section>' : '') +
44
+ ((entry.linkedWorkSessions || []).length ? '<section class="issue-evidence"><h3>Linked work sessions</h3>' + entry.linkedWorkSessions.map(function (link) { return action('data-issue-session="' + esc(link.sessionId) + '"', 'messages-square', 'Open Driver session'); }).join('') + '</section>' : '') +
45
+ ((entry.resolutionHistory || []).length ? '<section class="issue-evidence"><h3>Resolution history</h3>' + entry.resolutionHistory.map(function (item) { return prose(item.resolutionSummary) + '<code>' + esc(item.verifiedCommit && item.verifiedCommit.sha) + '</code>'; }).join('') + '</section>' : '') +
46
+ '<section class="issue-discussion"><h3>Discussion' + (comments ? ' <span>' + entry.comments.length + '</span>' : '') + '</h3>' + (comments || '<p class="issue-discussion-empty">No comments yet.</p>') +
47
+ '<form id="issue-comment-form"><label for="issue-comment-input">Add a comment</label><textarea id="issue-comment-input" rows="3" required placeholder="Add context, a correction, or a question."></textarea><p class="issue-comment-status" role="status"></p><div class="issue-comment-actions"><button type="submit" class="issue-primary">Comment</button></div></form></section></article>';
22
48
  }
23
49
  export function renderIssueForm(entry) {
24
50
  var item = entry || {};