@clagentic/console 1.9.0-beta.3 → 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.
- package/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +8 -2
- package/bin/cli.js +30 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/audit.js +3 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/cli/daemon-launch.js +17 -17
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +38 -0
- package/lib/daemon.js +202 -158
- 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/lore-attestation.js +73 -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/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 +23 -22
- package/lib/project-external-trigger.js +103 -10
- 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 +12 -5
- 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 +216 -0
- package/lib/project-sessions.js +164 -302
- package/lib/project-user-message.js +36 -11
- package/lib/project.js +189 -142
- 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 +673 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +50 -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/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +45 -45
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -58
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/diagnostics.js +60 -16
- 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 +67 -904
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +133 -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 +290 -273
- package/lib/sdk-message-processor.js +125 -145
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +141 -113
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/sessions.js +45 -28
- 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 +65 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +33 -22
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +35 -0
- package/lib/yoke/adapters/claude-worker.js +55 -87
- package/lib/yoke/adapters/claude.js +156 -62
- package/lib/yoke/adapters/codex-capabilities.js +37 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +347 -156
- 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 +104 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +23 -5
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +67 -173
- package/lib/yoke/install-probe.js +121 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +199 -3
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +340 -0
- package/package.json +12 -8
- 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.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -15,7 +15,7 @@ import { registerHandlers } from './app-messages.js';
|
|
|
15
15
|
|
|
16
16
|
var ctx;
|
|
17
17
|
var showDropHint = function () {};
|
|
18
|
-
var treeData =
|
|
18
|
+
var treeData = Object.create(null); // path -> { loaded, children }
|
|
19
19
|
var currentContent = null; // last read file content for copy
|
|
20
20
|
var currentFilePath = null; // path of the currently viewed file
|
|
21
21
|
var isRendered = false; // markdown render toggle state
|
|
@@ -26,9 +26,9 @@ var currentHistoryEntries = [];
|
|
|
26
26
|
var selectedEntries = []; // up to 2 selected for compare
|
|
27
27
|
var compareMode = false;
|
|
28
28
|
var inlineDiffActive = false;
|
|
29
|
-
var gitDiffCache =
|
|
29
|
+
var gitDiffCache = Object.create(null); // hash -> diff text
|
|
30
30
|
var pendingGitDiff = null; // callback for pending git diff
|
|
31
|
-
var fileAtCache =
|
|
31
|
+
var fileAtCache = Object.create(null); // hash -> file content
|
|
32
32
|
var pendingFileAt = null; // { hash, cb } for the in-flight fs_file_at request, or null
|
|
33
33
|
|
|
34
34
|
export function initFileBrowser(_ctx) {
|
|
@@ -419,7 +419,7 @@ export function resetFileBrowser() {
|
|
|
419
419
|
// Close viewer
|
|
420
420
|
closeFileViewer();
|
|
421
421
|
// Clear all cached state
|
|
422
|
-
treeData =
|
|
422
|
+
treeData = Object.create(null);
|
|
423
423
|
currentContent = null;
|
|
424
424
|
currentFilePath = null;
|
|
425
425
|
isRendered = false;
|
|
@@ -430,9 +430,9 @@ export function resetFileBrowser() {
|
|
|
430
430
|
selectedEntries = [];
|
|
431
431
|
compareMode = false;
|
|
432
432
|
inlineDiffActive = false;
|
|
433
|
-
gitDiffCache =
|
|
433
|
+
gitDiffCache = Object.create(null);
|
|
434
434
|
pendingGitDiff = null;
|
|
435
|
-
fileAtCache =
|
|
435
|
+
fileAtCache = Object.create(null);
|
|
436
436
|
pendingFileAt = null;
|
|
437
437
|
pendingReadPath = null;
|
|
438
438
|
pendingOpenMode = null;
|
|
@@ -563,13 +563,15 @@ export function handleFsSearch(msg) {
|
|
|
563
563
|
}
|
|
564
564
|
|
|
565
565
|
// Build a tree structure from flat search results
|
|
566
|
-
|
|
566
|
+
// Keyed by file and directory names, so a file called "constructor" or
|
|
567
|
+
// "__proto__" must not find an inherited entry.
|
|
568
|
+
var tree = Object.create(null);
|
|
567
569
|
for (var i = 0; i < entries.length; i++) {
|
|
568
570
|
var entry = entries[i];
|
|
569
571
|
var parts = entry.path.split("/");
|
|
570
572
|
var node = tree;
|
|
571
573
|
for (var j = 0; j < parts.length; j++) {
|
|
572
|
-
if (!node[parts[j]]) node[parts[j]] =
|
|
574
|
+
if (!node[parts[j]]) node[parts[j]] = Object.create(null);
|
|
573
575
|
if (j === parts.length - 1) {
|
|
574
576
|
node[parts[j]]._entry = entry;
|
|
575
577
|
} else {
|
|
@@ -713,7 +715,7 @@ export function handleFsList(msg) {
|
|
|
713
715
|
// Root level
|
|
714
716
|
if (dirPath === ".") {
|
|
715
717
|
// Preserve expanded state across re-render
|
|
716
|
-
var expandedSet =
|
|
718
|
+
var expandedSet = Object.create(null);
|
|
717
719
|
var expandedEls = ctx.fileTreeEl.querySelectorAll(".file-tree-item.expanded");
|
|
718
720
|
for (var ei = 0; ei < expandedEls.length; ei++) {
|
|
719
721
|
var sib = expandedEls[ei].nextElementSibling;
|
|
@@ -747,7 +749,7 @@ export function handleDirChanged(msg) {
|
|
|
747
749
|
}
|
|
748
750
|
|
|
749
751
|
// Collect expanded directories before re-render
|
|
750
|
-
var expandedSet =
|
|
752
|
+
var expandedSet = Object.create(null);
|
|
751
753
|
var expandedEls = ctx.fileTreeEl.querySelectorAll(".file-tree-item.expanded");
|
|
752
754
|
for (var i = 0; i < expandedEls.length; i++) {
|
|
753
755
|
var sib = expandedEls[i].nextElementSibling;
|
|
@@ -987,8 +989,8 @@ function showFileContent(msg) {
|
|
|
987
989
|
compareMode = false;
|
|
988
990
|
selectedEntries = [];
|
|
989
991
|
currentHistoryEntries = [];
|
|
990
|
-
gitDiffCache =
|
|
991
|
-
fileAtCache =
|
|
992
|
+
gitDiffCache = Object.create(null);
|
|
993
|
+
fileAtCache = Object.create(null);
|
|
992
994
|
var historyBtn2 = document.getElementById("file-viewer-history");
|
|
993
995
|
historyBtn2.classList.add("hidden");
|
|
994
996
|
historyBtn2.classList.remove("active");
|
|
@@ -1004,8 +1006,8 @@ function showFileContent(msg) {
|
|
|
1004
1006
|
compareMode = false;
|
|
1005
1007
|
selectedEntries = [];
|
|
1006
1008
|
currentHistoryEntries = [];
|
|
1007
|
-
gitDiffCache =
|
|
1008
|
-
fileAtCache =
|
|
1009
|
+
gitDiffCache = Object.create(null);
|
|
1010
|
+
fileAtCache = Object.create(null);
|
|
1009
1011
|
var historyBtn = document.getElementById("file-viewer-history");
|
|
1010
1012
|
historyBtn.classList.add("hidden");
|
|
1011
1013
|
historyBtn.classList.remove("active");
|
|
@@ -1728,7 +1730,7 @@ function editCodeSummary(oldStr, newStr) {
|
|
|
1728
1730
|
// Find the first meaningful added or changed line to use as a subtitle
|
|
1729
1731
|
var oldLines = oldStr ? oldStr.split("\n") : [];
|
|
1730
1732
|
var newLines = newStr ? newStr.split("\n") : [];
|
|
1731
|
-
var oldSet =
|
|
1733
|
+
var oldSet = Object.create(null);
|
|
1732
1734
|
for (var i = 0; i < oldLines.length; i++) {
|
|
1733
1735
|
var trimmed = oldLines[i].trim();
|
|
1734
1736
|
if (trimmed) oldSet[trimmed] = true;
|
|
@@ -1742,7 +1744,7 @@ function editCodeSummary(oldStr, newStr) {
|
|
|
1742
1744
|
}
|
|
1743
1745
|
}
|
|
1744
1746
|
// Fallback: find first removed line
|
|
1745
|
-
var newSet =
|
|
1747
|
+
var newSet = Object.create(null);
|
|
1746
1748
|
for (var k = 0; k < newLines.length; k++) {
|
|
1747
1749
|
var t = newLines[k].trim();
|
|
1748
1750
|
if (t) newSet[t] = true;
|
|
@@ -43,6 +43,10 @@ export var INVISIBLE_TYPES = {
|
|
|
43
43
|
thinking_delta: 1,
|
|
44
44
|
thinking_stop: 1,
|
|
45
45
|
ask_user_answered: 1,
|
|
46
|
+
prompt_request: 1,
|
|
47
|
+
prompt_pending: 1,
|
|
48
|
+
prompt_resolved: 1,
|
|
49
|
+
prompt_cancel: 1,
|
|
46
50
|
permission_request: 1,
|
|
47
51
|
permission_request_pending: 1,
|
|
48
52
|
permission_cancel: 1,
|
|
@@ -3,6 +3,7 @@ import { renderMarkdown, highlightCodeBlocks } from './markdown.js';
|
|
|
3
3
|
import { escapeHtml, copyToClipboard } from './utils.js';
|
|
4
4
|
import { iconHtml, refreshIcons } from './icons.js';
|
|
5
5
|
import { store } from './store.js';
|
|
6
|
+
import { gatedButtonAttrs } from './vendor-registry.js';
|
|
6
7
|
|
|
7
8
|
var ctx;
|
|
8
9
|
|
|
@@ -1000,8 +1001,8 @@ export function renderMentionUser(entry) {
|
|
|
1000
1001
|
actions.innerHTML =
|
|
1001
1002
|
'<span class="msg-action-time">' + ts2 + '</span>' +
|
|
1002
1003
|
'<button class="msg-action-btn msg-action-copy" type="button" title="Copy">' + iconHtml("copy") + '</button>' +
|
|
1003
|
-
'<button class="msg-action-btn msg-action-fork" type="button"
|
|
1004
|
-
|
|
1004
|
+
'<button class="msg-action-btn msg-action-fork" type="button" ' + gatedButtonAttrs("fork", "Fork") + '>' + iconHtml("git-branch") + '</button>' +
|
|
1005
|
+
'<button class="msg-action-btn msg-action-rewind msg-user-rewind-btn" type="button" ' + gatedButtonAttrs("rewind", "Rewind") + '>' + iconHtml("rotate-ccw") + '</button>' +
|
|
1005
1006
|
'<button class="msg-action-btn msg-action-hidden msg-action-edit" type="button" title="Edit">' + iconHtml("pencil") + '</button>';
|
|
1006
1007
|
div.appendChild(actions);
|
|
1007
1008
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// mode-options.js - the permission modes the config chip offers, and their
|
|
2
|
+
// labels. Import-free so it can be exercised without the frontend module
|
|
3
|
+
// graph.
|
|
4
|
+
//
|
|
5
|
+
// Default, Plan and Auto-accept edits are offered for every session. Don't
|
|
6
|
+
// ask and Auto exist only in Claude Code: they are offered for a session whose
|
|
7
|
+
// vendor declares them in capabilities.permissionModes, so a vendor that does
|
|
8
|
+
// not (Codex, or one whose capabilities are not known yet) never shows them.
|
|
9
|
+
// Full auto is offered when the daemon allows it. Labels follow the Claude
|
|
10
|
+
// Code CLI's wording.
|
|
11
|
+
|
|
12
|
+
var BASE_MODES = [
|
|
13
|
+
{ value: "default", label: "Default" },
|
|
14
|
+
{ value: "plan", label: "Plan" },
|
|
15
|
+
{ value: "acceptEdits", label: "Auto-accept edits" },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
var CAPABILITY_MODES = [
|
|
19
|
+
{ value: "dontAsk", label: "Don’t ask" },
|
|
20
|
+
{ value: "auto", label: "Auto" },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
var FULL_AUTO = { value: "bypassPermissions", label: "Full auto" };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {?object} capabilities - the session vendor's capabilities.
|
|
27
|
+
* @param {boolean} fullAutoEnabled
|
|
28
|
+
* @returns {{value: string, label: string}[]}
|
|
29
|
+
*/
|
|
30
|
+
export function modeOptions(capabilities, fullAutoEnabled) {
|
|
31
|
+
var declared = capabilities && Array.isArray(capabilities.permissionModes) ? capabilities.permissionModes : [];
|
|
32
|
+
var options = BASE_MODES.slice();
|
|
33
|
+
CAPABILITY_MODES.forEach(function (m) {
|
|
34
|
+
if (declared.indexOf(m.value) !== -1) options.push(m);
|
|
35
|
+
});
|
|
36
|
+
if (fullAutoEnabled) options.push(FULL_AUTO);
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
@@ -687,6 +687,21 @@ export function handleProjectEnv(msg) {
|
|
|
687
687
|
var notice = document.getElementById("ps-env-override-notice");
|
|
688
688
|
if (notice) notice.classList.toggle("hidden", !msg.hasEnvrc);
|
|
689
689
|
|
|
690
|
+
// Say whom these variables reach: in multi-user mode only the project owner's
|
|
691
|
+
// sessions get them, so no one else's runtime can be changed from here.
|
|
692
|
+
var scopeHint = document.getElementById("ps-env-scope-hint");
|
|
693
|
+
if (scopeHint) {
|
|
694
|
+
if (msg.canEdit === false) {
|
|
695
|
+
scopeHint.textContent = "Only the project owner or an administrator can view and change this project's variables. They apply only to the project owner's sessions; other users' sessions get the shared variables only. Applies to sessions started after saving.";
|
|
696
|
+
} else if (msg.appliesTo === "owner") {
|
|
697
|
+
scopeHint.textContent = "These variables apply only to sessions owned by the project owner. Other users' sessions in this project get the shared variables only. Applies to sessions started after saving.";
|
|
698
|
+
} else {
|
|
699
|
+
scopeHint.textContent = "These variables apply to every session in this project. Applies to sessions started after saving.";
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
var addBtn = document.getElementById("ps-env-add-btn");
|
|
703
|
+
if (addBtn) addBtn.disabled = msg.canEdit === false;
|
|
704
|
+
|
|
690
705
|
// Parse envrc string into key-value pairs
|
|
691
706
|
var list = document.getElementById("ps-env-list");
|
|
692
707
|
if (!list) return;
|
|
@@ -832,11 +847,9 @@ function autoSaveEnv() {
|
|
|
832
847
|
var envrc = buildEnvString();
|
|
833
848
|
if (ctx.ws && ctx.connected) {
|
|
834
849
|
ctx.ws.send(JSON.stringify({ type: "set_project_env", slug: currentSlug, envrc: envrc }));
|
|
850
|
+
// "Saved" or the reason it was refused is shown when the server answers.
|
|
835
851
|
var saveStatus = document.getElementById("ps-env-save-status");
|
|
836
|
-
if (saveStatus)
|
|
837
|
-
saveStatus.textContent = "Saved";
|
|
838
|
-
setTimeout(function () { saveStatus.textContent = ""; }, 2000);
|
|
839
|
-
}
|
|
852
|
+
if (saveStatus) saveStatus.textContent = "Saving...";
|
|
840
853
|
}
|
|
841
854
|
}, 800);
|
|
842
855
|
}
|
|
@@ -986,11 +999,9 @@ function autoSaveSharedEnv() {
|
|
|
986
999
|
var envrc = buildSharedEnvString();
|
|
987
1000
|
if (ctx.ws && ctx.connected) {
|
|
988
1001
|
ctx.ws.send(JSON.stringify({ type: "set_shared_env", envrc: envrc }));
|
|
1002
|
+
// "Saved" or the reason it was refused is shown when the server answers.
|
|
989
1003
|
var saveStatus = document.getElementById("ps-shared-env-save-status");
|
|
990
|
-
if (saveStatus)
|
|
991
|
-
saveStatus.textContent = "Saved";
|
|
992
|
-
setTimeout(function () { saveStatus.textContent = ""; }, 2000);
|
|
993
|
-
}
|
|
1004
|
+
if (saveStatus) saveStatus.textContent = "Saving...";
|
|
994
1005
|
}
|
|
995
1006
|
}, 800);
|
|
996
1007
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// prompt-banner.js - the answer buttons of a prompt's notification banner.
|
|
2
|
+
//
|
|
3
|
+
// A banner answers through the same state machine as the prompt's card
|
|
4
|
+
// (prompt-card.js): a click locks its answer buttons and shows "Sending..."
|
|
5
|
+
// until the server settles the prompt and dismisses the banner; no
|
|
6
|
+
// confirmation in time, or a dropped connection, makes them answerable
|
|
7
|
+
// again. Close and "Go to session" stay usable throughout.
|
|
8
|
+
//
|
|
9
|
+
// Deliberately free of DOM globals beyond the banner element it is given, so
|
|
10
|
+
// it can be exercised without the rest of the frontend module graph.
|
|
11
|
+
|
|
12
|
+
import { definePromptSurface, submitPromptResponse, restoreUnconfirmedUnder } from './prompt-card.js';
|
|
13
|
+
import { permissionChoices } from './prompt-kinds/permission-choices.js';
|
|
14
|
+
|
|
15
|
+
var DECISION_BUTTONS = "button[data-decision]";
|
|
16
|
+
var ACTIONS = ".notif-banner-actions";
|
|
17
|
+
|
|
18
|
+
var PERMISSION_BUTTONS = {
|
|
19
|
+
allow: { label: "Sure", className: "notif-banner-allow" },
|
|
20
|
+
allow_always: { label: "Allow for session", className: "notif-banner-always" },
|
|
21
|
+
deny: { label: "No", className: "notif-banner-deny" },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var PLAN_BUTTONS = [
|
|
25
|
+
{ decision: "allow", label: "Approve", className: "notif-banner-allow" },
|
|
26
|
+
{ decision: "deny", label: "Reject", className: "notif-banner-deny" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The answer buttons a prompt's banner offers; a kind with none offers only
|
|
31
|
+
* "Go to session". A tool-permission banner offers the card's answers, in the
|
|
32
|
+
* card's order: no Allow for session for an ask that may not offer it, and
|
|
33
|
+
* No first for an ask that must open on No.
|
|
34
|
+
* @param {string} kind
|
|
35
|
+
* @param {object} [meta] - the notification's meta (the ask's hints).
|
|
36
|
+
* @returns {{decision: string, label: string, className: string}[]}
|
|
37
|
+
*/
|
|
38
|
+
export function bannerActions(kind, meta) {
|
|
39
|
+
if (kind === "permission") {
|
|
40
|
+
return permissionChoices(meta).map(function (decision) {
|
|
41
|
+
return Object.assign({ decision: decision }, PERMISSION_BUTTONS[decision]);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (kind === "plan") return PLAN_BUTTONS.map(function (a) { return Object.assign({}, a); });
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Wire a banner's decision buttons to answer its prompt.
|
|
50
|
+
* @param {Element} banner
|
|
51
|
+
* @param {object} prompt
|
|
52
|
+
* @param {string} prompt.requestId
|
|
53
|
+
* @param {string} prompt.kind
|
|
54
|
+
* @param {?string} [prompt.slug] - the project the prompt belongs to.
|
|
55
|
+
* @param {function(object): boolean} send - sends a WS message; false when
|
|
56
|
+
* the socket is unusable.
|
|
57
|
+
*/
|
|
58
|
+
export function wirePromptBanner(banner, prompt, send) {
|
|
59
|
+
definePromptSurface(banner, { controls: DECISION_BUTTONS, actions: ACTIONS });
|
|
60
|
+
var buttons = banner.querySelectorAll(DECISION_BUTTONS);
|
|
61
|
+
for (var i = 0; i < buttons.length; i++) {
|
|
62
|
+
buttons[i].addEventListener("click", answerWith(buttons[i]));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function answerWith(btn) {
|
|
66
|
+
return function (e) {
|
|
67
|
+
if (e && e.stopPropagation) e.stopPropagation();
|
|
68
|
+
var msg = { type: "prompt_response", requestId: prompt.requestId, kind: prompt.kind, decision: btn.getAttribute("data-decision") };
|
|
69
|
+
if (prompt.slug) msg.targetSlug = prompt.slug;
|
|
70
|
+
submitPromptResponse(banner, function () { return send(msg); });
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Make every banner under root that awaits a confirmation answerable again. */
|
|
76
|
+
export function restoreUnconfirmedBanners(root, message) {
|
|
77
|
+
if (root) restoreUnconfirmedUnder(root, message);
|
|
78
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// prompt-card.js - the answer state machine every surface that answers an
|
|
2
|
+
// operator prompt shares (the transcript card and the notification banner),
|
|
3
|
+
// and the card's terminal rendering.
|
|
4
|
+
//
|
|
5
|
+
// A surface never displays an outcome ("Allowed", "Submitted") until the
|
|
6
|
+
// server has confirmed it. Answering only moves it to a "sending" state; the
|
|
7
|
+
// final label is applied when the server's prompt_resolved (or prompt_cancel)
|
|
8
|
+
// arrives, or, for a banner, the server dismisses it. If the socket is down,
|
|
9
|
+
// the connection drops, or no confirmation arrives in time, the surface
|
|
10
|
+
// returns to its answerable state so the operator can retry.
|
|
11
|
+
//
|
|
12
|
+
// Deliberately imports nothing but the import-free own-key.js, so it can be
|
|
13
|
+
// exercised without the rest of the frontend module graph.
|
|
14
|
+
|
|
15
|
+
import { ownValue } from './prompt-kinds/own-key.js';
|
|
16
|
+
|
|
17
|
+
export var SENDING_CLASS = "sending";
|
|
18
|
+
export var ACK_TIMEOUT_MS = 10000;
|
|
19
|
+
|
|
20
|
+
var NOTE_CLASS = "permission-sending-note";
|
|
21
|
+
var DEFAULT_CONTROLS = "button, input, select, textarea";
|
|
22
|
+
var DEFAULT_ACTIONS = ".permission-actions";
|
|
23
|
+
// container -> { timer, disabled: controls this send disabled, actions }
|
|
24
|
+
var sends = new WeakMap();
|
|
25
|
+
// container -> { controls, actions } for a surface that is not a card.
|
|
26
|
+
var surfaces = new WeakMap();
|
|
27
|
+
|
|
28
|
+
function surfaceOf(container) {
|
|
29
|
+
return surfaces.get(container) || { controls: DEFAULT_CONTROLS, actions: DEFAULT_ACTIONS };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Ends the send in flight: its timer stops and the controls it disabled are
|
|
33
|
+
// live again (those already disabled before it stay as they were).
|
|
34
|
+
function endSend(container, reenable) {
|
|
35
|
+
var send = sends.get(container);
|
|
36
|
+
if (!send) return;
|
|
37
|
+
sends.delete(container);
|
|
38
|
+
clearTimeout(send.timer);
|
|
39
|
+
if (reenable) send.disabled.forEach(function (el) { el.disabled = false; });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function removeNote(container) {
|
|
43
|
+
var notes = container.querySelectorAll("." + NOTE_CLASS);
|
|
44
|
+
for (var i = 0; i < notes.length; i++) notes[i].remove();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addNote(container, text, isError) {
|
|
48
|
+
removeNote(container);
|
|
49
|
+
var note = document.createElement("div");
|
|
50
|
+
note.className = NOTE_CLASS + (isError ? " permission-note-error" : "");
|
|
51
|
+
note.textContent = text;
|
|
52
|
+
var actions = container.querySelector(surfaceOf(container).actions);
|
|
53
|
+
if (actions && actions.parentNode) {
|
|
54
|
+
actions.parentNode.appendChild(note);
|
|
55
|
+
} else {
|
|
56
|
+
container.appendChild(note);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Declare a surface other than a card: which of its controls an answer
|
|
62
|
+
* locks, and where its notes go.
|
|
63
|
+
* @param {Element} container
|
|
64
|
+
* @param {{controls: string, actions: string}} opts - selectors.
|
|
65
|
+
*/
|
|
66
|
+
export function definePromptSurface(container, opts) {
|
|
67
|
+
surfaces.set(container, { controls: opts.controls, actions: opts.actions });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** True while a card is awaiting server confirmation. */
|
|
71
|
+
export function isUnconfirmed(container) {
|
|
72
|
+
return container.classList.contains(SENDING_CLASS);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** True once a card shows its final outcome. */
|
|
76
|
+
export function isSettled(container) {
|
|
77
|
+
return container.classList.contains("resolved");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Restore a sending card to its answerable state.
|
|
82
|
+
* @param {Element} container
|
|
83
|
+
* @param {string} [message] - shown as an inline note explaining why.
|
|
84
|
+
*/
|
|
85
|
+
export function restorePromptCard(container, message) {
|
|
86
|
+
if (isSettled(container)) {
|
|
87
|
+
endSend(container, false);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
endSend(container, true);
|
|
91
|
+
container.classList.remove(SENDING_CLASS);
|
|
92
|
+
if (message) addNote(container, message, true);
|
|
93
|
+
else removeNote(container);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Restore every surface under root that is awaiting a confirmation (the
|
|
98
|
+
* connection that would have carried it is gone).
|
|
99
|
+
* @param {Element} root
|
|
100
|
+
* @param {string} [message]
|
|
101
|
+
*/
|
|
102
|
+
export function restoreUnconfirmedUnder(root, message) {
|
|
103
|
+
var waiting = root.querySelectorAll("." + SENDING_CLASS);
|
|
104
|
+
for (var i = 0; i < waiting.length; i++) restorePromptCard(waiting[i], message);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Submit an answer for a card without claiming it took effect.
|
|
109
|
+
*
|
|
110
|
+
* @param {Element} container
|
|
111
|
+
* @param {function(): boolean} trySend - sends the payload; returns false when
|
|
112
|
+
* the socket is not usable.
|
|
113
|
+
* @param {object} [opts]
|
|
114
|
+
* @param {number} [opts.ackTimeoutMs]
|
|
115
|
+
* @param {function()} [opts.onSent]
|
|
116
|
+
* @returns {boolean} true when the answer was handed to the socket.
|
|
117
|
+
*/
|
|
118
|
+
export function submitPromptResponse(container, trySend, opts) {
|
|
119
|
+
opts = opts || {};
|
|
120
|
+
if (isSettled(container) || isUnconfirmed(container)) return false;
|
|
121
|
+
|
|
122
|
+
var sent = false;
|
|
123
|
+
try {
|
|
124
|
+
sent = !!trySend();
|
|
125
|
+
} catch (e) {
|
|
126
|
+
// A failure of the send itself is not a dropped connection, and saying so
|
|
127
|
+
// would send the operator to reconnect for nothing.
|
|
128
|
+
console.error("[prompt-card] sending an answer failed:", e);
|
|
129
|
+
addNote(container, "Could not send the answer (" + ((e && e.message) || "unexpected error") + "). Choose again to retry.", true);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (!sent) {
|
|
133
|
+
addNote(container, "Not connected. Reconnect, then choose again.", true);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
container.classList.add(SENDING_CLASS);
|
|
138
|
+
var disabled = [];
|
|
139
|
+
var controls = container.querySelectorAll(surfaceOf(container).controls);
|
|
140
|
+
for (var i = 0; i < controls.length; i++) {
|
|
141
|
+
if (controls[i].disabled) continue;
|
|
142
|
+
controls[i].disabled = true;
|
|
143
|
+
disabled.push(controls[i]);
|
|
144
|
+
}
|
|
145
|
+
addNote(container, "Sending...", false);
|
|
146
|
+
if (opts.onSent) opts.onSent();
|
|
147
|
+
|
|
148
|
+
var timeoutMs = opts.ackTimeoutMs || ACK_TIMEOUT_MS;
|
|
149
|
+
sends.set(container, {
|
|
150
|
+
disabled: disabled,
|
|
151
|
+
timer: setTimeout(function () {
|
|
152
|
+
restorePromptCard(container, "No confirmation from the server. Choose again to retry.");
|
|
153
|
+
}, timeoutMs),
|
|
154
|
+
});
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Called when the server confirms or ends the prompt. */
|
|
159
|
+
export function settlePromptCard(container) {
|
|
160
|
+
endSend(container, false);
|
|
161
|
+
container.classList.remove(SENDING_CLASS);
|
|
162
|
+
removeNote(container);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var TONE_CLASSES = { allowed: "resolved-allowed", denied: "resolved-denied", cancelled: "resolved-cancelled" };
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The terminal rendering every card shares: the card's actions are replaced
|
|
169
|
+
* by the outcome label and no control stays live.
|
|
170
|
+
* @param {Element} container
|
|
171
|
+
* @param {{text: string, tone: "allowed"|"denied"|"cancelled"}} outcome
|
|
172
|
+
*/
|
|
173
|
+
export function showOutcome(container, outcome) {
|
|
174
|
+
container.classList.add("resolved", ownValue(TONE_CLASSES, outcome.tone) || TONE_CLASSES.cancelled);
|
|
175
|
+
var actions = container.querySelector(".permission-actions");
|
|
176
|
+
if (actions) {
|
|
177
|
+
// The label is text, never markup, whatever a kind's outcome returns.
|
|
178
|
+
var label = document.createElement("span");
|
|
179
|
+
label.className = "permission-decision-label";
|
|
180
|
+
label.textContent = outcome.text;
|
|
181
|
+
actions.textContent = "";
|
|
182
|
+
actions.appendChild(label);
|
|
183
|
+
}
|
|
184
|
+
var feedbackRow = container.querySelector(".plan-feedback-row");
|
|
185
|
+
if (feedbackRow) feedbackRow.remove();
|
|
186
|
+
var controls = container.querySelectorAll("button, input, select, textarea");
|
|
187
|
+
for (var i = 0; i < controls.length; i++) controls[i].disabled = true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// How a prompt that ended without an answer reads, by reason. "stale" means
|
|
191
|
+
// the server no longer holds it (answered elsewhere, or its process ended
|
|
192
|
+
// before recording an outcome).
|
|
193
|
+
var CANCEL_LABELS = {
|
|
194
|
+
stale: "No longer active (already resolved or expired)",
|
|
195
|
+
expired: "Expired",
|
|
196
|
+
shutdown: "Ended by a daemon restart",
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export function cancelledLabel(reason) {
|
|
200
|
+
return ownValue(CANCEL_LABELS, reason) || "Cancelled";
|
|
201
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// ask-user-codec.js - the one definition of an AskUserQuestion answer, shared
|
|
2
|
+
// by the card (this directory) and the server (lib/prompt-kinds/ask-user.js).
|
|
3
|
+
//
|
|
4
|
+
// This file is the only copy: the server imports it as is
|
|
5
|
+
// (lib/prompt-kinds/codecs.js).
|
|
6
|
+
|
|
7
|
+
// How the CLI joins several labels into the one string its tool takes for
|
|
8
|
+
// a question; older histories recorded that joined string.
|
|
9
|
+
var MULTI_SELECT_SEPARATOR = ", ";
|
|
10
|
+
// Bound on "Other" text (lib/prompt-kinds/answer-limits.js applies the same).
|
|
11
|
+
var MAX_ANSWER_CHARS = 10000;
|
|
12
|
+
|
|
13
|
+
function questionList(input) {
|
|
14
|
+
return input && Array.isArray(input.questions) ? input.questions : [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A question's choices: its option labels, each once, in the order first
|
|
18
|
+
// offered. Options sharing a label are one choice, because the tool is
|
|
19
|
+
// answered with the label and cannot tell them apart.
|
|
20
|
+
function choiceLabels(question) {
|
|
21
|
+
var out = [];
|
|
22
|
+
var options = question && Array.isArray(question.options) ? question.options : [];
|
|
23
|
+
for (var i = 0; i < options.length; i++) {
|
|
24
|
+
var label = options[i] && options[i].label;
|
|
25
|
+
if (typeof label === "string" && out.indexOf(label) === -1) out.push(label);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// One question's answer as the operator gave it, or null when it is not a
|
|
31
|
+
// usable answer to that question: for a multi-select question the chosen
|
|
32
|
+
// labels (each one of its choices, once, in the order given); else non-blank
|
|
33
|
+
// text within the bound, trimmed (a choice's label or "Other" text).
|
|
34
|
+
function normalizeAnswer(question, value) {
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
if (!question || !question.multiSelect) return null;
|
|
37
|
+
var labels = choiceLabels(question);
|
|
38
|
+
var picked = [];
|
|
39
|
+
for (var i = 0; i < value.length; i++) {
|
|
40
|
+
if (labels.indexOf(value[i]) !== -1 && picked.indexOf(value[i]) === -1) picked.push(value[i]);
|
|
41
|
+
}
|
|
42
|
+
return picked.length ? picked : null;
|
|
43
|
+
}
|
|
44
|
+
if (typeof value !== "string" || value.length > MAX_ANSWER_CHARS) return null;
|
|
45
|
+
var text = value.trim();
|
|
46
|
+
return text ? text : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Every usable answer, keyed by question index, limited to the questions
|
|
50
|
+
// asked.
|
|
51
|
+
function normalizeAnswers(input, answers) {
|
|
52
|
+
var out = {};
|
|
53
|
+
var given = answers && typeof answers === "object" && !Array.isArray(answers) ? answers : {};
|
|
54
|
+
var questions = questionList(input);
|
|
55
|
+
for (var i = 0; i < questions.length; i++) {
|
|
56
|
+
var answer = normalizeAnswer(questions[i], given[i]);
|
|
57
|
+
if (answer !== null) out[i] = answer;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The answer a card's state stands for: the chosen labels of a multi-select
|
|
63
|
+
// question (in choice order), the chosen label of any other, else the
|
|
64
|
+
// "Other" text; null when the operator gave nothing.
|
|
65
|
+
function answerFromCard(question, chosen, other) {
|
|
66
|
+
var labels = choiceLabels(question).filter(function (label) { return chosen.indexOf(label) !== -1; });
|
|
67
|
+
if (labels.length) return normalizeAnswer(question, question && question.multiSelect ? labels : labels[0]);
|
|
68
|
+
return normalizeAnswer(question, other == null ? "" : String(other));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// One answer as the single string the CLI's tool takes.
|
|
72
|
+
function answerText(value) {
|
|
73
|
+
return Array.isArray(value) ? value.join(MULTI_SELECT_SEPARATOR) : String(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The answers keyed by question text, as the CLI's AskUserQuestion tool
|
|
77
|
+
// takes them. Questions that share their text share that one slot; each
|
|
78
|
+
// answer is kept, in question order, rather than the last one winning.
|
|
79
|
+
function toolAnswers(input, answers) {
|
|
80
|
+
var out = {};
|
|
81
|
+
var questions = questionList(input);
|
|
82
|
+
for (var i = 0; i < questions.length; i++) {
|
|
83
|
+
var text = questions[i] && questions[i].question;
|
|
84
|
+
if (typeof text !== "string" || !text || answers[i] == null) continue;
|
|
85
|
+
var value = answerText(answers[i]);
|
|
86
|
+
var prior = Object.prototype.hasOwnProperty.call(out, text) ? out[text] : null;
|
|
87
|
+
// Defined, not assigned, so a question text such as "__proto__" is a key.
|
|
88
|
+
Object.defineProperty(out, text, {
|
|
89
|
+
value: prior === null ? value : prior + MULTI_SELECT_SEPARATOR + value,
|
|
90
|
+
enumerable: true, writable: true, configurable: true,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The labels an older history's joined multi-select answer was made of, or
|
|
97
|
+
// null when value is not a join of distinct choices (it was "Other" text).
|
|
98
|
+
// Labels may themselves contain the separator, so every split is tried.
|
|
99
|
+
function splitJoinedLabels(value, labels) {
|
|
100
|
+
function from(pos, used) {
|
|
101
|
+
for (var i = 0; i < labels.length; i++) {
|
|
102
|
+
var label = labels[i];
|
|
103
|
+
if (!label || used.indexOf(label) !== -1 || value.indexOf(label, pos) !== pos) continue;
|
|
104
|
+
var end = pos + label.length;
|
|
105
|
+
if (end === value.length) return used.concat([label]);
|
|
106
|
+
if (value.indexOf(MULTI_SELECT_SEPARATOR, end) !== end) continue;
|
|
107
|
+
var rest = from(end + MULTI_SELECT_SEPARATOR.length, used.concat([label]));
|
|
108
|
+
if (rest) return rest;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return value ? from(0, []) : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// What a recorded answer shows on a card: the choices it selects and the
|
|
116
|
+
// "Other" text it carries (one or the other).
|
|
117
|
+
function readAnswer(question, value) {
|
|
118
|
+
var labels = choiceLabels(question);
|
|
119
|
+
if (Array.isArray(value)) {
|
|
120
|
+
return { labels: labels.filter(function (label) { return value.indexOf(label) !== -1; }), other: "" };
|
|
121
|
+
}
|
|
122
|
+
var text = value == null ? "" : String(value);
|
|
123
|
+
if (labels.indexOf(text) !== -1) return { labels: [text], other: "" };
|
|
124
|
+
var joined = question && question.multiSelect ? splitJoinedLabels(text, labels) : null;
|
|
125
|
+
return joined ? { labels: labels.filter(function (label) { return joined.indexOf(label) !== -1; }), other: "" } : { labels: [], other: text };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
MULTI_SELECT_SEPARATOR, MAX_ANSWER_CHARS, choiceLabels, normalizeAnswer, normalizeAnswers,
|
|
130
|
+
answerFromCard, answerText, toolAnswers, readAnswer,
|
|
131
|
+
};
|