@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,691 @@
1
+ // app-loop-ui.js - Ralph Loop UI: bars, banners, preview modal, execution modal
2
+ // Wizard logic extracted to app-loop-wizard.js
3
+
4
+ import { refreshIcons, iconHtml } from './icons.js';
5
+ import { escapeHtml } from './utils.js';
6
+ import { store } from './store.js';
7
+ import { getWs } from './ws-ref.js';
8
+ import { showConfirm } from './app-misc.js';
9
+ import { openRalphWizard } from './app-loop-wizard.js';
10
+ import { openSchedulerToTab } from './scheduler.js';
11
+ import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar } from './settings-defaults.js';
12
+
13
+ // Execution modal: module-internal UI var (not in store)
14
+ var pendingIterations = 20;
15
+
16
+ // ========================================================
17
+ // Init
18
+ // ========================================================
19
+ export function initLoopUi() {
20
+
21
+ // --- Reactive UI sync for loop state ---
22
+ store.subscribe(function (state, prev) {
23
+ if (state.loopActive !== prev.loopActive ||
24
+ state.ralphPhase !== prev.ralphPhase ||
25
+ state.loopIteration !== prev.loopIteration ||
26
+ state.loopMaxIterations !== prev.loopMaxIterations) {
27
+ updateLoopButton();
28
+ }
29
+ if (state.ralphPhase !== prev.ralphPhase ||
30
+ state.ralphCraftingSessionId !== prev.ralphCraftingSessionId ||
31
+ state.ralphCraftingSource !== prev.ralphCraftingSource ||
32
+ state.activeSessionId !== prev.activeSessionId) {
33
+ updateRalphBars();
34
+ }
35
+ });
36
+
37
+ // --- Preview modal listeners ---
38
+ // Backdrop click intentionally does NOT close the modal (no way to reopen it)
39
+
40
+ // Run button in preview modal footer
41
+ var previewRunBtn = document.getElementById("ralph-preview-run");
42
+ if (previewRunBtn) {
43
+ previewRunBtn.addEventListener("click", function (e) {
44
+ e.stopPropagation();
45
+ closeRalphPreviewModal();
46
+ startLoopFromUi();
47
+ });
48
+ }
49
+
50
+ // Delete/cancel button in preview modal header
51
+ var previewDeleteBtn = document.getElementById("ralph-preview-delete");
52
+ if (previewDeleteBtn) {
53
+ previewDeleteBtn.addEventListener("click", function (e) {
54
+ e.stopPropagation();
55
+ closeRalphPreviewModal();
56
+ showConfirm("Discard this loop setup?", function() {
57
+ var ws = getWs();
58
+ if (ws && ws.readyState === 1) {
59
+ ws.send(JSON.stringify({ type: "ralph_wizard_cancel" }));
60
+ }
61
+ var stickyEl = document.getElementById("ralph-sticky");
62
+ if (stickyEl) {
63
+ stickyEl.classList.add("hidden");
64
+ stickyEl.classList.remove("ralph-ready");
65
+ stickyEl.innerHTML = "";
66
+ }
67
+ });
68
+ });
69
+ }
70
+
71
+ var previewTabs = document.querySelectorAll(".ralph-tab");
72
+ for (var ti = 0; ti < previewTabs.length; ti++) {
73
+ previewTabs[ti].addEventListener("click", function() {
74
+ showRalphPreviewTab(this.getAttribute("data-tab"));
75
+ });
76
+ }
77
+
78
+ // Iterations input in preview modal footer
79
+ var previewIterInput = document.getElementById("ralph-preview-iterations");
80
+ if (previewIterInput) {
81
+ previewIterInput.addEventListener("input", function () {
82
+ pendingIterations = parseInt(this.value, 10) || pendingIterations;
83
+ syncIterationsUi();
84
+ });
85
+ }
86
+ }
87
+
88
+ // ========================================================
89
+ // Iteration sync helper
90
+ // ========================================================
91
+
92
+ function syncIterationsUi() {
93
+ var wizData = store.get('wizardData') || {};
94
+ var isSimple = wizData.loopMode === "simple";
95
+ var label = isSimple ? ("Run x" + pendingIterations) : ("Start (max " + pendingIterations + ")");
96
+
97
+ // Sync sticky bar input
98
+ var stickyIter = document.getElementById("ralph-sticky-iterations");
99
+ if (stickyIter && parseInt(stickyIter.value, 10) !== pendingIterations) {
100
+ stickyIter.value = pendingIterations;
101
+ }
102
+ var stickyStartBtn = document.querySelector(".ralph-sticky-start");
103
+ if (stickyStartBtn) stickyStartBtn.title = label;
104
+
105
+ // Sync preview modal input
106
+ var previewIter = document.getElementById("ralph-preview-iterations");
107
+ if (previewIter && parseInt(previewIter.value, 10) !== pendingIterations) {
108
+ previewIter.value = pendingIterations;
109
+ }
110
+ var comboLabel = document.getElementById("ralph-run-combo-label");
111
+ if (comboLabel) comboLabel.textContent = isSimple ? "Run x" : "Start max";
112
+ }
113
+
114
+ // ========================================================
115
+ // Start loop from UI (shared by sticky bar + exec modal)
116
+ // ========================================================
117
+
118
+ function startLoopFromUi() {
119
+ var basePath = store.get('basePath');
120
+ var stickyEl = document.getElementById("ralph-sticky");
121
+
122
+ fetch(basePath + "api/git-dirty")
123
+ .then(function (res) { return res.json(); })
124
+ .then(function (data) {
125
+ if (data.dirty) {
126
+ var fileList = (data.files || []).slice(0, 15).join("\n");
127
+ if (data.files && data.files.length > 15) fileList += "\n... and " + (data.files.length - 15) + " more";
128
+ var msg = "You have uncommitted changes. The loop uses git diff to track progress, so uncommitted files may cause unexpected results.\n\n" + fileList + "\n\nStart anyway?";
129
+ showConfirm(msg, function () {
130
+ sendLoopStart();
131
+ if (stickyEl) { stickyEl.classList.add("hidden"); stickyEl.innerHTML = ""; }
132
+ }, "Start anyway", false);
133
+ } else {
134
+ sendLoopStart();
135
+ if (stickyEl) { stickyEl.classList.add("hidden"); stickyEl.innerHTML = ""; }
136
+ }
137
+ })
138
+ .catch(function () {
139
+ sendLoopStart();
140
+ if (stickyEl) { stickyEl.classList.add("hidden"); stickyEl.innerHTML = ""; }
141
+ });
142
+ }
143
+
144
+ function sendLoopStart() {
145
+ var ws = getWs();
146
+ if (ws && ws.readyState === 1) {
147
+ var msg = { type: "loop_start", maxIterations: pendingIterations };
148
+ if (Object.keys(_previewLoopSettings).length > 0) {
149
+ msg.settings = _previewLoopSettings;
150
+ }
151
+ ws.send(JSON.stringify(msg));
152
+ }
153
+ }
154
+
155
+ // ========================================================
156
+ // Loop UI (exported)
157
+ // ========================================================
158
+
159
+ export function updateLoopInputVisibility(loop) {
160
+ var inputArea = document.getElementById("input-area");
161
+ if (!inputArea) return;
162
+ if (loop && loop.active && loop.role !== "crafting") {
163
+ inputArea.style.display = "none";
164
+ } else {
165
+ inputArea.style.display = "";
166
+ }
167
+ }
168
+
169
+ export function updateLoopButton() {
170
+ var section = document.getElementById("ralph-loop-section");
171
+ if (!section) return;
172
+
173
+ var s = store.snap();
174
+ var busy = s.loopActive || s.ralphPhase === "executing";
175
+ var phase = busy ? "executing" : s.ralphPhase;
176
+
177
+ var statusHtml = "";
178
+ var statusClass = "";
179
+ var clickAction = "wizard"; // default
180
+
181
+ if (phase === "crafting") {
182
+ statusHtml = '<span class="ralph-section-status crafting">' + iconHtml("loader", "icon-spin") + ' Crafting\u2026</span>';
183
+ clickAction = "none";
184
+ } else if (phase === "approval") {
185
+ statusHtml = '<span class="ralph-section-status ready">Ready</span>';
186
+ statusClass = "ralph-section-ready";
187
+ clickAction = "none";
188
+ } else if (phase === "executing") {
189
+ var iterText = s.loopIteration > 0 ? "Running \u00b7 iteration " + s.loopIteration + "/" + s.loopMaxIterations : "Starting\u2026";
190
+ statusHtml = '<span class="ralph-section-status running">' + iconHtml("loader", "icon-spin") + ' ' + iterText + '</span>';
191
+ statusClass = "ralph-section-running";
192
+ clickAction = "popover";
193
+ } else if (phase === "done") {
194
+ statusHtml = '<span class="ralph-section-status done">\u2713 Done</span>';
195
+ statusHtml += '<a href="#" class="ralph-section-tasks-link">View in Scheduled Tasks</a>';
196
+ statusClass = "ralph-section-done";
197
+ clickAction = "wizard";
198
+ } else {
199
+ // idle
200
+ statusHtml = '<span class="ralph-section-hint">Start a new loop</span>';
201
+ }
202
+
203
+ section.className = "ralph-loop-section" + (statusClass ? " " + statusClass : "");
204
+ section.innerHTML =
205
+ '<div class="ralph-section-inner">' +
206
+ '<div class="ralph-section-header">' +
207
+ '<span class="ralph-section-icon">' + iconHtml("repeat") + '</span>' +
208
+ '<span class="ralph-section-label">Loop</span>' +
209
+ '<span class="loop-experimental"><i data-lucide="flask-conical"></i> experimental</span>' +
210
+ '</div>' +
211
+ '<div class="ralph-section-body">' + statusHtml + '</div>' +
212
+ '</div>';
213
+
214
+ refreshIcons();
215
+
216
+ // Click handler on header
217
+ var header = section.querySelector(".ralph-section-header");
218
+ if (header) {
219
+ header.style.cursor = clickAction === "none" ? "default" : "pointer";
220
+ header.addEventListener("click", function() {
221
+ if (clickAction === "popover") {
222
+ toggleLoopPopover();
223
+ } else if (clickAction === "wizard") {
224
+ openRalphWizard();
225
+ }
226
+ });
227
+ }
228
+
229
+ // "View in Scheduled Tasks" link
230
+ var tasksLink = section.querySelector(".ralph-section-tasks-link");
231
+ if (tasksLink) {
232
+ tasksLink.addEventListener("click", function(e) {
233
+ e.preventDefault();
234
+ e.stopPropagation();
235
+ openSchedulerToTab("library");
236
+ });
237
+ }
238
+ }
239
+
240
+ export function showLoopBanner(show) {
241
+ var stickyEl = document.getElementById("ralph-sticky");
242
+ if (!stickyEl) { updateLoopButton(); return; }
243
+ if (!show) {
244
+ stickyEl.classList.add("hidden");
245
+ stickyEl.classList.remove("ralph-running");
246
+ stickyEl.innerHTML = "";
247
+ updateLoopButton();
248
+ return;
249
+ }
250
+
251
+ var bannerLabel = store.get('loopBannerName') || "Loop";
252
+ stickyEl.innerHTML =
253
+ '<div class="ralph-sticky-inner">' +
254
+ '<div class="ralph-sticky-header">' +
255
+ '<button class="ralph-sticky-nav" title="Go to loop session">' +
256
+ '<span class="ralph-sticky-icon">' + iconHtml("repeat") + '</span>' +
257
+ '<span class="ralph-sticky-label">' + escapeHtml(bannerLabel) + '</span>' +
258
+ '<span class="ralph-sticky-status" id="loop-status">Starting\u2026</span>' +
259
+ '</button>' +
260
+ '<button class="ralph-sticky-action ralph-sticky-stop" title="Stop loop">' + iconHtml("square") + '</button>' +
261
+ '</div>' +
262
+ '</div>';
263
+ stickyEl.classList.remove("hidden", "ralph-ready");
264
+ stickyEl.classList.add("ralph-running");
265
+ refreshIcons();
266
+
267
+ stickyEl.querySelector(".ralph-sticky-nav").addEventListener("click", function(e) {
268
+ e.stopPropagation();
269
+ var sid = store.get('loopCurrentSessionId');
270
+ var w = getWs();
271
+ if (sid && w && w.readyState === 1) {
272
+ w.send(JSON.stringify({ type: "switch_session", id: sid }));
273
+ }
274
+ });
275
+
276
+ stickyEl.querySelector(".ralph-sticky-stop").addEventListener("click", function(e) {
277
+ e.stopPropagation();
278
+ var w = getWs();
279
+ if (w && w.readyState === 1) {
280
+ w.send(JSON.stringify({ type: "loop_stop" }));
281
+ }
282
+ });
283
+ updateLoopButton();
284
+ }
285
+
286
+ export function updateLoopBanner(iteration, maxIterations, phase) {
287
+ var statusEl = document.getElementById("loop-status");
288
+ if (!statusEl) return;
289
+ var text;
290
+ if (phase === "stopping") {
291
+ text = "Stopping\u2026";
292
+ } else if (maxIterations <= 1) {
293
+ text = phase === "judging" ? "judging\u2026" : "running";
294
+ } else {
295
+ text = "#" + iteration + "/" + maxIterations;
296
+ if (phase === "judging") text += " judging\u2026";
297
+ else text += " running";
298
+ }
299
+ statusEl.textContent = text;
300
+ }
301
+
302
+ export function updateRalphBars() {
303
+ // Task source uses the scheduler panel, not the sticky bar
304
+ var s = store.snap();
305
+ var isTaskSource = s.ralphCraftingSource !== "ralph";
306
+ var onCraftingSession = s.ralphCraftingSessionId && s.activeSessionId === s.ralphCraftingSessionId;
307
+ // If approval phase but no craftingSessionId (recovered after server restart), show bar anyway
308
+ var recoveredApproval = s.ralphPhase === "approval" && !s.ralphCraftingSessionId;
309
+ if (!isTaskSource && s.ralphPhase === "crafting" && onCraftingSession) {
310
+ showRalphCraftingBar(true);
311
+ } else {
312
+ showRalphCraftingBar(false);
313
+ }
314
+ if (!isTaskSource && s.ralphPhase === "approval") {
315
+ showRalphApprovalBar(true);
316
+ } else {
317
+ showRalphApprovalBar(false);
318
+ }
319
+ // Restore running loop banner on session switch
320
+ if (s.loopActive && s.ralphPhase === "executing") {
321
+ showLoopBanner(true);
322
+ if (s.loopIteration > 0) {
323
+ updateLoopBanner(s.loopIteration, s.loopMaxIterations, "running");
324
+ }
325
+ }
326
+
327
+ }
328
+
329
+ // ========================================================
330
+ // Internal: toggleLoopPopover
331
+ // ========================================================
332
+
333
+ function toggleLoopPopover() {
334
+ var existing = document.getElementById("loop-status-modal");
335
+ if (existing) {
336
+ existing.remove();
337
+ return;
338
+ }
339
+
340
+ var wizData = store.get('wizardData') || {};
341
+ var taskPreview = wizData.task || "\u2014";
342
+ if (taskPreview.length > 120) taskPreview = taskPreview.substring(0, 120) + "\u2026";
343
+ var _s = store.snap();
344
+ var statusText = "Iteration #" + _s.loopIteration + " / " + _s.loopMaxIterations;
345
+
346
+ var modal = document.createElement("div");
347
+ modal.id = "loop-status-modal";
348
+ modal.className = "loop-status-modal";
349
+ modal.innerHTML =
350
+ '<div class="loop-status-backdrop"></div>' +
351
+ '<div class="loop-status-dialog">' +
352
+ '<div class="loop-status-dialog-header">' +
353
+ '<span class="loop-status-dialog-icon">' + iconHtml("repeat") + '</span>' +
354
+ '<span class="loop-status-dialog-title">Loop</span>' +
355
+ '<button class="loop-status-dialog-close" title="Close">' + iconHtml("x") + '</button>' +
356
+ '</div>' +
357
+ '<div class="loop-status-dialog-body">' +
358
+ '<div class="loop-status-dialog-row">' +
359
+ '<span class="loop-status-dialog-label">Progress</span>' +
360
+ '<span class="loop-status-dialog-value">' + escapeHtml(statusText) + '</span>' +
361
+ '</div>' +
362
+ '<div class="loop-status-dialog-row">' +
363
+ '<span class="loop-status-dialog-label">Task</span>' +
364
+ '<span class="loop-status-dialog-value loop-status-dialog-task">' + escapeHtml(taskPreview) + '</span>' +
365
+ '</div>' +
366
+ '</div>' +
367
+ '<div class="loop-status-dialog-footer">' +
368
+ '<button class="loop-status-dialog-stop">' + iconHtml("square") + ' Stop loop</button>' +
369
+ '</div>' +
370
+ '</div>';
371
+
372
+ document.body.appendChild(modal);
373
+ refreshIcons();
374
+
375
+ function closeModal() { modal.remove(); }
376
+
377
+ modal.querySelector(".loop-status-backdrop").addEventListener("click", closeModal);
378
+ modal.querySelector(".loop-status-dialog-close").addEventListener("click", closeModal);
379
+
380
+ modal.querySelector(".loop-status-dialog-stop").addEventListener("click", function(e) {
381
+ e.stopPropagation();
382
+ closeModal();
383
+ showConfirm("Stop the running " + (store.get('loopBannerName') || "loop") + "?", function() {
384
+ var w = getWs();
385
+ if (w && w.readyState === 1) {
386
+ w.send(JSON.stringify({ type: "loop_stop" }));
387
+ }
388
+ });
389
+ });
390
+ }
391
+
392
+ // ========================================================
393
+ // Crafting / Approval bars (exported)
394
+ // ========================================================
395
+
396
+ export function showRalphCraftingBar(show) {
397
+ var stickyEl = document.getElementById("ralph-sticky");
398
+ if (!stickyEl) return;
399
+ if (!show) {
400
+ stickyEl.classList.add("hidden");
401
+ stickyEl.innerHTML = "";
402
+ return;
403
+ }
404
+ stickyEl.innerHTML =
405
+ '<div class="ralph-sticky-inner">' +
406
+ '<div class="ralph-sticky-header">' +
407
+ '<span class="ralph-sticky-icon">' + iconHtml("repeat") + '</span>' +
408
+ '<span class="ralph-sticky-label">Ralph</span>' +
409
+ '<span class="ralph-sticky-status">' + iconHtml("loader", "icon-spin") + ' Preparing\u2026</span>' +
410
+ '<button class="ralph-sticky-cancel" title="Cancel">' + iconHtml("x") + '</button>' +
411
+ '</div>' +
412
+ '</div>';
413
+ stickyEl.classList.remove("hidden");
414
+ refreshIcons();
415
+
416
+ var cancelBtn = stickyEl.querySelector(".ralph-sticky-cancel");
417
+ if (cancelBtn) {
418
+ cancelBtn.addEventListener("click", function(e) {
419
+ e.stopPropagation();
420
+ var ws = getWs();
421
+ if (ws && ws.readyState === 1) {
422
+ ws.send(JSON.stringify({ type: "ralph_cancel_crafting" }));
423
+ }
424
+ showRalphCraftingBar(false);
425
+ showRalphApprovalBar(false);
426
+ });
427
+ }
428
+ }
429
+
430
+ export function showRalphApprovalBar(show) {
431
+ var stickyEl = document.getElementById("ralph-sticky");
432
+ if (!stickyEl) return;
433
+ if (!show) {
434
+ // Only clear if we're in approval mode (don't clobber crafting)
435
+ if (store.get('ralphPhase') !== "crafting") {
436
+ stickyEl.classList.add("hidden");
437
+ stickyEl.innerHTML = "";
438
+ }
439
+ return;
440
+ }
441
+
442
+ var wizData = store.get('wizardData') || {};
443
+ var isSimple = wizData.loopMode === "simple";
444
+ var defaultIter = isSimple ? 5 : 20;
445
+ pendingIterations = defaultIter;
446
+
447
+ var runLabel = isSimple ? ("Run x" + defaultIter) : ("Start (max " + defaultIter + ")");
448
+
449
+ stickyEl.innerHTML =
450
+ '<div class="ralph-sticky-inner">' +
451
+ '<div class="ralph-sticky-header" id="ralph-sticky-header">' +
452
+ '<span class="ralph-sticky-icon">' + iconHtml("repeat") + '</span>' +
453
+ '<span class="ralph-sticky-label">Ralph</span>' +
454
+ '<span class="ralph-sticky-status" id="ralph-sticky-status">Ready</span>' +
455
+ '<input type="number" id="ralph-sticky-iterations" class="ralph-input-number ralph-sticky-iter" value="' + defaultIter + '" min="1" max="100">' +
456
+ '<button class="ralph-sticky-action ralph-sticky-preview" title="Preview files">' + iconHtml("eye") + '</button>' +
457
+ '<button class="ralph-sticky-action ralph-sticky-start" title="' + runLabel + '">' + iconHtml(wizData.cron ? "calendar-clock" : "play") + '</button>' +
458
+ '<button class="ralph-sticky-action ralph-sticky-dismiss" title="Cancel and discard">' + iconHtml("x") + '</button>' +
459
+ '</div>' +
460
+ '</div>';
461
+ stickyEl.classList.remove("hidden");
462
+ refreshIcons();
463
+
464
+ // Iteration input handler
465
+ var stickyIterInput = document.getElementById("ralph-sticky-iterations");
466
+ if (stickyIterInput) {
467
+ stickyIterInput.addEventListener("input", function () {
468
+ pendingIterations = parseInt(this.value, 10) || pendingIterations;
469
+ syncIterationsUi();
470
+ });
471
+ }
472
+
473
+ stickyEl.querySelector(".ralph-sticky-preview").addEventListener("click", function(e) {
474
+ e.stopPropagation();
475
+ var ws = getWs();
476
+ if (ws && ws.readyState === 1) {
477
+ ws.send(JSON.stringify({ type: "ralph_preview_files" }));
478
+ }
479
+ });
480
+
481
+ stickyEl.querySelector(".ralph-sticky-start").addEventListener("click", function(e) {
482
+ e.stopPropagation();
483
+ startLoopFromUi();
484
+ });
485
+
486
+ stickyEl.querySelector(".ralph-sticky-dismiss").addEventListener("click", function(e) {
487
+ e.stopPropagation();
488
+ showConfirm("Discard this Ralph Loop setup?", function() {
489
+ var ws = getWs();
490
+ if (ws && ws.readyState === 1) {
491
+ ws.send(JSON.stringify({ type: "ralph_wizard_cancel" }));
492
+ }
493
+ stickyEl.classList.add("hidden");
494
+ stickyEl.classList.remove("ralph-ready");
495
+ stickyEl.innerHTML = "";
496
+ });
497
+ });
498
+
499
+ updateRalphApprovalStatus();
500
+ }
501
+
502
+ export function updateRalphApprovalStatus() {
503
+ var stickyEl = document.getElementById("ralph-sticky");
504
+ var statusEl = document.getElementById("ralph-sticky-status");
505
+ var startBtn = document.querySelector(".ralph-sticky-start");
506
+ if (!statusEl) return;
507
+
508
+ var wizData = store.get('wizardData') || {};
509
+ var isSimple = wizData.loopMode === "simple";
510
+ var _rf = store.get('ralphFilesReady');
511
+ var ready = isSimple ? _rf.promptReady : _rf.bothReady;
512
+
513
+ if (ready) {
514
+ statusEl.textContent = "Ready";
515
+ if (startBtn) startBtn.disabled = false;
516
+ if (stickyEl) stickyEl.classList.add("ralph-ready");
517
+ } else if (_rf.promptReady || _rf.judgeReady) {
518
+ statusEl.textContent = "Partial\u2026";
519
+ if (startBtn) startBtn.disabled = true;
520
+ if (stickyEl) stickyEl.classList.remove("ralph-ready");
521
+ } else {
522
+ statusEl.textContent = "Waiting\u2026";
523
+ if (startBtn) startBtn.disabled = true;
524
+ if (stickyEl) stickyEl.classList.remove("ralph-ready");
525
+ }
526
+ }
527
+
528
+ // ========================================================
529
+ // Preview modal (exported: openRalphPreviewModal, showExecModal)
530
+ // The preview modal doubles as the execution modal.
531
+ // showExecModal opens it with auto-popup flag set.
532
+ // ========================================================
533
+
534
+ export function showExecModal() {
535
+ store.set({ execModalShown: true });
536
+ // Open the preview modal immediately, then request file content to fill in
537
+ openRalphPreviewModal();
538
+ var ws = getWs();
539
+ if (ws && ws.readyState === 1) {
540
+ ws.send(JSON.stringify({ type: "ralph_preview_files" }));
541
+ }
542
+ }
543
+
544
+ export function closeExecModal() {
545
+ closeRalphPreviewModal();
546
+ }
547
+
548
+ export function updateExecModalStatus() {
549
+ // no-op, preview modal updates on open
550
+ }
551
+
552
+ export function openRalphPreviewModal() {
553
+ // Only show for loop (ralph) source, not scheduled tasks
554
+ var st = store.snap();
555
+ if (st.ralphCraftingSource !== "ralph") return;
556
+
557
+ var modal = document.getElementById("ralph-preview-modal");
558
+ if (!modal) return;
559
+
560
+ var wizData = st.wizardData || {};
561
+ var isSimple = wizData.loopMode === "simple";
562
+
563
+ // Set defaults if not yet set
564
+ if (!pendingIterations || pendingIterations <= 0) {
565
+ pendingIterations = isSimple ? 5 : 20;
566
+ }
567
+
568
+ // Set name
569
+ var nameEl = document.getElementById("ralph-preview-name");
570
+ if (nameEl) {
571
+ nameEl.textContent = (wizData && wizData.name) || "Loop";
572
+ }
573
+
574
+ // Hide JUDGE.md tab for simple loop
575
+ var judgeTab = document.querySelector('#ralph-preview-modal .ralph-tab[data-tab="judge"]');
576
+ if (judgeTab) judgeTab.style.display = isSimple ? "none" : "";
577
+
578
+ // Update footer: iteration label + run button
579
+ var iterInput = document.getElementById("ralph-preview-iterations");
580
+ if (iterInput) iterInput.value = pendingIterations;
581
+
582
+ var comboLabel = document.getElementById("ralph-run-combo-label");
583
+ if (comboLabel) comboLabel.textContent = isSimple ? "Run x" : "Start max";
584
+
585
+ var runBtn = document.getElementById("ralph-preview-run");
586
+ if (runBtn) runBtn.disabled = !store.get('ralphFilesReady').bothReady;
587
+
588
+ _previewLoopSettings = {};
589
+ showRalphPreviewTab("prompt");
590
+ modal.classList.remove("hidden");
591
+ refreshIcons();
592
+ syncIterationsUi();
593
+ }
594
+
595
+ function closeRalphPreviewModal() {
596
+ var modal = document.getElementById("ralph-preview-modal");
597
+ if (modal) modal.classList.add("hidden");
598
+ }
599
+
600
+ // Pending loop settings for the preview modal (saved to LOOP.json on launch)
601
+ var _previewLoopSettings = {};
602
+
603
+ function getPreviewLoopSettings() { return _previewLoopSettings; }
604
+
605
+ function showRalphPreviewTab(tab) {
606
+ var tabs = document.querySelectorAll("#ralph-preview-modal .ralph-tab");
607
+ for (var i = 0; i < tabs.length; i++) {
608
+ if (tabs[i].getAttribute("data-tab") === tab) {
609
+ tabs[i].classList.add("active");
610
+ } else {
611
+ tabs[i].classList.remove("active");
612
+ }
613
+ }
614
+ var body = document.getElementById("ralph-preview-body");
615
+ if (!body) return;
616
+
617
+ if (tab === "model") {
618
+ renderPreviewModelTab(body);
619
+ return;
620
+ }
621
+
622
+ var _rpc = store.get('ralphPreviewContent');
623
+ var content = tab === "prompt" ? _rpc.prompt : _rpc.judge;
624
+ if (typeof marked !== "undefined" && marked.parse) {
625
+ body.innerHTML = '<div class="md-content">' + DOMPurify.sanitize(marked.parse(content)) + '</div>';
626
+ } else {
627
+ body.textContent = content;
628
+ }
629
+ }
630
+
631
+ function renderPreviewModelTab(bodyEl) {
632
+ var s = store.snap();
633
+
634
+ bodyEl.innerHTML =
635
+ '<div class="scheduler-model-settings">' +
636
+ '<div class="settings-card"><div class="settings-field">' +
637
+ '<label class="settings-label">Model</label>' +
638
+ '<div class="settings-hint">Choose the Claude model for this loop.</div>' +
639
+ '<div id="rp-model-list" class="settings-model-list"></div>' +
640
+ '</div></div>' +
641
+ '<div class="settings-card"><div class="settings-field">' +
642
+ '<label class="settings-label">Mode</label>' +
643
+ '<div class="settings-hint">Controls how Claude handles tool use and file edits.</div>' +
644
+ '<div id="rp-mode-list" class="settings-model-list"></div>' +
645
+ '</div></div>' +
646
+ '<div class="settings-card"><div class="settings-field">' +
647
+ '<label class="settings-label">Effort</label>' +
648
+ '<div class="settings-hint">Controls how much thinking effort Claude puts into responses.</div>' +
649
+ '<div class="settings-btn-group" id="rp-effort-bar"></div>' +
650
+ '</div></div>' +
651
+ '<div class="settings-card"><div class="settings-field">' +
652
+ '<label class="settings-label">Thinking</label>' +
653
+ '<div class="settings-hint">Controls whether Claude shows its reasoning process.</div>' +
654
+ '<div class="settings-btn-group" id="rp-thinking-bar"></div>' +
655
+ '<div id="rp-thinking-budget-row" class="settings-budget-row" style="display:none">' +
656
+ '<label class="settings-budget-label">Budget tokens</label>' +
657
+ '<input id="rp-thinking-budget" type="number" class="settings-budget-input" min="1024" max="128000" step="1024" value="10000">' +
658
+ '</div>' +
659
+ '</div></div>' +
660
+ '</div>';
661
+
662
+ function savePreviewSetting(key, value) {
663
+ _previewLoopSettings[key] = value;
664
+ }
665
+
666
+ var opts = {
667
+ models: s.currentModels || [],
668
+ currentModel: _previewLoopSettings.model || "",
669
+ currentMode: _previewLoopSettings.permissionMode || "default",
670
+ currentEffort: _previewLoopSettings.effort || "medium",
671
+ currentThinking: _previewLoopSettings.thinking || "adaptive",
672
+ currentThinkingBudget: _previewLoopSettings.thinkingBudget || 10000,
673
+ sendMsg: function (msgType, data) {
674
+ if (msgType === "rp_set_model") savePreviewSetting("model", data.model);
675
+ else if (msgType === "rp_set_mode") savePreviewSetting("permissionMode", data.mode);
676
+ else if (msgType === "rp_set_effort") savePreviewSetting("effort", data.effort);
677
+ else if (msgType === "set_thinking") {
678
+ savePreviewSetting("thinking", data.thinking);
679
+ if (data.budgetTokens) savePreviewSetting("thinkingBudget", data.budgetTokens);
680
+ }
681
+ },
682
+ modelMsgType: "rp_set_model",
683
+ modeMsgType: "rp_set_mode",
684
+ effortMsgType: "rp_set_effort",
685
+ };
686
+
687
+ renderModelList("rp", opts);
688
+ renderModeList("rp", opts);
689
+ renderEffortBar("rp", opts);
690
+ renderThinkingBar("rp", opts);
691
+ }