clay-server 5.6.0 → 5.7.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 (74) hide show
  1. package/lib/clay-product-control.js +2 -1
  2. package/lib/daemon.js +12 -0
  3. package/lib/mcp-agent-management.js +98 -0
  4. package/lib/mcp-agent-tools.js +4 -3
  5. package/lib/mcp-local-configuration.js +20 -0
  6. package/lib/mcp-management-service.js +96 -0
  7. package/lib/mcp-remote-connections.js +127 -35
  8. package/lib/mcp-settings-navigation.js +34 -0
  9. package/lib/mcp-xcode.js +43 -0
  10. package/lib/project-admin-overview.js +2 -2
  11. package/lib/project-mcp.js +28 -6
  12. package/lib/project-ownership-diagnostics.js +37 -0
  13. package/lib/project-ownership-recovery.js +59 -0
  14. package/lib/project-ownership.js +1 -34
  15. package/lib/public/app.js +3 -0
  16. package/lib/public/css/mcp-connections.css +15 -0
  17. package/lib/public/css/mcp-skills-workbench.css +6 -4
  18. package/lib/public/css/project-admin-overview.css +4 -0
  19. package/lib/public/css/project-settings-modal.css +8 -0
  20. package/lib/public/css/settings-shell.css +42 -0
  21. package/lib/public/index.html +4 -4
  22. package/lib/public/modules/clay-tool-presentation.js +7 -0
  23. package/lib/public/modules/extension-settings.js +1 -1
  24. package/lib/public/modules/mcp-connection-view.js +52 -24
  25. package/lib/public/modules/mcp-skills-workbench.js +10 -3
  26. package/lib/public/modules/mcp-ui.js +40 -11
  27. package/lib/public/modules/mcp-xcode-view.js +42 -0
  28. package/lib/public/modules/project-admin-overview.js +9 -0
  29. package/lib/public/modules/project-ownership-recovery.js +56 -0
  30. package/lib/public/modules/project-session-visibility-settings.js +1 -1
  31. package/lib/public/modules/project-settings-access.js +91 -0
  32. package/lib/public/modules/project-settings-environment.js +3 -2
  33. package/lib/public/modules/project-settings.js +39 -5
  34. package/lib/public/modules/settings-project-tree.js +74 -0
  35. package/lib/public/modules/settings-shell-view.js +3 -1
  36. package/lib/public/modules/settings-shell.js +3 -2
  37. package/lib/public/pane-assets/{app-QR6W64PK.js → app-KYK2HXZR.js} +1 -1
  38. package/lib/public/pane-assets/chunk-3CGVMON5.js +1 -0
  39. package/lib/public/pane-assets/{chunk-YDQZXMHJ.js → chunk-3WQWIQ53.js} +1 -1
  40. package/lib/public/pane-assets/{chunk-I5RM7KNO.js → chunk-42POZKMA.js} +1 -1
  41. package/lib/public/pane-assets/chunk-53PJD7FQ.js +1 -0
  42. package/lib/public/pane-assets/{chunk-HXD34AZT.js → chunk-5525OCE4.js} +1 -1
  43. package/lib/public/pane-assets/{chunk-K3AFWB4T.js → chunk-6WHHBK62.js} +100 -100
  44. package/lib/public/pane-assets/{chunk-H6RI6IG5.js → chunk-7DMFCL3J.js} +1 -1
  45. package/lib/public/pane-assets/chunk-7IDJFDUF.js +1 -0
  46. package/lib/public/pane-assets/chunk-C4BC5QKM.js +1 -0
  47. package/lib/public/pane-assets/{chunk-OHKQX2VV.js → chunk-G2OD6CYE.js} +1 -1
  48. package/lib/public/pane-assets/{chunk-TUZOISN6.js → chunk-H2Z5IANY.js} +1 -1
  49. package/lib/public/pane-assets/{chunk-4KCNVBBD.js → chunk-I74MAWWL.js} +1 -1
  50. package/lib/public/pane-assets/{chunk-UBGZO6GV.js → chunk-IPEGITRJ.js} +1 -1
  51. package/lib/public/pane-assets/{chunk-25X3V6RW.js → chunk-NTWCEBHU.js} +1 -1
  52. package/lib/public/pane-assets/{chunk-KLRVHJC5.js → chunk-NZYCUCTU.js} +1 -1
  53. package/lib/public/pane-assets/chunk-OX66WEZB.js +1 -0
  54. package/lib/public/pane-assets/{chunk-WI7YYJ5R.js → chunk-SDEVOBXA.js} +1 -1
  55. package/lib/public/pane-assets/chunk-TA6KA3QG.js +1 -0
  56. package/lib/public/pane-assets/chunk-TDKHZ2NU.js +1 -0
  57. package/lib/public/pane-assets/{chunk-H3BOT3SB.js → chunk-UEQM5YNB.js} +1 -1
  58. package/lib/public/pane-assets/{chunk-IIZZTDLB.js → chunk-WBLXJD4Q.js} +1 -1
  59. package/lib/public/pane-assets/{chunk-TKD25TLY.js → chunk-YZAEN74U.js} +1 -1
  60. package/lib/public/pane-assets/chunk-ZBCR4WTM.js +1 -0
  61. package/lib/public/pane-assets/manifest.json +416 -412
  62. package/lib/public/pane-assets/style-WRLOVB6B.css +1 -0
  63. package/lib/server-project-ownership.js +39 -0
  64. package/lib/server.js +5 -0
  65. package/package.json +1 -1
  66. package/lib/public/pane-assets/chunk-AKFJO7SA.js +0 -1
  67. package/lib/public/pane-assets/chunk-DX7R6GRL.js +0 -1
  68. package/lib/public/pane-assets/chunk-F33TBKP2.js +0 -1
  69. package/lib/public/pane-assets/chunk-PTZ2QTNA.js +0 -1
  70. package/lib/public/pane-assets/chunk-QWNMLSVA.js +0 -1
  71. package/lib/public/pane-assets/chunk-VG32EEIQ.js +0 -1
  72. package/lib/public/pane-assets/chunk-W2W4CPO7.js +0 -1
  73. package/lib/public/pane-assets/chunk-XX2GY7T5.js +0 -1
  74. package/lib/public/pane-assets/style-BCUGGAD3.css +0 -1
@@ -0,0 +1,42 @@
1
+ import { escapeHtml } from './utils.js';
2
+ import { iconHtml, refreshIcons } from './icons.js';
3
+
4
+ function button(label, action, primary, disabled) {
5
+ return '<button type="button" class="mc-button' + (primary ? ' mc-primary' : '') + '" data-xcode="' + action + '"' + (disabled ? ' disabled' : '') + '>' + label + '</button>';
6
+ }
7
+ export function renderXcode(root, state, events) {
8
+ var focused = root.contains(document.activeElement) && document.activeElement.dataset.xcode;
9
+ var open = Array.from(root.querySelectorAll('details[open]')).map(function (item) { return item.dataset.tool; });
10
+ var row = (state.servers || []).find(function (item) { return item.integration === 'xcode'; });
11
+ var check = state.xcode, busy = !!state.pending;
12
+ var connected = !!(row && row.projectEnabled), ready = row && row.status === 'ready';
13
+ var status = connected ? ready ? 'Connected' : row.status === 'unavailable' ? 'Connection unavailable' : 'Enabled · connects when used' : 'Not connected';
14
+ var html = '<div class="mc-xcode"><div class="mc-heading"><span class="mc-emblem">' + iconHtml('hammer') + '</span><h2>Xcode</h2><p>Build and test your Apple apps from your Clay Studio conversations.</p></div>';
15
+ html += '<p class="mc-status" data-status="' + (connected && ready ? 'ready' : 'idle') + '"><span aria-hidden="true"></span>' + status + '</p>';
16
+ html += '<p class="mc-footnote">Xcode must run on the same Mac and under the same macOS user as the Clay Studio server.</p>';
17
+ var steps = '<ol class="mc-steps mc-xcode-steps"><li><span class="mc-step-marker">1</span><div><strong>Open your project in Xcode</strong><p>Keep Xcode open while your agent uses its tools.</p></div></li><li><span class="mc-step-marker">2</span><div><strong>Allow external agents</strong><p>In Xcode Settings → Intelligence, turn on “Allow external agents to use Xcode tools”. Approve Clay’s connection in Xcode if asked.</p></div></li><li><span class="mc-step-marker">3</span><div><strong>Connect to Clay Studio</strong><p>No commands, vendor configuration, or browser extension required.</p></div></li></ol>';
18
+ html += connected ? '<details class="mc-manage" data-tool="setup"' + (open.includes('setup') ? ' open' : '') + '><summary>Setup instructions</summary>' + steps + '</details>' : steps;
19
+ if (check && (!connected || !check.ready)) html += '<p class="mc-notice" role="status">' + escapeHtml(check.message) + '</p>';
20
+ if (state.error) html += '<p class="mc-alert" role="alert">' + escapeHtml(state.error) + '</p>';
21
+ if (row && row.error && row.error !== state.error) html += '<p class="mc-alert" role="status">' + escapeHtml(row.error) + '</p>';
22
+ if (state.notice) html += '<p class="mc-notice" role="status">' + escapeHtml(state.notice) + '</p>';
23
+ html += '<div class="mc-detail-actions">' + button(connected ? 'Reconnect Xcode' : 'Connect Xcode', 'connect', true, busy || !state.loaded || !!(check && !check.ready)) + button('Check again', 'check', false, busy) + (busy && state.pending.action === 'xcode_connect' ? button('Cancel connection', 'disconnect', false, false) : connected ? button('Disconnect', 'disconnect', false, false) : row ? button('Remove connection', 'remove', false, busy) : '') + '</div>';
24
+ if (busy) html += '<p class="mc-working" role="status">' + iconHtml('loader-circle') + (state.pending.action === 'xcode_check' ? 'Checking this Mac…' : 'Updating connection…') + '</p>';
25
+ if (row && row.tools && row.tools.length) {
26
+ html += '<div class="mc-section-heading"><h2>Available tools (' + row.tools.length + ')</h2></div><div class="mc-tools">';
27
+ html += row.tools.map(function (tool) { return '<details data-tool="' + escapeHtml(tool.name) + '"' + (open.includes(tool.name) ? ' open' : '') + '><summary>' + escapeHtml(tool.name) + '</summary><p>' + escapeHtml(tool.description || 'No description provided.') + '</p></details>'; }).join('') + '</div>';
28
+ }
29
+ html += '<p class="mc-footnote">Connect enables these tools for your supported private sessions and Mates. Tools become available on the next turn; some runtimes need a new session. Your session’s tool approval policy still applies. Disconnect blocks further calls but cannot undo work already performed in Xcode.</p></div>';
30
+ root.innerHTML = html;
31
+ root.querySelectorAll('[data-xcode]').forEach(function (element) {
32
+ element.onclick = function () {
33
+ var action = element.dataset.xcode;
34
+ if (action === 'connect') events.action('xcode_connect');
35
+ if (action === 'check') events.action('xcode_check');
36
+ if (action === 'disconnect') events.disconnect();
37
+ if (action === 'remove' && row) events.action('remove', { id: row.id });
38
+ };
39
+ });
40
+ if (focused) { var target = root.querySelector('[data-xcode="' + focused + '"]'); if (target && !target.disabled) target.focus({ preventScroll: true }); }
41
+ refreshIcons(root);
42
+ }
@@ -1,3 +1,4 @@
1
+ import { mountOwnershipRecovery } from './project-ownership-recovery.js';
1
2
  // Restricted projects use public shell primitives without opening a project socket.
2
3
  import { createStore, store } from './store.js';
3
4
  import { groupProjects, getProjectAbbrev } from './project-grouping.js';
@@ -134,3 +135,11 @@ document.addEventListener('visibilitychange', function () { if (document.hidden)
134
135
  window.addEventListener('pagehide', function () { clearTimeout(store.get('adminUsageTimer')); store.set({ adminUsageGeneration: store.get('adminUsageGeneration') + 1 }); });
135
136
  window.addEventListener('pageshow', function (event) { if (event.persisted) { clearUsage(); store.set({ adminUsageLoading: false }); loadUsage(false); } });
136
137
  loadUsage(false);
138
+
139
+ if (data.project.ownershipRecovery) {
140
+ var recovery = document.createElement('div'); recovery.id = 'overview-ownership-recovery'; recovery.className = 'ownership-recovery';
141
+ document.getElementById('access-panel').appendChild(recovery);
142
+ if (data.project.isWorktree) {
143
+ var parentLink = document.createElement('a'); parentLink.href = '/p/' + encodeURIComponent(data.project.parentSlug) + '/'; parentLink.textContent = 'Recover ownership in the parent project'; recovery.appendChild(parentLink);
144
+ } else mountOwnershipRecovery(recovery, data.project.slug);
145
+ }
@@ -0,0 +1,56 @@
1
+ import { store } from './store.js';
2
+
3
+ function node(tag, text, className) { var el = document.createElement(tag); if (text) el.textContent = text; if (className) el.className = className; return el; }
4
+ function action(text, fn) { var el = node('button', text, 'settings-btn-sm'); el.type = 'button'; el.onclick = fn; return el; }
5
+ async function request(slug, revision) {
6
+ var response = await fetch('/api/project-settings/' + encodeURIComponent(slug) + '/ownership', {
7
+ method: revision ? 'POST' : 'GET', credentials: 'same-origin', signal: AbortSignal.timeout(10000),
8
+ headers: { 'Content-Type': 'application/json' }, body: revision ? JSON.stringify({ revision: revision }) : undefined
9
+ });
10
+ var result = await response.json(); if (!response.ok) throw new Error(result.error || 'Recovery check failed.'); return result;
11
+ }
12
+ export function mountOwnershipRecovery(root, slug) {
13
+ var key = root.id, token = crypto.randomUUID();
14
+ var panels = Object.assign({}, store.get('ownershipRecoveryPanels'));
15
+ panels[key] = { slug: slug, token: token }; store.set({ ownershipRecoveryPanels: panels });
16
+ function current() { var item = (store.get('ownershipRecoveryPanels') || {})[key]; return root.isConnected && item && item.token === token; }
17
+ function status(text) { var el = node('p', text, 'settings-status'); el.setAttribute('role', 'status'); return el; }
18
+ async function check() {
19
+ if (!current()) return;
20
+ root.replaceChildren(status('Checking ownership…'));
21
+ try { var result = await request(slug); if (current()) render(result); }
22
+ catch (error) { if (current()) root.replaceChildren(status(error.message), action('Check again', check)); }
23
+ }
24
+ function render(result) {
25
+ root.replaceChildren(node('h3', result.status === 'healthy' ? 'Ownership verified' : 'Ownership recovery'), status(result.message));
26
+ root.appendChild(node('p', 'Checked ' + new Date(result.checkedAt).toLocaleTimeString() + '. Recovery keeps session owners and sharing unchanged.', 'settings-hint'));
27
+ if (result.owner) root.appendChild(node('p', (result.status === 'ready' ? 'Verified recovery owner: ' : 'Owner: ') + result.owner.name));
28
+ var controls = node('div', '', 'settings-form-actions'); controls.appendChild(action('Check again', check));
29
+ if (result.status === 'ready') controls.appendChild(action('Review recovery', function () {
30
+ if (!current()) return;
31
+ var review = node('div', '', 'ownership-review');
32
+ review.appendChild(node('p', 'Restore ' + slug + ' to ' + result.owner.name + '? This updates the parent and all its worktrees. Private session ownership stays unchanged.'));
33
+ review.append(action('Cancel', function () { render(result); }), action('Recover ownership', async function () {
34
+ if (!current()) return;
35
+ root.replaceChildren(status('Recovering ownership…'));
36
+ try {
37
+ var saved = await request(slug, result.revision);
38
+ if (current()) root.replaceChildren(status('Ownership recovered for ' + saved.owner.name + '.'), action('Reload project', function () { location.assign('/p/' + encodeURIComponent(slug) + '/'); }));
39
+ } catch (error) {
40
+ if (current()) root.replaceChildren(status(error.message + ' The result may be unknown if the connection was interrupted. Check the saved ownership before another review.'), action('Check again', check));
41
+ }
42
+ }));
43
+ root.appendChild(review); review.querySelector('button').focus();
44
+ }));
45
+ root.appendChild(controls);
46
+ if (result.status !== 'healthy') {
47
+ var help = node('details'); help.appendChild(node('summary', 'Server operator instructions'));
48
+ help.appendChild(node('p', 'On the system running Clay Studio, verify the original project directory, its filesystem owner, and the original account’s provisioned system user and home. Restore missing accounts or mounts through your normal server provisioning process. Resolve shared UIDs, overlapping homes or symlink aliases before checking again.'));
49
+ help.appendChild(node('p', 'Application administrator status cannot prove private project ownership. Do not assign an arbitrary account or change filesystem ownership just to pass this check.'));
50
+ help.appendChild(action('Copy diagnostic summary', function () {
51
+ navigator.clipboard.writeText(JSON.stringify({ project: slug, status: result.status, code: result.code, message: result.message }, null, 2)).then(function () { if (current()) help.appendChild(status('Diagnostic summary copied.')); }, function () { if (current()) help.appendChild(status('Copy unavailable. Select the diagnostic text above.')); });
52
+ })); root.appendChild(help);
53
+ }
54
+ }
55
+ check();
56
+ }
@@ -56,7 +56,7 @@ function visibilityAccess(project) {
56
56
  var permitted = !store.get('permissions') || store.get('permissions').projectSettings !== false;
57
57
  var owner = !!(project && project.projectOwnerId && project.projectOwnerId === userId);
58
58
  var admin = !!(currentUser && currentUser.role === "admin");
59
- var multi = !!(store.get('isMultiUserMode') && project && permitted);
59
+ var multi = !!(store.get('isMultiUserMode') && project && project.contentAccess !== false && permitted);
60
60
  return { visible: multi && (owner || admin), editable: multi && owner };
61
61
  }
62
62
 
@@ -0,0 +1,91 @@
1
+ import { enhanceSettingsSelects } from './settings-select.js';
2
+ import { store } from './store.js';
3
+ import { openSettings } from './settings-shell.js';
4
+ import { mountOwnershipRecovery } from './project-ownership-recovery.js';
5
+ import { confirmSettingsAction } from './server-settings-state.js';
6
+
7
+ function node(tag, text, className) { var el = document.createElement(tag); el.textContent = text || ''; if (className) el.className = className; return el; }
8
+ function button(text, fn) { var el = node('button', text, 'settings-btn-sm'); el.type = 'button'; el.onclick = fn; return el; }
9
+ async function request(slug, suffix, data) {
10
+ var response = await fetch('/api/admin/projects/' + encodeURIComponent(slug) + '/' + suffix, { credentials: 'same-origin', method: data ? 'PUT' : 'GET', headers: { 'Content-Type': 'application/json' }, body: data ? JSON.stringify(data) : undefined, signal: AbortSignal.timeout(10000) });
11
+ var result = await response.json(); if (!response.ok) { var error = new Error(result.error || 'Project access unavailable.'); error.status = response.status; throw error; } return result;
12
+ }
13
+ export function clearProjectSettingsAccess() { store.set({ projectSettingsAccess: null }); }
14
+ export function loadProjectSettingsAccess(slug, project) {
15
+ var root = document.getElementById('ps-access-management');
16
+ var token = crypto.randomUUID(); store.set({ projectSettingsAccess: { slug: slug, token: token } });
17
+ function current() { var s = store.get('projectSettingsAccess'); return s && s.token === token && store.get('projectSettingsSlug') === slug; }
18
+ function update(values) { if (current()) store.set({ projectSettingsAccess: Object.assign({}, store.get('projectSettingsAccess'), values) }); }
19
+ function reload() { if (current()) loadProjectSettingsAccess(slug, project); }
20
+ root.replaceChildren();
21
+ if (!store.get('isMultiUserMode')) { root.appendChild(node('p', 'This single-user server is private to its operator.', 'settings-hint')); return; }
22
+ root.appendChild(node('p', 'Loading access…', 'settings-status'));
23
+ request(slug, 'access').then(function (access) {
24
+ if (!current()) return;
25
+ root.replaceChildren();
26
+ var ownerId = access.ownerId || access.projectOwnerId;
27
+ var owner = ownerId === store.get('myUserId');
28
+ var inherited = project.isWorktree;
29
+ var parentSlug = project.parentSlug || access.parentSlug;
30
+ var ownerAccount = (store.get('cachedAllUsers') || []).find(function (account) { return account.id === ownerId; });
31
+ root.appendChild(node('p', 'Owner: ' + (access.ownerName || ownerAccount && (ownerAccount.displayName || ownerAccount.username) || ownerId || 'Ownership needs recovery')));
32
+ root.appendChild(node('p', 'Project access: ' + (access.visibility === 'public' ? 'Public — authenticated users' : 'Private')));
33
+ if (inherited) {
34
+ root.appendChild(node('p', 'Inherited from ' + parentSlug + '. Parent access covers every existing and future worktree.', 'settings-hint'));
35
+ root.appendChild(button('Manage parent access', function () { openSettings({ scope: 'project', slug: parentSlug, page: 'access' }); }));
36
+ } else root.appendChild(node('p', 'Access applies to this project and all existing and future worktrees. Removing a parent grant removes inherited access; separate exact-worktree grants remain independent.', 'settings-hint'));
37
+ if (owner && !inherited) root.appendChild(button('Manage access and ownership', function () { edit(access); }));
38
+ if (!owner) root.appendChild(node('p', 'Only the verified owner can change project access. Project content remains subject to your current permissions.', 'settings-hint'));
39
+ if (project.ownershipRecovery || access.ownershipRecovery || !ownerId) {
40
+ var recovery = node('div', '', 'ownership-recovery'); recovery.id = 'ps-ownership-recovery'; root.appendChild(recovery);
41
+ if (inherited) recovery.appendChild(node('p', 'Recover ownership in the parent project.', 'settings-hint'));
42
+ else mountOwnershipRecovery(recovery, slug);
43
+ }
44
+ root.appendChild(button('Refresh access', reload));
45
+ }).catch(function (error) {
46
+ if (!current()) return;
47
+ root.replaceChildren(node('p', error.status === 403 ? 'Only the project owner can inspect or change detailed access settings.' : error.message, 'settings-status'));
48
+ if (error.status === 403 && project.contentAccess !== false && project.isWorktree) {
49
+ root.appendChild(node('p', 'Inherited from ' + project.parentSlug + '. Parent access covers every existing and future worktree.', 'settings-hint'));
50
+ if ((store.get('projectsHubList') || []).some(function (entry) { return entry.slug === project.parentSlug; })) root.appendChild(button('Manage parent access', function () { openSettings({ scope: 'project', slug: project.parentSlug, page: 'access' }); }));
51
+ }
52
+ root.appendChild(button('Retry', reload));
53
+ });
54
+ async function edit(access) {
55
+ var response;
56
+ try { response = await fetch('/api/admin/users', { credentials: 'same-origin', signal: AbortSignal.timeout(10000) }); var data = await response.json(); if (!response.ok) throw new Error(data.error || 'Accounts unavailable.'); }
57
+ catch (error) { if (current()) root.appendChild(node('p', error.message, 'settings-status')); return; }
58
+ if (!current()) return;
59
+ var users = data.users || [];
60
+ var editor = node('div', '', 'ps-access-editor'); root.replaceChildren(editor);
61
+ editor.addEventListener('change', function () { update({ dirty: true }); });
62
+ var status = node('p', '', 'settings-status'); status.setAttribute('role', 'status');
63
+ async function save(suffix, value) {
64
+ if (!current()) return;
65
+ update({ saving: true });
66
+ Array.from(editor.querySelectorAll('button,input,select')).forEach(function (el) { el.disabled = true; if (el.tagName === 'SELECT') el.dispatchEvent(new Event('settings-sync')); }); status.textContent = 'Saving…';
67
+ try { await request(slug, suffix, value); if (current()) { status.textContent = 'Saved.'; reload(); } }
68
+ catch (error) { if (current()) { update({ saving: false }); status.textContent = error.message + ' Check the saved state before retrying; your draft is retained.'; Array.from(editor.querySelectorAll('button,input,select')).forEach(function (el) { el.disabled = false; if (el.tagName === 'SELECT') el.dispatchEvent(new Event('settings-sync')); }); } }
69
+ }
70
+ var visibility = node('select'); visibility.setAttribute('aria-label', 'Project access');
71
+ ['private', 'public'].forEach(function (value) { var option = node('option', value === 'private' ? 'Private' : 'Public — authenticated users'); option.value = value; visibility.appendChild(option); }); visibility.value = access.visibility;
72
+ editor.append(node('h3', 'Project access'), visibility, button('Save project access', function () { var value = visibility.value; confirmSettingsAction('Change access for this project and all its worktrees to ' + value + '?', 'Save project access', function () { save('visibility', { visibility: value }); }); }));
73
+ var members = node('div');
74
+ users.filter(function (user) { return user.id !== access.ownerId; }).forEach(function (user) {
75
+ var label = node('label', '', 'ps-access-member'); var input = node('input'); input.type = 'checkbox'; input.value = user.id; input.checked = (access.allowedUsers || []).includes(user.id);
76
+ label.append(input, node('span', user.displayName || user.username)); members.appendChild(label);
77
+ });
78
+ editor.append(node('h3', 'Allowed users'), node('p', 'These grants cover all worktrees. Public access takes precedence while the project is public.', 'settings-hint'), members,
79
+ button('Save allowed users', function () { save('users', { allowedUsers: Array.from(members.querySelectorAll('input:checked')).map(function (el) { return el.value; }) }); }));
80
+ var owners = node('select'); owners.setAttribute('aria-label', 'New project owner');
81
+ users.forEach(function (user) { var option = node('option', user.displayName || user.username); option.value = user.id; owners.appendChild(option); }); owners.value = access.ownerId;
82
+ editor.append(node('h3', 'Transfer ownership'), owners, button('Review ownership transfer', function () {
83
+ if (owners.value === access.ownerId) { status.textContent = 'Choose a different owner.'; return; }
84
+ var nextOwner = owners.value;
85
+ confirmSettingsAction('Transfer this project and its worktrees to ' + owners.selectedOptions[0].textContent + '? Existing session owners stay unchanged. You may lose access.', 'Transfer ownership', function () { save('owner', { userId: nextOwner }); });
86
+ }), status, button('Back to access', function () {
87
+ if ((store.get('projectSettingsAccess') || {}).dirty) confirmSettingsAction('Discard unsaved access changes?', 'Discard changes', reload); else reload();
88
+ }));
89
+ enhanceSettingsSelects(editor);
90
+ }
91
+ }
@@ -5,7 +5,7 @@ import { parseEnvString, serializeEnvValue, looksLikeEnv } from './settings-env-
5
5
 
6
6
  function state() { return store.get('projectEnvironmentEditor') || {}; }
7
7
  function update(values) { store.set({ projectEnvironmentEditor: Object.assign({}, state(), values) }); }
8
- function status(text) { document.getElementById('ps-env-save-status').textContent = text; }
8
+ function status(text) { document.getElementById('ps-env-save-status').textContent = text; var retry = document.getElementById('ps-env-retry'); if (retry) retry.hidden = !state().slug || !!state().loaded || !!state().loading; }
9
9
  function send(message) {
10
10
  var ws = getWs();
11
11
  if (!ws || ws.readyState !== 1) { status('Disconnected. Your draft is kept. Reconnect and try again.'); return false; }
@@ -22,7 +22,7 @@ export function openProjectEnvironment(slug) {
22
22
  render(); status('Loading…');
23
23
  var requestId = crypto.randomUUID();
24
24
  update({ requestId: requestId });
25
- if (send({ type: 'get_project_env', slug: slug, requestId: requestId })) update({ loading: true });
25
+ if (send({ type: 'get_project_env', slug: slug, requestId: requestId })) { update({ loading: true }); status('Loading…'); }
26
26
  }
27
27
  export function handleProjectEnv(msg) {
28
28
  if (!state().loading || (msg.slug !== state().slug || msg.requestId !== state().requestId)) return;
@@ -104,6 +104,7 @@ function save() {
104
104
  update({ submitted: envrc, saving: true }); render(); status('Saving…');
105
105
  }
106
106
  export function initProjectEnvironment() {
107
+ var retry = document.getElementById('ps-env-retry'); if (retry) retry.onclick = function () { openProjectEnvironment(store.get('projectSettingsSlug')); };
107
108
  document.getElementById('ps-env-add-btn').onclick = function () { changeRows((state().rows || []).concat([{ key: '', value: '' }])); render(); document.querySelector('#ps-env-list .ps-env-row:last-child input').focus(); };
108
109
  document.getElementById('ps-env-save').onclick = save;
109
110
  store.subscribe(function (next, previous) {
@@ -1,3 +1,4 @@
1
+ import { loadProjectSettingsAccess, clearProjectSettingsAccess } from './project-settings-access.js';
1
2
  import { store } from './store.js';
2
3
  import { getWs } from './ws-ref.js';
3
4
  import { initProjectEnvironment, openProjectEnvironment, projectEnvironmentDirty, discardProjectEnvironment } from './project-settings-environment.js';
@@ -34,10 +35,15 @@ var controller = {
34
35
  enter: function () {},
35
36
  activate: function (page) { switchSection(page); },
36
37
  leave: function () { closePsEmojiPicker(); },
37
- busy: function (kind) { return kind !== "page" && (store.get("projectEnvironmentEditor") || {}).saving ? "Wait for the environment save to finish." : ""; },
38
+ busy: function (kind) { if ((store.get("projectSettingsAccess") || {}).saving) return "Wait for the access save to finish."; return kind !== "page" && (store.get("projectEnvironmentEditor") || {}).saving ? "Wait for the environment save to finish." : ""; },
38
39
  leavePrompt: function (kind) {
40
+ var access = store.get("projectSettingsAccess");
39
41
  var env = projectEnvironmentDirty();
40
42
  var rename = renameDirty();
43
+ if (kind !== "page" && access && access.dirty) return {
44
+ message: kind === "close" ? "Discard unsaved project changes and close?" : "Discard unsaved project access and name changes? Environment drafts remain in this tab.",
45
+ action: "Discard changes", apply: function () { clearProjectSettingsAccess(); if (kind === "close") discardDrafts(); else cancelRename(); }
46
+ };
41
47
  if (!env && !rename) return null;
42
48
  if (kind === "close") return { message: "Your changes have not been saved. Discard them and close?", action: "Discard changes", apply: discardDrafts };
43
49
  if (kind === "page") return null;
@@ -122,18 +128,26 @@ function bindProjectSettings(slug, project) {
122
128
  if (env && !env.dirty && !env.saving) store.set({ projectEnvironmentEditor: Object.assign({}, env, { loaded: false, loading: false }) });
123
129
  if (same) refreshProjectSettings(slug, project);
124
130
  else { closePsEmojiPicker(); populateProfile(); }
125
- var active = panelEl.querySelector(".ps-section.active");
126
- if (active && active.dataset.section === "environment") openProjectEnvironment(slug);
131
+ loadProjectSettingsAccess(slug, project);
132
+ if (project.contentAccess !== false) openProjectEnvironment(slug);
127
133
  }
128
134
 
129
135
  function refreshProjectSettings(slug, project) {
130
136
  if (settingsSlug() !== slug) return;
137
+ var previousProject = settingsProject();
138
+ var changedAccess = previousProject && (previousProject.contentAccess !== project.contentAccess || previousProject.projectOwnerId !== project.projectOwnerId || previousProject.ownershipRecovery !== project.ownershipRecovery);
139
+ if (project.contentAccess === false) {
140
+ store.set({ projectEnvironmentEditor: {}, projectEnvironmentDrafts: {} });
141
+ document.getElementById('ps-env-list').replaceChildren();
142
+ }
131
143
  var name = project.title || project.project || project.name || slug;
132
144
  store.set({ projectSettingsProject: Object.assign({}, project, { name: name }) });
133
145
  var nameEl = document.getElementById("ps-project-name");
134
146
  if (nameEl) nameEl.textContent = name || "-";
135
147
  updateIconPreview(project.icon || null);
148
+ if (changedAccess) { loadProjectSettingsAccess(slug, project); switchSection(); }
136
149
  populateProjectSessionVisibilitySettings(slug, settingsProject());
150
+ document.getElementById("ps-target-title").textContent = name;
137
151
  document.getElementById('ps-project-path').textContent = project.path || (slug === store.get('currentSlug') ? store.get('cwd') : '') || 'Folder information unavailable';
138
152
  }
139
153
 
@@ -144,6 +158,12 @@ function clearProjectSettings(slug) {
144
158
  delete drafts[slug];
145
159
  store.set({ projectSettingsSlug: null, projectSettingsProject: null, projectEnvironmentDrafts: drafts });
146
160
  if (env.slug === slug) { store.set({ projectEnvironmentEditor: {} }); }
161
+ clearProjectSettingsAccess();
162
+ document.getElementById('ps-access-management').replaceChildren();
163
+ document.getElementById('ps-target-title').textContent = '';
164
+ document.getElementById('ps-target-context').textContent = '';
165
+ var openLink = document.getElementById('ps-open-project'); if (openLink) openLink.hidden = true;
166
+ document.getElementById('ps-env-list').replaceChildren();
147
167
  closePsEmojiPicker();
148
168
  cancelRename();
149
169
  }
@@ -192,12 +212,26 @@ export function isProjectSettingsOpen() {
192
212
  }
193
213
 
194
214
  function switchSection(name) {
215
+ var project = settingsProject();
216
+ var restricted = project && project.contentAccess === false;
217
+ var editable = !store.get('isMultiUserMode') || project && project.projectOwnerId === store.get('myUserId');
218
+ ['ps-rename-btn', 'ps-icon-btn', 'ps-icon-remove-btn'].forEach(function (id) { document.getElementById(id).disabled = !editable || restricted; });
195
219
  for (var j = 0; j < sections.length; j++) {
196
- sections[j].classList.toggle("active", sections[j].dataset.section === name);
220
+ sections[j].classList.add("active");
221
+ sections[j].hidden = !!restricted && sections[j].dataset.section !== "access";
197
222
  }
198
- if (name === "environment" && settingsSlug()) openProjectEnvironment(settingsSlug());
223
+ var title = document.getElementById('ps-target-title');
224
+ title.textContent = project ? project.name : '';
225
+ var openLink = document.getElementById('ps-open-project'); if (openLink) openLink.hidden = !project;
226
+ if (project && openLink) { openLink.href = '/p/' + encodeURIComponent(settingsSlug()) + '/'; openLink.textContent = restricted ? 'Open overview' : 'Open project'; }
227
+ document.getElementById('ps-target-context').textContent = !project ? '' : restricted ? 'Administrative metadata only' : project.isWorktree ? 'Worktree / ' + (project.parentSlug || '') : 'Project settings';
228
+ if (project && !restricted) openProjectEnvironment(settingsSlug());
199
229
  enhanceSettingsSelects(panelEl);
200
230
  refreshIcons();
231
+ if (name && name !== 'profile') requestAnimationFrame(function () {
232
+ var section = panelEl.querySelector('[data-section="' + name + '"]');
233
+ if (section && !section.hidden) section.scrollIntoView({ block: 'start' });
234
+ });
201
235
  }
202
236
 
203
237
  function populateProfile() {
@@ -0,0 +1,74 @@
1
+ import { store } from './store.js';
2
+ import { groupProjects } from './project-grouping.js';
3
+
4
+ function state() { return store.get('settingsProjectTree') || { expanded: {}, query: '' }; }
5
+ function button(text, label, action) {
6
+ var node = document.createElement('button'); node.type = 'button'; node.textContent = text;
7
+ node.setAttribute('aria-label', label); node.onclick = action; return node;
8
+ }
9
+ export function renderProjectTree(choices, selected, onSelect, placeholder) {
10
+ var root = document.getElementById('settings-project-tree');
11
+ if (!root) return;
12
+ var focus = root.contains(document.activeElement) && document.activeElement.dataset.treeKey;
13
+ var data = state();
14
+ root.replaceChildren();
15
+ var search = document.createElement('input'); search.type = 'search'; search.placeholder = 'Find a project or worktree…';
16
+ search.setAttribute('aria-label', 'Find a project or worktree'); search.value = data.query; search.dataset.treeKey = 'search';
17
+ search.oninput = function () {
18
+ store.set({ settingsProjectTree: Object.assign({}, state(), { query: search.value }) });
19
+ renderProjectTree(choices, selected, onSelect, placeholder);
20
+ };
21
+ root.onkeydown = function (event) {
22
+ if (event.target === search) return;
23
+ var items = Array.from(root.querySelectorAll('button')).filter(function (el) { return !el.closest('[hidden]'); });
24
+ var index = items.indexOf(document.activeElement);
25
+ if (index < 0) return;
26
+ if (['ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) {
27
+ event.preventDefault();
28
+ var next = event.key === 'Home' ? 0 : event.key === 'End' ? items.length - 1 : Math.max(0, Math.min(items.length - 1, index + (event.key === 'ArrowDown' ? 1 : -1)));
29
+ items[next].focus();
30
+ } else if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
31
+ var toggle = event.target.closest('.settings-project-row').querySelector('[aria-expanded]');
32
+ if (toggle && toggle.getAttribute('aria-expanded') !== String(event.key === 'ArrowRight')) { event.preventDefault(); toggle.click(); }
33
+ }
34
+ };
35
+ root.appendChild(search);
36
+ var list = document.createElement('div'); list.className = 'settings-project-list'; list.setAttribute('aria-label', 'Projects'); root.appendChild(list);
37
+ var query = data.query.trim().toLowerCase();
38
+ var grouped = groupProjects(choices.map(function (choice) { return Object.assign({}, choice.project, { settingsChoice: choice }); }));
39
+ function matches(project) { return !query || (project.settingsChoice.label + ' ' + project.slug).toLowerCase().includes(query); }
40
+ function row(project, children, child) {
41
+ var item = document.createElement('div'); item.className = 'settings-project-row' + (child ? ' settings-worktree-row' : '');
42
+ var expanded = !!data.expanded[project.slug];
43
+ if (children.length) {
44
+ var toggle = button(expanded ? '⌄' : '›', (expanded ? 'Collapse ' : 'Expand ') + project.settingsChoice.label + ' worktrees', function () {
45
+ var next = Object.assign({}, state().expanded); next[project.slug] = !expanded;
46
+ store.set({ settingsProjectTree: Object.assign({}, state(), { expanded: next }) });
47
+ renderProjectTree(choices, selected, onSelect, placeholder);
48
+ });
49
+ toggle.className = 'settings-project-expand'; toggle.dataset.treeKey = 'expand:' + project.slug;
50
+ toggle.setAttribute('aria-expanded', String(expanded)); toggle.setAttribute('aria-controls', 'settings-children-' + project.slug); item.appendChild(toggle);
51
+ } else { var spacer = document.createElement('span'); spacer.className = 'settings-project-expand-spacer'; item.appendChild(spacer); }
52
+ var select = button(project.settingsChoice.label, project.settingsChoice.label + (child ? ' worktree' : ' project'), function () { onSelect(project.slug); });
53
+ select.className = 'settings-project-item'; select.dataset.slug = project.slug; select.dataset.treeKey = 'select:' + project.slug;
54
+ select.classList.toggle('active', project.slug === selected);
55
+ if (project.slug === selected) select.setAttribute('aria-current', 'page');
56
+ var label = document.createElement('span'); label.className = 'settings-project-label'; label.textContent = project.settingsChoice.label;
57
+ var detail = document.createElement('small');
58
+ detail.textContent = project.ownershipRecovery ? 'Needs recovery' : children.length ? children.length + ' worktrees' : child ? 'Worktree' : '';
59
+ select.replaceChildren(label, detail); item.appendChild(select); list.appendChild(item);
60
+ if (children.length) {
61
+ var group = document.createElement('div'); group.id = 'settings-children-' + project.slug; group.hidden = !expanded; group.className = 'settings-project-children';
62
+ list.appendChild(group);
63
+ children.filter(function (entry) { return matches(project) || matches(entry); }).forEach(function (entry) {
64
+ row(entry, [], true); group.appendChild(list.lastChild);
65
+ });
66
+ }
67
+ }
68
+ grouped.parents.forEach(function (project) {
69
+ var children = grouped.wtByParent[project.slug] || [];
70
+ if (matches(project) || children.some(matches)) row(project, children, project.isWorktree);
71
+ });
72
+ if (!list.children.length) { var empty = document.createElement('p'); empty.className = 'settings-hint'; empty.textContent = choices.length ? 'No matching projects or worktrees.' : placeholder || 'No projects available'; list.appendChild(empty); }
73
+ if (focus) Array.from(root.querySelectorAll('[data-tree-key]')).some(function (node) { if (node.dataset.treeKey !== focus) return false; node.focus(); return true; });
74
+ }
@@ -1,5 +1,6 @@
1
1
  // DOM rendering for the unified settings shell chrome: scope tabs, page
2
2
  // navigation (desktop list + narrow select) and the project selector.
3
+ import { renderProjectTree } from './settings-project-tree.js';
3
4
  import { SETTINGS_SCOPES } from './settings-shell-registry.js';
4
5
  import { optionLabel } from './settings-project-target.js';
5
6
  import { enhanceSettingsSelects } from './settings-select.js';
@@ -94,6 +95,7 @@ export function markActivePage(activePage) {
94
95
  // The selector is a plain select; settings-select upgrades it to the shared
95
96
  // desktop picker and leaves the native control on narrow screens.
96
97
  export function renderProjectSelect(choices, selectedSlug, onChange, placeholder) {
98
+ renderProjectTree(choices, selectedSlug, onChange, placeholder);
97
99
  var wrap = el('settings-project-picker');
98
100
  var select = el('settings-project-select');
99
101
  select.replaceChildren();
@@ -113,7 +115,7 @@ export function renderProjectSelect(choices, selectedSlug, onChange, placeholder
113
115
  select.dispatchEvent(new Event('settings-sync'));
114
116
  }
115
117
 
116
- export function showProjectPicker(visible) { el('settings-project-picker').hidden = !visible; }
118
+ export function showProjectPicker(visible) { el('settings-project-picker').hidden = !visible; el('settings-shell').classList.toggle('settings-project-scope', visible); }
117
119
  export function selectedProjectValue() { return el('settings-project-select').value; }
118
120
  export function syncProjectSelect(slug) {
119
121
  var select = el('settings-project-select');
@@ -19,7 +19,7 @@ var binding = createTargetBinding();
19
19
  var root = null;
20
20
  var lastChoices = '';
21
21
  var OFFLINE = 'Offline. The project list and your project access may be out of date until the connection returns.';
22
- var shell = { verified: false, pending: null, waiting: null, offline: false, open: false, scope: null, pages: {}, slug: null, access: defaultAccess(), returnFocus: null, restoreInert: null, notesReopen: false, token: 0, pending: null };
22
+ var shell = { verified: false, pending: null, waiting: null, offline: false, open: false, scope: null, pages: {}, slug: null, access: defaultAccess(), returnFocus: null, restoreInert: null, notesReopen: false, token: 0 };
23
23
  var OVERLAYS = '.admin-modal-overlay, #settings-confirm, .confirm-above-settings, .avatar-positioner-overlay, .email-setup-overlay, .settings-subview';
24
24
 
25
25
  export function registerSettingsScope(id, controller) { controllers[id] = controller; }
@@ -81,7 +81,7 @@ function guard(kind, proceed, pageId) {
81
81
  }
82
82
 
83
83
  function choicesSignature(choices, slug) {
84
- return choices.map(function (choice) { return choice.slug + '|' + choice.label + '|' + choice.isCurrent; }).join('\n') + '#' + (slug || '');
84
+ return choices.map(function (choice) { return choice.slug + '|' + choice.label + '|' + choice.isCurrent + '|' + !!choice.project.ownershipRecovery + '|' + choice.project.parentSlug; }).join('\n') + '#' + (slug || '');
85
85
  }
86
86
 
87
87
  function applyProject(ctrl, route, page) {
@@ -201,6 +201,7 @@ export function openSettings(route) {
201
201
  if (!root) return Promise.resolve();
202
202
  route = route || store.get('settingsLastRoute') || { scope: 'personal' };
203
203
  if (shell.open) { navigateSettings(route); return Promise.resolve(); }
204
+ store.set({ settingsProjectTree: { expanded: {}, query: '' } });
204
205
  shell.open = true;
205
206
  shell.token += 1;
206
207
  var token = shell.token;