clay-server 4.0.1-beta.1 → 4.1.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -21
- package/LICENSES/MIT-legacy.txt +21 -0
- package/LICENSES/README.md +7 -0
- package/README.md +2 -2
- package/bin/cli.js +1 -3
- package/lib/ask-user-request-identity.js +23 -0
- package/lib/autonomous-run-record.js +32 -0
- package/lib/autonomous-run-scheduler.js +92 -0
- package/lib/context-usage.js +47 -0
- package/lib/daemon-project-access.js +118 -0
- package/lib/daemon-projects.js +19 -5
- package/lib/daemon.js +19 -20
- package/lib/default-ai-runtime.js +117 -0
- package/lib/durable-scheduler-record.js +61 -0
- package/lib/durable-scheduler-store.js +185 -0
- package/lib/durable-scheduler.js +495 -0
- package/lib/git-cli.js +1 -0
- package/lib/issue-work-session.js +10 -0
- package/lib/issues-comments.js +40 -0
- package/lib/issues-commit-verification.js +30 -0
- package/lib/issues-mcp-server.js +27 -0
- package/lib/issues-schema.js +119 -0
- package/lib/issues-service.js +339 -0
- package/lib/issues-store.js +210 -0
- package/lib/loop-cron.js +47 -0
- package/lib/loop-durable-schedule.js +159 -0
- package/lib/loop-guidance.js +35 -0
- package/lib/loop-registry-occurrence.js +76 -0
- package/lib/model-entry.js +15 -0
- package/lib/project-ask-user.js +4 -1
- package/lib/project-autonomous-run.js +498 -0
- package/lib/project-capsule-turn.js +1 -0
- package/lib/project-connection.js +8 -1
- package/lib/project-delegated-session.js +1 -0
- package/lib/project-filesystem.js +10 -10
- package/lib/project-full-access.js +86 -0
- package/lib/project-http.js +3 -1
- package/lib/project-issue-launch.js +154 -0
- package/lib/project-issues.js +58 -0
- package/lib/project-logs-access-scope.js +94 -0
- package/lib/project-logs-mcp-server.js +8 -12
- package/lib/project-logs-query.js +3 -0
- package/lib/project-logs-service.js +86 -84
- package/lib/project-logs-store.js +5 -3
- package/lib/project-loop-interview.js +163 -0
- package/lib/project-loop.js +150 -64
- package/lib/project-message-delivery.js +4 -2
- package/lib/project-models.js +71 -3
- package/lib/project-notifications.js +1 -1
- package/lib/project-pair-autonomous-stop.js +16 -0
- package/lib/project-pair-lifecycle.js +140 -102
- package/lib/project-pair-message.js +50 -0
- package/lib/project-pair-owned-stop.js +18 -0
- package/lib/project-pair-replacement-state.js +72 -0
- package/lib/project-pair-task-control.js +277 -0
- package/lib/project-pair-usage.js +76 -0
- package/lib/project-pending-message-queue.js +328 -0
- package/lib/project-scheduled-messages.js +499 -0
- package/lib/project-scheduled-task-execution.js +236 -0
- package/lib/project-scheduled-tasks.js +481 -0
- package/lib/project-session-notes.js +11 -4
- package/lib/project-session-pair.js +123 -127
- package/lib/project-sessions.js +143 -32
- package/lib/project-tool-llm-runtime.js +48 -0
- package/lib/project-user-message.js +224 -62
- package/lib/project-worker-proposal.js +69 -58
- package/lib/project-workspace-query.js +25 -0
- package/lib/project.js +396 -73
- package/lib/public/app.js +96 -26
- package/lib/public/css/default-ai.css +33 -0
- package/lib/public/css/home-hub.css +15 -2
- package/lib/public/css/home-sidebar.css +50 -2
- package/lib/public/css/icon-strip.css +40 -0
- package/lib/public/css/input.css +160 -114
- package/lib/public/css/issues.css +101 -0
- package/lib/public/css/mates.css +0 -1
- package/lib/public/css/messages.css +19 -0
- package/lib/public/css/pane.css +98 -2
- package/lib/public/css/pending-message-queue.css +190 -0
- package/lib/public/css/rewind.css +11 -2
- package/lib/public/css/scheduled-tasks.css +122 -0
- package/lib/public/css/sticky-notes.css +24 -4
- package/lib/public/index.html +43 -150
- package/lib/public/modules/app-connection.js +3 -0
- package/lib/public/modules/app-cursors.js +29 -12
- package/lib/public/modules/app-loop-ui.js +4 -8
- package/lib/public/modules/app-message-router.js +8 -0
- package/lib/public/modules/app-messages.js +38 -22
- package/lib/public/modules/app-notifications.js +2 -0
- package/lib/public/modules/app-panels.js +9 -1
- package/lib/public/modules/app-projects.js +3 -0
- package/lib/public/modules/app-rate-limit.js +0 -179
- package/lib/public/modules/ask-user-state.js +66 -0
- package/lib/public/modules/autonomous-run.js +285 -0
- package/lib/public/modules/chat-render-runtime.js +0 -2
- package/lib/public/modules/clay-file-links.js +111 -0
- package/lib/public/modules/clay-issue-links.js +131 -0
- package/lib/public/modules/clay-log-links.js +2 -0
- package/lib/public/modules/cursor-sharing-preference.js +38 -0
- package/lib/public/modules/default-ai.js +377 -0
- package/lib/public/modules/filebrowser.js +43 -2
- package/lib/public/modules/home-sidebar.js +16 -8
- package/lib/public/modules/home-surface.js +5 -0
- package/lib/public/modules/input.js +92 -40
- package/lib/public/modules/issues-context.js +117 -0
- package/lib/public/modules/issues-render.js +29 -0
- package/lib/public/modules/issues.js +270 -0
- package/lib/public/modules/loop-interview.js +151 -0
- package/lib/public/modules/markdown.js +4 -0
- package/lib/public/modules/message-delivery.js +5 -3
- package/lib/public/modules/pending-message-image-editor.js +143 -0
- package/lib/public/modules/pending-message-queue-model.js +22 -0
- package/lib/public/modules/pending-message-queue.js +491 -0
- package/lib/public/modules/permission-hints.js +13 -0
- package/lib/public/modules/project-access.js +141 -0
- package/lib/public/modules/project-grouping.js +22 -0
- package/lib/public/modules/project-logs.js +2 -2
- package/lib/public/modules/scheduled-message-state.js +22 -0
- package/lib/public/modules/scheduled-task-edit-state.js +7 -0
- package/lib/public/modules/scheduled-task-engine.js +48 -0
- package/lib/public/modules/scheduled-task-form.js +122 -0
- package/lib/public/modules/scheduled-task-recurrence.js +46 -0
- package/lib/public/modules/scheduled-task-schedule-rule.js +115 -0
- package/lib/public/modules/scheduled-tasks.js +459 -0
- package/lib/public/modules/scheduler-config.js +6 -52
- package/lib/public/modules/scheduler.js +9 -21
- package/lib/public/modules/sidebar-mobile.js +3 -0
- package/lib/public/modules/sidebar-projects.js +14 -171
- package/lib/public/modules/sidebar.js +0 -11
- package/lib/public/modules/split-pair-ui.js +5 -0
- package/lib/public/modules/split-view.js +3 -0
- package/lib/public/modules/sticky-note-markdown.js +1 -0
- package/lib/public/modules/sticky-notes-browser.js +1 -1
- package/lib/public/modules/sticky-notes.js +117 -4
- package/lib/public/modules/terminal.js +2 -0
- package/lib/public/modules/tool-palette-order.js +3 -3
- package/lib/public/modules/tools.js +26 -5
- package/lib/public/modules/worker-proposal.js +4 -0
- package/lib/public/style.css +3 -0
- package/lib/record-revision.js +11 -0
- package/lib/schedule-rule.js +151 -0
- package/lib/schedule-validation.js +124 -0
- package/lib/scheduled-run-state.js +87 -0
- package/lib/scheduled-task-records.js +127 -0
- package/lib/scheduler.js +179 -196
- package/lib/sdk-bridge.js +191 -22
- package/lib/sdk-message-processor.js +32 -2
- package/lib/sdk-turn-queue.js +14 -0
- package/lib/server-admin.js +3 -3
- package/lib/server-cursor-sharing.js +65 -0
- package/lib/server-default-ai.js +265 -0
- package/lib/server-durable-scheduler.js +26 -0
- package/lib/server-global-ws.js +10 -0
- package/lib/server-home-chat.js +29 -9
- package/lib/server-home-clay-entry.js +4 -1
- package/lib/server-home-debate-planning.js +32 -14
- package/lib/server-home-mate-creation.js +30 -11
- package/lib/server-home-models.js +14 -6
- package/lib/server-issue-links.js +18 -0
- package/lib/server-mates.js +4 -3
- package/lib/server-palette.js +17 -14
- package/lib/server.js +247 -102
- package/lib/session-notes-mcp-server.js +2 -2
- package/lib/session-pair-factory.js +45 -4
- package/lib/session-pair-history.js +40 -0
- package/lib/session-pair-mcp-server.js +22 -4
- package/lib/session-pair-operation.js +11 -0
- package/lib/session-pair-prompts.js +31 -2
- package/lib/session-pair-query-start.js +22 -0
- package/lib/session-pair-turn-control.js +8 -3
- package/lib/session-provenance.js +1 -0
- package/lib/session-query-tool-bridge.js +52 -0
- package/lib/session-search.js +4 -1
- package/lib/session-spawn-mcp-server.js +2 -1
- package/lib/session-split-groups.js +35 -1
- package/lib/sessions.js +53 -3
- package/lib/tool-llm.js +1 -0
- package/lib/users-default-ai-preferences.js +80 -0
- package/lib/users-home-surface-preferences.js +2 -1
- package/lib/users-preferences.js +35 -0
- package/lib/users-scheduled-task-preferences.js +44 -0
- package/lib/users.js +16 -0
- package/lib/worker-proposal-control.js +69 -0
- package/lib/worker-proposal-decision.js +7 -0
- package/lib/worker-runtime-catalog.js +52 -0
- package/lib/workspace-query-access.js +3 -2
- package/lib/workspace-query-projection.js +29 -0
- package/lib/workspace-query-service.js +20 -30
- package/lib/worktree.js +8 -4
- package/lib/ws-schema.js +62 -1
- package/lib/yoke/adapters/antigravity.js +1 -0
- package/lib/yoke/adapters/claude-worker.js +22 -18
- package/lib/yoke/adapters/claude.js +85 -16
- package/lib/yoke/adapters/codex.js +28 -7
- package/lib/yoke/claude-context-usage.js +57 -0
- package/lib/yoke/claude-message-correlation.js +31 -0
- package/lib/yoke/claude-model-switch.js +15 -0
- package/lib/yoke/claude-user-input.js +2 -0
- package/lib/yoke/index.js +2 -0
- package/lib/yoke/mcp-bridge-server.js +7 -1
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/session-tool-transport.js +53 -0
- package/lib/yoke/user-input.js +21 -7
- package/package.json +9 -10
- package/bin/claude-relay.js +0 -6
- package/lib/public/modules/app-loop-wizard.js +0 -439
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { store } from './store.js';
|
|
2
|
+
import { getWs } from './ws-ref.js';
|
|
3
|
+
import { showToast } from './utils.js';
|
|
4
|
+
import { closeProjectLogs } from './project-logs.js';
|
|
5
|
+
import { closeScheduledTasks } from './scheduled-tasks.js';
|
|
6
|
+
import { closeNotesBrowser } from './sticky-notes-browser.js';
|
|
7
|
+
import { closeFileViewer } from './filebrowser.js';
|
|
8
|
+
import { closeTerminal } from './terminal.js';
|
|
9
|
+
import { refreshIcons } from './icons.js';
|
|
10
|
+
import { renderIssueList, renderIssueDetail, renderIssueForm, renderIssueHistory, statusLabel } from './issues-render.js';
|
|
11
|
+
function panel() { return document.getElementById('issues-panel'); }
|
|
12
|
+
function content() { return panel().querySelector('.issues-content'); }
|
|
13
|
+
function bumpViewGeneration() { store.set({ issuesViewGeneration: (store.get('issuesViewGeneration') || 0) + 1 }); }
|
|
14
|
+
function request(action, args, intent) {
|
|
15
|
+
var ws = getWs();
|
|
16
|
+
if (!ws || ws.readyState !== 1) { showToast('Reconnect to use Issues', 'warn'); return; }
|
|
17
|
+
var id = 'issues-' + crypto.randomUUID();
|
|
18
|
+
var pending = Object.assign({}, store.get('issuesRequests') || {});
|
|
19
|
+
pending[id] = { action: action, intent: intent, slug: store.get('currentSlug'), sourceRef: entryRef(), view: store.get('issuesView'), viewGeneration: store.get('issuesViewGeneration') || 0 };
|
|
20
|
+
store.set({ issuesRequests: pending });
|
|
21
|
+
ws.send(JSON.stringify({ type: action, args: args || {}, requestId: id }));
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
function markMutation(id, details) {
|
|
25
|
+
if (!id) return;
|
|
26
|
+
var pending = Object.assign({}, store.get('issuesRequests') || {});
|
|
27
|
+
if (!pending[id]) return;
|
|
28
|
+
pending[id] = Object.assign({}, pending[id], details || {});
|
|
29
|
+
store.set({ issuesRequests: pending });
|
|
30
|
+
}
|
|
31
|
+
function listing(cursor) {
|
|
32
|
+
var args = { limit: 50, query: panel().querySelector('[name="query"]').value };
|
|
33
|
+
['status', 'type'].forEach(function (key) { var value = panel().querySelector('[name="filter-' + key + '"]').value; if (value) args[key] = value; });
|
|
34
|
+
if (cursor) args.cursor = cursor;
|
|
35
|
+
bumpViewGeneration(); store.set({ issuesView: 'list', issuesSelected: null });
|
|
36
|
+
panel().querySelector('.issues-filters').hidden = false;
|
|
37
|
+
panel().querySelector('[data-issues-back]').classList.add('hidden');
|
|
38
|
+
store.set({ issuesViewRequest: request('issues_list', args, cursor ? 'more' : 'list') });
|
|
39
|
+
}
|
|
40
|
+
function detail(entry) {
|
|
41
|
+
panel().querySelector('.issues-notice').textContent = '';
|
|
42
|
+
bumpViewGeneration(); store.set({ issuesSelected: entry, issuesView: 'detail' });
|
|
43
|
+
panel().querySelector('.issues-filters').hidden = true;
|
|
44
|
+
panel().querySelector('[data-issues-back]').classList.remove('hidden');
|
|
45
|
+
content().innerHTML = renderIssueDetail(entry);
|
|
46
|
+
refreshIcons();
|
|
47
|
+
}
|
|
48
|
+
function entryRef() {
|
|
49
|
+
var entry = store.get('issuesSelected');
|
|
50
|
+
return entry && entry.ref;
|
|
51
|
+
}
|
|
52
|
+
function closeDeleteDialog() {
|
|
53
|
+
var dialog = panel().querySelector('.issues-delete-dialog');
|
|
54
|
+
if (dialog) dialog.classList.add('hidden');
|
|
55
|
+
}
|
|
56
|
+
function deleteDialogKeydown(event) {
|
|
57
|
+
var dialog = panel().querySelector('.issues-delete-dialog');
|
|
58
|
+
if (!dialog || dialog.classList.contains('hidden')) return;
|
|
59
|
+
var buttons = dialog.querySelectorAll('button:not(:disabled)');
|
|
60
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeDeleteDialog(); return; }
|
|
61
|
+
if (event.key !== 'Tab' || !buttons.length) return;
|
|
62
|
+
var index = Array.prototype.indexOf.call(buttons, document.activeElement);
|
|
63
|
+
if (event.shiftKey && index <= 0) { event.preventDefault(); buttons[buttons.length - 1].focus(); }
|
|
64
|
+
else if (!event.shiftKey && index === buttons.length - 1) { event.preventDefault(); buttons[0].focus(); }
|
|
65
|
+
}
|
|
66
|
+
function openDeleteDialog(entry) {
|
|
67
|
+
if (!entry || !entry.canDelete) return;
|
|
68
|
+
var dialog = panel().querySelector('.issues-delete-dialog');
|
|
69
|
+
dialog.querySelector('.issues-delete-title').textContent = entry.title;
|
|
70
|
+
dialog.querySelector('.issues-delete-status').textContent = '';
|
|
71
|
+
dialog.querySelector('[data-issue-delete-confirm]').disabled = false;
|
|
72
|
+
dialog.classList.remove('hidden');
|
|
73
|
+
dialog.querySelector('[data-issue-delete-cancel]').focus();
|
|
74
|
+
}
|
|
75
|
+
function confirmDelete() {
|
|
76
|
+
var entry = store.get('issuesSelected');
|
|
77
|
+
if (!entry) return;
|
|
78
|
+
var dialog = panel().querySelector('.issues-delete-dialog');
|
|
79
|
+
dialog.querySelector('.issues-delete-status').textContent = 'Deleting...';
|
|
80
|
+
dialog.querySelector('[data-issue-delete-confirm]').disabled = true;
|
|
81
|
+
store.set({ issuesMutationRequest: request('issue_delete', { ref: entry.ref, expectedRevision: entry.revision }, 'delete') });
|
|
82
|
+
}
|
|
83
|
+
export function closeIssues() {
|
|
84
|
+
bumpViewGeneration();
|
|
85
|
+
if (panel()) panel().classList.add('hidden');
|
|
86
|
+
store.set({ issuesOpen: false });
|
|
87
|
+
var button = document.getElementById('issues-btn');
|
|
88
|
+
if (button) button.classList.remove('active');
|
|
89
|
+
}
|
|
90
|
+
export function openIssues(ref) {
|
|
91
|
+
if (!panel() || store.get('isMate')) return;
|
|
92
|
+
panel().querySelector('.issues-notice').textContent = '';
|
|
93
|
+
bumpViewGeneration();
|
|
94
|
+
closeProjectLogs(); closeScheduledTasks(); closeNotesBrowser(); closeFileViewer(); closeTerminal();
|
|
95
|
+
panel().classList.remove('hidden');
|
|
96
|
+
store.set({ issuesOpen: true });
|
|
97
|
+
var button = document.getElementById('issues-btn');
|
|
98
|
+
if (button) button.classList.add('active');
|
|
99
|
+
if (ref) { store.set({ issuesView: 'detail', issuesSelected: null, issuesViewRequest: request('issue_read', { ref: ref }, 'detail') }); }
|
|
100
|
+
else listing();
|
|
101
|
+
}
|
|
102
|
+
export function initIssues() {
|
|
103
|
+
var host = document.getElementById('main-panels');
|
|
104
|
+
if (!host || panel()) return;
|
|
105
|
+
var el = document.createElement('section');
|
|
106
|
+
el.id = 'issues-panel'; el.className = 'hidden'; el.setAttribute('aria-label', 'Project Issues');
|
|
107
|
+
el.innerHTML = '<header class="issues-topbar"><button class="issues-icon-btn" data-issues-back aria-label="Back to issues" title="Back to issue list"><i data-lucide="arrow-left"></i></button><span class="issues-title"><i data-lucide="circle-dot"></i>Issues</span><span class="issues-subtitle">Manage issues through Driver chat.</span><div class="issues-window-actions"><button class="issues-icon-btn" data-issues-wide aria-label="Widen Issues" title="Widen Issues" aria-pressed="false"><i data-lucide="chevrons-left-right"></i></button><button class="issues-icon-btn" data-issues-full aria-label="Toggle Issues fullscreen" title="Toggle fullscreen" aria-pressed="false"><i data-lucide="maximize-2"></i></button><button class="issues-icon-btn" data-issues-close aria-label="Close Issues" title="Close Issues"><i data-lucide="x"></i></button></div></header><div class="issues-filters"><label class="issues-search"><i data-lucide="search"></i><input name="query" type="search" placeholder="Search issues" aria-label="Search issues"></label><select name="filter-status" aria-label="Filter status"><option value="">All statuses</option><option value="open">Open</option><option value="in_progress">In progress</option><option value="resolved">Resolved</option><option value="closed">Closed</option></select><select name="filter-type" aria-label="Filter type"><option value="">All types</option><option>bug</option><option>feature</option><option>plan</option></select></div><p class="issues-notice" role="status"></p><main class="issues-content" role="region" aria-live="polite"></main><div class="issues-delete-dialog hidden" role="dialog" aria-modal="true" aria-labelledby="issues-delete-heading"><div class="issues-delete-card"><h2 id="issues-delete-heading">Delete this issue?</h2><p>This removes the issue from the board but preserves its history.</p><p class="issues-delete-title"></p><p class="issues-delete-status" role="status"></p><div><button type="button" data-issue-delete-cancel>Cancel</button><button type="button" data-issue-delete-confirm>Delete issue</button></div></div></div>';
|
|
108
|
+
host.appendChild(el);
|
|
109
|
+
var button = document.getElementById('issues-btn');
|
|
110
|
+
if (button) button.addEventListener('click', function () { if (store.get('issuesOpen')) closeIssues(); else openIssues(); });
|
|
111
|
+
el.addEventListener('change', function (event) { if (event.target.closest('.issues-filters')) listing(); });
|
|
112
|
+
el.querySelector('[name="query"]').addEventListener('input', function () { clearTimeout(store.get('issuesSearchTimer')); store.set({ issuesSearchTimer: setTimeout(function () { listing(); }, 200) }); });
|
|
113
|
+
el.addEventListener('click', function (event) {
|
|
114
|
+
var target = event.target.closest('button'); if (!target) return;
|
|
115
|
+
var entry = store.get('issuesSelected');
|
|
116
|
+
if (target.hasAttribute('data-issues-close')) closeIssues();
|
|
117
|
+
else if (target.hasAttribute('data-issues-back')) listing();
|
|
118
|
+
else if (target.hasAttribute('data-issue-delete')) openDeleteDialog(entry);
|
|
119
|
+
else if (target.hasAttribute('data-issue-delete-cancel')) closeDeleteDialog();
|
|
120
|
+
else if (target.hasAttribute('data-issue-delete-confirm')) confirmDelete();
|
|
121
|
+
else if (target.hasAttribute('data-issue-edit')) showIssueEdit(entry);
|
|
122
|
+
else if (target.hasAttribute('data-issue-cancel')) detail(entry);
|
|
123
|
+
else if (target.dataset.openIssue) openIssues(target.dataset.openIssue);
|
|
124
|
+
else if (target.hasAttribute('data-issues-more')) listing(target.dataset.issuesMore);
|
|
125
|
+
else if (target.hasAttribute('data-issue-history')) { bumpViewGeneration(); store.set({ issuesView: 'history', issuesViewRequest: request('issue_history', { ref: entry.ref }, 'history') }); }
|
|
126
|
+
else if (target.dataset.issueRevision) { bumpViewGeneration(); store.set({ issuesView: 'revision', issuesViewRequest: request('issue_revision', { ref: entry.ref, revision: Number(target.dataset.issueRevision) }, 'revision') }); }
|
|
127
|
+
else if (target.hasAttribute('data-issue-copy')) navigator.clipboard.writeText(entry.ref).catch(function () { showToast(entry.ref); });
|
|
128
|
+
else if (target.hasAttribute('data-issue-work')) { target.disabled = true; request('issue_start_work', { ref: entry.ref, expectedRevision: entry.revision }, 'work'); }
|
|
129
|
+
else if (target.dataset.issueSession) request('issue_open_work', { ref: entry.ref, sessionOriginId: target.dataset.issueSession }, 'work');
|
|
130
|
+
else if (target.hasAttribute('data-issues-wide') || target.hasAttribute('data-issues-full')) { var name = target.hasAttribute('data-issues-wide') ? 'issues-wide' : 'panel-fullscreen'; var active = el.classList.toggle(name); target.setAttribute('aria-pressed', String(active)); }
|
|
131
|
+
});
|
|
132
|
+
refreshIcons();
|
|
133
|
+
el.addEventListener('submit', function (event) {
|
|
134
|
+
if (event.target.id === 'issue-comment-form') {
|
|
135
|
+
event.preventDefault(); var input = event.target.querySelector('#issue-comment-input'); var status = event.target.querySelector('.issue-comment-status');
|
|
136
|
+
if (!input.value.trim()) { status.textContent = 'A comment cannot be empty.'; return; }
|
|
137
|
+
var commentRef = entryRef(); var commentBody = input.value.trim(); var commentRequest = request('issue_comment', { ref: commentRef, body: commentBody }, 'comment');
|
|
138
|
+
markMutation(commentRequest, { ref: commentRef, view: store.get('issuesView'), body: commentBody });
|
|
139
|
+
status.textContent = 'Posting...'; store.set({ issuesMutationRequest: commentRequest }); return;
|
|
140
|
+
}
|
|
141
|
+
if (event.target.id !== 'issue-form') return;
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
var data = Object.fromEntries(new FormData(event.target));
|
|
144
|
+
if (data.status !== 'closed') delete data.closeReason;
|
|
145
|
+
if (data.status !== 'resolved') { delete data.commitSha; delete data.resolutionSummary; }
|
|
146
|
+
var entry = store.get('issuesSelected');
|
|
147
|
+
if (!entry) return;
|
|
148
|
+
data.ref = entry.ref; data.expectedRevision = entry.revision;
|
|
149
|
+
event.target.querySelector('[type="submit"]').disabled = true;
|
|
150
|
+
var saveRequest = request('issue_update', data, 'save');
|
|
151
|
+
markMutation(saveRequest, { ref: entry.ref });
|
|
152
|
+
store.set({ issuesViewRequest: saveRequest });
|
|
153
|
+
});
|
|
154
|
+
el.addEventListener('input', function (event) {
|
|
155
|
+
if (event.target.id === 'issue-comment-input' || event.target.closest('#issue-form')) bumpViewGeneration();
|
|
156
|
+
});
|
|
157
|
+
store.subscribe(function (state, previous) {
|
|
158
|
+
if (state.currentSlug !== previous.currentSlug || (previous.connected && !state.connected)) { closeIssues(); store.set({ issuesRequests: {}, issuesSelected: null, issuesCache: {}, issuesMutationRequest: null }); }
|
|
159
|
+
if (state.issuesOpen && (state.projectLogsOpen || state.scheduledTasksOpen)) closeIssues();
|
|
160
|
+
});
|
|
161
|
+
document.addEventListener('keydown', function (event) { if (store.get('issuesOpen')) { deleteDialogKeydown(event); if (!event.defaultPrevented && event.key === 'Escape') closeIssues(); } });
|
|
162
|
+
}
|
|
163
|
+
function showIssueEdit(entry) {
|
|
164
|
+
if (!entry) return;
|
|
165
|
+
var detailEl = content();
|
|
166
|
+
panel().querySelector('.issues-filters').hidden = true;
|
|
167
|
+
panel().querySelector('[data-issues-back]').classList.remove('hidden');
|
|
168
|
+
bumpViewGeneration(); store.set({ issuesView: 'edit', issuesSelected: entry, issuesViewRequest: null });
|
|
169
|
+
detailEl.innerHTML = '<p class="issues-edit-note">Update an existing Driver-authored issue. New issues must be discussed and created by the Project Driver.</p>' + renderIssueForm(entry);
|
|
170
|
+
var formEl = document.getElementById('issue-form');
|
|
171
|
+
function syncFields() {
|
|
172
|
+
var status = formEl.elements.status.value;
|
|
173
|
+
formEl.querySelector('[data-resolution-fields]').hidden = status !== 'resolved';
|
|
174
|
+
formEl.querySelector('[data-close-fields]').hidden = status !== 'closed';
|
|
175
|
+
}
|
|
176
|
+
formEl.addEventListener('change', syncFields);
|
|
177
|
+
syncFields();
|
|
178
|
+
}
|
|
179
|
+
export function handleIssuesMessage(msg) {
|
|
180
|
+
if (msg.type === 'issue_commented') {
|
|
181
|
+
var selected = store.get('issuesSelected');
|
|
182
|
+
var mutationId = store.get('issuesMutationRequest');
|
|
183
|
+
var mutation = mutationId && (store.get('issuesRequests') || {})[mutationId];
|
|
184
|
+
if (mutation && mutation.intent === 'comment' && mutation.action === 'issue_comment') {
|
|
185
|
+
panel().querySelector('.issues-notice').textContent = 'Comment submitted.';
|
|
186
|
+
} else if (store.get('issuesOpen') && selected && selected.ref === msg.ref && store.get('issuesView') === 'detail') {
|
|
187
|
+
var commentInput = panel().querySelector('#issue-comment-input');
|
|
188
|
+
if (commentInput && commentInput.value) panel().querySelector('.issues-notice').textContent = 'An issue comment changed. Your draft is preserved.';
|
|
189
|
+
else store.set({ issuesViewRequest: request('issue_read', { ref: msg.ref }, 'detail') });
|
|
190
|
+
} else if (store.get('issuesOpen') && selected && selected.ref === msg.ref) {
|
|
191
|
+
panel().querySelector('.issues-notice').textContent = 'An issue comment changed. Return to the detail view to refresh it.';
|
|
192
|
+
} else if (store.get('issuesOpen') && store.get('issuesView') === 'list') listing();
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
if (msg.type === 'issue_deleted') {
|
|
196
|
+
var cache = Object.assign({}, store.get('issuesCache') || {});
|
|
197
|
+
delete cache[msg.ref];
|
|
198
|
+
store.set({ issuesCache: cache });
|
|
199
|
+
document.querySelectorAll('[data-issue-ref]').forEach(function (node) { if (node.dataset.issueRef === msg.ref) { node.textContent = 'Issue unavailable'; node.title = 'This issue was deleted'; node.dataset.status = 'deleted'; } });
|
|
200
|
+
if (store.get('issuesSelected') && store.get('issuesSelected').ref === msg.ref) {
|
|
201
|
+
closeDeleteDialog(); listing();
|
|
202
|
+
} else if (store.get('issuesOpen')) listing();
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
if (msg.type === 'issue_updated') {
|
|
206
|
+
var cache = Object.assign({}, store.get('issuesCache') || {}); cache[msg.ref] = Object.assign({}, cache[msg.ref] || {}, msg, { projectSlug: store.get('currentSlug') }); store.set({ issuesCache: cache });
|
|
207
|
+
document.querySelectorAll('[data-issue-ref]').forEach(function (node) { if (node.dataset.issueRef === msg.ref) { node.textContent = statusLabel(msg.status) + ' · ' + msg.title; node.dataset.status = msg.status; } });
|
|
208
|
+
if (store.get('issuesOpen')) panel().querySelector('.issues-notice').textContent = 'An issue changed. Back returns to the latest list; reopening an issue loads its latest revision.';
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
if (msg.type !== 'issues_result') return false;
|
|
212
|
+
var pending = store.get('issuesRequests') || {}; var item = pending[msg.requestId];
|
|
213
|
+
if (!item || item.slug !== store.get('currentSlug')) return true;
|
|
214
|
+
var next = Object.assign({}, pending); delete next[msg.requestId]; store.set({ issuesRequests: next });
|
|
215
|
+
if (item.intent === 'comment' || item.intent === 'delete') {
|
|
216
|
+
if (msg.requestId !== store.get('issuesMutationRequest')) return true;
|
|
217
|
+
store.set({ issuesMutationRequest: null });
|
|
218
|
+
} else if (item.intent !== 'work' && msg.requestId !== store.get('issuesViewRequest')) return true;
|
|
219
|
+
var mutationIntent = item.intent === 'comment' || item.intent === 'delete' || item.intent === 'save';
|
|
220
|
+
var currentEntry = store.get('issuesSelected');
|
|
221
|
+
if (mutationIntent && (item.viewGeneration !== (store.get('issuesViewGeneration') || 0) ||
|
|
222
|
+
item.sourceRef !== (currentEntry && currentEntry.ref) || item.view !== store.get('issuesView'))) {
|
|
223
|
+
if (!msg.error && item.intent !== 'delete' && msg.result && msg.result.ref) {
|
|
224
|
+
var preservedCache = Object.assign({}, store.get('issuesCache') || {});
|
|
225
|
+
preservedCache[msg.result.ref] = Object.assign({}, msg.result, { canDelete: msg.canDelete === true, projectSlug: store.get('currentSlug') });
|
|
226
|
+
store.set({ issuesCache: preservedCache });
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
if (msg.error) {
|
|
231
|
+
panel().querySelector('.issues-notice').textContent = msg.error;
|
|
232
|
+
if (item.intent === 'comment') {
|
|
233
|
+
var commentStatus = panel().querySelector('.issue-comment-status');
|
|
234
|
+
if (commentStatus) commentStatus.textContent = msg.error;
|
|
235
|
+
}
|
|
236
|
+
if (item.intent === 'delete') {
|
|
237
|
+
var deleteStatus = panel().querySelector('.issues-delete-status');
|
|
238
|
+
if (deleteStatus) deleteStatus.textContent = msg.error;
|
|
239
|
+
}
|
|
240
|
+
panel().querySelectorAll('button:disabled').forEach(function (button) { button.disabled = false; });
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
panel().querySelector('.issues-notice').textContent = '';
|
|
244
|
+
if (item.intent === 'work') { closeIssues(); return true; }
|
|
245
|
+
if (item.intent === 'comment') {
|
|
246
|
+
var commented = Object.assign({}, msg.result, { canDelete: msg.canDelete === true });
|
|
247
|
+
var currentSelected = store.get('issuesSelected');
|
|
248
|
+
var currentCommentInput = panel().querySelector('#issue-comment-input');
|
|
249
|
+
var sameView = store.get('issuesView') === item.view && currentSelected && currentSelected.ref === item.ref && item.viewGeneration === (store.get('issuesViewGeneration') || 0);
|
|
250
|
+
var unchangedDraft = !currentCommentInput || !currentCommentInput.value || currentCommentInput.value.trim() === item.body;
|
|
251
|
+
if (!sameView || !unchangedDraft) {
|
|
252
|
+
panel().querySelector('.issues-notice').textContent = 'Comment added. Your current view or draft was preserved.';
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
detail(commented);
|
|
256
|
+
panel().querySelector('.issues-notice').textContent = 'Comment added.';
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (item.intent === 'delete') { closeDeleteDialog(); listing(); return true; }
|
|
260
|
+
if (item.intent === 'list' || item.intent === 'more') {
|
|
261
|
+
var result = msg.result;
|
|
262
|
+
if (item.intent === 'more') result.issues = (store.get('issuesRows') || []).concat(result.issues);
|
|
263
|
+
result = Object.assign({}, result, { query: panel().querySelector('[name="query"]').value,
|
|
264
|
+
status: panel().querySelector('[name="filter-status"]').value, type: panel().querySelector('[name="filter-type"]').value });
|
|
265
|
+
store.set({ issuesRows: result.issues }); content().innerHTML = renderIssueList(result); refreshIcons();
|
|
266
|
+
} else if (item.intent === 'history') { content().innerHTML = renderIssueHistory(msg.result); refreshIcons(); }
|
|
267
|
+
else if (item.intent === 'revision') { content().innerHTML = '<p class="issues-history-note">Historical revision · use Back to return to current issues</p>' + renderIssueDetail(msg.result); content().querySelectorAll('.issue-actions, [data-issue-session]').forEach(function (node) { node.remove(); }); refreshIcons(); }
|
|
268
|
+
else detail(Object.assign({}, msg.result, { canDelete: msg.canDelete === true }));
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { store } from './store.js';
|
|
2
|
+
import { getWs } from './ws-ref.js';
|
|
3
|
+
import { refreshIcons } from './icons.js';
|
|
4
|
+
import { showToast } from './utils.js';
|
|
5
|
+
import { isDriverOperatedView } from './worker-pane-lock.js';
|
|
6
|
+
|
|
7
|
+
function requestId() {
|
|
8
|
+
if (globalThis.crypto && typeof globalThis.crypto.randomUUID === "function") return "loop-interview-" + globalThis.crypto.randomUUID();
|
|
9
|
+
return "loop-interview-" + Date.now() + "-" + Math.random().toString(36).slice(2);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function eligible() {
|
|
13
|
+
var state = store.snap();
|
|
14
|
+
var home = document.getElementById("home-hub");
|
|
15
|
+
var onHome = home && !home.classList.contains("hidden");
|
|
16
|
+
return !state.dmMode && !onHome && state.activeSessionMode === "gui" && !isDriverOperatedView(state);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function render() {
|
|
20
|
+
var button = document.getElementById("loop-interview-btn");
|
|
21
|
+
var card = document.getElementById("loop-interview-card");
|
|
22
|
+
if (!button) return;
|
|
23
|
+
var state = store.snap();
|
|
24
|
+
var visible = eligible();
|
|
25
|
+
button.classList.toggle("hidden", !visible);
|
|
26
|
+
button.disabled = !visible || !!state.loopInterviewStarting || !!state.processing;
|
|
27
|
+
button.classList.toggle("arming", !!state.loopInterviewStarting);
|
|
28
|
+
button.setAttribute("aria-label", state.loopInterviewStarting ? "Starting Loop interview" : "Start Loop interview");
|
|
29
|
+
button.title = state.processing ? "Wait for the current task to finish" : "Start a Loop interview with the Driver";
|
|
30
|
+
if (card) {
|
|
31
|
+
var proposal = state.loopInterviewBrief;
|
|
32
|
+
card.classList.toggle("hidden", !proposal);
|
|
33
|
+
if (proposal) {
|
|
34
|
+
var cardKey = proposal.id + ":" + proposal.version + ":" + (state.loopInterviewEditing ? "edit" : "view");
|
|
35
|
+
if (cardKey !== card.getAttribute("data-loop-render-key")) {
|
|
36
|
+
if (state.loopInterviewEditing) {
|
|
37
|
+
card.innerHTML = "<strong>Edit Loop brief</strong><label for=\"loop-interview-objective-input\">Objective</label><textarea id=\"loop-interview-objective-input\" data-loop-field=\"objective\"></textarea><label for=\"loop-interview-criteria-input\">Completion checks</label><textarea id=\"loop-interview-criteria-input\" data-loop-field=\"criteria\"></textarea><div class=\"loop-interview-actions\"><button type=\"button\" data-loop-action=\"save\">Save</button><button type=\"button\" data-loop-action=\"cancel-edit\">Cancel</button></div>";
|
|
38
|
+
card.querySelector('[data-loop-field="objective"]').value = proposal.objective;
|
|
39
|
+
card.querySelector('[data-loop-field="criteria"]').value = proposal.successCriteria.join("\n");
|
|
40
|
+
} else {
|
|
41
|
+
card.innerHTML = "<strong>Loop brief ready for review</strong><div class=\"loop-interview-objective\"></div><div class=\"loop-interview-criteria\"></div><div class=\"loop-interview-limits\"></div><div class=\"loop-interview-disclosure\">Start enables Skip Permissions for this run. Your previous setting is restored when it ends.</div><div class=\"loop-interview-actions\"><button type=\"button\" data-loop-action=\"start\">Start</button><button type=\"button\" data-loop-action=\"edit\">Edit</button><button type=\"button\" data-loop-action=\"cancel\">Cancel</button></div>";
|
|
42
|
+
card.querySelector(".loop-interview-objective").textContent = proposal.objective;
|
|
43
|
+
card.querySelector(".loop-interview-criteria").textContent = proposal.successCriteria.join(" · ");
|
|
44
|
+
card.querySelector(".loop-interview-limits").textContent = "Limits: " + proposal.maxContinuations + " continuations · " + proposal.maxMinutes + " minutes";
|
|
45
|
+
}
|
|
46
|
+
card.setAttribute("data-loop-render-key", cardKey);
|
|
47
|
+
}
|
|
48
|
+
var startButton = card.querySelector('[data-loop-action="start"]');
|
|
49
|
+
if (startButton) startButton.disabled = !!state.loopInterviewRunRequestId;
|
|
50
|
+
} else {
|
|
51
|
+
card.removeAttribute("data-loop-render-key");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function sendAction(type, payload) {
|
|
57
|
+
var ws = getWs();
|
|
58
|
+
if (!ws || ws.readyState !== 1) {
|
|
59
|
+
showToast("Loop action could not be sent while disconnected.", "error");
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
ws.send(JSON.stringify(Object.assign({ type: type, sessionId: store.get("activeSessionId"), requestId: requestId() }, payload || {})));
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function startBrief() {
|
|
67
|
+
var proposal = store.get("loopInterviewBrief");
|
|
68
|
+
if (!proposal || store.get("processing") || store.get("loopInterviewRunRequestId")) return;
|
|
69
|
+
var id = requestId();
|
|
70
|
+
if (sendAction("loop_interview_start_run", { requestId: id, proposalId: proposal.id, version: proposal.version })) {
|
|
71
|
+
store.set({ loopInterviewRunRequestId: id, loopInterviewRunSessionId: store.get("activeSessionId") });
|
|
72
|
+
render();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function start() {
|
|
77
|
+
if (!eligible() || store.get("loopInterviewStarting") || store.get("processing")) return;
|
|
78
|
+
var sessionId = store.get("activeSessionId");
|
|
79
|
+
var id = requestId();
|
|
80
|
+
store.set({ loopInterviewStarting: true, loopInterviewRequestId: id, loopInterviewSessionId: sessionId });
|
|
81
|
+
render();
|
|
82
|
+
var ws = getWs();
|
|
83
|
+
if (!ws || ws.readyState !== 1) {
|
|
84
|
+
store.set({ loopInterviewStarting: false, loopInterviewRequestId: null, loopInterviewSessionId: null });
|
|
85
|
+
render();
|
|
86
|
+
showToast("Loop interview could not start while disconnected.", "error");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
ws.send(JSON.stringify({ type: "loop_interview_start", sessionId: sessionId, requestId: id }));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function handleLoopInterviewMessage(msg) {
|
|
93
|
+
if (msg.type === "loop_interview_brief") {
|
|
94
|
+
if (Number(msg.sessionId) !== Number(store.get("activeSessionId"))) return true;
|
|
95
|
+
store.set({ loopInterviewBrief: msg.brief || null });
|
|
96
|
+
render();
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (msg.type === "loop_interview_start_run_result" && Number(msg.sessionId) === Number(store.get("activeSessionId")) && Number(msg.sessionId) === Number(store.get("loopInterviewRunSessionId")) && msg.requestId === store.get("loopInterviewRunRequestId")) {
|
|
100
|
+
store.set({ loopInterviewBrief: msg.ok ? null : store.get("loopInterviewBrief"), loopInterviewRunRequestId: null, loopInterviewRunSessionId: null });
|
|
101
|
+
if (!msg.ok) showToast(msg.error || "The approved Loop run could not start.", "error");
|
|
102
|
+
render();
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (msg.type !== "loop_interview_start_result") return false;
|
|
106
|
+
var state = store.snap();
|
|
107
|
+
if (Number(msg.sessionId) !== Number(state.loopInterviewSessionId) || msg.requestId !== state.loopInterviewRequestId) return true;
|
|
108
|
+
store.set({ loopInterviewStarting: false, loopInterviewRequestId: null, loopInterviewSessionId: null, loopInterviewRunRequestId: null, loopInterviewRunSessionId: null, loopInterviewEditing: false });
|
|
109
|
+
if (!msg.ok) showToast(msg.error || "Loop interview could not start.", "error");
|
|
110
|
+
render();
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function syncLoopInterviewForSession() {
|
|
115
|
+
store.set({ loopInterviewStarting: false, loopInterviewRequestId: null, loopInterviewSessionId: null, loopInterviewBrief: null, loopInterviewRunRequestId: null, loopInterviewRunSessionId: null, loopInterviewEditing: false });
|
|
116
|
+
requestLoopInterviewState();
|
|
117
|
+
render();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function requestLoopInterviewState() {
|
|
121
|
+
var ws = getWs();
|
|
122
|
+
if (ws && ws.readyState === 1 && store.get("activeSessionId")) ws.send(JSON.stringify({ type: "loop_interview_state", sessionId: store.get("activeSessionId") }));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function initLoopInterview() {
|
|
126
|
+
var button = document.getElementById("loop-interview-btn");
|
|
127
|
+
if (!button) return;
|
|
128
|
+
button.addEventListener("click", start);
|
|
129
|
+
var card = document.getElementById("loop-interview-card");
|
|
130
|
+
if (card) card.addEventListener("click", function (event) {
|
|
131
|
+
var action = event.target.getAttribute("data-loop-action");
|
|
132
|
+
if (action === "start") startBrief();
|
|
133
|
+
if (action === "cancel") { var cancelBrief = store.get("loopInterviewBrief"); if (cancelBrief) sendAction("loop_interview_cancel", { proposalId: cancelBrief.id, version: cancelBrief.version }); }
|
|
134
|
+
if (action === "edit") { store.set({ loopInterviewEditing: true }); render(); }
|
|
135
|
+
if (action === "cancel-edit") { store.set({ loopInterviewEditing: false }); render(); }
|
|
136
|
+
if (action === "save") {
|
|
137
|
+
var proposal = store.get("loopInterviewBrief");
|
|
138
|
+
var objective = card.querySelector('[data-loop-field="objective"]').value;
|
|
139
|
+
var successCriteria = card.querySelector('[data-loop-field="criteria"]').value.split("\n");
|
|
140
|
+
if (sendAction("loop_interview_edit", { proposalId: proposal.id, version: proposal.version, brief: { id: proposal.id, objective: objective, successCriteria: successCriteria, maxContinuations: proposal.maxContinuations, maxMinutes: proposal.maxMinutes } })) store.set({ loopInterviewEditing: false });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
store.subscribe(function (state, prev) {
|
|
144
|
+
if (state.activeSessionId !== prev.activeSessionId || state.connected !== prev.connected) syncLoopInterviewForSession();
|
|
145
|
+
if (state.processing !== prev.processing || state.dmMode !== prev.dmMode || state.activeSessionMode !== prev.activeSessionMode || state.splitGroups !== prev.splitGroups || state.paneSessionId !== prev.paneSessionId) render();
|
|
146
|
+
});
|
|
147
|
+
var home = document.getElementById("home-hub");
|
|
148
|
+
if (home && typeof MutationObserver === "function") new MutationObserver(function () { if (!home.classList.contains("hidden")) syncLoopInterviewForSession(); }).observe(home, { attributes: true, attributeFilter: ["class"] });
|
|
149
|
+
render();
|
|
150
|
+
refreshIcons();
|
|
151
|
+
}
|
|
@@ -3,6 +3,7 @@ import { refreshIcons } from './icons.js';
|
|
|
3
3
|
import { getMermaidThemeVars } from './theme.js';
|
|
4
4
|
import { store } from './store.js';
|
|
5
5
|
import { enhanceClayLogLinks } from './clay-log-links.js';
|
|
6
|
+
import { renderLocalFileLink, enhanceClayFileLinks } from './clay-file-links.js';
|
|
6
7
|
|
|
7
8
|
// Initialize markdown parser
|
|
8
9
|
marked.use({ gfm: true, breaks: false });
|
|
@@ -11,6 +12,8 @@ marked.use({ gfm: true, breaks: false });
|
|
|
11
12
|
marked.use({
|
|
12
13
|
renderer: {
|
|
13
14
|
link({ href, title, text }) {
|
|
15
|
+
var localLink = renderLocalFileLink(href, title, text);
|
|
16
|
+
if (localLink) return localLink;
|
|
14
17
|
var isExternal = href && (href.startsWith('http://') || href.startsWith('https://'));
|
|
15
18
|
var titleAttr = title ? ' title="' + title + '"' : '';
|
|
16
19
|
var targetAttr = isExternal ? ' target="_blank" rel="noopener noreferrer"' : '';
|
|
@@ -91,6 +94,7 @@ export function enhanceClaySessionLinks(root) {
|
|
|
91
94
|
nodes[i].parentNode.replaceChild(fragment, nodes[i]);
|
|
92
95
|
}
|
|
93
96
|
enhanceClayLogLinks(root);
|
|
97
|
+
enhanceClayFileLinks(root);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
/**
|
|
@@ -75,15 +75,17 @@ export function sendAcknowledgedMessage(payload) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export function acknowledgeMessage(clientMessageId) {
|
|
78
|
-
if (typeof clientMessageId !== "string") return
|
|
78
|
+
if (typeof clientMessageId !== "string") return null;
|
|
79
79
|
var pending = pendingMessages();
|
|
80
|
+
var acknowledged = null;
|
|
80
81
|
var next = pending.filter(function (entry) {
|
|
82
|
+
if (entry.payload.clientMessageId === clientMessageId) acknowledged = entry;
|
|
81
83
|
return entry.payload.clientMessageId !== clientMessageId;
|
|
82
84
|
});
|
|
83
|
-
if (next.length === pending.length) return
|
|
85
|
+
if (next.length === pending.length) return null;
|
|
84
86
|
clearAckTimer(clientMessageId);
|
|
85
87
|
replacePending(next);
|
|
86
|
-
return
|
|
88
|
+
return acknowledged;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export function replayPendingMessages(sessionId) {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var MAX_IMAGES = 20;
|
|
2
|
+
var MAX_IMAGE_DATA = 25 * 1024 * 1024;
|
|
3
|
+
var MAX_TOTAL_BYTES = 32 * 1024 * 1024;
|
|
4
|
+
var IMAGE_TYPE_RE = /^image\/[a-z0-9.+-]{1,64}$/i;
|
|
5
|
+
|
|
6
|
+
export function imageSrc(image) {
|
|
7
|
+
if (!image) return "";
|
|
8
|
+
if (image.data && image.mediaType) return "data:" + image.mediaType + ";base64," + image.data;
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function imageDraft(image) {
|
|
13
|
+
return { mediaType: image.mediaType, data: image.data };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function focusElement(element) {
|
|
17
|
+
if (!element) return;
|
|
18
|
+
try { element.focus({ preventScroll: true }); }
|
|
19
|
+
catch (e) { element.focus(); }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function openImagePreview(src, alt) {
|
|
23
|
+
if (!src) return;
|
|
24
|
+
var trigger = document.activeElement;
|
|
25
|
+
var backdrop = document.createElement("div");
|
|
26
|
+
backdrop.className = "pending-message-image-backdrop";
|
|
27
|
+
backdrop.setAttribute("role", "dialog");
|
|
28
|
+
backdrop.setAttribute("aria-modal", "true");
|
|
29
|
+
backdrop.setAttribute("aria-label", "Image preview");
|
|
30
|
+
var close = document.createElement("button");
|
|
31
|
+
close.type = "button";
|
|
32
|
+
close.className = "pending-message-image-close";
|
|
33
|
+
close.textContent = "Close";
|
|
34
|
+
var image = document.createElement("img");
|
|
35
|
+
image.src = src;
|
|
36
|
+
image.alt = alt || "Queued image preview";
|
|
37
|
+
backdrop.appendChild(close);
|
|
38
|
+
backdrop.appendChild(image);
|
|
39
|
+
function dismiss() {
|
|
40
|
+
document.removeEventListener("keydown", onKey);
|
|
41
|
+
backdrop.remove();
|
|
42
|
+
if (trigger && trigger.isConnected) focusElement(trigger);
|
|
43
|
+
}
|
|
44
|
+
function onKey(event) {
|
|
45
|
+
if (event.key === "Escape") {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
dismiss();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (event.key !== "Tab") return;
|
|
52
|
+
var focusable = backdrop.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
53
|
+
if (!focusable.length) return;
|
|
54
|
+
var first = focusable[0];
|
|
55
|
+
var last = focusable[focusable.length - 1];
|
|
56
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
focusElement(last);
|
|
59
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
focusElement(first);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
close.addEventListener("click", dismiss);
|
|
65
|
+
backdrop.addEventListener("click", function (event) { if (event.target === backdrop) dismiss(); });
|
|
66
|
+
document.body.appendChild(backdrop);
|
|
67
|
+
document.addEventListener("keydown", onKey);
|
|
68
|
+
focusElement(close);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function imageBytes(image) {
|
|
72
|
+
return image && image.data ? Math.ceil(image.data.length * 0.75) : 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function validateFiles(files, currentImages, replaceIndex) {
|
|
76
|
+
var count = currentImages.length + files.length - (replaceIndex == null ? 0 : 1);
|
|
77
|
+
if (count > MAX_IMAGES) return "Too many image attachments";
|
|
78
|
+
var total = 0;
|
|
79
|
+
for (var i = 0; i < currentImages.length; i++) if (i !== replaceIndex) total += imageBytes(currentImages[i]);
|
|
80
|
+
for (var j = 0; j < files.length; j++) {
|
|
81
|
+
if (!IMAGE_TYPE_RE.test(files[j].type || "") || files[j].size > MAX_IMAGE_DATA) return "Invalid image attachment";
|
|
82
|
+
total += files[j].size;
|
|
83
|
+
}
|
|
84
|
+
if (total > MAX_TOTAL_BYTES) return "Message payload is too large";
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function chooseImages(id, replaceIndex, deps) {
|
|
89
|
+
var edit = deps.getEdit();
|
|
90
|
+
if (!edit || edit.id !== id || edit.pendingReads || (deps.isEditable && !deps.isEditable(id))) return;
|
|
91
|
+
var capturedContext = deps.getContext();
|
|
92
|
+
var capturedToken = edit.token;
|
|
93
|
+
var input = document.createElement("input");
|
|
94
|
+
input.type = "file";
|
|
95
|
+
input.accept = "image/*";
|
|
96
|
+
input.multiple = replaceIndex == null;
|
|
97
|
+
input.addEventListener("change", function () {
|
|
98
|
+
var files = Array.prototype.slice.call(input.files || []);
|
|
99
|
+
if (!files.length) return;
|
|
100
|
+
var capturedEdit = deps.getEdit();
|
|
101
|
+
if (!capturedEdit || capturedEdit.id !== id || capturedEdit.token !== capturedToken || !deps.sameContext(deps.getContext(), capturedContext) || (deps.isEditable && !deps.isEditable(id))) return;
|
|
102
|
+
var validationError = validateFiles(files, capturedEdit.images || [], replaceIndex);
|
|
103
|
+
if (validationError) {
|
|
104
|
+
deps.setEdit({ error: validationError });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
var capturedGeneration = capturedEdit.generation;
|
|
108
|
+
var readCount = files.length;
|
|
109
|
+
var startIndex = replaceIndex == null ? (capturedEdit.images || []).length : replaceIndex;
|
|
110
|
+
var staged = [];
|
|
111
|
+
var completed = 0;
|
|
112
|
+
var failed = false;
|
|
113
|
+
deps.setEdit({ pendingReads: readCount });
|
|
114
|
+
files.forEach(function (file, fileIndex) {
|
|
115
|
+
var reader = new FileReader();
|
|
116
|
+
reader.onload = function () {
|
|
117
|
+
var current = deps.getEdit();
|
|
118
|
+
if (!current || current.id !== id || current.token !== capturedToken || current.generation < capturedGeneration || !deps.sameContext(deps.getContext(), capturedContext) || (deps.isEditable && !deps.isEditable(id))) return;
|
|
119
|
+
staged[fileIndex] = { mediaType: file.type, data: String(reader.result).split(",")[1] || "" };
|
|
120
|
+
completed++;
|
|
121
|
+
if (completed === readCount) {
|
|
122
|
+
if (failed) deps.setEdit({ pendingReads: 0, error: "Could not read image" });
|
|
123
|
+
else {
|
|
124
|
+
var next = (current.images || []).slice();
|
|
125
|
+
for (var stagedIndex = 0; stagedIndex < staged.length; stagedIndex++) next[startIndex + stagedIndex] = staged[stagedIndex];
|
|
126
|
+
deps.setEdit({ images: next, pendingReads: 0 });
|
|
127
|
+
}
|
|
128
|
+
} else deps.setEdit({ pendingReads: readCount - completed, error: failed ? "Could not read image" : "" });
|
|
129
|
+
};
|
|
130
|
+
reader.onerror = function () {
|
|
131
|
+
var current = deps.getEdit();
|
|
132
|
+
if (current && current.id === id && current.token === capturedToken && deps.sameContext(deps.getContext(), capturedContext) && (!deps.isEditable || deps.isEditable(id))) {
|
|
133
|
+
failed = true;
|
|
134
|
+
completed++;
|
|
135
|
+
if (completed === readCount) deps.setEdit({ pendingReads: 0, error: "Could not read image" });
|
|
136
|
+
else deps.setEdit({ pendingReads: readCount - completed, error: "Could not read image" });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
reader.readAsDataURL(file);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
input.click();
|
|
143
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function activeQueueItems(items) {
|
|
2
|
+
return (items || []).filter(function (item) { return item.state === "pending" || item.state === "claimed"; });
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function moveQueueId(ids, id, direction, targetId) {
|
|
6
|
+
var next = (ids || []).slice();
|
|
7
|
+
var from = next.indexOf(id);
|
|
8
|
+
if (from < 0) return next;
|
|
9
|
+
var to = targetId ? next.indexOf(targetId) : from + direction;
|
|
10
|
+
if (to < 0 || to >= next.length || to === from) return next;
|
|
11
|
+
next.splice(from, 1);
|
|
12
|
+
next.splice(to, 0, id);
|
|
13
|
+
return next;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function matchesQueueContext(value, projectSlug, sessionId) {
|
|
17
|
+
return !!value && value.projectSlug === projectSlug && String(value.sessionId) === String(sessionId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function canApplyQueueRevision(currentRevision, incomingRevision) {
|
|
21
|
+
return Number(incomingRevision) >= Number(currentRevision);
|
|
22
|
+
}
|