@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.
- package/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +9 -3
- package/bin/cli.js +40 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/audit.js +3 -2
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +25 -22
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +57 -0
- package/lib/daemon.js +288 -205
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/memory-shed.js +13 -32
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +37 -22
- package/lib/project-external-trigger.js +166 -105
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +17 -9
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +217 -0
- package/lib/project-sessions.js +192 -355
- package/lib/project-user-message.js +27 -15
- package/lib/project.js +212 -147
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +680 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +80 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +52 -47
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -59
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +170 -20
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +81 -906
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +142 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +348 -284
- package/lib/sdk-message-processor.js +117 -146
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +156 -115
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +61 -30
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +66 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +36 -23
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +34 -0
- package/lib/yoke/adapters/claude-worker.js +57 -87
- package/lib/yoke/adapters/claude.js +182 -88
- package/lib/yoke/adapters/codex-capabilities.js +40 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +462 -211
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +91 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +30 -56
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +84 -174
- package/lib/yoke/install-probe.js +136 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +206 -4
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +377 -0
- package/package.json +12 -9
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed-build.js +59 -17
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -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
|
+
' & 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
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// prompt-state.js - client copy of the server's operator-prompt state.
|
|
2
|
+
//
|
|
3
|
+
// The server owns every prompt's lifecycle (lib/prompt-registry.js); this
|
|
4
|
+
// store only mirrors what the server has said about each requestId, from
|
|
5
|
+
// whichever message said it first: a live event, a replayed request stamped
|
|
6
|
+
// with promptState, or the pending snapshot sent on connect. Terminal states
|
|
7
|
+
// are final on the server, so they are final here too - a later "pending"
|
|
8
|
+
// can never reopen a settled prompt, which is what makes card rendering
|
|
9
|
+
// independent of message order (paged history delivers outcomes before the
|
|
10
|
+
// requests they close).
|
|
11
|
+
//
|
|
12
|
+
// Deliberately free of imports so it can be exercised without the rest of the
|
|
13
|
+
// frontend module graph.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{state: "pending"|"resolved"|"cancelled", decision?: ?string,
|
|
17
|
+
* answers?: ?object, skipped?: boolean, action?: ?string,
|
|
18
|
+
* reason?: ?string}} PromptState
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var OUTCOME_FIELDS = ["decision", "answers", "skipped", "action"];
|
|
22
|
+
|
|
23
|
+
export function isTerminal(st) {
|
|
24
|
+
return !!st && (st.state === "resolved" || st.state === "cancelled");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeState(next) {
|
|
28
|
+
var out = { state: next.state, reason: next.reason || null };
|
|
29
|
+
OUTCOME_FIELDS.forEach(function (k) { out[k] = next[k] === undefined ? null : next[k]; });
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createPromptStates() {
|
|
34
|
+
var states = Object.create(null);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
/**
|
|
38
|
+
* Merge what the server said about requestId; returns the effective state.
|
|
39
|
+
* @param {string} requestId
|
|
40
|
+
* @param {PromptState} next
|
|
41
|
+
* @returns {?PromptState}
|
|
42
|
+
*/
|
|
43
|
+
apply: function (requestId, next) {
|
|
44
|
+
var cur = states[requestId];
|
|
45
|
+
if (!next || isTerminal(cur)) return cur || null;
|
|
46
|
+
if (isTerminal(next) || !cur) states[requestId] = normalizeState(next);
|
|
47
|
+
return states[requestId];
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
/** @returns {?PromptState} */
|
|
51
|
+
get: function (requestId) {
|
|
52
|
+
return states[requestId] || null;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/** Whether any prompt is still awaiting the operator. */
|
|
56
|
+
hasPending: function () {
|
|
57
|
+
return Object.keys(states).some(function (id) { return !isTerminal(states[id]); });
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
clear: function () {
|
|
61
|
+
states = Object.create(null);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function pick(msg, keys) {
|
|
67
|
+
var out = {};
|
|
68
|
+
keys.forEach(function (k) { if (msg[k] !== undefined) out[k] = msg[k]; });
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function toolApprovalKind(toolName) {
|
|
73
|
+
return toolName === "ExitPlanMode" ? "plan" : "permission";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* One prompt event in the single client shape, or null for a message that
|
|
78
|
+
* is not about a prompt. Accepts the prompt_* messages and the per-kind
|
|
79
|
+
* messages recorded in history before prompts had one shape (and the
|
|
80
|
+
* AskUserQuestion tool call, which draws that prompt's card).
|
|
81
|
+
*
|
|
82
|
+
* @returns {?{phase: "request"|"pending"|"resolved"|"cancel", requestId: string,
|
|
83
|
+
* kind: ?string, fields: object, serverState: ?PromptState}}
|
|
84
|
+
*/
|
|
85
|
+
export function normalizePromptMessage(msg) {
|
|
86
|
+
if (!msg || typeof msg.type !== "string") return null;
|
|
87
|
+
switch (msg.type) {
|
|
88
|
+
case "prompt_request":
|
|
89
|
+
case "prompt_pending":
|
|
90
|
+
return {
|
|
91
|
+
phase: msg.type === "prompt_pending" ? "pending" : "request",
|
|
92
|
+
requestId: msg.requestId,
|
|
93
|
+
kind: msg.kind,
|
|
94
|
+
fields: msg,
|
|
95
|
+
serverState: msg.promptState || null,
|
|
96
|
+
};
|
|
97
|
+
case "permission_request":
|
|
98
|
+
case "permission_request_pending":
|
|
99
|
+
return {
|
|
100
|
+
phase: msg.type === "permission_request_pending" ? "pending" : "request",
|
|
101
|
+
requestId: msg.requestId,
|
|
102
|
+
kind: toolApprovalKind(msg.toolName),
|
|
103
|
+
fields: msg,
|
|
104
|
+
serverState: msg.promptState || msg.permissionState || null,
|
|
105
|
+
};
|
|
106
|
+
case "elicitation_request":
|
|
107
|
+
return { phase: "request", requestId: msg.requestId, kind: "elicitation", fields: msg, serverState: msg.promptState || null };
|
|
108
|
+
case "tool_executing":
|
|
109
|
+
if (msg.name !== "AskUserQuestion" || !msg.input || !msg.input.questions) return null;
|
|
110
|
+
return {
|
|
111
|
+
phase: "request",
|
|
112
|
+
requestId: msg.id,
|
|
113
|
+
kind: "ask_user",
|
|
114
|
+
fields: { input: msg.input, toolUseId: msg.id },
|
|
115
|
+
serverState: msg.promptState || null,
|
|
116
|
+
};
|
|
117
|
+
case "prompt_resolved":
|
|
118
|
+
case "permission_resolved":
|
|
119
|
+
case "elicitation_resolved":
|
|
120
|
+
return {
|
|
121
|
+
phase: "resolved",
|
|
122
|
+
requestId: msg.requestId,
|
|
123
|
+
kind: msg.kind || null,
|
|
124
|
+
fields: pick(msg, OUTCOME_FIELDS),
|
|
125
|
+
serverState: null,
|
|
126
|
+
};
|
|
127
|
+
case "ask_user_answered":
|
|
128
|
+
if (msg.answers && Object.keys(msg.answers).length) {
|
|
129
|
+
return { phase: "resolved", requestId: msg.toolId, kind: "ask_user", fields: { answers: msg.answers }, serverState: null };
|
|
130
|
+
}
|
|
131
|
+
// A recorded skip is an answer, not an ending nobody chose.
|
|
132
|
+
if (msg.skipped === true) {
|
|
133
|
+
return { phase: "resolved", requestId: msg.toolId, kind: "ask_user", fields: { skipped: true }, serverState: null };
|
|
134
|
+
}
|
|
135
|
+
return { phase: "cancel", requestId: msg.toolId, kind: "ask_user", fields: { reason: null }, serverState: null };
|
|
136
|
+
case "prompt_cancel":
|
|
137
|
+
case "permission_cancel":
|
|
138
|
+
return { phase: "cancel", requestId: msg.requestId, kind: msg.kind || null, fields: { reason: msg.reason || null }, serverState: null };
|
|
139
|
+
default:
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// prompts.js - the client's single owner of operator-prompt cards.
|
|
2
|
+
//
|
|
3
|
+
// Every prompt message, whatever its kind and whether it arrives live, in a
|
|
4
|
+
// replayed history page or in the pending snapshot sent on connect, goes
|
|
5
|
+
// through apply(). A card is a pure function of the server's state for its
|
|
6
|
+
// requestId (prompt-state.js), never of the order messages arrived in; the
|
|
7
|
+
// kind renderer (prompt-kinds/) only draws the body and answer controls.
|
|
8
|
+
//
|
|
9
|
+
// Deliberately free of DOM globals beyond document.createElement (via the
|
|
10
|
+
// renderers), so a host can drive it with a hand-built DOM.
|
|
11
|
+
|
|
12
|
+
import { createPromptStates, normalizePromptMessage, isTerminal } from './prompt-state.js';
|
|
13
|
+
import {
|
|
14
|
+
submitPromptResponse, restorePromptCard, settlePromptCard, isUnconfirmed,
|
|
15
|
+
showOutcome, cancelledLabel,
|
|
16
|
+
} from './prompt-card.js';
|
|
17
|
+
import { PROMPT_KINDS } from './prompt-kinds/index.js';
|
|
18
|
+
import { ownValue } from './prompt-kinds/own-key.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {object} host
|
|
22
|
+
* @param {function(Element, ?string)} host.place - insert a new card into
|
|
23
|
+
* the transcript, focusing the element matching the selector if given.
|
|
24
|
+
* @param {function(object): boolean} host.send - send a WS message; false
|
|
25
|
+
* when the socket is unusable.
|
|
26
|
+
* @param {function(): string} host.layout - "channel" or "bubble".
|
|
27
|
+
* @param {function(string, object): string} host.toolSummary
|
|
28
|
+
* @param {function(?string): {name: string, avatar: string}} host.vendorIdentity
|
|
29
|
+
* @param {function(): number} host.getContextPercent
|
|
30
|
+
* @param {function(): ?string} host.getPlanContent
|
|
31
|
+
* @param {function(boolean)} host.setMainInputDisabled
|
|
32
|
+
* @param {function(Element): boolean} host.contains - whether an element is
|
|
33
|
+
* still in the transcript.
|
|
34
|
+
* @param {function(string): ?Element} host.findInTranscript - the card for a
|
|
35
|
+
* requestId in the transcript, if one is there.
|
|
36
|
+
*/
|
|
37
|
+
export function createPromptController(host) {
|
|
38
|
+
var states = createPromptStates();
|
|
39
|
+
// requestId -> { container, kind, fields }
|
|
40
|
+
var cards = Object.create(null);
|
|
41
|
+
|
|
42
|
+
// The card currently in the transcript for requestId, if any. A transcript
|
|
43
|
+
// rebuilt without clear() leaves a detached element behind; it is looked
|
|
44
|
+
// up again rather than updated out of sight.
|
|
45
|
+
function cardFor(requestId) {
|
|
46
|
+
var rec = cards[requestId];
|
|
47
|
+
if (!rec) return null;
|
|
48
|
+
if (rec.container && host.contains(rec.container)) return rec;
|
|
49
|
+
rec.container = host.findInTranscript(requestId);
|
|
50
|
+
return rec.container ? rec : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function respond(requestId, kind, container, fields) {
|
|
54
|
+
var payload = Object.assign({ type: "prompt_response", requestId: requestId, kind: kind }, fields);
|
|
55
|
+
submitPromptResponse(container, function () { return host.send(payload); });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function draw(n) {
|
|
59
|
+
var renderer = ownValue(PROMPT_KINDS, n.kind);
|
|
60
|
+
if (!renderer) return null;
|
|
61
|
+
var rendererHost = Object.assign({}, host, {
|
|
62
|
+
respond: function (container, fields) { respond(n.requestId, n.kind, container, fields); },
|
|
63
|
+
});
|
|
64
|
+
var container = renderer.draw(n.fields, n.requestId, rendererHost);
|
|
65
|
+
container.dataset.promptKind = n.kind;
|
|
66
|
+
cards[n.requestId] = { container: container, kind: n.kind, fields: n.fields, host: rendererHost };
|
|
67
|
+
host.place(container, renderer.focusSelector || null);
|
|
68
|
+
return cards[n.requestId];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function settle(rec, st) {
|
|
72
|
+
var renderer = ownValue(PROMPT_KINDS, rec.kind);
|
|
73
|
+
if (rec.container.classList.contains("resolved")) return;
|
|
74
|
+
settlePromptCard(rec.container);
|
|
75
|
+
var outcome = st.state === "cancelled"
|
|
76
|
+
? { text: cancelledLabel(st.reason), tone: "cancelled" }
|
|
77
|
+
: renderer.outcome(st);
|
|
78
|
+
showOutcome(rec.container, outcome);
|
|
79
|
+
if (renderer.settle) renderer.settle(rec.container, st, rec.fields, outcome, rec.host);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Bring a card in line with its requestId's state. serverPending is the
|
|
83
|
+
// server's assertion that the prompt is still unanswered: a card left
|
|
84
|
+
// mid-send by a dropped socket becomes answerable again.
|
|
85
|
+
function sync(requestId, serverPending) {
|
|
86
|
+
var st = states.get(requestId);
|
|
87
|
+
var rec = cardFor(requestId);
|
|
88
|
+
if (!st || !rec) return;
|
|
89
|
+
if (isTerminal(st)) settle(rec, st);
|
|
90
|
+
else if (serverPending && isUnconfirmed(rec.container)) restorePromptCard(rec.container);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
/**
|
|
95
|
+
* Apply one prompt message (any kind, current or legacy shape). Returns
|
|
96
|
+
* the prompt's effective state, or null for an unrelated message.
|
|
97
|
+
*/
|
|
98
|
+
apply: function (msg) {
|
|
99
|
+
var n = normalizePromptMessage(msg);
|
|
100
|
+
if (!n || !n.requestId) return null;
|
|
101
|
+
if (n.phase === "request" || n.phase === "pending") {
|
|
102
|
+
states.apply(n.requestId, n.serverState || { state: "pending" });
|
|
103
|
+
if (!cardFor(n.requestId)) draw(n);
|
|
104
|
+
sync(n.requestId, n.phase === "pending");
|
|
105
|
+
} else if (n.phase === "resolved") {
|
|
106
|
+
states.apply(n.requestId, Object.assign({ state: "resolved" }, n.fields));
|
|
107
|
+
sync(n.requestId);
|
|
108
|
+
} else {
|
|
109
|
+
states.apply(n.requestId, { state: "cancelled", reason: n.fields.reason });
|
|
110
|
+
sync(n.requestId);
|
|
111
|
+
}
|
|
112
|
+
return states.get(n.requestId);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/** Return every card awaiting a server confirmation to its answerable state. */
|
|
116
|
+
restoreUnconfirmed: function (message) {
|
|
117
|
+
Object.keys(cards).forEach(function (id) {
|
|
118
|
+
var rec = cards[id];
|
|
119
|
+
if (rec.container && isUnconfirmed(rec.container)) restorePromptCard(rec.container, message);
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/** Forget everything (a different session's transcript is shown). */
|
|
124
|
+
clear: function () {
|
|
125
|
+
states.clear();
|
|
126
|
+
cards = Object.create(null);
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
get: function (requestId) { return states.get(requestId); },
|
|
130
|
+
|
|
131
|
+
/** Whether any prompt, of any kind, is still awaiting the operator. */
|
|
132
|
+
hasPending: function () { return states.hasPending(); },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { escapeHtml } from './utils.js';
|
|
2
2
|
import { iconHtml, refreshIcons } from './icons.js';
|
|
3
|
+
import { capabilityGate } from './vendor-registry.js';
|
|
3
4
|
|
|
4
5
|
var ctx;
|
|
5
6
|
var rewindMode = false;
|
|
@@ -337,7 +338,9 @@ export function addRewindButton(msgEl) {
|
|
|
337
338
|
var btn = document.createElement("button");
|
|
338
339
|
btn.className = "msg-user-rewind-btn";
|
|
339
340
|
btn.type = "button";
|
|
340
|
-
|
|
341
|
+
var gate = capabilityGate("rewind");
|
|
342
|
+
btn.title = gate.enabled ? "Rewind to here" : "Rewind to here (unavailable): " + gate.reason;
|
|
343
|
+
btn.disabled = !gate.enabled;
|
|
341
344
|
btn.innerHTML = iconHtml("rotate-ccw");
|
|
342
345
|
msgEl.appendChild(btn);
|
|
343
346
|
refreshIcons();
|
|
@@ -1351,11 +1351,9 @@ function autoSaveSharedEnv() {
|
|
|
1351
1351
|
var ws = ctx.ws;
|
|
1352
1352
|
if (ws && ws.readyState === 1) {
|
|
1353
1353
|
ws.send(JSON.stringify({ type: "set_shared_env", envrc: envrc }));
|
|
1354
|
+
// "Saved" or the reason it was refused is shown when the server answers.
|
|
1354
1355
|
var saveStatus = document.getElementById("ss-env-save-status");
|
|
1355
|
-
if (saveStatus)
|
|
1356
|
-
saveStatus.textContent = "Saved";
|
|
1357
|
-
setTimeout(function () { saveStatus.textContent = ""; }, 2000);
|
|
1358
|
-
}
|
|
1356
|
+
if (saveStatus) saveStatus.textContent = "Saving...";
|
|
1359
1357
|
}
|
|
1360
1358
|
}, 800);
|
|
1361
1359
|
}
|