@clagentic/console 1.9.0 → 1.10.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 (146) 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 +8 -2
  5. package/bin/cli.js +30 -5
  6. package/deploy/clagentic-console.service +10 -6
  7. package/lib/audit.js +3 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-check.js +138 -0
  10. package/lib/cli/daemon-launch.js +17 -17
  11. package/lib/config.js +32 -20
  12. package/lib/daemon-env-settings.js +84 -0
  13. package/lib/daemon-projects.js +38 -0
  14. package/lib/daemon.js +202 -158
  15. package/lib/drain.js +74 -17
  16. package/lib/env-compat.js +61 -0
  17. package/lib/extension-commands.js +45 -0
  18. package/lib/history-visibility.js +4 -0
  19. package/lib/idle-adapter-reaper.js +71 -0
  20. package/lib/link-trap.js +78 -0
  21. package/lib/lore-attestation.js +73 -0
  22. package/lib/mcp-local.js +8 -6
  23. package/lib/mcp-tool-input.js +116 -0
  24. package/lib/mcp-tool-schema.js +179 -0
  25. package/lib/memory-limits.js +61 -5
  26. package/lib/memory-setting-validate.js +65 -0
  27. package/lib/new-work-gate.js +47 -0
  28. package/lib/os-users.js +5 -3
  29. package/lib/project-access.js +139 -0
  30. package/lib/project-connection.js +23 -22
  31. package/lib/project-external-trigger.js +103 -10
  32. package/lib/project-file-scope.js +172 -0
  33. package/lib/project-file-watch.js +86 -61
  34. package/lib/project-filesystem.js +144 -128
  35. package/lib/project-git.js +119 -0
  36. package/lib/project-http.js +44 -28
  37. package/lib/project-loop.js +12 -5
  38. package/lib/project-mcp.js +53 -72
  39. package/lib/project-message-gate.js +70 -0
  40. package/lib/project-notifications.js +31 -4
  41. package/lib/project-prompt-responses.js +216 -0
  42. package/lib/project-sessions.js +164 -302
  43. package/lib/project-user-message.js +36 -11
  44. package/lib/project.js +189 -142
  45. package/lib/projects-dir.js +90 -0
  46. package/lib/prompt-access.js +22 -0
  47. package/lib/prompt-kinds/answer-limits.js +15 -0
  48. package/lib/prompt-kinds/ask-user.js +58 -0
  49. package/lib/prompt-kinds/codecs.js +97 -0
  50. package/lib/prompt-kinds/elicitation.js +77 -0
  51. package/lib/prompt-kinds/extension.js +39 -0
  52. package/lib/prompt-kinds/index.js +68 -0
  53. package/lib/prompt-kinds/permission.js +114 -0
  54. package/lib/prompt-kinds/plan.js +79 -0
  55. package/lib/prompt-kinds/tool-call.js +38 -0
  56. package/lib/prompt-registry.js +673 -0
  57. package/lib/public/app.js +1 -1
  58. package/lib/public/css/diagnostics.css +50 -0
  59. package/lib/public/css/input.css +17 -3
  60. package/lib/public/css/menus.css +10 -0
  61. package/lib/public/css/messages.css +5 -0
  62. package/lib/public/css/rewind.css +22 -0
  63. package/lib/public/index.html +4 -12
  64. package/lib/public/modules/app-connection.js +7 -0
  65. package/lib/public/modules/app-cursors.js +7 -5
  66. package/lib/public/modules/app-messages.js +45 -45
  67. package/lib/public/modules/app-notifications.js +47 -71
  68. package/lib/public/modules/app-panels.js +61 -58
  69. package/lib/public/modules/app-projects.js +2 -1
  70. package/lib/public/modules/app-rendering.js +4 -10
  71. package/lib/public/modules/diagnostics.js +60 -16
  72. package/lib/public/modules/filebrowser.js +18 -16
  73. package/lib/public/modules/history-visibility.js +4 -0
  74. package/lib/public/modules/mention.js +3 -2
  75. package/lib/public/modules/mode-options.js +38 -0
  76. package/lib/public/modules/project-settings.js +19 -8
  77. package/lib/public/modules/prompt-banner.js +78 -0
  78. package/lib/public/modules/prompt-card.js +201 -0
  79. package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
  80. package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
  81. package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
  82. package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
  83. package/lib/public/modules/prompt-kinds/index.js +18 -0
  84. package/lib/public/modules/prompt-kinds/own-key.js +29 -0
  85. package/lib/public/modules/prompt-kinds/package.json +3 -0
  86. package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
  87. package/lib/public/modules/prompt-kinds/permission.js +209 -0
  88. package/lib/public/modules/prompt-kinds/plan.js +102 -0
  89. package/lib/public/modules/prompt-state.js +142 -0
  90. package/lib/public/modules/prompts.js +134 -0
  91. package/lib/public/modules/rewind.js +4 -1
  92. package/lib/public/modules/server-settings.js +2 -4
  93. package/lib/public/modules/sidebar-mobile.js +19 -9
  94. package/lib/public/modules/sidebar-sessions.js +21 -14
  95. package/lib/public/modules/sticky-notes.js +3 -2
  96. package/lib/public/modules/team-panel.js +5 -4
  97. package/lib/public/modules/tools.js +67 -904
  98. package/lib/public/modules/vendor-picker.js +53 -0
  99. package/lib/public/modules/vendor-registry.js +133 -0
  100. package/lib/public/sw.js +3 -1
  101. package/lib/rc-migrate.js +44 -0
  102. package/lib/runtime-env-keys.js +109 -0
  103. package/lib/runtime-env.js +236 -0
  104. package/lib/sdk-bridge.js +290 -273
  105. package/lib/sdk-message-processor.js +125 -145
  106. package/lib/server-hub-sessions.js +13 -10
  107. package/lib/server-palette.js +28 -19
  108. package/lib/server.js +141 -113
  109. package/lib/service-install.js +96 -0
  110. package/lib/session-capabilities.js +76 -0
  111. package/lib/sessions.js +45 -28
  112. package/lib/users-permissions.js +9 -6
  113. package/lib/users.js +9 -0
  114. package/lib/utils.js +4 -2
  115. package/lib/vendor-auth.js +22 -0
  116. package/lib/vendor-registry-message.js +65 -0
  117. package/lib/ws-origin.js +99 -0
  118. package/lib/ws-schema.js +33 -22
  119. package/lib/yoke/adapters/claude-capabilities.js +38 -0
  120. package/lib/yoke/adapters/claude-vendor.js +35 -0
  121. package/lib/yoke/adapters/claude-worker.js +55 -87
  122. package/lib/yoke/adapters/claude.js +156 -62
  123. package/lib/yoke/adapters/codex-capabilities.js +37 -0
  124. package/lib/yoke/adapters/codex-vendor.js +46 -0
  125. package/lib/yoke/adapters/codex.js +347 -156
  126. package/lib/yoke/adapters/effort-control.js +34 -0
  127. package/lib/yoke/adapters/permission-relay.js +58 -0
  128. package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
  129. package/lib/yoke/auth-checks.js +104 -0
  130. package/lib/yoke/capabilities.js +49 -0
  131. package/lib/yoke/codex-app-server.js +23 -5
  132. package/lib/yoke/env-ownership.js +40 -0
  133. package/lib/yoke/index.js +67 -173
  134. package/lib/yoke/install-probe.js +121 -0
  135. package/lib/yoke/instructions.js +7 -11
  136. package/lib/yoke/interface.js +199 -3
  137. package/lib/yoke/package.json +1 -1
  138. package/lib/yoke/provider-credentials.js +96 -0
  139. package/lib/yoke/registry.js +340 -0
  140. package/package.json +12 -8
  141. package/scripts/check-sdk-lock-drift.js +160 -0
  142. package/scripts/check-test-count.js +76 -1
  143. package/scripts/postinstall.js +218 -136
  144. package/scripts/prompt-harness-history.js +202 -0
  145. package/scripts/verify-installed.js +67 -0
  146. package/lib/sdk-permission-ownership.js +0 -136
@@ -0,0 +1,176 @@
1
+ // MCP elicitation card: a server asks for form input (form mode) or for
2
+ // approval to open a URL (url mode). The shell (prompts.js, prompt-card.js)
3
+ // owns its state.
4
+ //
5
+ // What the form offers and submits is the shared codec's
6
+ // (./elicitation-codec.js, which the server holds answers to): a field left
7
+ // empty is absent (never "", 0 or false), a typed field takes only values of
8
+ // its type, a required field must be filled before Submit sends, and a URL
9
+ // request is approved only when its URL is a web page. A form whose schema
10
+ // is outside the subset the codec supports is not drawn at all: the card
11
+ // says why and can only be declined.
12
+
13
+ import { escapeHtml } from '../utils.js';
14
+ import { iconHtml } from '../icons.js';
15
+ import {
16
+ requestMode, isOpenableUrl, schemaProblem, lengthLimit, schemaFields, initialControlText, choiceLabel,
17
+ contentFromControls,
18
+ } from './elicitation-codec.js';
19
+
20
+ var FIELD_STYLE = "padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-primary); font-size: 13px;";
21
+ var ERROR_CLASS = "elicitation-error";
22
+
23
+ function drawField(field) {
24
+ var wrapper = document.createElement("div");
25
+ wrapper.style.cssText = "display: flex; flex-direction: column; gap: 2px;";
26
+ var label = document.createElement("label");
27
+ label.style.cssText = "font-size: 12px; font-weight: 500; color: var(--text-secondary);";
28
+ label.textContent = field.name + (field.required ? " *" : "");
29
+ if (field.prop.description) label.title = field.prop.description;
30
+
31
+ var input;
32
+ if (field.choices) {
33
+ // A choice starts unmade unless the schema names a default: an answer
34
+ // the operator did not pick is never sent as theirs.
35
+ input = document.createElement("select");
36
+ input.style.cssText = FIELD_STYLE;
37
+ var none = document.createElement("option");
38
+ none.value = "";
39
+ none.textContent = "";
40
+ input.appendChild(none);
41
+ field.choices.forEach(function (choice) {
42
+ var opt = document.createElement("option");
43
+ opt.value = String(choice);
44
+ opt.textContent = choiceLabel(field, choice);
45
+ input.appendChild(opt);
46
+ });
47
+ } else {
48
+ var numeric = field.type === "number" || field.type === "integer";
49
+ input = document.createElement("input");
50
+ input.type = numeric ? "number" : "text";
51
+ if (numeric) input.step = field.type === "integer" ? "1" : "any";
52
+ else input.maxLength = lengthLimit(field.prop);
53
+ input.placeholder = field.prop.description || field.name;
54
+ input.style.cssText = FIELD_STYLE;
55
+ }
56
+ input.value = initialControlText(field);
57
+ input.dataset.propName = field.name;
58
+ if (field.required) input.dataset.required = "true";
59
+ wrapper.appendChild(label);
60
+ wrapper.appendChild(input);
61
+ return wrapper;
62
+ }
63
+
64
+ function controlTexts(container) {
65
+ var byName = Object.create(null);
66
+ var inputs = container.querySelectorAll("[data-prop-name]");
67
+ for (var i = 0; i < inputs.length; i++) byName[inputs[i].dataset.propName] = inputs[i].value;
68
+ return function (name) { return byName[name]; };
69
+ }
70
+
71
+ function showErrors(container, errors) {
72
+ var old = container.querySelectorAll("." + ERROR_CLASS);
73
+ for (var i = 0; i < old.length; i++) old[i].remove();
74
+ if (!errors.length) return;
75
+ var note = document.createElement("div");
76
+ note.className = ERROR_CLASS + " permission-note-error";
77
+ note.textContent = errors.join("; ");
78
+ container.appendChild(note);
79
+ }
80
+
81
+ function urlNote(url) {
82
+ if (!url) return "No address was given, so there is nothing to open.";
83
+ if (!isOpenableUrl(url)) return "Not a web address, so it cannot be opened: " + url;
84
+ return "Opens: " + url;
85
+ }
86
+
87
+ export default {
88
+ kind: "elicitation",
89
+
90
+ draw: function (fields, requestId, host) {
91
+ var container = document.createElement("div");
92
+ container.className = "permission-container elicitation-container";
93
+ container.dataset.requestId = requestId;
94
+
95
+ var header = document.createElement("div");
96
+ header.className = "permission-header";
97
+ header.innerHTML =
98
+ '<span class="permission-icon">' + iconHtml("key") + '</span>' +
99
+ '<span class="permission-title">' + escapeHtml(fields.serverName || "MCP Server") + ' requests input</span>';
100
+
101
+ var body = document.createElement("div");
102
+ body.className = "permission-body";
103
+ if (fields.message) {
104
+ var messageEl = document.createElement("div");
105
+ messageEl.className = "permission-reason";
106
+ messageEl.textContent = fields.message;
107
+ body.appendChild(messageEl);
108
+ }
109
+
110
+ var isUrl = requestMode(fields) === "url";
111
+ var schema = fields.requestedSchema || null;
112
+ var unsupported = isUrl ? null : schemaProblem(schema);
113
+ if (isUrl) {
114
+ var urlInfo = document.createElement("div");
115
+ urlInfo.className = "elicitation-url-info";
116
+ urlInfo.style.cssText = "margin-top: 8px; font-size: 12px; color: var(--text-muted);";
117
+ urlInfo.textContent = urlNote(fields.url);
118
+ body.appendChild(urlInfo);
119
+ } else if (unsupported) {
120
+ var refusal = document.createElement("div");
121
+ refusal.className = "elicitation-unsupported permission-note-error";
122
+ refusal.textContent = "This form cannot be shown: " + unsupported + ". It can only be declined.";
123
+ body.appendChild(refusal);
124
+ } else {
125
+ var formFields = schemaFields(schema);
126
+ if (formFields.length) {
127
+ var formEl = document.createElement("div");
128
+ formEl.className = "elicitation-form";
129
+ formEl.style.cssText = "margin-top: 8px; display: flex; flex-direction: column; gap: 8px;";
130
+ formFields.forEach(function (field) { formEl.appendChild(drawField(field)); });
131
+ body.appendChild(formEl);
132
+ }
133
+ }
134
+
135
+ var actions = document.createElement("div");
136
+ actions.className = "permission-actions";
137
+ var acceptBtn = document.createElement("button");
138
+ acceptBtn.className = "permission-btn permission-allow";
139
+ var openable = isUrl && isOpenableUrl(fields.url);
140
+ acceptBtn.textContent = isUrl ? "Open & Approve" : "Submit";
141
+ // A URL that is not a web page is never opened, and a form outside the
142
+ // supported schema is never drawn, so neither can be approved.
143
+ if ((isUrl && !openable) || unsupported) acceptBtn.disabled = true;
144
+ acceptBtn.addEventListener("click", function () {
145
+ if (unsupported) return;
146
+ if (isUrl) {
147
+ if (!openable) return;
148
+ window.open(fields.url, "_blank", "noopener,noreferrer");
149
+ host.respond(container, { action: "accept", content: {} });
150
+ return;
151
+ }
152
+ var form = contentFromControls(schema, controlTexts(container));
153
+ showErrors(container, form.errors);
154
+ if (form.errors.length) return;
155
+ host.respond(container, { action: "accept", content: form.content });
156
+ });
157
+ var denyBtn = document.createElement("button");
158
+ denyBtn.className = "permission-btn permission-deny";
159
+ denyBtn.textContent = "Deny";
160
+ denyBtn.addEventListener("click", function () {
161
+ host.respond(container, { action: "reject" });
162
+ });
163
+ actions.appendChild(acceptBtn);
164
+ actions.appendChild(denyBtn);
165
+
166
+ container.appendChild(header);
167
+ container.appendChild(body);
168
+ container.appendChild(actions);
169
+ return container;
170
+ },
171
+
172
+ outcome: function (state) {
173
+ if (state.action === "accept") return { text: "Submitted", tone: "allowed" };
174
+ return { text: "Denied", tone: "denied" };
175
+ },
176
+ };
@@ -0,0 +1,18 @@
1
+ // Client renderers for every operator-prompt kind. A renderer draws the
2
+ // card body and its answer controls and names its outcome labels; the
3
+ // lifecycle (pending, sending, settled, server state) is the shell's
4
+ // (prompts.js, prompt-card.js).
5
+
6
+ import permission from './permission.js';
7
+ import plan from './plan.js';
8
+ import askUser from './ask-user.js';
9
+ import elicitation from './elicitation.js';
10
+
11
+ export var PROMPT_KINDS = {
12
+ permission: permission,
13
+ plan: plan,
14
+ ask_user: askUser,
15
+ elicitation: elicitation,
16
+ };
17
+
18
+ export { askWording } from './permission.js';
@@ -0,0 +1,29 @@
1
+ // own-key.js - keyed lookups on names that arrive from outside: a
2
+ // requestId, a decision, a cancel reason, a kind. A plain object answers a
3
+ // name it only inherits (constructor, toString, __proto__, ...) as if it
4
+ // held it, so prompt cards and the server's prompt path read every such map
5
+ // through ownValue() and write one through putOwn().
6
+ //
7
+ // This file is the only copy: the server imports it as is
8
+ // (lib/prompt-kinds/codecs.js).
9
+
10
+ var hasOwn = Object.prototype.hasOwnProperty;
11
+
12
+ // Whether map holds key itself. Only a string names an entry: any other
13
+ // value would be coerced, and an object can refuse coercion by throwing.
14
+ function hasOwnKey(map, key) {
15
+ return typeof key === "string" && map !== null && map !== undefined && hasOwn.call(map, key);
16
+ }
17
+
18
+ // map[key] when map holds key itself, else undefined.
19
+ function ownValue(map, key) {
20
+ return hasOwnKey(map, key) ? map[key] : undefined;
21
+ }
22
+
23
+ // Defined, not assigned, so a key named "__proto__" is an entry rather than
24
+ // a change of map's prototype.
25
+ function putOwn(map, key, value) {
26
+ Object.defineProperty(map, key, { value: value, enumerable: true, writable: true, configurable: true });
27
+ }
28
+
29
+ export { hasOwnKey, ownValue, putOwn };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,31 @@
1
+ // permission-choices.js - which answers a tool-permission ask offers, and in
2
+ // what order. The card (permission.js) and the notification banner
3
+ // (../prompt-banner.js) both read it, so they cannot offer different answers
4
+ // to one ask.
5
+ //
6
+ // The Claude Agent SDK may attach presentation hints to an ask:
7
+ // suppressAlwaysAllowRule no persistent "allow for session" choice;
8
+ // defaultToNo the ask opens on its decline choice, so a stray
9
+ // keystroke or tap cannot approve it.
10
+ // The server refuses an Allow-for-session answer to a suppressed ask whatever
11
+ // a client sends (lib/prompt-kinds/permission.js); omitting the choice here is
12
+ // the presentation of that rule, not its enforcement.
13
+ //
14
+ // Deliberately free of imports so the banner can load it without the rest of
15
+ // the frontend module graph.
16
+
17
+ /**
18
+ * @param {object} [hints] - the ask's request fields.
19
+ * @returns {string[]} decisions in the order they are shown; the first is the
20
+ * default choice when the ask is defaultToNo.
21
+ */
22
+ export function permissionChoices(hints) {
23
+ var h = hints || {};
24
+ var approve = h.suppressAlwaysAllowRule === true ? ["allow"] : ["allow", "allow_always"];
25
+ return h.defaultToNo === true ? ["deny"].concat(approve) : approve.concat(["deny"]);
26
+ }
27
+
28
+ /** Whether an ask must open on its decline choice. */
29
+ export function opensOnNo(hints) {
30
+ return !!hints && hints.defaultToNo === true;
31
+ }
@@ -0,0 +1,209 @@
1
+ // Tool-call approval card: Allow Once / Allow for Session / Deny, drawn as a
2
+ // formal dialog (bubble layout) or a conversational "Can I ...?" (channel
3
+ // layout). The shell (prompts.js, prompt-card.js) owns its state. Which
4
+ // answers it offers, and which leads, follows the ask's SDK hints
5
+ // (permission-choices.js).
6
+
7
+ import { escapeHtml } from '../utils.js';
8
+ import { iconHtml } from '../icons.js';
9
+ import { permissionChoices, opensOnNo } from './permission-choices.js';
10
+
11
+ var FORMAL_CHOICES = {
12
+ allow: { className: "permission-btn permission-allow", label: "Allow Once" },
13
+ allow_always: { className: "permission-btn permission-allow-session", label: "Allow for Session" },
14
+ deny: { className: "permission-btn permission-deny", label: "Deny" },
15
+ };
16
+
17
+ var CONVERSATIONAL_CHOICES = {
18
+ allow: { className: "perm-reply perm-allow", label: "Sure" },
19
+ allow_always: { className: "perm-reply perm-always", label: "Allow for session" },
20
+ deny: { className: "perm-reply perm-deny", label: "No" },
21
+ };
22
+
23
+ // The buttons for an ask's answers, in the order the ask allows. An ask that
24
+ // must open on No leads with its decline button and marks it the default;
25
+ // no approve button is ever marked.
26
+ function choiceButtons(fields, table, container, host) {
27
+ var leadsWithNo = opensOnNo(fields);
28
+ return permissionChoices(fields).map(function (decision, i) {
29
+ var spec = table[decision];
30
+ var btn = button(spec.className, spec.label, function () {
31
+ host.respond(container, { decision: decision });
32
+ });
33
+ if (leadsWithNo && i === 0) btn.dataset.defaultChoice = "true";
34
+ return btn;
35
+ });
36
+ }
37
+
38
+ // The user's own ask rule that forced this prompt, when the SDK says so.
39
+ function ruleNote(fields) {
40
+ var rule = fields.matchedAskRule;
41
+ if (!rule || typeof rule !== "object") return null;
42
+ var rendered = (rule.toolName || "") + (rule.ruleContent ? "(" + rule.ruleContent + ")" : "");
43
+ var note = document.createElement("div");
44
+ note.className = "permission-rule";
45
+ note.textContent = "Asked because of your rule" + (rendered ? " " + rendered : "") + (rule.source ? " (" + rule.source + ")" : "");
46
+ return note;
47
+ }
48
+
49
+ function shortPath(p) {
50
+ if (!p) return "";
51
+ var parts = p.split("/");
52
+ return parts.length > 3 ? ".../" + parts.slice(-3).join("/") : p;
53
+ }
54
+
55
+ function inputSummary(toolName, input, host) {
56
+ if (!input || typeof input !== "object") return "";
57
+ switch (toolName) {
58
+ case "Bash": return input.command || input.description || "";
59
+ case "Edit": return shortPath(input.file_path);
60
+ case "Write": return shortPath(input.file_path);
61
+ case "Read": return shortPath(input.file_path);
62
+ case "Glob": return input.pattern || "";
63
+ case "Grep": return (input.pattern || "") + (input.path ? " in " + shortPath(input.path) : "");
64
+ default: return host.toolSummary(toolName, input);
65
+ }
66
+ }
67
+
68
+ /** "Can I <verb> <target>?" wording for a tool call. */
69
+ export function askWording(toolName, toolInput) {
70
+ var input = toolInput && typeof toolInput === "object" ? toolInput : {};
71
+ var verb = "use " + toolName;
72
+ var target = "";
73
+ switch (toolName) {
74
+ case "Write": verb = "write to"; target = shortPath(input.file_path); break;
75
+ case "Edit": verb = "edit"; target = shortPath(input.file_path); break;
76
+ case "Read": verb = "read"; target = shortPath(input.file_path); break;
77
+ case "Bash": verb = "run"; target = input.description || (input.command || "").substring(0, 80); break;
78
+ case "Grep": verb = "search"; target = input.pattern || ""; break;
79
+ case "Glob": verb = "search for files in"; target = input.pattern || ""; break;
80
+ case "WebFetch": verb = "fetch"; target = input.url || ""; break;
81
+ case "WebSearch": verb = "search the web for"; target = input.query || ""; break;
82
+ }
83
+ return { verb: verb, target: target };
84
+ }
85
+
86
+ function detailsElement(className, toolInput) {
87
+ var details = document.createElement("details");
88
+ details.className = className;
89
+ var summary = document.createElement("summary");
90
+ summary.textContent = "Details";
91
+ var pre = document.createElement("pre");
92
+ pre.textContent = JSON.stringify(toolInput, null, 2);
93
+ details.appendChild(summary);
94
+ details.appendChild(pre);
95
+ return details;
96
+ }
97
+
98
+ function button(className, label, onClick) {
99
+ var btn = document.createElement("button");
100
+ btn.className = className;
101
+ btn.textContent = label;
102
+ btn.addEventListener("click", onClick);
103
+ return btn;
104
+ }
105
+
106
+ function drawFormal(fields, requestId, host) {
107
+ var container = document.createElement("div");
108
+ container.className = "permission-container";
109
+ container.dataset.requestId = requestId;
110
+
111
+ var header = document.createElement("div");
112
+ header.className = "permission-header";
113
+ header.innerHTML =
114
+ '<span class="permission-icon">' + iconHtml("shield") + '</span>' +
115
+ '<span class="permission-title">Permission Required</span>';
116
+
117
+ var body = document.createElement("div");
118
+ body.className = "permission-body";
119
+ var summary = document.createElement("div");
120
+ summary.className = "permission-summary";
121
+ var toolNameEl = document.createElement("span");
122
+ toolNameEl.className = "permission-tool-name";
123
+ toolNameEl.textContent = fields.toolName;
124
+ summary.appendChild(toolNameEl);
125
+ var summaryText = inputSummary(fields.toolName, fields.toolInput, host);
126
+ if (summaryText) {
127
+ var descEl = document.createElement("span");
128
+ descEl.className = "permission-tool-desc";
129
+ descEl.textContent = summaryText;
130
+ summary.appendChild(descEl);
131
+ }
132
+ body.appendChild(summary);
133
+ if (fields.decisionReason) {
134
+ var reason = document.createElement("div");
135
+ reason.className = "permission-reason";
136
+ reason.textContent = fields.decisionReason;
137
+ body.appendChild(reason);
138
+ }
139
+ var rule = ruleNote(fields);
140
+ if (rule) body.appendChild(rule);
141
+ body.appendChild(detailsElement("permission-details", fields.toolInput));
142
+
143
+ var actions = document.createElement("div");
144
+ actions.className = "permission-actions";
145
+ choiceButtons(fields, FORMAL_CHOICES, container, host).forEach(function (btn) { actions.appendChild(btn); });
146
+ if (opensOnNo(fields)) container.dataset.defaultToNo = "true";
147
+
148
+ container.appendChild(header);
149
+ container.appendChild(body);
150
+ container.appendChild(actions);
151
+ return container;
152
+ }
153
+
154
+ function drawConversational(fields, requestId, host) {
155
+ var identity = host.vendorIdentity(fields.vendor);
156
+ var wording = askWording(fields.toolName, fields.toolInput);
157
+
158
+ var container = document.createElement("div");
159
+ container.className = "permission-container";
160
+ container.dataset.requestId = requestId;
161
+
162
+ var avi = document.createElement("img");
163
+ avi.className = "dm-bubble-avatar dm-bubble-avatar-agent";
164
+ avi.src = identity.avatar;
165
+ avi.alt = "";
166
+ container.appendChild(avi);
167
+
168
+ var content = document.createElement("div");
169
+ content.className = "dm-bubble-content";
170
+ var now = new Date();
171
+ var headerRow = document.createElement("div");
172
+ headerRow.className = "dm-bubble-header";
173
+ headerRow.innerHTML =
174
+ '<span class="dm-bubble-name">' + escapeHtml(identity.name) + '</span>' +
175
+ '<span class="dm-bubble-time">' + String(now.getHours()).padStart(2, "0") + ":" + String(now.getMinutes()).padStart(2, "0") + '</span>';
176
+ content.appendChild(headerRow);
177
+
178
+ var askEl = document.createElement("div");
179
+ askEl.className = "perm-ask";
180
+ askEl.textContent = "Can I " + wording.verb + (wording.target ? " " + wording.target : "") + "?";
181
+ content.appendChild(askEl);
182
+ var rule = ruleNote(fields);
183
+ if (rule) content.appendChild(rule);
184
+ content.appendChild(detailsElement("perm-details", fields.toolInput));
185
+
186
+ var actions = document.createElement("div");
187
+ actions.className = "permission-actions";
188
+ choiceButtons(fields, CONVERSATIONAL_CHOICES, container, host).forEach(function (btn) { actions.appendChild(btn); });
189
+ if (opensOnNo(fields)) container.dataset.defaultToNo = "true";
190
+ content.appendChild(actions);
191
+ container.appendChild(content);
192
+ return container;
193
+ }
194
+
195
+ export default {
196
+ kind: "permission",
197
+
198
+ draw: function (fields, requestId, host) {
199
+ return host.layout() === "channel"
200
+ ? drawConversational(fields, requestId, host)
201
+ : drawFormal(fields, requestId, host);
202
+ },
203
+
204
+ outcome: function (state) {
205
+ if (state.decision === "deny") return { text: "Denied", tone: "denied" };
206
+ if (state.decision === "allow_always") return { text: "Allowed for session", tone: "allowed" };
207
+ return { text: "Allowed", tone: "allowed" };
208
+ },
209
+ };
@@ -0,0 +1,102 @@
1
+ // Plan approval card (ExitPlanMode): approve into a fresh context, approve
2
+ // with edits auto-accepted, approve with manual edit approval, reject, or
3
+ // reject with feedback. The shell (prompts.js, prompt-card.js) owns its state.
4
+
5
+ import { iconHtml } from '../icons.js';
6
+ import { ownValue } from './own-key.js';
7
+
8
+ function button(className, html, onClick) {
9
+ var btn = document.createElement("button");
10
+ btn.className = className;
11
+ btn.innerHTML = html;
12
+ btn.addEventListener("click", onClick);
13
+ return btn;
14
+ }
15
+
16
+ var LABELS = {
17
+ allow_accept_edits: { text: "Approved (auto-accept)", tone: "allowed" },
18
+ allow_clear_context: { text: "Approved (clear + auto-accept)", tone: "allowed" },
19
+ deny_with_feedback: { text: "Feedback sent", tone: "denied" },
20
+ deny: { text: "Denied", tone: "denied" },
21
+ };
22
+
23
+ export default {
24
+ kind: "plan",
25
+
26
+ draw: function (fields, requestId, host) {
27
+ var container = document.createElement("div");
28
+ container.className = "permission-container plan-permission";
29
+ container.dataset.requestId = requestId;
30
+
31
+ var header = document.createElement("div");
32
+ header.className = "permission-header plan-permission-header";
33
+ header.innerHTML =
34
+ '<span class="permission-icon">' + iconHtml("check-circle") + '</span>' +
35
+ '<span class="permission-title">Plan Approval</span>';
36
+
37
+ // The plan itself is already rendered above the card.
38
+ var body = document.createElement("div");
39
+ body.className = "permission-body";
40
+
41
+ var actions = document.createElement("div");
42
+ actions.className = "permission-actions plan-permission-actions";
43
+ var contextPct = host.getContextPercent();
44
+ actions.appendChild(button("permission-btn plan-btn-clear",
45
+ iconHtml("refresh-cw") + ' <span>Clear context' +
46
+ (contextPct > 0 ? ' <span class="plan-ctx-pct">(' + contextPct + '% used)</span>' : '') +
47
+ ' &amp; auto-accept</span>',
48
+ function () {
49
+ var response = { decision: "allow_clear_context" };
50
+ var planContent = host.getPlanContent();
51
+ if (planContent) response.planContent = planContent;
52
+ host.respond(container, response);
53
+ }));
54
+ actions.appendChild(button("permission-btn permission-allow", "Auto-accept edits", function () {
55
+ host.respond(container, { decision: "allow_accept_edits" });
56
+ }));
57
+ actions.appendChild(button("permission-btn permission-allow-session", "Manually approve", function () {
58
+ host.respond(container, { decision: "allow" });
59
+ }));
60
+ actions.appendChild(button("permission-btn permission-deny", "Reject", function () {
61
+ host.respond(container, { decision: "deny" });
62
+ }));
63
+
64
+ var feedbackRow = document.createElement("div");
65
+ feedbackRow.className = "plan-feedback-row";
66
+ var feedbackInput = document.createElement("input");
67
+ feedbackInput.type = "text";
68
+ feedbackInput.className = "plan-feedback-input";
69
+ feedbackInput.placeholder = "Tell Claude what to change...";
70
+ var feedbackSendBtn = button("plan-feedback-send", iconHtml("arrow-up"), function () {
71
+ submitFeedback();
72
+ });
73
+ feedbackSendBtn.disabled = true;
74
+ function submitFeedback() {
75
+ var text = feedbackInput.value.trim();
76
+ if (text) host.respond(container, { decision: "deny_with_feedback", feedback: text });
77
+ }
78
+ feedbackInput.addEventListener("input", function () {
79
+ feedbackSendBtn.disabled = !feedbackInput.value.trim();
80
+ });
81
+ feedbackInput.addEventListener("keydown", function (e) {
82
+ if (e.key === "Enter" && !e.shiftKey && feedbackInput.value.trim()) {
83
+ e.preventDefault();
84
+ submitFeedback();
85
+ }
86
+ });
87
+ feedbackRow.appendChild(feedbackInput);
88
+ feedbackRow.appendChild(feedbackSendBtn);
89
+
90
+ container.appendChild(header);
91
+ container.appendChild(body);
92
+ container.appendChild(actions);
93
+ container.appendChild(feedbackRow);
94
+ return container;
95
+ },
96
+
97
+ focusSelector: ".plan-feedback-input",
98
+
99
+ outcome: function (state) {
100
+ return ownValue(LABELS, state.decision) || { text: "Allowed", tone: "allowed" };
101
+ },
102
+ };