@clagentic/console 1.9.0 → 1.10.0-beta.2

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 (172) hide show
  1. package/LICENSE +117 -12
  2. package/LICENSES/MIT-legacy.txt +22 -0
  3. package/LICENSES/README.md +15 -0
  4. package/README.md +9 -3
  5. package/bin/cli.js +40 -5
  6. package/deploy/clagentic-console.service +10 -6
  7. package/lib/agent-dispatch-tool.js +20 -0
  8. package/lib/audit.js +3 -2
  9. package/lib/build-changes.js +79 -0
  10. package/lib/build-identity.js +192 -0
  11. package/lib/build-monitor.js +125 -0
  12. package/lib/build-sha.json +2 -2
  13. package/lib/build-update-check.js +138 -0
  14. package/lib/build-update-offer.js +141 -0
  15. package/lib/build-update-restart.js +142 -0
  16. package/lib/build-update-standing.js +184 -0
  17. package/lib/cli/daemon-launch.js +25 -22
  18. package/lib/cli/ipc-subcommands.js +6 -0
  19. package/lib/cli/session-subcommands.js +122 -0
  20. package/lib/cli-sessions.js +8 -1
  21. package/lib/codex-defaults.js +8 -2
  22. package/lib/config.js +32 -20
  23. package/lib/daemon-env-settings.js +84 -0
  24. package/lib/daemon-projects.js +57 -0
  25. package/lib/daemon.js +288 -205
  26. package/lib/drain.js +74 -17
  27. package/lib/env-compat.js +61 -0
  28. package/lib/extension-commands.js +45 -0
  29. package/lib/history-visibility.js +4 -0
  30. package/lib/idle-adapter-reaper.js +71 -0
  31. package/lib/link-trap.js +78 -0
  32. package/lib/mcp-local.js +8 -6
  33. package/lib/mcp-tool-input.js +116 -0
  34. package/lib/mcp-tool-schema.js +179 -0
  35. package/lib/memory-limits.js +61 -5
  36. package/lib/memory-setting-validate.js +65 -0
  37. package/lib/memory-shed.js +13 -32
  38. package/lib/new-work-gate.js +47 -0
  39. package/lib/os-users.js +5 -3
  40. package/lib/project-access.js +139 -0
  41. package/lib/project-connection.js +37 -22
  42. package/lib/project-external-trigger.js +166 -105
  43. package/lib/project-file-scope.js +172 -0
  44. package/lib/project-file-watch.js +86 -61
  45. package/lib/project-filesystem.js +144 -128
  46. package/lib/project-git.js +119 -0
  47. package/lib/project-http.js +44 -28
  48. package/lib/project-loop.js +17 -9
  49. package/lib/project-mcp.js +53 -72
  50. package/lib/project-message-gate.js +70 -0
  51. package/lib/project-notifications.js +31 -4
  52. package/lib/project-prompt-responses.js +217 -0
  53. package/lib/project-sessions.js +192 -355
  54. package/lib/project-user-message.js +27 -15
  55. package/lib/project.js +212 -147
  56. package/lib/projects-dir.js +90 -0
  57. package/lib/prompt-access.js +22 -0
  58. package/lib/prompt-kinds/answer-limits.js +15 -0
  59. package/lib/prompt-kinds/ask-user.js +58 -0
  60. package/lib/prompt-kinds/codecs.js +97 -0
  61. package/lib/prompt-kinds/elicitation.js +77 -0
  62. package/lib/prompt-kinds/extension.js +39 -0
  63. package/lib/prompt-kinds/index.js +68 -0
  64. package/lib/prompt-kinds/permission.js +114 -0
  65. package/lib/prompt-kinds/plan.js +79 -0
  66. package/lib/prompt-kinds/tool-call.js +38 -0
  67. package/lib/prompt-registry.js +680 -0
  68. package/lib/public/app.js +1 -1
  69. package/lib/public/css/diagnostics.css +80 -0
  70. package/lib/public/css/input.css +17 -3
  71. package/lib/public/css/menus.css +10 -0
  72. package/lib/public/css/messages.css +5 -0
  73. package/lib/public/css/rewind.css +22 -0
  74. package/lib/public/index.html +4 -12
  75. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  76. package/lib/public/modules/app-connection.js +7 -0
  77. package/lib/public/modules/app-cursors.js +7 -5
  78. package/lib/public/modules/app-messages.js +52 -47
  79. package/lib/public/modules/app-notifications.js +47 -71
  80. package/lib/public/modules/app-panels.js +61 -59
  81. package/lib/public/modules/app-projects.js +2 -1
  82. package/lib/public/modules/app-rendering.js +4 -10
  83. package/lib/public/modules/build-update-detail.js +54 -0
  84. package/lib/public/modules/diagnostics.js +170 -20
  85. package/lib/public/modules/filebrowser.js +18 -16
  86. package/lib/public/modules/history-visibility.js +4 -0
  87. package/lib/public/modules/mention.js +3 -2
  88. package/lib/public/modules/mode-options.js +38 -0
  89. package/lib/public/modules/project-settings.js +19 -8
  90. package/lib/public/modules/prompt-banner.js +78 -0
  91. package/lib/public/modules/prompt-card.js +201 -0
  92. package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
  93. package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
  94. package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
  95. package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
  96. package/lib/public/modules/prompt-kinds/index.js +18 -0
  97. package/lib/public/modules/prompt-kinds/own-key.js +29 -0
  98. package/lib/public/modules/prompt-kinds/package.json +3 -0
  99. package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
  100. package/lib/public/modules/prompt-kinds/permission.js +209 -0
  101. package/lib/public/modules/prompt-kinds/plan.js +102 -0
  102. package/lib/public/modules/prompt-state.js +142 -0
  103. package/lib/public/modules/prompts.js +134 -0
  104. package/lib/public/modules/rewind.js +4 -1
  105. package/lib/public/modules/server-settings.js +2 -4
  106. package/lib/public/modules/sidebar-mobile.js +19 -9
  107. package/lib/public/modules/sidebar-sessions.js +21 -14
  108. package/lib/public/modules/sticky-notes.js +3 -2
  109. package/lib/public/modules/team-panel.js +5 -4
  110. package/lib/public/modules/tools.js +81 -906
  111. package/lib/public/modules/vendor-picker.js +53 -0
  112. package/lib/public/modules/vendor-registry.js +142 -0
  113. package/lib/public/sw.js +3 -1
  114. package/lib/rc-migrate.js +44 -0
  115. package/lib/runtime-env-keys.js +109 -0
  116. package/lib/runtime-env.js +236 -0
  117. package/lib/sdk-bridge.js +348 -284
  118. package/lib/sdk-message-processor.js +117 -146
  119. package/lib/sdk-skill-discovery.js +65 -60
  120. package/lib/server-hub-sessions.js +13 -10
  121. package/lib/server-palette.js +28 -19
  122. package/lib/server.js +156 -115
  123. package/lib/service-install.js +96 -0
  124. package/lib/session-capabilities.js +76 -0
  125. package/lib/session-id.js +33 -0
  126. package/lib/session-input-ipc.js +32 -0
  127. package/lib/session-input.js +379 -0
  128. package/lib/session-reclaim.js +284 -0
  129. package/lib/session-resume.js +172 -0
  130. package/lib/sessions.js +61 -30
  131. package/lib/supervisor.js +39 -0
  132. package/lib/turn-initiator.js +108 -0
  133. package/lib/users-permissions.js +9 -6
  134. package/lib/users.js +9 -0
  135. package/lib/utils.js +4 -2
  136. package/lib/vendor-auth.js +22 -0
  137. package/lib/vendor-registry-message.js +66 -0
  138. package/lib/ws-origin.js +99 -0
  139. package/lib/ws-schema.js +36 -23
  140. package/lib/yoke/adapters/claude-capabilities.js +38 -0
  141. package/lib/yoke/adapters/claude-vendor.js +34 -0
  142. package/lib/yoke/adapters/claude-worker.js +57 -87
  143. package/lib/yoke/adapters/claude.js +182 -88
  144. package/lib/yoke/adapters/codex-capabilities.js +40 -0
  145. package/lib/yoke/adapters/codex-vendor.js +46 -0
  146. package/lib/yoke/adapters/codex.js +462 -211
  147. package/lib/yoke/adapters/effort-control.js +34 -0
  148. package/lib/yoke/adapters/permission-relay.js +58 -0
  149. package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
  150. package/lib/yoke/auth-checks.js +91 -0
  151. package/lib/yoke/capabilities.js +49 -0
  152. package/lib/yoke/codex-app-server.js +30 -56
  153. package/lib/yoke/codex-binary.js +254 -0
  154. package/lib/yoke/codex-command.js +122 -0
  155. package/lib/yoke/codex-protocol.js +96 -0
  156. package/lib/yoke/codex-version.js +135 -0
  157. package/lib/yoke/env-ownership.js +40 -0
  158. package/lib/yoke/index.js +84 -174
  159. package/lib/yoke/install-probe.js +136 -0
  160. package/lib/yoke/instructions.js +7 -11
  161. package/lib/yoke/interface.js +206 -4
  162. package/lib/yoke/package.json +1 -1
  163. package/lib/yoke/provider-credentials.js +96 -0
  164. package/lib/yoke/registry.js +377 -0
  165. package/package.json +12 -9
  166. package/scripts/check-sdk-lock-drift.js +160 -0
  167. package/scripts/check-test-count.js +76 -1
  168. package/scripts/postinstall.js +218 -136
  169. package/scripts/prompt-harness-history.js +202 -0
  170. package/scripts/verify-installed-build.js +59 -17
  171. package/scripts/verify-installed.js +67 -0
  172. package/lib/sdk-permission-ownership.js +0 -136
@@ -6,6 +6,8 @@ import { openFile } from './filebrowser.js';
6
6
  import { getChatLayout } from './theme.js';
7
7
  import { store } from './store.js';
8
8
  import { VENDOR_NAMES } from './app-rendering.js';
9
+ import { createPromptController } from './prompts.js';
10
+ import { isAgentDispatchTool } from './agent-dispatch-tool.js';
9
11
 
10
12
  var ctx;
11
13
 
@@ -57,7 +59,6 @@ var todoMeta = {
57
59
  var tools = {};
58
60
  var currentThinking = null;
59
61
  var thinkingGroup = null; // { el, count, totalDuration }
60
- var pendingPermissions = {};
61
62
 
62
63
  // --- Tool group tracking ---
63
64
  var currentToolGroup = null;
@@ -92,10 +93,21 @@ function toolGroupSummary(group) {
92
93
  counts[names[i]] = (counts[names[i]] || 0) + 1;
93
94
  }
94
95
  var uniqueNames = Object.keys(counts);
96
+ // A group mixing "Task" and "Agent" dispatches is still one kind of tool.
97
+ var dispatchKinds = uniqueNames.filter(isAgentDispatchTool);
98
+ if (dispatchKinds.length > 1 && dispatchKinds.length === uniqueNames.length) {
99
+ var dispatchTotal = 0;
100
+ dispatchKinds.forEach(function (k) { dispatchTotal += counts[k]; });
101
+ uniqueNames = ["Task"];
102
+ counts = { Task: dispatchTotal };
103
+ }
95
104
 
96
105
  if (uniqueNames.length === 1) {
97
106
  var name = uniqueNames[0];
107
+ // Read the count under the name it was tallied with, then pick the label
108
+ // family: an Agent-only group has no "Task" entry in counts.
98
109
  var n = counts[name];
110
+ if (isAgentDispatchTool(name)) name = "Task";
99
111
  if (allDone) {
100
112
  switch (name) {
101
113
  case "Read": return "Read " + n + " file" + (n > 1 ? "s" : "");
@@ -169,6 +181,7 @@ function isPlanFile(filePath) {
169
181
 
170
182
  export function toolSummary(name, input) {
171
183
  if (!input || typeof input !== "object") return "";
184
+ if (isAgentDispatchTool(name)) return input.description || "";
172
185
  switch (name) {
173
186
  case "Read": return shortPath(input.file_path);
174
187
  case "Edit": return shortPath(input.file_path);
@@ -178,7 +191,6 @@ export function toolSummary(name, input) {
178
191
  case "Grep": return (input.pattern || "") + (input.path ? " in " + shortPath(input.path) : "");
179
192
  case "WebFetch": return input.url || "";
180
193
  case "WebSearch": return input.query || "";
181
- case "Task": return input.description || "";
182
194
  case "EnterPlanMode": return "";
183
195
  case "ExitPlanMode": return "";
184
196
  default: return JSON.stringify(input).substring(0, 60);
@@ -194,7 +206,7 @@ export function toolActivityText(name, input) {
194
206
  if (name === "Glob" && input && input.pattern) return "Finding " + input.pattern;
195
207
  if (name === "WebSearch" && input && input.query) return "Searching: " + input.query;
196
208
  if (name === "WebFetch") return "Fetching URL...";
197
- if (name === "Task" && input && input.description) return input.description;
209
+ if (isAgentDispatchTool(name) && input && input.description) return input.description;
198
210
  if (name === "EnterPlanMode") return "Entering plan mode...";
199
211
  if (name === "ExitPlanMode") return "Finalizing the plan...";
200
212
  return "Running " + name + "...";
@@ -206,158 +218,6 @@ function shortPath(p) {
206
218
  return parts.length > 3 ? ".../" + parts.slice(-3).join("/") : p;
207
219
  }
208
220
 
209
- // --- AskUserQuestion ---
210
- export function renderAskUserQuestion(toolId, input) {
211
- ctx.finalizeAssistantBlock();
212
- stopThinking();
213
- closeToolGroup();
214
-
215
- var questions = input.questions || [];
216
- if (questions.length === 0) return;
217
-
218
- var container = document.createElement("div");
219
- container.className = "ask-user-container";
220
- container.dataset.toolId = toolId;
221
-
222
- var mateContentWrap = null;
223
-
224
- var answers = {};
225
- var multiSelections = {};
226
-
227
- questions.forEach(function (q, qIdx) {
228
- var qDiv = document.createElement("div");
229
- qDiv.className = "ask-user-question";
230
-
231
- if (q.header) {
232
- var qHeader = document.createElement("div");
233
- qHeader.className = "ask-user-question-header";
234
- qHeader.textContent = q.header;
235
- qDiv.appendChild(qHeader);
236
- }
237
-
238
- var qText = document.createElement("div");
239
- qText.className = "ask-user-question-text";
240
- qText.textContent = q.question || "";
241
- qDiv.appendChild(qText);
242
-
243
- var optionsDiv = document.createElement("div");
244
- optionsDiv.className = "ask-user-options";
245
-
246
- var isMulti = q.multiSelect || false;
247
- if (isMulti) multiSelections[qIdx] = new Set();
248
-
249
- (q.options || []).forEach(function (opt) {
250
- var btn = document.createElement("button");
251
- btn.className = "ask-user-option";
252
- btn.innerHTML =
253
- '<div class="option-label"></div>' +
254
- (opt.description ? '<div class="option-desc"></div>' : '');
255
- btn.querySelector(".option-label").textContent = opt.label;
256
- if (opt.description) btn.querySelector(".option-desc").textContent = opt.description;
257
- if (opt.markdown) {
258
- var pre = document.createElement("pre");
259
- pre.className = "option-markdown";
260
- pre.textContent = opt.markdown;
261
- btn.appendChild(pre);
262
- }
263
-
264
- btn.addEventListener("click", function () {
265
- if (container.classList.contains("answered")) return;
266
-
267
- if (isMulti) {
268
- var set = multiSelections[qIdx];
269
- if (set.has(opt.label)) {
270
- set.delete(opt.label);
271
- btn.classList.remove("selected");
272
- } else {
273
- set.add(opt.label);
274
- btn.classList.add("selected");
275
- }
276
- } else {
277
- optionsDiv.querySelectorAll(".ask-user-option").forEach(function (b) {
278
- b.classList.remove("selected");
279
- });
280
- btn.classList.add("selected");
281
- answers[qIdx] = opt.label;
282
- var otherInput = qDiv.querySelector(".ask-user-other input");
283
- if (otherInput) otherInput.value = "";
284
- }
285
- });
286
-
287
- optionsDiv.appendChild(btn);
288
- });
289
-
290
- qDiv.appendChild(optionsDiv);
291
-
292
- // "Other" text input
293
- var otherDiv = document.createElement("div");
294
- otherDiv.className = "ask-user-other";
295
- var otherInput = document.createElement("input");
296
- otherInput.type = "text";
297
- otherInput.placeholder = "Other...";
298
- otherInput.addEventListener("input", function () {
299
- if (container.classList.contains("answered")) return;
300
- if (otherInput.value.trim()) {
301
- optionsDiv.querySelectorAll(".ask-user-option").forEach(function (b) {
302
- b.classList.remove("selected");
303
- });
304
- if (isMulti) multiSelections[qIdx] = new Set();
305
- answers[qIdx] = otherInput.value.trim();
306
- }
307
- });
308
- otherInput.addEventListener("keydown", function (e) {
309
- if (e.key === "Enter" && !e.shiftKey) {
310
- e.preventDefault();
311
- submitAskUserAnswer(container, toolId, questions, answers, multiSelections);
312
- }
313
- });
314
- otherDiv.appendChild(otherInput);
315
- qDiv.appendChild(otherDiv);
316
- container.appendChild(qDiv);
317
- });
318
-
319
- // Submit button: always show
320
- var submitBtn = document.createElement("button");
321
- submitBtn.className = "ask-user-submit";
322
- submitBtn.textContent = "Submit";
323
- submitBtn.addEventListener("click", function () {
324
- submitAskUserAnswer(container, toolId, questions, answers, multiSelections);
325
- });
326
- container.appendChild(submitBtn);
327
-
328
- // Skip button
329
- var skipBtn = document.createElement("button");
330
- skipBtn.className = "ask-user-skip";
331
- skipBtn.textContent = "Skip";
332
- skipBtn.addEventListener("click", function () {
333
- if (container.classList.contains("answered")) return;
334
- container.classList.add("answered");
335
- enableMainInput();
336
- if (ctx.ws && ctx.connected) {
337
- ctx.ws.send(JSON.stringify({ type: "stop" }));
338
- }
339
- });
340
- container.appendChild(skipBtn);
341
-
342
- // Mate DM: move all content into the bubble content wrapper
343
- if (mateContentWrap) {
344
- var children = [];
345
- for (var ci = 0; ci < container.childNodes.length; ci++) {
346
- if (container.childNodes[ci] !== container.querySelector(".dm-bubble-avatar")) {
347
- children.push(container.childNodes[ci]);
348
- }
349
- }
350
- for (var cj = 0; cj < children.length; cj++) {
351
- mateContentWrap.appendChild(children[cj]);
352
- }
353
- container.appendChild(mateContentWrap);
354
- }
355
-
356
- ctx.addToMessages(container);
357
- disableMainInput();
358
- maybeScrollToBottom();
359
- }
360
-
361
221
  export function disableMainInput() {
362
222
  ctx.inputEl.disabled = true;
363
223
  ctx.inputEl.placeholder = "Answer the question above to continue...";
@@ -369,764 +229,81 @@ export function enableMainInput() {
369
229
  ctx.inputEl.placeholder = "Message " + (VENDOR_NAMES[_v] || VENDOR_NAMES.claude) + "...";
370
230
  }
371
231
 
372
- function submitAskUserAnswer(container, toolId, questions, answers, multiSelections) {
373
- if (container.classList.contains("answered")) return;
374
-
375
- var result = {};
376
- for (var i = 0; i < questions.length; i++) {
377
- var q = questions[i];
378
- if (q.multiSelect && multiSelections[i] && multiSelections[i].size > 0) {
379
- result[i] = Array.from(multiSelections[i]).join(", ");
380
- } else if (answers[i]) {
381
- result[i] = answers[i];
382
- }
383
- }
384
-
385
- if (Object.keys(result).length === 0) return;
386
-
387
- container.classList.add("answered");
388
- enableMainInput();
389
- if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
390
-
391
- // Show user's answers inline
392
- showAnswerSummary(container, questions, result);
393
-
394
- if (ctx.ws && ctx.connected) {
395
- ctx.ws.send(JSON.stringify({
396
- type: "ask_user_response",
397
- toolId: toolId,
398
- answers: result,
399
- }));
400
- }
401
- }
402
-
403
- function showAnswerSummary(container, questions, answers) {
404
- if (!answers || Object.keys(answers).length === 0) return;
405
- var existing = container.querySelector(".ask-user-answer-summary");
406
- if (existing) return;
407
- var summary = document.createElement("div");
408
- summary.className = "ask-user-answer-summary";
409
- for (var key in answers) {
410
- if (!answers.hasOwnProperty(key)) continue;
411
- var row = document.createElement("div");
412
- row.className = "ask-user-answer-row";
413
- var qi = parseInt(key, 10);
414
- var label = (questions && questions[qi] && questions[qi].question) ? questions[qi].question : "Answer";
415
- row.innerHTML = '<span class="ask-user-answer-label">' + escapeHtml(label) + '</span>' +
416
- '<span class="ask-user-answer-value">' + escapeHtml(String(answers[key])) + '</span>';
417
- summary.appendChild(row);
418
- }
419
- // Insert before submit button
420
- var submitBtn = container.querySelector(".ask-user-submit");
421
- if (submitBtn) {
422
- submitBtn.parentNode.insertBefore(summary, submitBtn);
423
- } else {
424
- container.appendChild(summary);
425
- }
426
- }
427
-
428
- export function markAskUserAnswered(toolId, answers) {
429
- var container = document.querySelector('.ask-user-container[data-tool-id="' + toolId + '"]');
430
- if (container && !container.classList.contains("answered")) {
431
- container.classList.add("answered");
432
- enableMainInput();
433
- // Restore answers from history replay
434
- if (answers && Object.keys(answers).length > 0) {
435
- // Find matching questions from the tool_executing input
436
- var questions = null;
437
- var askQuestions = container.querySelectorAll(".ask-user-question");
438
- if (askQuestions.length > 0) {
439
- questions = [];
440
- for (var qi = 0; qi < askQuestions.length; qi++) {
441
- var qTextEl = askQuestions[qi].querySelector(".ask-user-question-text");
442
- questions.push({ question: qTextEl ? qTextEl.textContent : "" });
443
- }
444
- }
445
- showAnswerSummary(container, questions, answers);
446
- // Also mark selected options to match the answers
447
- for (var key in answers) {
448
- if (!answers.hasOwnProperty(key)) continue;
449
- var idx = parseInt(key, 10);
450
- if (askQuestions[idx]) {
451
- var answerVal = String(answers[key]);
452
- var options = askQuestions[idx].querySelectorAll(".ask-user-option");
453
- var matched = false;
454
- for (var oi = 0; oi < options.length; oi++) {
455
- var labelEl = options[oi].querySelector(".option-label");
456
- if (labelEl && labelEl.textContent === answerVal) {
457
- options[oi].classList.add("selected");
458
- matched = true;
459
- }
460
- }
461
- // If not matched to an option, fill the "Other" input
462
- if (!matched) {
463
- var otherInput = askQuestions[idx].querySelector(".ask-user-other input");
464
- if (otherInput) otherInput.value = answerVal;
465
- }
466
- }
467
- }
468
- }
469
- }
470
- }
471
-
472
- // --- Permission request ---
473
- function permissionInputSummary(toolName, input) {
474
- if (!input || typeof input !== "object") return "";
475
- switch (toolName) {
476
- case "Bash": return input.command || input.description || "";
477
- case "Edit": return shortPath(input.file_path);
478
- case "Write": return shortPath(input.file_path);
479
- case "Read": return shortPath(input.file_path);
480
- case "Glob": return input.pattern || "";
481
- case "Grep": return (input.pattern || "") + (input.path ? " in " + shortPath(input.path) : "");
482
- default: return toolSummary(toolName, input);
483
- }
484
- }
485
-
486
- export function renderPermissionRequest(requestId, toolName, toolInput, decisionReason, mateId, vendor) {
487
- if (pendingPermissions[requestId]) return;
488
- // On WS reconnect the DOM node may survive a pendingPermissions reset.
489
- // Guard against duplicating the card in that case.
490
- if (ctx && ctx.messagesEl && ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]')) return;
491
- ctx.finalizeAssistantBlock();
492
- stopThinking();
493
- closeToolGroup();
494
-
495
- // ExitPlanMode: render as plan confirmation instead of generic permission
496
- if (toolName === "ExitPlanMode") {
497
- renderPlanPermission(requestId);
498
- return;
499
- }
500
-
501
- // Channel layout: conversational "Can I ...?" style
502
- if (getChatLayout() === "channel") {
503
- renderConversationalPermission(requestId, toolName, toolInput, mateId, vendor);
504
- return;
505
- }
506
-
507
- // Bubble layout: formal "Permission Required" dialog
508
- renderFormalPermission(requestId, toolName, toolInput, decisionReason);
509
- }
510
-
511
- function renderFormalPermission(requestId, toolName, toolInput, decisionReason) {
512
- var container = document.createElement("div");
513
- container.className = "permission-container";
514
- container.dataset.requestId = requestId;
515
-
516
- // Header
517
- var header = document.createElement("div");
518
- header.className = "permission-header";
519
- header.innerHTML =
520
- '<span class="permission-icon">' + iconHtml("shield") + '</span>' +
521
- '<span class="permission-title">Permission Required</span>';
522
-
523
- // Body
524
- var body = document.createElement("div");
525
- body.className = "permission-body";
526
-
527
- var summary = document.createElement("div");
528
- summary.className = "permission-summary";
529
- var summaryText = permissionInputSummary(toolName, toolInput);
530
- summary.innerHTML =
531
- '<span class="permission-tool-name"></span>' +
532
- (summaryText ? '<span class="permission-tool-desc"></span>' : '');
533
- summary.querySelector(".permission-tool-name").textContent = toolName;
534
- if (summaryText) {
535
- summary.querySelector(".permission-tool-desc").textContent = summaryText;
536
- }
537
- body.appendChild(summary);
538
-
539
- if (decisionReason) {
540
- var reason = document.createElement("div");
541
- reason.className = "permission-reason";
542
- reason.textContent = decisionReason;
543
- body.appendChild(reason);
544
- }
545
-
546
- // Collapsible details
547
- var details = document.createElement("details");
548
- details.className = "permission-details";
549
- var detailsSummary = document.createElement("summary");
550
- detailsSummary.textContent = "Details";
551
- var detailsPre = document.createElement("pre");
552
- detailsPre.textContent = JSON.stringify(toolInput, null, 2);
553
- details.appendChild(detailsSummary);
554
- details.appendChild(detailsPre);
555
- body.appendChild(details);
556
-
557
- // Actions
558
- var actions = document.createElement("div");
559
- actions.className = "permission-actions";
560
-
561
- var allowBtn = document.createElement("button");
562
- allowBtn.className = "permission-btn permission-allow";
563
- allowBtn.textContent = "Allow Once";
564
- allowBtn.addEventListener("click", function () {
565
- sendPermissionResponse(container, requestId, "allow");
566
- });
567
-
568
- var allowAlwaysBtn = document.createElement("button");
569
- allowAlwaysBtn.className = "permission-btn permission-allow-session";
570
- allowAlwaysBtn.textContent = "Allow for Session";
571
- allowAlwaysBtn.addEventListener("click", function () {
572
- sendPermissionResponse(container, requestId, "allow_always");
573
- });
574
-
575
- var denyBtn = document.createElement("button");
576
- denyBtn.className = "permission-btn permission-deny";
577
- denyBtn.textContent = "Deny";
578
- denyBtn.addEventListener("click", function () {
579
- sendPermissionResponse(container, requestId, "deny");
580
- });
581
-
582
- actions.appendChild(allowBtn);
583
- actions.appendChild(allowAlwaysBtn);
584
- actions.appendChild(denyBtn);
585
-
586
- container.appendChild(header);
587
- container.appendChild(body);
588
- container.appendChild(actions);
589
- ctx.addToMessages(container);
590
-
591
- pendingPermissions[requestId] = container;
592
- refreshIcons(container);
593
- maybeScrollToBottom();
594
- }
595
-
596
- function renderPlanPermission(requestId) {
597
- if (pendingPermissions[requestId]) return;
598
- var container = document.createElement("div");
599
- container.className = "permission-container plan-permission";
600
- container.dataset.requestId = requestId;
601
-
602
- // Header
603
- var header = document.createElement("div");
604
- header.className = "permission-header plan-permission-header";
605
- header.innerHTML =
606
- '<span class="permission-icon">' + iconHtml("check-circle") + '</span>' +
607
- '<span class="permission-title">Plan Approval</span>';
608
-
609
- // Body (plan content already visible above, no need to repeat)
610
- var body = document.createElement("div");
611
- body.className = "permission-body";
612
-
613
- // Actions row 1: main buttons
614
- var actions = document.createElement("div");
615
- actions.className = "permission-actions plan-permission-actions";
616
-
617
- // Option 1: Clear context & auto-accept
618
- var clearBtn = document.createElement("button");
619
- clearBtn.className = "permission-btn plan-btn-clear";
620
- var contextPct = ctx.getContextPercent ? ctx.getContextPercent() : 0;
621
- clearBtn.innerHTML = iconHtml("refresh-cw") + ' <span>Clear context' +
622
- (contextPct > 0 ? ' <span class="plan-ctx-pct">(' + contextPct + '% used)</span>' : '') +
623
- ' &amp; auto-accept</span>';
624
- clearBtn.addEventListener("click", function () {
625
- sendPlanResponse(container, requestId, "allow_clear_context");
626
- });
627
-
628
- // Option 2: Auto-accept edits
629
- var approveBtn = document.createElement("button");
630
- approveBtn.className = "permission-btn permission-allow";
631
- approveBtn.textContent = "Auto-accept edits";
632
- approveBtn.addEventListener("click", function () {
633
- sendPlanResponse(container, requestId, "allow_accept_edits");
634
- });
635
-
636
- // Option 3: Manually approve edits
637
- var manualBtn = document.createElement("button");
638
- manualBtn.className = "permission-btn permission-allow-session";
639
- manualBtn.textContent = "Manually approve";
640
- manualBtn.addEventListener("click", function () {
641
- sendPlanResponse(container, requestId, "allow");
642
- });
643
-
644
- // Option 4: Reject
645
- var rejectBtn = document.createElement("button");
646
- rejectBtn.className = "permission-btn permission-deny";
647
- rejectBtn.textContent = "Reject";
648
- rejectBtn.addEventListener("click", function () {
649
- sendPlanResponse(container, requestId, "deny");
650
- });
651
-
652
- actions.appendChild(clearBtn);
653
- actions.appendChild(approveBtn);
654
- actions.appendChild(manualBtn);
655
- actions.appendChild(rejectBtn);
656
-
657
- // Feedback input row (Option 4: tell Claude what to change)
658
- var feedbackRow = document.createElement("div");
659
- feedbackRow.className = "plan-feedback-row";
660
- var feedbackInput = document.createElement("input");
661
- feedbackInput.type = "text";
662
- feedbackInput.className = "plan-feedback-input";
663
- feedbackInput.placeholder = "Tell Claude what to change...";
664
- var feedbackSendBtn = document.createElement("button");
665
- feedbackSendBtn.className = "plan-feedback-send";
666
- feedbackSendBtn.innerHTML = iconHtml("arrow-up");
667
- feedbackSendBtn.disabled = true;
668
-
669
- feedbackInput.addEventListener("input", function () {
670
- feedbackSendBtn.disabled = !feedbackInput.value.trim();
671
- });
672
- feedbackInput.addEventListener("keydown", function (e) {
673
- if (e.key === "Enter" && !e.shiftKey && feedbackInput.value.trim()) {
674
- e.preventDefault();
675
- submitPlanFeedback();
676
- }
677
- });
678
- feedbackSendBtn.addEventListener("click", function () {
679
- if (feedbackInput.value.trim()) submitPlanFeedback();
680
- });
681
-
682
- function submitPlanFeedback() {
683
- var text = feedbackInput.value.trim();
684
- if (!text) return;
685
- sendPlanResponse(container, requestId, "deny_with_feedback", text);
686
- }
232
+ // --- Operator prompts (permission, plan, AskUserQuestion, elicitation) ---
687
233
 
688
- feedbackRow.appendChild(feedbackInput);
689
- feedbackRow.appendChild(feedbackSendBtn);
690
-
691
- container.appendChild(header);
692
- container.appendChild(body);
693
- container.appendChild(actions);
694
- container.appendChild(feedbackRow);
695
- ctx.addToMessages(container);
696
-
697
- pendingPermissions[requestId] = container;
698
- refreshIcons(container);
699
- maybeScrollToBottom();
700
- // Focus the feedback input after render
701
- setTimeout(function () { feedbackInput.focus(); }, 50);
702
- }
703
-
704
- function sendPlanResponse(container, requestId, decision, feedback) {
705
- if (container.classList.contains("resolved")) return;
706
- container.classList.add("resolved");
707
- if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
708
-
709
- var labelMap = {
710
- "allow": "Approved (manual)",
711
- "allow_accept_edits": "Approved (auto-accept)",
712
- "allow_clear_context": "Approved (clear + auto-accept)",
713
- "deny": "Rejected",
714
- "deny_with_feedback": "Feedback sent",
715
- };
716
- var label = labelMap[decision] || decision;
717
- var isDeny = decision === "deny" || decision === "deny_with_feedback";
718
- var resolvedClass = isDeny ? "resolved-denied" : "resolved-allowed";
719
- container.classList.add(resolvedClass);
720
-
721
- // Replace actions + feedback with decision label
722
- var actionsEl = container.querySelector(".plan-permission-actions");
723
- if (actionsEl) {
724
- actionsEl.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
725
- }
726
- var feedbackRowEl = container.querySelector(".plan-feedback-row");
727
- if (feedbackRowEl) feedbackRowEl.remove();
728
-
729
- if (ctx.ws && ctx.connected) {
730
- var payload = {
731
- type: "permission_response",
732
- requestId: requestId,
733
- decision: decision,
734
- };
735
- if (feedback) payload.feedback = feedback;
736
- if (decision === "allow_clear_context" && planContent) {
737
- payload.planContent = planContent;
234
+ // Cards are drawn and kept in line with the server's state by one
235
+ // controller (prompts.js). Its state is not cleared by resetToolState: an
236
+ // older-history page resets tool state after newer pages already delivered
237
+ // the outcomes it needs. Cleared on session switch.
238
+ var prompts = createPromptController({
239
+ place: function (container, focusSelector) {
240
+ ctx.finalizeAssistantBlock();
241
+ stopThinking();
242
+ closeToolGroup();
243
+ ctx.addToMessages(container);
244
+ refreshIcons(container);
245
+ maybeScrollToBottom();
246
+ if (focusSelector) {
247
+ setTimeout(function () {
248
+ var target = container.querySelector(focusSelector);
249
+ if (target) target.focus();
250
+ }, 50);
738
251
  }
252
+ },
253
+ send: function (payload) {
254
+ if (!(ctx.ws && ctx.connected)) return false;
739
255
  ctx.ws.send(JSON.stringify(payload));
740
- }
741
-
742
- delete pendingPermissions[requestId];
743
- }
744
-
745
- function matePermissionInfo(toolName, toolInput) {
746
- var input = toolInput && typeof toolInput === "object" ? toolInput : {};
747
- var verb = "use " + toolName;
748
- var target = "";
749
-
750
- switch (toolName) {
751
- case "Write": verb = "write to"; target = shortPath(input.file_path); break;
752
- case "Edit": verb = "edit"; target = shortPath(input.file_path); break;
753
- case "Read": verb = "read"; target = shortPath(input.file_path); break;
754
- case "Bash": verb = "run"; target = input.description || (input.command || "").substring(0, 80); break;
755
- case "Grep": verb = "search"; target = input.pattern || ""; break;
756
- case "Glob": verb = "search for files in"; target = input.pattern || ""; break;
757
- case "WebFetch": verb = "fetch"; target = input.url || ""; break;
758
- case "WebSearch": verb = "search the web for"; target = input.query || ""; break;
759
- }
760
- return { verb: verb, target: target };
761
- }
762
-
763
- function resolvePermissionIdentity(mateId, vendor) {
764
- // Use vendor name and avatar
256
+ return true;
257
+ },
258
+ layout: function () { return getChatLayout(); },
259
+ toolSummary: toolSummary,
260
+ vendorIdentity: vendorIdentity,
261
+ getContextPercent: function () { return ctx.getContextPercent ? ctx.getContextPercent() : 0; },
262
+ getPlanContent: function () { return planContent; },
263
+ setMainInputDisabled: function (disabled) {
264
+ if (!ctx.inputEl) return;
265
+ if (disabled) disableMainInput();
266
+ else enableMainInput();
267
+ },
268
+ contains: function (el) {
269
+ return !(ctx.messagesEl && typeof ctx.messagesEl.contains === "function") || ctx.messagesEl.contains(el);
270
+ },
271
+ findInTranscript: function (requestId) {
272
+ return ctx && ctx.messagesEl ? ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]') : null;
273
+ },
274
+ });
275
+
276
+ /**
277
+ * Apply one prompt message of any kind, live or replayed (including the
278
+ * per-kind messages of older history). Returns the prompt's effective state,
279
+ * or null for a message that is not about a prompt.
280
+ */
281
+ export function applyPromptMessage(msg) {
282
+ return prompts.apply(msg);
283
+ }
284
+
285
+ export function clearPromptStates() {
286
+ prompts.clear();
287
+ }
288
+
289
+ /** Whether any prompt, of any kind, is still awaiting the operator. */
290
+ export function hasPendingPrompts() {
291
+ return prompts.hasPending();
292
+ }
293
+
294
+ /** Return every card awaiting a server confirmation to its answerable state. */
295
+ export function restoreUnconfirmedPrompts(message) {
296
+ prompts.restoreUnconfirmed(message);
297
+ }
298
+
299
+ function vendorIdentity(vendor) {
765
300
  var vendorAvatars = { claude: "/claude-code-avatar.png", codex: "/codex-avatar.png" };
766
- var vendorName = (vendor && VENDOR_NAMES[vendor]) || VENDOR_NAMES.claude;
767
301
  return {
768
- name: vendorName,
302
+ name: (vendor && VENDOR_NAMES[vendor]) || VENDOR_NAMES.claude,
769
303
  avatar: (vendor && vendorAvatars[vendor]) || vendorAvatars.claude,
770
304
  };
771
305
  }
772
306
 
773
- function renderConversationalPermission(requestId, toolName, toolInput, mateId, vendor) {
774
- var identity = resolvePermissionIdentity(mateId, vendor);
775
- var info = matePermissionInfo(toolName, toolInput);
776
- var askMsg = "Can I " + info.verb + (info.target ? " " + info.target : "") + "?";
777
-
778
- var container = document.createElement("div");
779
- container.className = "permission-container";
780
- container.dataset.requestId = requestId;
781
-
782
- // Avatar (left column)
783
- var avi = document.createElement("img");
784
- avi.className = "dm-bubble-avatar dm-bubble-avatar-agent";
785
- avi.src = identity.avatar;
786
- avi.alt = "";
787
- container.appendChild(avi);
788
-
789
- // Content (right column)
790
- var content = document.createElement("div");
791
- content.className = "dm-bubble-content";
792
-
793
- // Name + time header
794
- var headerRow = document.createElement("div");
795
- headerRow.className = "dm-bubble-header";
796
- headerRow.innerHTML =
797
- '<span class="dm-bubble-name">' + escapeHtml(identity.name) + '</span>' +
798
- '<span class="dm-bubble-time">' + String(new Date().getHours()).padStart(2, "0") + ":" + String(new Date().getMinutes()).padStart(2, "0") + '</span>';
799
- content.appendChild(headerRow);
800
-
801
- // Ask text
802
- var askEl = document.createElement("div");
803
- askEl.className = "perm-ask";
804
- askEl.textContent = askMsg;
805
- content.appendChild(askEl);
806
-
807
- // Collapsible details
808
- var details = document.createElement("details");
809
- details.className = "perm-details";
810
- var summary = document.createElement("summary");
811
- summary.textContent = "Details";
812
- var pre = document.createElement("pre");
813
- pre.textContent = JSON.stringify(toolInput, null, 2);
814
- details.appendChild(summary);
815
- details.appendChild(pre);
816
- content.appendChild(details);
817
-
818
- // Buttons
819
- var actions = document.createElement("div");
820
- actions.className = "permission-actions";
821
-
822
- var allowBtn = document.createElement("button");
823
- allowBtn.className = "perm-reply perm-allow";
824
- allowBtn.textContent = "Sure";
825
- allowBtn.addEventListener("click", function () {
826
- sendPermissionResponse(container, requestId, "allow");
827
- });
828
-
829
- var alwaysBtn = document.createElement("button");
830
- alwaysBtn.className = "perm-reply perm-always";
831
- alwaysBtn.textContent = "Allow for session";
832
- alwaysBtn.addEventListener("click", function () {
833
- sendPermissionResponse(container, requestId, "allow_always");
834
- });
835
-
836
- var denyBtn = document.createElement("button");
837
- denyBtn.className = "perm-reply perm-deny";
838
- denyBtn.textContent = "No";
839
- denyBtn.addEventListener("click", function () {
840
- sendPermissionResponse(container, requestId, "deny");
841
- });
842
-
843
- actions.appendChild(allowBtn);
844
- actions.appendChild(alwaysBtn);
845
- actions.appendChild(denyBtn);
846
- content.appendChild(actions);
847
-
848
- container.appendChild(content);
849
-
850
- ctx.addToMessages(container);
851
- pendingPermissions[requestId] = container;
852
- refreshIcons(container);
853
- maybeScrollToBottom();
854
- }
855
-
856
- function sendPermissionResponse(container, requestId, decision) {
857
- if (container.classList.contains("resolved")) return;
858
- container.classList.add("resolved");
859
- if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
860
-
861
- var label = decision === "deny" ? "Denied" : decision === "allow_always" ? "Allowed for session" : "Allowed";
862
- var resolvedClass = decision === "deny" ? "resolved-denied" : "resolved-allowed";
863
- container.classList.add(resolvedClass);
864
-
865
- // Replace actions with decision label
866
- var actions = container.querySelector(".permission-actions");
867
- if (actions) {
868
- actions.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
869
- }
870
-
871
- if (ctx.ws && ctx.connected) {
872
- ctx.ws.send(JSON.stringify({
873
- type: "permission_response",
874
- requestId: requestId,
875
- decision: decision,
876
- }));
877
- }
878
-
879
- delete pendingPermissions[requestId];
880
- }
881
-
882
- export function markPermissionResolved(requestId, decision) {
883
- var container = pendingPermissions[requestId];
884
- if (!container) {
885
- // Find by data attribute (history replay)
886
- container = ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]');
887
- }
888
- if (!container || container.classList.contains("resolved")) return;
889
-
890
- container.classList.add("resolved");
891
-
892
- // Plan-specific decisions
893
- var planLabelMap = {
894
- "allow_accept_edits": "Approved (auto-accept)",
895
- "allow_clear_context": "Approved (clear + auto-accept)",
896
- "deny_with_feedback": "Feedback sent",
897
- };
898
- var isDeny = decision === "deny" || decision === "deny_with_feedback";
899
- var resolvedClass = isDeny ? "resolved-denied" : "resolved-allowed";
900
- container.classList.add(resolvedClass);
901
-
902
- var label = planLabelMap[decision] || (decision === "deny" ? "Denied" : decision === "allow_always" ? "Allowed for session" : "Allowed");
903
- var actions = container.querySelector(".permission-actions") || container.querySelector(".plan-permission-actions");
904
- if (actions) {
905
- actions.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
906
- }
907
- // Remove feedback row if present (plan permission)
908
- var feedbackRow = container.querySelector(".plan-feedback-row");
909
- if (feedbackRow) feedbackRow.remove();
910
-
911
- delete pendingPermissions[requestId];
912
- }
913
-
914
- export function markPermissionCancelled(requestId) {
915
- var container = pendingPermissions[requestId];
916
- if (!container) {
917
- container = ctx.messagesEl.querySelector('[data-request-id="' + requestId + '"]');
918
- }
919
- if (!container || container.classList.contains("resolved")) return;
920
-
921
- container.classList.add("resolved", "resolved-cancelled");
922
- var actions = container.querySelector(".permission-actions");
923
- if (actions) {
924
- actions.innerHTML = '<span class="permission-decision-label">Cancelled</span>';
925
- }
926
-
927
- delete pendingPermissions[requestId];
928
- }
929
-
930
- // --- MCP elicitation rendering ---
931
-
932
- var pendingElicitations = {};
933
-
934
- export function renderElicitationRequest(msg) {
935
- if (pendingElicitations[msg.requestId]) return;
936
- ctx.finalizeAssistantBlock();
937
- stopThinking();
938
- closeToolGroup();
939
-
940
- var container = document.createElement("div");
941
- container.className = "permission-container elicitation-container";
942
- container.dataset.requestId = msg.requestId;
943
-
944
- // Header
945
- var header = document.createElement("div");
946
- header.className = "permission-header";
947
- header.innerHTML =
948
- '<span class="permission-icon">' + iconHtml("key") + '</span>' +
949
- '<span class="permission-title">' + escapeHtml(msg.serverName || "MCP Server") + ' requests input</span>';
950
-
951
- // Body
952
- var body = document.createElement("div");
953
- body.className = "permission-body";
954
-
955
- if (msg.message) {
956
- var messageEl = document.createElement("div");
957
- messageEl.className = "permission-reason";
958
- messageEl.textContent = msg.message;
959
- body.appendChild(messageEl);
960
- }
961
-
962
- // Form fields (form mode) or URL button (url mode)
963
- var formData = {};
964
-
965
- if (msg.mode === "url" && msg.url) {
966
- var urlInfo = document.createElement("div");
967
- urlInfo.className = "elicitation-url-info";
968
- urlInfo.style.cssText = "margin-top: 8px; font-size: 12px; color: var(--text-muted);";
969
- urlInfo.textContent = "Opens: " + msg.url;
970
- body.appendChild(urlInfo);
971
- } else if (msg.requestedSchema && msg.requestedSchema.properties) {
972
- var formEl = document.createElement("div");
973
- formEl.className = "elicitation-form";
974
- formEl.style.cssText = "margin-top: 8px; display: flex; flex-direction: column; gap: 8px;";
975
-
976
- var props = msg.requestedSchema.properties;
977
- var required = msg.requestedSchema.required || [];
978
- var propNames = Object.keys(props);
979
- for (var i = 0; i < propNames.length; i++) {
980
- var propName = propNames[i];
981
- var prop = props[propName];
982
- var isRequired = required.indexOf(propName) !== -1;
983
-
984
- var fieldWrapper = document.createElement("div");
985
- fieldWrapper.style.cssText = "display: flex; flex-direction: column; gap: 2px;";
986
-
987
- var label = document.createElement("label");
988
- label.style.cssText = "font-size: 12px; font-weight: 500; color: var(--text-secondary);";
989
- label.textContent = propName + (isRequired ? " *" : "");
990
- if (prop.description) {
991
- label.title = prop.description;
992
- }
993
-
994
- var input;
995
- if (prop.type === "boolean") {
996
- input = document.createElement("input");
997
- input.type = "checkbox";
998
- input.dataset.propName = propName;
999
- input.dataset.propType = "boolean";
1000
- } else if (prop.enum) {
1001
- input = document.createElement("select");
1002
- input.dataset.propName = propName;
1003
- input.dataset.propType = "enum";
1004
- input.style.cssText = "padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-primary); font-size: 13px;";
1005
- for (var ei = 0; ei < prop.enum.length; ei++) {
1006
- var opt = document.createElement("option");
1007
- opt.value = prop.enum[ei];
1008
- opt.textContent = prop.enum[ei];
1009
- input.appendChild(opt);
1010
- }
1011
- } else {
1012
- input = document.createElement("input");
1013
- input.type = prop.type === "number" || prop.type === "integer" ? "number" : "text";
1014
- input.dataset.propName = propName;
1015
- input.dataset.propType = prop.type || "string";
1016
- input.placeholder = prop.description || propName;
1017
- input.style.cssText = "padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-primary); font-size: 13px;";
1018
- }
1019
-
1020
- fieldWrapper.appendChild(label);
1021
- fieldWrapper.appendChild(input);
1022
- formEl.appendChild(fieldWrapper);
1023
- }
1024
- body.appendChild(formEl);
1025
- }
1026
-
1027
- // Actions
1028
- var actions = document.createElement("div");
1029
- actions.className = "permission-actions";
1030
-
1031
- var acceptBtn = document.createElement("button");
1032
- acceptBtn.className = "permission-btn permission-allow";
1033
-
1034
- if (msg.mode === "url" && msg.url) {
1035
- acceptBtn.textContent = "Open & Approve";
1036
- acceptBtn.addEventListener("click", function () {
1037
- window.open(msg.url, "_blank");
1038
- sendElicitationResponse(container, msg.requestId, "accept", {});
1039
- });
1040
- } else {
1041
- acceptBtn.textContent = "Submit";
1042
- acceptBtn.addEventListener("click", function () {
1043
- // Collect form values
1044
- var content = {};
1045
- var inputs = container.querySelectorAll("[data-prop-name]");
1046
- for (var j = 0; j < inputs.length; j++) {
1047
- var inp = inputs[j];
1048
- var name = inp.dataset.propName;
1049
- var pType = inp.dataset.propType;
1050
- if (pType === "boolean") {
1051
- content[name] = inp.checked;
1052
- } else if (pType === "number" || pType === "integer") {
1053
- content[name] = Number(inp.value);
1054
- } else {
1055
- content[name] = inp.value;
1056
- }
1057
- }
1058
- sendElicitationResponse(container, msg.requestId, "accept", content);
1059
- });
1060
- }
1061
-
1062
- var denyBtn = document.createElement("button");
1063
- denyBtn.className = "permission-btn permission-deny";
1064
- denyBtn.textContent = "Deny";
1065
- denyBtn.addEventListener("click", function () {
1066
- sendElicitationResponse(container, msg.requestId, "reject", null);
1067
- });
1068
-
1069
- actions.appendChild(acceptBtn);
1070
- actions.appendChild(denyBtn);
1071
-
1072
- container.appendChild(header);
1073
- container.appendChild(body);
1074
- container.appendChild(actions);
1075
- ctx.addToMessages(container);
1076
-
1077
- pendingElicitations[msg.requestId] = container;
1078
- refreshIcons(container);
1079
- maybeScrollToBottom();
1080
- }
1081
-
1082
- function sendElicitationResponse(container, requestId, action, content) {
1083
- if (container.classList.contains("resolved")) return;
1084
- container.classList.add("resolved");
1085
- if (ctx.stopUrgentBlink) ctx.stopUrgentBlink();
1086
-
1087
- var label = action === "reject" ? "Denied" : "Submitted";
1088
- var resolvedClass = action === "reject" ? "resolved-denied" : "resolved-allowed";
1089
- container.classList.add(resolvedClass);
1090
-
1091
- var actions = container.querySelector(".permission-actions");
1092
- if (actions) {
1093
- actions.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
1094
- }
1095
-
1096
- if (ctx.ws && ctx.connected) {
1097
- var msg = {
1098
- type: "elicitation_response",
1099
- requestId: requestId,
1100
- action: action,
1101
- };
1102
- if (action === "accept" && content) {
1103
- msg.content = content;
1104
- }
1105
- ctx.ws.send(JSON.stringify(msg));
1106
- }
1107
-
1108
- delete pendingElicitations[requestId];
1109
- }
1110
-
1111
- export function markElicitationResolved(requestId, action) {
1112
- var container = pendingElicitations[requestId];
1113
- if (!container) {
1114
- container = ctx.messagesEl.querySelector('.elicitation-container[data-request-id="' + requestId + '"]');
1115
- }
1116
- if (!container || container.classList.contains("resolved")) return;
1117
-
1118
- container.classList.add("resolved");
1119
- var isDeny = action === "reject";
1120
- container.classList.add(isDeny ? "resolved-denied" : "resolved-allowed");
1121
-
1122
- var label = isDeny ? "Denied" : "Submitted";
1123
- var actionsEl = container.querySelector(".permission-actions");
1124
- if (actionsEl) {
1125
- actionsEl.innerHTML = '<span class="permission-decision-label">' + label + '</span>';
1126
- }
1127
- delete pendingElicitations[requestId];
1128
- }
1129
-
1130
307
  // --- Plan mode rendering ---
1131
308
  export function renderPlanBanner(type) {
1132
309
  ctx.finalizeAssistantBlock();
@@ -2276,8 +1453,6 @@ export function resetToolState() {
2276
1453
  todoWidgetEl = null;
2277
1454
  todoWidgetVisible = true;
2278
1455
  if (todoObserver) { todoObserver.disconnect(); todoObserver = null; }
2279
- pendingPermissions = {};
2280
- pendingElicitations = {};
2281
1456
  currentToolGroup = null;
2282
1457
  toolGroupCounter = 0;
2283
1458
  toolGroups = {};