@clagentic/console 1.0.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 (221) hide show
  1. package/CREDITS.md +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +250 -0
  4. package/bin/cli.js +2812 -0
  5. package/lib/agents-favorites.js +164 -0
  6. package/lib/agents.js +282 -0
  7. package/lib/ask-user-mcp-server.js +120 -0
  8. package/lib/browser-mcp-server.js +484 -0
  9. package/lib/build-user-env.js +63 -0
  10. package/lib/certs/fullchain.pem +47 -0
  11. package/lib/certs/privkey.pem +5 -0
  12. package/lib/cli-sessions.js +265 -0
  13. package/lib/codex-defaults.js +18 -0
  14. package/lib/config.js +332 -0
  15. package/lib/crisis-safety.js +60 -0
  16. package/lib/daemon-projects.js +164 -0
  17. package/lib/daemon.js +1602 -0
  18. package/lib/dm.js +128 -0
  19. package/lib/ipc.js +125 -0
  20. package/lib/ipv4-only.js +39 -0
  21. package/lib/mcp-local.js +385 -0
  22. package/lib/notes.js +141 -0
  23. package/lib/os-users.js +529 -0
  24. package/lib/pages.js +1325 -0
  25. package/lib/project-connection.js +302 -0
  26. package/lib/project-external-trigger.js +236 -0
  27. package/lib/project-file-watch.js +120 -0
  28. package/lib/project-filesystem.js +528 -0
  29. package/lib/project-http.js +753 -0
  30. package/lib/project-image.js +95 -0
  31. package/lib/project-knowledge.js +88 -0
  32. package/lib/project-loop.js +1304 -0
  33. package/lib/project-mcp.js +374 -0
  34. package/lib/project-memory.js +39 -0
  35. package/lib/project-notifications.js +262 -0
  36. package/lib/project-sessions.js +1581 -0
  37. package/lib/project-user-mention.js +193 -0
  38. package/lib/project-user-message.js +628 -0
  39. package/lib/project.js +1303 -0
  40. package/lib/public/app.js +1031 -0
  41. package/lib/public/apple-touch-icon.png +0 -0
  42. package/lib/public/claude-code-avatar.png +0 -0
  43. package/lib/public/codex-avatar.png +0 -0
  44. package/lib/public/console-icon.png +0 -0
  45. package/lib/public/css/admin.css +736 -0
  46. package/lib/public/css/agent-picker.css +119 -0
  47. package/lib/public/css/base.css +235 -0
  48. package/lib/public/css/channel-layout.css +441 -0
  49. package/lib/public/css/command-palette.css +559 -0
  50. package/lib/public/css/debate.css +1609 -0
  51. package/lib/public/css/diff.css +139 -0
  52. package/lib/public/css/filebrowser.css +1976 -0
  53. package/lib/public/css/highlight.css +144 -0
  54. package/lib/public/css/home-hub.css +545 -0
  55. package/lib/public/css/icon-strip.css +1856 -0
  56. package/lib/public/css/input.css +1349 -0
  57. package/lib/public/css/loop.css +1248 -0
  58. package/lib/public/css/mention.css +317 -0
  59. package/lib/public/css/menus.css +857 -0
  60. package/lib/public/css/messages.css +1833 -0
  61. package/lib/public/css/mobile-nav.css +1332 -0
  62. package/lib/public/css/notifications-center.css +296 -0
  63. package/lib/public/css/overlays.css +1273 -0
  64. package/lib/public/css/playbook.css +264 -0
  65. package/lib/public/css/profile.css +397 -0
  66. package/lib/public/css/rewind.css +671 -0
  67. package/lib/public/css/scheduler-modal.css +1495 -0
  68. package/lib/public/css/scheduler.css +1420 -0
  69. package/lib/public/css/server-settings.css +909 -0
  70. package/lib/public/css/session-search.css +159 -0
  71. package/lib/public/css/sidebar.css +2012 -0
  72. package/lib/public/css/skills.css +789 -0
  73. package/lib/public/css/sticky-notes.css +854 -0
  74. package/lib/public/css/stt.css +155 -0
  75. package/lib/public/css/title-bar.css +674 -0
  76. package/lib/public/css/tooltip.css +67 -0
  77. package/lib/public/css/user-settings.css +702 -0
  78. package/lib/public/emoji-data.json +1 -0
  79. package/lib/public/favicon-banded-32.png +0 -0
  80. package/lib/public/favicon-banded.png +0 -0
  81. package/lib/public/favicon-dark.svg +32 -0
  82. package/lib/public/favicon.svg +32 -0
  83. package/lib/public/icon-192.png +0 -0
  84. package/lib/public/icon-512.png +0 -0
  85. package/lib/public/icon-banded-76.png +0 -0
  86. package/lib/public/icon-banded-96.png +0 -0
  87. package/lib/public/icon-mono.svg +25 -0
  88. package/lib/public/icons/email/gmail.svg +7 -0
  89. package/lib/public/icons/email/outlook.svg +35 -0
  90. package/lib/public/icons/email/yahoo.svg +1 -0
  91. package/lib/public/index.html +1946 -0
  92. package/lib/public/manifest.json +27 -0
  93. package/lib/public/markdown-worker.js +43 -0
  94. package/lib/public/marked.min.js +6 -0
  95. package/lib/public/modules/admin.js +954 -0
  96. package/lib/public/modules/agent-picker.js +429 -0
  97. package/lib/public/modules/app-connection.js +216 -0
  98. package/lib/public/modules/app-cursors.js +492 -0
  99. package/lib/public/modules/app-dm.js +265 -0
  100. package/lib/public/modules/app-favicon.js +231 -0
  101. package/lib/public/modules/app-header.js +242 -0
  102. package/lib/public/modules/app-home-hub.js +432 -0
  103. package/lib/public/modules/app-loop-ui.js +691 -0
  104. package/lib/public/modules/app-loop-wizard.js +439 -0
  105. package/lib/public/modules/app-messages.js +1415 -0
  106. package/lib/public/modules/app-misc.js +463 -0
  107. package/lib/public/modules/app-notifications.js +651 -0
  108. package/lib/public/modules/app-panels.js +1061 -0
  109. package/lib/public/modules/app-projects.js +875 -0
  110. package/lib/public/modules/app-rate-limit.js +529 -0
  111. package/lib/public/modules/app-rendering.js +739 -0
  112. package/lib/public/modules/app-skills-install.js +285 -0
  113. package/lib/public/modules/avatar.js +36 -0
  114. package/lib/public/modules/command-palette.js +491 -0
  115. package/lib/public/modules/console-logo.js +162 -0
  116. package/lib/public/modules/context-sources.js +365 -0
  117. package/lib/public/modules/diff.js +412 -0
  118. package/lib/public/modules/dom-refs.js +21 -0
  119. package/lib/public/modules/emoji-picker.js +222 -0
  120. package/lib/public/modules/events.js +21 -0
  121. package/lib/public/modules/filebrowser.js +1966 -0
  122. package/lib/public/modules/fileicons.js +172 -0
  123. package/lib/public/modules/icons.js +80 -0
  124. package/lib/public/modules/input.js +1102 -0
  125. package/lib/public/modules/longpress.js +74 -0
  126. package/lib/public/modules/markdown.js +486 -0
  127. package/lib/public/modules/mcp-ui.js +295 -0
  128. package/lib/public/modules/mention.js +1093 -0
  129. package/lib/public/modules/notifications.js +613 -0
  130. package/lib/public/modules/playbook.js +578 -0
  131. package/lib/public/modules/profile.js +594 -0
  132. package/lib/public/modules/project-settings.js +849 -0
  133. package/lib/public/modules/project-switcher.js +375 -0
  134. package/lib/public/modules/qrcode.js +87 -0
  135. package/lib/public/modules/rewind.js +381 -0
  136. package/lib/public/modules/scheduler-config.js +1611 -0
  137. package/lib/public/modules/scheduler-history.js +131 -0
  138. package/lib/public/modules/scheduler.js +1689 -0
  139. package/lib/public/modules/server-settings.js +842 -0
  140. package/lib/public/modules/session-search.js +456 -0
  141. package/lib/public/modules/settings-defaults.js +253 -0
  142. package/lib/public/modules/sidebar-mobile.js +1425 -0
  143. package/lib/public/modules/sidebar-projects.js +2022 -0
  144. package/lib/public/modules/sidebar-sessions.js +1548 -0
  145. package/lib/public/modules/sidebar-users.js +449 -0
  146. package/lib/public/modules/sidebar.js +348 -0
  147. package/lib/public/modules/skills.js +793 -0
  148. package/lib/public/modules/state.js +3 -0
  149. package/lib/public/modules/sticky-notes.js +1221 -0
  150. package/lib/public/modules/store.js +34 -0
  151. package/lib/public/modules/stt.js +266 -0
  152. package/lib/public/modules/terminal.js +987 -0
  153. package/lib/public/modules/theme.js +812 -0
  154. package/lib/public/modules/tool-palette.js +562 -0
  155. package/lib/public/modules/tools.js +2285 -0
  156. package/lib/public/modules/tooltip.js +150 -0
  157. package/lib/public/modules/user-settings.js +544 -0
  158. package/lib/public/modules/utils.js +56 -0
  159. package/lib/public/modules/ws-ref.js +26 -0
  160. package/lib/public/style.css +34 -0
  161. package/lib/public/sw.js +159 -0
  162. package/lib/push.js +149 -0
  163. package/lib/scheduler.js +471 -0
  164. package/lib/sdk-bridge.js +1792 -0
  165. package/lib/sdk-message-processor.js +740 -0
  166. package/lib/sdk-message-queue.js +42 -0
  167. package/lib/sdk-skill-discovery.js +131 -0
  168. package/lib/sdk-worker.js +677 -0
  169. package/lib/server-admin.js +712 -0
  170. package/lib/server-auth.js +737 -0
  171. package/lib/server-dm.js +170 -0
  172. package/lib/server-palette.js +104 -0
  173. package/lib/server-settings.js +553 -0
  174. package/lib/server-skills.js +280 -0
  175. package/lib/server.js +1390 -0
  176. package/lib/session-search.js +693 -0
  177. package/lib/sessions.js +946 -0
  178. package/lib/smtp.js +221 -0
  179. package/lib/terminal-manager.js +219 -0
  180. package/lib/terminal.js +39 -0
  181. package/lib/themes/ayu-light.json +9 -0
  182. package/lib/themes/catppuccin-latte.json +9 -0
  183. package/lib/themes/catppuccin-mocha.json +9 -0
  184. package/lib/themes/clagentic-dark.json +10 -0
  185. package/lib/themes/clagentic-light.json +10 -0
  186. package/lib/themes/dracula.json +9 -0
  187. package/lib/themes/everforest-light.json +9 -0
  188. package/lib/themes/everforest.json +9 -0
  189. package/lib/themes/github-light.json +9 -0
  190. package/lib/themes/gruvbox-dark.json +9 -0
  191. package/lib/themes/gruvbox-light.json +9 -0
  192. package/lib/themes/monokai.json +9 -0
  193. package/lib/themes/nord-light.json +9 -0
  194. package/lib/themes/nord.json +9 -0
  195. package/lib/themes/one-dark.json +9 -0
  196. package/lib/themes/one-light.json +9 -0
  197. package/lib/themes/rose-pine-dawn.json +9 -0
  198. package/lib/themes/rose-pine.json +9 -0
  199. package/lib/themes/solarized-dark.json +9 -0
  200. package/lib/themes/solarized-light.json +9 -0
  201. package/lib/themes/tokyo-night-light.json +9 -0
  202. package/lib/themes/tokyo-night.json +9 -0
  203. package/lib/updater.js +124 -0
  204. package/lib/user-presence.js +92 -0
  205. package/lib/users-auth.js +146 -0
  206. package/lib/users-permissions.js +118 -0
  207. package/lib/users-preferences.js +254 -0
  208. package/lib/users.js +465 -0
  209. package/lib/utils.js +64 -0
  210. package/lib/worktree.js +134 -0
  211. package/lib/ws-schema.js +464 -0
  212. package/lib/yoke/adapters/claude-worker.js +759 -0
  213. package/lib/yoke/adapters/claude.js +1599 -0
  214. package/lib/yoke/adapters/codex.js +1559 -0
  215. package/lib/yoke/codex-app-server.js +352 -0
  216. package/lib/yoke/index.js +319 -0
  217. package/lib/yoke/instructions.js +61 -0
  218. package/lib/yoke/interface.js +98 -0
  219. package/lib/yoke/mcp-bridge-server.js +302 -0
  220. package/lib/yoke/package.json +7 -0
  221. package/package.json +72 -0
@@ -0,0 +1,849 @@
1
+ // project-settings.js — Project settings panel (profile, defaults, instructions, env)
2
+ import { refreshIcons } from './icons.js';
3
+ import { buildEmojiPicker } from './emoji-picker.js';
4
+ import { showToast } from './utils.js';
5
+ import { parseEmojis } from './markdown.js';
6
+ import { closeFileViewer } from './filebrowser.js';
7
+ import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar, renderBetaCard } from './settings-defaults.js';
8
+
9
+ var ctx = null;
10
+ var panelEl = null;
11
+ var navItems = null;
12
+ var sections = null;
13
+ var currentSlug = null;
14
+ var currentProject = null; // { slug, name, icon }
15
+
16
+ // ===== Init =====
17
+ export function initProjectSettings(appCtx) {
18
+ ctx = appCtx;
19
+ panelEl = document.getElementById("project-settings");
20
+ if (!panelEl) return;
21
+
22
+ navItems = panelEl.querySelectorAll(".settings-nav-item");
23
+ sections = panelEl.querySelectorAll(".ps-section");
24
+
25
+ // Nav clicks
26
+ for (var i = 0; i < navItems.length; i++) {
27
+ navItems[i].addEventListener("click", function () {
28
+ switchSection(this.dataset.section);
29
+ });
30
+ }
31
+
32
+ // Mobile dropdown nav
33
+ var psNavDropdown = document.getElementById("ps-nav-dropdown");
34
+ if (psNavDropdown) {
35
+ psNavDropdown.addEventListener("change", function () {
36
+ switchSection(psNavDropdown.value);
37
+ });
38
+ }
39
+
40
+ // Close button
41
+ var closeBtn = document.getElementById("project-settings-close");
42
+ if (closeBtn) {
43
+ closeBtn.addEventListener("click", function () {
44
+ closeProjectSettings();
45
+ });
46
+ }
47
+
48
+ // ESC key
49
+ document.addEventListener("keydown", function (e) {
50
+ if (e.key === "Escape" && panelEl && !panelEl.classList.contains("hidden")) {
51
+ closeProjectSettings();
52
+ }
53
+ });
54
+
55
+ // Profile: rename
56
+ var renameBtn = document.getElementById("ps-rename-btn");
57
+ var renameForm = document.getElementById("ps-rename-form");
58
+ var renameInput = document.getElementById("ps-rename-input");
59
+ var renameSave = document.getElementById("ps-rename-save");
60
+ var renameCancel = document.getElementById("ps-rename-cancel");
61
+
62
+ if (renameBtn) {
63
+ renameBtn.addEventListener("click", function () {
64
+ renameForm.classList.remove("hidden");
65
+ renameInput.value = currentProject ? currentProject.name || "" : "";
66
+ renameBtn.classList.add("hidden");
67
+ renameInput.focus();
68
+ renameInput.select();
69
+ });
70
+ }
71
+ if (renameSave) {
72
+ renameSave.addEventListener("click", function () { commitRename(); });
73
+ }
74
+ if (renameCancel) {
75
+ renameCancel.addEventListener("click", function () { cancelRename(); });
76
+ }
77
+ if (renameInput) {
78
+ renameInput.addEventListener("keydown", function (e) {
79
+ e.stopPropagation();
80
+ if (e.key === "Enter") { e.preventDefault(); commitRename(); }
81
+ if (e.key === "Escape") { e.preventDefault(); cancelRename(); }
82
+ });
83
+ }
84
+
85
+ // Profile: icon
86
+ var iconBtn = document.getElementById("ps-icon-btn");
87
+ var iconRemoveBtn = document.getElementById("ps-icon-remove-btn");
88
+ if (iconBtn) {
89
+ iconBtn.addEventListener("click", function () {
90
+ showPsEmojiPicker();
91
+ });
92
+ }
93
+ if (iconRemoveBtn) {
94
+ iconRemoveBtn.addEventListener("click", function () {
95
+ if (ctx.ws && ctx.connected) {
96
+ ctx.ws.send(JSON.stringify({ type: "set_project_icon", slug: currentSlug, icon: null }));
97
+ }
98
+ updateIconPreview(null);
99
+ });
100
+ }
101
+
102
+ // Instructions: save
103
+ var instrSave = document.getElementById("ps-instructions-save");
104
+ if (instrSave) {
105
+ instrSave.addEventListener("click", function () { saveInstructions(); });
106
+ }
107
+
108
+ // Environment: add button
109
+ var envAddBtn = document.getElementById("ps-env-add-btn");
110
+ if (envAddBtn) {
111
+ envAddBtn.addEventListener("click", function () {
112
+ addEnvRow("", "", true);
113
+ autoSaveEnv();
114
+ });
115
+ }
116
+
117
+ // Environment: tab switching
118
+ var envTabs = panelEl.querySelectorAll(".ps-env-tab");
119
+ var envTabContents = panelEl.querySelectorAll(".ps-env-tab-content");
120
+ for (var ti = 0; ti < envTabs.length; ti++) {
121
+ envTabs[ti].addEventListener("click", function () {
122
+ var tab = this.dataset.tab;
123
+ for (var a = 0; a < envTabs.length; a++) {
124
+ envTabs[a].classList.toggle("active", envTabs[a].dataset.tab === tab);
125
+ }
126
+ for (var b = 0; b < envTabContents.length; b++) {
127
+ envTabContents[b].classList.toggle("active", envTabContents[b].dataset.tab === tab);
128
+ }
129
+ if (tab === "shared") loadSharedEnv();
130
+ });
131
+ }
132
+
133
+ // Environment: shared env add button
134
+ var sharedEnvAddBtn = document.getElementById("ps-shared-env-add-btn");
135
+ if (sharedEnvAddBtn) {
136
+ sharedEnvAddBtn.addEventListener("click", function () {
137
+ addSharedEnvRow("", "", true);
138
+ autoSaveSharedEnv();
139
+ });
140
+ }
141
+
142
+ // Owner: transfer
143
+ var transferBtn = document.getElementById("ps-transfer-btn");
144
+ if (transferBtn) {
145
+ transferBtn.addEventListener("click", function () {
146
+ showTransferForm();
147
+ });
148
+ }
149
+ var transferSave = document.getElementById("ps-transfer-save");
150
+ if (transferSave) {
151
+ transferSave.addEventListener("click", function () {
152
+ commitTransfer();
153
+ });
154
+ }
155
+ var transferCancel = document.getElementById("ps-transfer-cancel");
156
+ if (transferCancel) {
157
+ transferCancel.addEventListener("click", function () {
158
+ hideTransferForm();
159
+ });
160
+ }
161
+ }
162
+
163
+ // ===== Open / Close =====
164
+ export function openProjectSettings(slug, project) {
165
+ if (!panelEl) return;
166
+ currentSlug = slug;
167
+ currentProject = project;
168
+
169
+ // Set nav title
170
+ var navTitle = document.getElementById("ps-nav-title");
171
+ if (navTitle) navTitle.textContent = project.name || slug;
172
+
173
+ // Reset to first section
174
+ switchSection("profile");
175
+
176
+ // Populate profile
177
+ populateProfile();
178
+
179
+ // Close file viewer if open (prevent split-screen)
180
+ closeFileViewer();
181
+
182
+ // Show panel
183
+ panelEl.classList.remove("hidden");
184
+ refreshIcons();
185
+ }
186
+
187
+ export function closeProjectSettings() {
188
+ if (!panelEl) return;
189
+ panelEl.classList.add("hidden");
190
+ closePsEmojiPicker();
191
+ }
192
+
193
+ export function isProjectSettingsOpen() {
194
+ return panelEl && !panelEl.classList.contains("hidden");
195
+ }
196
+
197
+ export function refreshProjectSettingsModels() {
198
+ if (!isProjectSettingsOpen()) return;
199
+ var defaultsSection = panelEl && panelEl.querySelector('[data-section="defaults"].active');
200
+ if (!defaultsSection) return;
201
+ populateDefaults();
202
+ }
203
+
204
+ // ===== Section switching =====
205
+ function switchSection(name) {
206
+ for (var i = 0; i < navItems.length; i++) {
207
+ var active = navItems[i].dataset.section === name;
208
+ navItems[i].classList.toggle("active", active);
209
+ }
210
+ for (var j = 0; j < sections.length; j++) {
211
+ var active2 = sections[j].dataset.section === name;
212
+ sections[j].classList.toggle("active", active2);
213
+ }
214
+
215
+ // Sync mobile dropdown
216
+ var psNavDropdown = document.getElementById("ps-nav-dropdown");
217
+ if (psNavDropdown && psNavDropdown.value !== name) {
218
+ psNavDropdown.value = name;
219
+ }
220
+
221
+ // Lazy-load section data
222
+ if (name === "defaults") populateDefaults();
223
+ if (name === "instructions") loadInstructions();
224
+ if (name === "environment") {
225
+ // Reset tabs to "project" tab
226
+ var envTabs = panelEl.querySelectorAll(".ps-env-tab");
227
+ var envTabContents = panelEl.querySelectorAll(".ps-env-tab-content");
228
+ for (var t = 0; t < envTabs.length; t++) {
229
+ envTabs[t].classList.toggle("active", envTabs[t].dataset.tab === "project");
230
+ }
231
+ for (var u = 0; u < envTabContents.length; u++) {
232
+ envTabContents[u].classList.toggle("active", envTabContents[u].dataset.tab === "project");
233
+ }
234
+ loadEnvironment();
235
+ }
236
+ }
237
+
238
+ // ===== Profile =====
239
+ function populateProfile() {
240
+ var nameEl = document.getElementById("ps-project-name");
241
+ if (nameEl) nameEl.textContent = currentProject ? currentProject.name || "-" : "-";
242
+
243
+ // Reset rename form
244
+ var renameForm = document.getElementById("ps-rename-form");
245
+ var renameBtn = document.getElementById("ps-rename-btn");
246
+ if (renameForm) renameForm.classList.add("hidden");
247
+ if (renameBtn) renameBtn.classList.remove("hidden");
248
+
249
+ // Icon
250
+ updateIconPreview(currentProject ? currentProject.icon : null);
251
+
252
+ // Owner (only in multi-user mode)
253
+ var ownerField = document.getElementById("ps-owner-field");
254
+ if (ownerField) {
255
+ var ownerId = currentProject ? currentProject.projectOwnerId : null;
256
+ var isOwnerLocked = currentProject ? currentProject.ownerLocked : false;
257
+ var isMultiUser = ctx.multiUser;
258
+ if (isMultiUser) {
259
+ ownerField.style.display = "";
260
+ var ownerNameEl = document.getElementById("ps-owner-name");
261
+ var transferBtn = document.getElementById("ps-transfer-btn");
262
+ var ownerLockedHint = document.getElementById("ps-owner-locked-hint");
263
+ if (transferBtn) transferBtn.style.display = "none";
264
+ if (ownerLockedHint) {
265
+ if (isOwnerLocked) { ownerLockedHint.classList.remove("hidden"); } else { ownerLockedHint.classList.add("hidden"); }
266
+ }
267
+ // Fetch user list (only succeeds for admin)
268
+ fetch("/api/admin/users").then(function (r) {
269
+ if (!r.ok) throw new Error("not admin");
270
+ return r.json();
271
+ }).then(function (data) {
272
+ var users = data.users || [];
273
+ // Show owner name
274
+ if (ownerId) {
275
+ var owner = null;
276
+ for (var i = 0; i < users.length; i++) {
277
+ if (users[i].id === ownerId) { owner = users[i]; break; }
278
+ }
279
+ if (ownerNameEl) ownerNameEl.textContent = owner ? (owner.displayName || owner.username) : ownerId;
280
+ } else {
281
+ if (ownerNameEl) ownerNameEl.textContent = "Not set";
282
+ }
283
+ // Admin can transfer unless ownership is locked (home directory projects)
284
+ if (transferBtn && !isOwnerLocked) transferBtn.style.display = "";
285
+ }).catch(function () {
286
+ // Not admin, show owner name from limited info
287
+ if (ownerId) {
288
+ if (ownerNameEl) ownerNameEl.textContent = ownerId;
289
+ // Project owner can also transfer unless locked
290
+ if (!isOwnerLocked && ctx.myUserId && ctx.myUserId === ownerId && transferBtn) {
291
+ transferBtn.style.display = "";
292
+ }
293
+ } else {
294
+ if (ownerNameEl) ownerNameEl.textContent = "Not set";
295
+ }
296
+ });
297
+ hideTransferForm();
298
+ } else {
299
+ ownerField.style.display = "none";
300
+ }
301
+ }
302
+ }
303
+
304
+ function commitRename() {
305
+ var renameInput = document.getElementById("ps-rename-input");
306
+ var nameEl = document.getElementById("ps-project-name");
307
+ var newName = renameInput ? renameInput.value.trim() : "";
308
+ if (newName && ctx.ws && ctx.connected) {
309
+ ctx.ws.send(JSON.stringify({ type: "set_project_title", slug: currentSlug, title: newName }));
310
+ if (nameEl) nameEl.textContent = newName;
311
+ if (currentProject) currentProject.name = newName;
312
+ var navTitle = document.getElementById("ps-nav-title");
313
+ if (navTitle) navTitle.textContent = newName;
314
+ }
315
+ cancelRename();
316
+ }
317
+
318
+ function cancelRename() {
319
+ var renameForm = document.getElementById("ps-rename-form");
320
+ var renameBtn = document.getElementById("ps-rename-btn");
321
+ if (renameForm) renameForm.classList.add("hidden");
322
+ if (renameBtn) renameBtn.classList.remove("hidden");
323
+ }
324
+
325
+ // ===== Owner transfer =====
326
+ function showTransferForm() {
327
+ var form = document.getElementById("ps-transfer-form");
328
+ var btn = document.getElementById("ps-transfer-btn");
329
+ var select = document.getElementById("ps-transfer-select");
330
+ if (!form || !select) return;
331
+
332
+ // Fetch user list and populate select
333
+ select.innerHTML = '<option value="">Loading...</option>';
334
+ fetch("/api/admin/users").then(function (r) { return r.json(); }).then(function (data) {
335
+ var users = data.users || [];
336
+ select.innerHTML = "";
337
+ for (var i = 0; i < users.length; i++) {
338
+ var u = users[i];
339
+ var opt = document.createElement("option");
340
+ opt.value = u.id;
341
+ opt.textContent = (u.displayName || u.username) + (u.linuxUser ? " (" + u.linuxUser + ")" : "");
342
+ if (currentProject && u.id === currentProject.projectOwnerId) opt.selected = true;
343
+ select.appendChild(opt);
344
+ }
345
+ }).catch(function () {
346
+ select.innerHTML = '<option value="">Failed to load users</option>';
347
+ });
348
+
349
+ form.classList.remove("hidden");
350
+ if (btn) btn.classList.add("hidden");
351
+ }
352
+
353
+ function hideTransferForm() {
354
+ var form = document.getElementById("ps-transfer-form");
355
+ var btn = document.getElementById("ps-transfer-btn");
356
+ if (form) form.classList.add("hidden");
357
+ if (btn) btn.classList.remove("hidden");
358
+ }
359
+
360
+ function commitTransfer() {
361
+ var select = document.getElementById("ps-transfer-select");
362
+ var userId = select ? select.value : "";
363
+ if (!userId || !ctx.ws || !ctx.connected) return;
364
+ ctx.ws.send(JSON.stringify({ type: "transfer_project_owner", slug: currentSlug, userId: userId }));
365
+ hideTransferForm();
366
+ }
367
+
368
+ function updateIconPreview(icon) {
369
+ var preview = document.getElementById("ps-icon-preview");
370
+ var removeBtn = document.getElementById("ps-icon-remove-btn");
371
+ if (preview) {
372
+ preview.textContent = icon || "";
373
+ if (icon) parseEmojis(preview);
374
+ }
375
+ if (removeBtn) {
376
+ removeBtn.classList.toggle("hidden", !icon);
377
+ }
378
+ }
379
+
380
+ // ===== Emoji picker (inline in settings) =====
381
+ var psEmojiPickerEl = null;
382
+
383
+ function closePsEmojiPicker() {
384
+ if (psEmojiPickerEl) {
385
+ psEmojiPickerEl.remove();
386
+ psEmojiPickerEl = null;
387
+ }
388
+ }
389
+
390
+ function showPsEmojiPicker() {
391
+ closePsEmojiPicker();
392
+
393
+ var anchor = document.getElementById("ps-emoji-picker-anchor");
394
+ if (!anchor) return;
395
+
396
+ var picker = buildEmojiPicker({
397
+ onSelect: function (emoji) {
398
+ closePsEmojiPicker();
399
+ if (ctx.ws && ctx.connected) {
400
+ ctx.ws.send(JSON.stringify({ type: "set_project_icon", slug: currentSlug, icon: emoji }));
401
+ }
402
+ updateIconPreview(emoji);
403
+ },
404
+ });
405
+
406
+ picker.style.position = "relative";
407
+ picker.style.left = "0";
408
+ picker.style.top = "0";
409
+ picker.style.marginTop = "8px";
410
+
411
+ anchor.innerHTML = "";
412
+ anchor.appendChild(picker);
413
+ psEmojiPickerEl = picker;
414
+ }
415
+
416
+ // ===== Defaults =====
417
+ function psSendMsg(type, data) {
418
+ var ws = ctx.ws;
419
+ if (ws && ws.readyState === 1) {
420
+ var msg = Object.assign({ type: type }, data);
421
+ ws.send(JSON.stringify(msg));
422
+ }
423
+ }
424
+
425
+ function psDefaultsOpts() {
426
+ return {
427
+ models: ctx.currentModels || [],
428
+ currentModel: ctx.currentModel || "",
429
+ currentMode: ctx.currentMode || "default",
430
+ currentEffort: ctx.currentEffort || "medium",
431
+ currentThinking: ctx.currentThinking || "adaptive",
432
+ currentThinkingBudget: ctx.currentThinkingBudget || 10000,
433
+ currentBetas: ctx.currentBetas || [],
434
+ sendMsg: psSendMsg,
435
+ modelMsgType: "set_project_default_model",
436
+ modeMsgType: "set_project_default_mode",
437
+ effortMsgType: "set_project_default_effort",
438
+ betasMsgType: "set_project_default_betas",
439
+ onModelSelect: function (model) {
440
+ renderBetaCard("ps", Object.assign({}, psDefaultsOpts(), { overrideModel: model }));
441
+ },
442
+ };
443
+ }
444
+
445
+ function populateDefaults() {
446
+ var opts = psDefaultsOpts();
447
+ renderModelList("ps", opts);
448
+ renderBetaCard("ps", opts);
449
+ renderModeList("ps", opts);
450
+ renderEffortBar("ps", opts);
451
+ renderThinkingBar("ps", opts);
452
+ }
453
+
454
+ // ===== Instructions (CLAUDE.md) =====
455
+ function loadInstructions() {
456
+ var editor = document.getElementById("ps-instructions-editor");
457
+ var status = document.getElementById("ps-instructions-status");
458
+ var saveStatus = document.getElementById("ps-instructions-save-status");
459
+ if (saveStatus) saveStatus.textContent = "";
460
+
461
+ if (status) status.textContent = "Loading...";
462
+
463
+ if (ctx.ws && ctx.connected) {
464
+ ctx.ws.send(JSON.stringify({ type: "fs_read", path: "CLAUDE.md" }));
465
+ }
466
+ }
467
+
468
+ export function handleInstructionsRead(msg) {
469
+ var editor = document.getElementById("ps-instructions-editor");
470
+ var status = document.getElementById("ps-instructions-status");
471
+ if (!editor) return;
472
+
473
+ if (msg.error) {
474
+ editor.value = "";
475
+ if (status) status.textContent = "No CLAUDE.md file found. Save to create one.";
476
+ } else {
477
+ editor.value = msg.content || "";
478
+ if (status) status.textContent = "";
479
+ }
480
+ }
481
+
482
+ function saveInstructions() {
483
+ var editor = document.getElementById("ps-instructions-editor");
484
+ var saveStatus = document.getElementById("ps-instructions-save-status");
485
+ if (!editor) return;
486
+
487
+ if (ctx.ws && ctx.connected) {
488
+ ctx.ws.send(JSON.stringify({ type: "fs_write", path: "CLAUDE.md", content: editor.value }));
489
+ if (saveStatus) saveStatus.textContent = "Saving...";
490
+ }
491
+ }
492
+
493
+ export function handleInstructionsWrite(msg) {
494
+ var saveStatus = document.getElementById("ps-instructions-save-status");
495
+ if (!saveStatus) return;
496
+ if (msg.ok) {
497
+ saveStatus.textContent = "Saved";
498
+ setTimeout(function () { saveStatus.textContent = ""; }, 2000);
499
+ } else {
500
+ saveStatus.textContent = "Error: " + (msg.error || "Failed to save");
501
+ }
502
+ }
503
+
504
+ // ===== Environment (key-value list) =====
505
+ var envSaveTimer = null;
506
+
507
+ function loadEnvironment() {
508
+ var saveStatus = document.getElementById("ps-env-save-status");
509
+ if (saveStatus) saveStatus.textContent = "";
510
+
511
+ if (ctx.ws && ctx.connected) {
512
+ ctx.ws.send(JSON.stringify({ type: "get_project_env", slug: currentSlug }));
513
+ }
514
+ }
515
+
516
+ export function handleProjectEnv(msg) {
517
+ var notice = document.getElementById("ps-env-override-notice");
518
+ if (notice) notice.classList.toggle("hidden", !msg.hasEnvrc);
519
+
520
+ // Parse envrc string into key-value pairs
521
+ var list = document.getElementById("ps-env-list");
522
+ if (!list) return;
523
+ list.innerHTML = "";
524
+
525
+ var pairs = parseEnvString(msg.envrc || "");
526
+ for (var i = 0; i < pairs.length; i++) {
527
+ addEnvRow(pairs[i].key, pairs[i].value, false);
528
+ }
529
+ refreshIcons();
530
+ }
531
+
532
+ // Check if text looks like env format: first line starts with a valid VAR_NAME=
533
+ export function looksLikeEnv(text) {
534
+ var first = text.split("\n")[0].trim();
535
+ if (first.indexOf("export ") === 0) first = first.substring(7);
536
+ return /^[A-Za-z_][A-Za-z0-9_]*=/.test(first);
537
+ }
538
+
539
+ export function parseEnvString(str) {
540
+ var pairs = [];
541
+ if (!str) return pairs;
542
+ var lines = str.split("\n");
543
+ for (var i = 0; i < lines.length; i++) {
544
+ var line = lines[i].trim();
545
+ if (!line || line.charAt(0) === "#") continue;
546
+ // Strip leading "export "
547
+ if (line.indexOf("export ") === 0) line = line.substring(7);
548
+ var eq = line.indexOf("=");
549
+ if (eq === -1) continue;
550
+ var key = line.substring(0, eq).trim();
551
+ var val = line.substring(eq + 1).trim();
552
+ // Strip surrounding quotes
553
+ if ((val.charAt(0) === '"' && val.charAt(val.length - 1) === '"') ||
554
+ (val.charAt(0) === "'" && val.charAt(val.length - 1) === "'")) {
555
+ val = val.substring(1, val.length - 1);
556
+ }
557
+ if (key) pairs.push({ key: key, value: val });
558
+ }
559
+ return pairs;
560
+ }
561
+
562
+ function buildEnvString() {
563
+ var list = document.getElementById("ps-env-list");
564
+ if (!list) return "";
565
+ var rows = list.querySelectorAll(".ps-env-row");
566
+ var lines = [];
567
+ for (var i = 0; i < rows.length; i++) {
568
+ var keyInput = rows[i].querySelector(".ps-env-key");
569
+ var valInput = rows[i].querySelector(".ps-env-val");
570
+ var key = keyInput ? keyInput.value.trim() : "";
571
+ var val = valInput ? valInput.value : "";
572
+ if (key) lines.push("export " + key + "=" + val);
573
+ }
574
+ return lines.join("\n");
575
+ }
576
+
577
+ function addEnvRow(key, value, focus) {
578
+ var list = document.getElementById("ps-env-list");
579
+ if (!list) return;
580
+
581
+ var row = document.createElement("div");
582
+ row.className = "ps-env-row";
583
+
584
+ var keyInput = document.createElement("input");
585
+ keyInput.type = "text";
586
+ keyInput.className = "ps-env-key";
587
+ keyInput.placeholder = "KEY";
588
+ keyInput.value = key;
589
+ keyInput.spellcheck = false;
590
+ keyInput.autocomplete = "off";
591
+
592
+ var valInput = document.createElement("input");
593
+ valInput.type = "text";
594
+ valInput.className = "ps-env-val";
595
+ valInput.placeholder = "value";
596
+ valInput.value = value;
597
+ valInput.spellcheck = false;
598
+ valInput.autocomplete = "off";
599
+
600
+ var delBtn = document.createElement("button");
601
+ delBtn.className = "ps-env-del";
602
+ delBtn.title = "Remove";
603
+ delBtn.innerHTML = '<i data-lucide="x"></i>';
604
+
605
+ delBtn.addEventListener("click", function () {
606
+ row.remove();
607
+ autoSaveEnv();
608
+ });
609
+
610
+ // Auto-save on change
611
+ keyInput.addEventListener("input", function () { autoSaveEnv(); });
612
+ valInput.addEventListener("input", function () { autoSaveEnv(); });
613
+
614
+ // Paste detection: if pasting KEY=VALUE content into key field, parse it
615
+ keyInput.addEventListener("paste", function (e) {
616
+ var text = (e.clipboardData || window.clipboardData).getData("text");
617
+ if (text && looksLikeEnv(text)) {
618
+ e.preventDefault();
619
+ var pairs = parseEnvString(text);
620
+ if (pairs.length > 0) {
621
+ // Fill current row with first pair
622
+ keyInput.value = pairs[0].key;
623
+ valInput.value = pairs[0].value;
624
+ // Add remaining as new rows
625
+ for (var p = 1; p < pairs.length; p++) {
626
+ addEnvRow(pairs[p].key, pairs[p].value, false);
627
+ }
628
+ autoSaveEnv();
629
+ }
630
+ }
631
+ });
632
+
633
+ // Also handle paste into value field
634
+ valInput.addEventListener("paste", function (e) {
635
+ var text = (e.clipboardData || window.clipboardData).getData("text");
636
+ if (text && text.indexOf("\n") !== -1 && text.indexOf("=") !== -1) {
637
+ e.preventDefault();
638
+ var pairs = parseEnvString(text);
639
+ if (pairs.length > 0) {
640
+ keyInput.value = pairs[0].key;
641
+ valInput.value = pairs[0].value;
642
+ for (var p = 1; p < pairs.length; p++) {
643
+ addEnvRow(pairs[p].key, pairs[p].value, false);
644
+ }
645
+ autoSaveEnv();
646
+ }
647
+ }
648
+ });
649
+
650
+ row.appendChild(keyInput);
651
+ row.appendChild(valInput);
652
+ row.appendChild(delBtn);
653
+ list.appendChild(row);
654
+ refreshIcons();
655
+
656
+ if (focus) keyInput.focus();
657
+ }
658
+
659
+ function autoSaveEnv() {
660
+ if (envSaveTimer) clearTimeout(envSaveTimer);
661
+ envSaveTimer = setTimeout(function () {
662
+ var envrc = buildEnvString();
663
+ if (ctx.ws && ctx.connected) {
664
+ ctx.ws.send(JSON.stringify({ type: "set_project_env", slug: currentSlug, envrc: envrc }));
665
+ var saveStatus = document.getElementById("ps-env-save-status");
666
+ if (saveStatus) {
667
+ saveStatus.textContent = "Saved";
668
+ setTimeout(function () { saveStatus.textContent = ""; }, 2000);
669
+ }
670
+ }
671
+ }, 800);
672
+ }
673
+
674
+ export function handleProjectEnvSaved(msg) {
675
+ var saveStatus = document.getElementById("ps-env-save-status");
676
+ if (!saveStatus) return;
677
+ if (msg.ok) {
678
+ saveStatus.textContent = "Saved";
679
+ setTimeout(function () { saveStatus.textContent = ""; }, 2000);
680
+ } else {
681
+ saveStatus.textContent = "Error: " + (msg.error || "Failed to save");
682
+ }
683
+ }
684
+
685
+ // ===== Shared Environment (via tabs) =====
686
+ var sharedEnvSaveTimer = null;
687
+
688
+ function loadSharedEnv() {
689
+ var saveStatus = document.getElementById("ps-shared-env-save-status");
690
+ if (saveStatus) saveStatus.textContent = "";
691
+
692
+ if (ctx.ws && ctx.connected) {
693
+ ctx.ws.send(JSON.stringify({ type: "get_shared_env" }));
694
+ }
695
+ }
696
+
697
+ export function handleProjectSharedEnv(msg) {
698
+ var list = document.getElementById("ps-shared-env-list");
699
+ if (!list) return;
700
+ list.innerHTML = "";
701
+
702
+ var pairs = parseEnvString(msg.envrc || "");
703
+ for (var i = 0; i < pairs.length; i++) {
704
+ addSharedEnvRow(pairs[i].key, pairs[i].value, false);
705
+ }
706
+ refreshIcons();
707
+ }
708
+
709
+ export function handleProjectSharedEnvSaved(msg) {
710
+ var saveStatus = document.getElementById("ps-shared-env-save-status");
711
+ if (!saveStatus) return;
712
+ if (msg.ok) {
713
+ saveStatus.textContent = "Saved";
714
+ setTimeout(function () { saveStatus.textContent = ""; }, 2000);
715
+ } else {
716
+ saveStatus.textContent = "Error: " + (msg.error || "Failed to save");
717
+ }
718
+ }
719
+
720
+ function buildSharedEnvString() {
721
+ var list = document.getElementById("ps-shared-env-list");
722
+ if (!list) return "";
723
+ var rows = list.querySelectorAll(".ps-env-row");
724
+ var lines = [];
725
+ for (var i = 0; i < rows.length; i++) {
726
+ var keyInput = rows[i].querySelector(".ps-env-key");
727
+ var valInput = rows[i].querySelector(".ps-env-val");
728
+ var key = keyInput ? keyInput.value.trim() : "";
729
+ var val = valInput ? valInput.value : "";
730
+ if (key) lines.push("export " + key + "=" + val);
731
+ }
732
+ return lines.join("\n");
733
+ }
734
+
735
+ function addSharedEnvRow(key, value, focus) {
736
+ var list = document.getElementById("ps-shared-env-list");
737
+ if (!list) return;
738
+
739
+ var row = document.createElement("div");
740
+ row.className = "ps-env-row";
741
+
742
+ var keyInput = document.createElement("input");
743
+ keyInput.type = "text";
744
+ keyInput.className = "ps-env-key";
745
+ keyInput.placeholder = "KEY";
746
+ keyInput.value = key;
747
+ keyInput.spellcheck = false;
748
+ keyInput.autocomplete = "off";
749
+
750
+ var valInput = document.createElement("input");
751
+ valInput.type = "text";
752
+ valInput.className = "ps-env-val";
753
+ valInput.placeholder = "value";
754
+ valInput.value = value;
755
+ valInput.spellcheck = false;
756
+ valInput.autocomplete = "off";
757
+
758
+ var delBtn = document.createElement("button");
759
+ delBtn.className = "ps-env-del";
760
+ delBtn.title = "Remove";
761
+ delBtn.innerHTML = '<i data-lucide="x"></i>';
762
+
763
+ delBtn.addEventListener("click", function () {
764
+ row.remove();
765
+ autoSaveSharedEnv();
766
+ });
767
+
768
+ keyInput.addEventListener("input", function () { autoSaveSharedEnv(); });
769
+ valInput.addEventListener("input", function () { autoSaveSharedEnv(); });
770
+
771
+ // Paste detection
772
+ keyInput.addEventListener("paste", function (e) {
773
+ var text = (e.clipboardData || window.clipboardData).getData("text");
774
+ if (text && looksLikeEnv(text)) {
775
+ e.preventDefault();
776
+ var pairs = parseEnvString(text);
777
+ if (pairs.length > 0) {
778
+ keyInput.value = pairs[0].key;
779
+ valInput.value = pairs[0].value;
780
+ for (var p = 1; p < pairs.length; p++) {
781
+ addSharedEnvRow(pairs[p].key, pairs[p].value, false);
782
+ }
783
+ autoSaveSharedEnv();
784
+ }
785
+ }
786
+ });
787
+
788
+ valInput.addEventListener("paste", function (e) {
789
+ var text = (e.clipboardData || window.clipboardData).getData("text");
790
+ if (text && text.indexOf("\n") !== -1 && text.indexOf("=") !== -1) {
791
+ e.preventDefault();
792
+ var pairs = parseEnvString(text);
793
+ if (pairs.length > 0) {
794
+ keyInput.value = pairs[0].key;
795
+ valInput.value = pairs[0].value;
796
+ for (var p = 1; p < pairs.length; p++) {
797
+ addSharedEnvRow(pairs[p].key, pairs[p].value, false);
798
+ }
799
+ autoSaveSharedEnv();
800
+ }
801
+ }
802
+ });
803
+
804
+ row.appendChild(keyInput);
805
+ row.appendChild(valInput);
806
+ row.appendChild(delBtn);
807
+ list.appendChild(row);
808
+ refreshIcons();
809
+
810
+ if (focus) keyInput.focus();
811
+ }
812
+
813
+ function autoSaveSharedEnv() {
814
+ if (sharedEnvSaveTimer) clearTimeout(sharedEnvSaveTimer);
815
+ sharedEnvSaveTimer = setTimeout(function () {
816
+ var envrc = buildSharedEnvString();
817
+ if (ctx.ws && ctx.connected) {
818
+ ctx.ws.send(JSON.stringify({ type: "set_shared_env", envrc: envrc }));
819
+ var saveStatus = document.getElementById("ps-shared-env-save-status");
820
+ if (saveStatus) {
821
+ saveStatus.textContent = "Saved";
822
+ setTimeout(function () { saveStatus.textContent = ""; }, 2000);
823
+ }
824
+ }
825
+ }, 800);
826
+ }
827
+
828
+ // ===== Update from external events =====
829
+ export function updateProjectSettingsIcon(icon) {
830
+ if (currentProject) currentProject.icon = icon;
831
+ updateIconPreview(icon);
832
+ }
833
+
834
+ export function updateProjectSettingsName(name) {
835
+ if (currentProject) currentProject.name = name;
836
+ var nameEl = document.getElementById("ps-project-name");
837
+ if (nameEl) nameEl.textContent = name || "-";
838
+ var navTitle = document.getElementById("ps-nav-title");
839
+ if (navTitle) navTitle.textContent = name || "-";
840
+ }
841
+
842
+ export function handleProjectOwnerChanged(msg) {
843
+ if (currentProject) {
844
+ currentProject.projectOwnerId = msg.ownerId;
845
+ }
846
+ var ownerNameEl = document.getElementById("ps-owner-name");
847
+ if (ownerNameEl) ownerNameEl.textContent = msg.ownerName || msg.ownerId || "Not set";
848
+ showToast("Project ownership transferred to " + (msg.ownerName || "new owner"));
849
+ }