@clagentic/console 1.9.0 → 1.10.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/LICENSE +117 -12
  2. package/LICENSES/MIT-legacy.txt +22 -0
  3. package/LICENSES/README.md +15 -0
  4. package/README.md +9 -3
  5. package/bin/cli.js +40 -5
  6. package/deploy/clagentic-console.service +10 -6
  7. package/lib/agent-dispatch-tool.js +20 -0
  8. package/lib/audit.js +3 -2
  9. package/lib/build-changes.js +79 -0
  10. package/lib/build-identity.js +192 -0
  11. package/lib/build-monitor.js +125 -0
  12. package/lib/build-sha.json +2 -2
  13. package/lib/build-update-check.js +138 -0
  14. package/lib/build-update-offer.js +141 -0
  15. package/lib/build-update-restart.js +142 -0
  16. package/lib/build-update-standing.js +184 -0
  17. package/lib/cli/daemon-launch.js +25 -22
  18. package/lib/cli/ipc-subcommands.js +6 -0
  19. package/lib/cli/session-subcommands.js +122 -0
  20. package/lib/cli-sessions.js +8 -1
  21. package/lib/codex-defaults.js +8 -2
  22. package/lib/config.js +32 -20
  23. package/lib/daemon-env-settings.js +84 -0
  24. package/lib/daemon-projects.js +57 -0
  25. package/lib/daemon.js +288 -205
  26. package/lib/drain.js +74 -17
  27. package/lib/env-compat.js +61 -0
  28. package/lib/extension-commands.js +45 -0
  29. package/lib/history-visibility.js +4 -0
  30. package/lib/idle-adapter-reaper.js +71 -0
  31. package/lib/link-trap.js +78 -0
  32. package/lib/mcp-local.js +8 -6
  33. package/lib/mcp-tool-input.js +116 -0
  34. package/lib/mcp-tool-schema.js +179 -0
  35. package/lib/memory-limits.js +61 -5
  36. package/lib/memory-setting-validate.js +65 -0
  37. package/lib/memory-shed.js +13 -32
  38. package/lib/new-work-gate.js +47 -0
  39. package/lib/os-users.js +5 -3
  40. package/lib/project-access.js +139 -0
  41. package/lib/project-connection.js +37 -22
  42. package/lib/project-external-trigger.js +166 -105
  43. package/lib/project-file-scope.js +172 -0
  44. package/lib/project-file-watch.js +86 -61
  45. package/lib/project-filesystem.js +144 -128
  46. package/lib/project-git.js +119 -0
  47. package/lib/project-http.js +44 -28
  48. package/lib/project-loop.js +17 -9
  49. package/lib/project-mcp.js +53 -72
  50. package/lib/project-message-gate.js +70 -0
  51. package/lib/project-notifications.js +31 -4
  52. package/lib/project-prompt-responses.js +217 -0
  53. package/lib/project-sessions.js +192 -355
  54. package/lib/project-user-message.js +27 -15
  55. package/lib/project.js +212 -147
  56. package/lib/projects-dir.js +90 -0
  57. package/lib/prompt-access.js +22 -0
  58. package/lib/prompt-kinds/answer-limits.js +15 -0
  59. package/lib/prompt-kinds/ask-user.js +58 -0
  60. package/lib/prompt-kinds/codecs.js +97 -0
  61. package/lib/prompt-kinds/elicitation.js +77 -0
  62. package/lib/prompt-kinds/extension.js +39 -0
  63. package/lib/prompt-kinds/index.js +68 -0
  64. package/lib/prompt-kinds/permission.js +114 -0
  65. package/lib/prompt-kinds/plan.js +79 -0
  66. package/lib/prompt-kinds/tool-call.js +38 -0
  67. package/lib/prompt-registry.js +680 -0
  68. package/lib/public/app.js +1 -1
  69. package/lib/public/css/diagnostics.css +80 -0
  70. package/lib/public/css/input.css +17 -3
  71. package/lib/public/css/menus.css +10 -0
  72. package/lib/public/css/messages.css +5 -0
  73. package/lib/public/css/rewind.css +22 -0
  74. package/lib/public/index.html +4 -12
  75. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  76. package/lib/public/modules/app-connection.js +7 -0
  77. package/lib/public/modules/app-cursors.js +7 -5
  78. package/lib/public/modules/app-messages.js +52 -47
  79. package/lib/public/modules/app-notifications.js +47 -71
  80. package/lib/public/modules/app-panels.js +61 -59
  81. package/lib/public/modules/app-projects.js +2 -1
  82. package/lib/public/modules/app-rendering.js +4 -10
  83. package/lib/public/modules/build-update-detail.js +54 -0
  84. package/lib/public/modules/diagnostics.js +170 -20
  85. package/lib/public/modules/filebrowser.js +18 -16
  86. package/lib/public/modules/history-visibility.js +4 -0
  87. package/lib/public/modules/mention.js +3 -2
  88. package/lib/public/modules/mode-options.js +38 -0
  89. package/lib/public/modules/project-settings.js +19 -8
  90. package/lib/public/modules/prompt-banner.js +78 -0
  91. package/lib/public/modules/prompt-card.js +201 -0
  92. package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
  93. package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
  94. package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
  95. package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
  96. package/lib/public/modules/prompt-kinds/index.js +18 -0
  97. package/lib/public/modules/prompt-kinds/own-key.js +29 -0
  98. package/lib/public/modules/prompt-kinds/package.json +3 -0
  99. package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
  100. package/lib/public/modules/prompt-kinds/permission.js +209 -0
  101. package/lib/public/modules/prompt-kinds/plan.js +102 -0
  102. package/lib/public/modules/prompt-state.js +142 -0
  103. package/lib/public/modules/prompts.js +134 -0
  104. package/lib/public/modules/rewind.js +4 -1
  105. package/lib/public/modules/server-settings.js +2 -4
  106. package/lib/public/modules/sidebar-mobile.js +19 -9
  107. package/lib/public/modules/sidebar-sessions.js +21 -14
  108. package/lib/public/modules/sticky-notes.js +3 -2
  109. package/lib/public/modules/team-panel.js +5 -4
  110. package/lib/public/modules/tools.js +81 -906
  111. package/lib/public/modules/vendor-picker.js +53 -0
  112. package/lib/public/modules/vendor-registry.js +142 -0
  113. package/lib/public/sw.js +3 -1
  114. package/lib/rc-migrate.js +44 -0
  115. package/lib/runtime-env-keys.js +109 -0
  116. package/lib/runtime-env.js +236 -0
  117. package/lib/sdk-bridge.js +348 -284
  118. package/lib/sdk-message-processor.js +117 -146
  119. package/lib/sdk-skill-discovery.js +65 -60
  120. package/lib/server-hub-sessions.js +13 -10
  121. package/lib/server-palette.js +28 -19
  122. package/lib/server.js +156 -115
  123. package/lib/service-install.js +96 -0
  124. package/lib/session-capabilities.js +76 -0
  125. package/lib/session-id.js +33 -0
  126. package/lib/session-input-ipc.js +32 -0
  127. package/lib/session-input.js +379 -0
  128. package/lib/session-reclaim.js +284 -0
  129. package/lib/session-resume.js +172 -0
  130. package/lib/sessions.js +61 -30
  131. package/lib/supervisor.js +39 -0
  132. package/lib/turn-initiator.js +108 -0
  133. package/lib/users-permissions.js +9 -6
  134. package/lib/users.js +9 -0
  135. package/lib/utils.js +4 -2
  136. package/lib/vendor-auth.js +22 -0
  137. package/lib/vendor-registry-message.js +66 -0
  138. package/lib/ws-origin.js +99 -0
  139. package/lib/ws-schema.js +36 -23
  140. package/lib/yoke/adapters/claude-capabilities.js +38 -0
  141. package/lib/yoke/adapters/claude-vendor.js +34 -0
  142. package/lib/yoke/adapters/claude-worker.js +57 -87
  143. package/lib/yoke/adapters/claude.js +182 -88
  144. package/lib/yoke/adapters/codex-capabilities.js +40 -0
  145. package/lib/yoke/adapters/codex-vendor.js +46 -0
  146. package/lib/yoke/adapters/codex.js +462 -211
  147. package/lib/yoke/adapters/effort-control.js +34 -0
  148. package/lib/yoke/adapters/permission-relay.js +58 -0
  149. package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
  150. package/lib/yoke/auth-checks.js +91 -0
  151. package/lib/yoke/capabilities.js +49 -0
  152. package/lib/yoke/codex-app-server.js +30 -56
  153. package/lib/yoke/codex-binary.js +254 -0
  154. package/lib/yoke/codex-command.js +122 -0
  155. package/lib/yoke/codex-protocol.js +96 -0
  156. package/lib/yoke/codex-version.js +135 -0
  157. package/lib/yoke/env-ownership.js +40 -0
  158. package/lib/yoke/index.js +84 -174
  159. package/lib/yoke/install-probe.js +136 -0
  160. package/lib/yoke/instructions.js +7 -11
  161. package/lib/yoke/interface.js +206 -4
  162. package/lib/yoke/package.json +1 -1
  163. package/lib/yoke/provider-credentials.js +96 -0
  164. package/lib/yoke/registry.js +377 -0
  165. package/package.json +12 -9
  166. package/scripts/check-sdk-lock-drift.js +160 -0
  167. package/scripts/check-test-count.js +76 -1
  168. package/scripts/postinstall.js +218 -136
  169. package/scripts/prompt-harness-history.js +202 -0
  170. package/scripts/verify-installed-build.js +59 -17
  171. package/scripts/verify-installed.js +67 -0
  172. package/lib/sdk-permission-ownership.js +0 -136
@@ -0,0 +1,90 @@
1
+ // projects-dir.js — where new projects (create / clone) are placed.
2
+ //
3
+ // The directories resolved here hold users' git repositories. Daemon config
4
+ // stores ABSOLUTE project paths under them, worktrees reference them, and
5
+ // session history is keyed by the encoded cwd. So this module only ever
6
+ // READS the filesystem (stat). It never moves, renames, copies or links.
7
+ //
8
+ // Resolution order (non-os-users mode):
9
+ // 1. config.projectsDir, when set.
10
+ // 2. The console-scoped default, when it already exists. Console only ever
11
+ // creates it when no legacy dir existed, so its presence means console
12
+ // already chose it; a legacy-named dir that appeared later (the bare
13
+ // brand name is shared by other clagentic products) must not redirect
14
+ // where new projects land.
15
+ // 3. A legacy dir, when one exists: used in place.
16
+ // 4. The console-scoped default (created by the caller on first use).
17
+ //
18
+ // os-users mode keeps ignoring config.projectsDir, as it always has, and uses
19
+ // a system path instead of a home-relative one.
20
+
21
+ var fs = require("fs");
22
+ var path = require("path");
23
+
24
+ var DEFAULT_DIRNAME = "clagentic-console-projects";
25
+ // FHS: variable state data belongs under /var/lib/<name>.
26
+ var OS_USERS_DEFAULT_DIR = "/var/lib/clagentic-console/projects";
27
+ var OS_USERS_LEGACY_DIR = "/var/clagentic/projects";
28
+ var HOME_LEGACY_DIRNAMES = ["clagentic-projects", "clay-projects"];
29
+
30
+ function isDirectory(fsImpl, p) {
31
+ try {
32
+ return fsImpl.statSync(p).isDirectory();
33
+ } catch (e) {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * @param {object} opts
40
+ * @param {object} opts.config Daemon config ({projectsDir, osUsers}).
41
+ * @param {string} opts.realHome
42
+ * @param {object} [opts.fs] fs-like exposing statSync only; for tests.
43
+ * @returns {{dir: string, source: "config"|"default"|"legacy", legacy: boolean}}
44
+ */
45
+ function resolveProjectsDir(opts) {
46
+ var config = opts.config || {};
47
+ var fsImpl = opts.fs || fs;
48
+
49
+ if (config.osUsers) {
50
+ if (isDirectory(fsImpl, OS_USERS_DEFAULT_DIR)) {
51
+ return { dir: OS_USERS_DEFAULT_DIR, source: "default", legacy: false };
52
+ }
53
+ if (isDirectory(fsImpl, OS_USERS_LEGACY_DIR)) {
54
+ return { dir: OS_USERS_LEGACY_DIR, source: "legacy", legacy: true };
55
+ }
56
+ return { dir: OS_USERS_DEFAULT_DIR, source: "default", legacy: false };
57
+ }
58
+
59
+ if (config.projectsDir) {
60
+ return { dir: config.projectsDir, source: "config", legacy: false };
61
+ }
62
+
63
+ var defaultDir = path.join(opts.realHome, DEFAULT_DIRNAME);
64
+ if (isDirectory(fsImpl, defaultDir)) {
65
+ return { dir: defaultDir, source: "default", legacy: false };
66
+ }
67
+ for (var i = 0; i < HOME_LEGACY_DIRNAMES.length; i++) {
68
+ var legacyDir = path.join(opts.realHome, HOME_LEGACY_DIRNAMES[i]);
69
+ if (isDirectory(fsImpl, legacyDir)) {
70
+ return { dir: legacyDir, source: "legacy", legacy: true };
71
+ }
72
+ }
73
+ return { dir: defaultDir, source: "default", legacy: false };
74
+ }
75
+
76
+ /**
77
+ * One-line startup notice for a legacy resolution, or null.
78
+ */
79
+ function legacyNotice(resolved, configFile) {
80
+ if (!resolved || !resolved.legacy) return null;
81
+ return "[daemon] Projects directory " + resolved.dir + " is a legacy location; it is used in place and is not moved or copied. " +
82
+ "To choose another location for NEW projects, set \"projectsDir\" in " + configFile + ".";
83
+ }
84
+
85
+ module.exports = {
86
+ resolveProjectsDir: resolveProjectsDir,
87
+ legacyNotice: legacyNotice,
88
+ OS_USERS_DEFAULT_DIR: OS_USERS_DEFAULT_DIR,
89
+ OS_USERS_LEGACY_DIR: OS_USERS_LEGACY_DIR,
90
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ // Who may answer an operator prompt. Every path that applies an answer (the
4
+ // WS card, the push notification's HTTP route) asks this one rule, the same
5
+ // one switchSession applies to viewing: a user may answer only prompts of a
6
+ // session they can see. A request with no authenticated user (single-user
7
+ // mode) owns everything, and a prompt with no session (a project-scope
8
+ // browser-extension command) is answerable by whoever reached the project.
9
+
10
+ var users = require("./users");
11
+
12
+ /**
13
+ * @param {?{id: string}} user - the authenticated user, or null.
14
+ * @param {?object} session - the prompt's session, or null.
15
+ * @returns {boolean}
16
+ */
17
+ function mayAnswerPrompt(user, session) {
18
+ if (!user || !session) return true;
19
+ return users.canAccessSession(user.id, session, { visibility: "public" });
20
+ }
21
+
22
+ module.exports = { mayAnswerPrompt: mayAnswerPrompt };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ // Bound on operator-typed answer text. The WebSocket accepts frames far
4
+ // larger than any answer (it also carries uploads), so a kind bounds the free
5
+ // text it hands to a vendor callback and records in history. A value over the
6
+ // bound is refused rather than cut: an answer is never silently altered.
7
+ //
8
+ // The answer codecs the server shares with the client (./codecs.js) each
9
+ // carry this bound; test/shared-codecs.test.js holds them to this value.
10
+
11
+ var MAX_ANSWER_CHARS = 10000;
12
+
13
+ module.exports = {
14
+ MAX_ANSWER_CHARS: MAX_ANSWER_CHARS,
15
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ // AskUserQuestion: the operator answers one or more multiple-choice
4
+ // questions, or skips them. The prompt's id is the tool-use id, so the card
5
+ // drawn from the tool call and the prompt are the same request on every
6
+ // client and in every recorded history.
7
+ //
8
+ // What an answer is - chosen labels, "Other" text, how it reaches the CLI's
9
+ // tool - is defined once, in the card's ask-user-codec.js (./codecs.js).
10
+
11
+ var toolCall = require("./tool-call");
12
+ var codecs = require("./codecs");
13
+
14
+ module.exports = {
15
+ name: "ask_user",
16
+ scope: "session",
17
+ store: "pendingAskUser",
18
+ journal: true,
19
+ idFromToolUse: true,
20
+
21
+ fields: function (req) {
22
+ return { input: req.input || {} };
23
+ },
24
+
25
+ requestFields: function (record) {
26
+ return { input: record.input || {} };
27
+ },
28
+
29
+ decisions: ["answer", "skip"],
30
+
31
+ // A multi-select answer travels and is recorded as the list of chosen
32
+ // labels, so a replayed card can show exactly what was chosen. A response
33
+ // with no usable answer left is a skip: the tool is never handed an empty
34
+ // answer set the operator did not give.
35
+ parse: function (msg, record) {
36
+ if (msg.decision === "skip") return { skipped: true };
37
+ var answers = codecs.askUser().normalizeAnswers(record && record.input, msg.answers);
38
+ return Object.keys(answers).length ? { answers: answers } : { skipped: true };
39
+ },
40
+
41
+ outcome: function (record, response) {
42
+ if (response.skipped) return toolCall.deny("The user skipped the question.");
43
+ // Both spellings: the SDK passes the object through and the stdio
44
+ // permission handler reads the snake_case key.
45
+ var updatedInput = Object.assign({}, record.input, { answers: codecs.askUser().toolAnswers(record.input, response.answers) });
46
+ return { behavior: "allow", updatedInput: updatedInput, updated_input: updatedInput };
47
+ },
48
+
49
+ grantsSession: function () { return false; },
50
+
51
+ resolvedFields: function (response) {
52
+ return response.skipped ? { skipped: true } : { answers: response.answers };
53
+ },
54
+
55
+ cancelled: function () {
56
+ return toolCall.deny("Cancelled");
57
+ },
58
+ };
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ // The server's handle on the modules it shares with the browser: the answer
4
+ // codecs (ask-user-codec.js, elicitation-codec.js) and the own-key lookups.
5
+ // Each has one source, the ES module the browser is served from
6
+ // lib/public/modules/prompt-kinds/; the package.json beside them declares
7
+ // them ES modules, so every supported Node loads them as such.
8
+ //
9
+ // load() runs once, when the prompt registry is first required. Where Node
10
+ // can require() an ES module it does, so the codecs are in before any
11
+ // caller of the registry runs. Where it cannot (Node before 20.19 / 22.12),
12
+ // load() imports the same files with import(), and the daemon awaits it
13
+ // before it accepts a connection. Either way a codec that fails to load
14
+ // rejects load(), and a codec read before load() has finished throws: no
15
+ // prompt is opened or answered without one.
16
+
17
+ var path = require("path");
18
+ var { pathToFileURL } = require("url");
19
+
20
+ var SOURCE_DIR = path.join(__dirname, "..", "public", "modules", "prompt-kinds");
21
+ var FILES = {
22
+ askUser: "ask-user-codec.js",
23
+ elicitation: "elicitation-codec.js",
24
+ ownKey: "own-key.js",
25
+ };
26
+ var NAMES = Object.keys(FILES);
27
+ // How a Node that cannot require() these modules refuses; they then load
28
+ // through import().
29
+ var NEEDS_IMPORT = ["ERR_REQUIRE_ESM", "ERR_REQUIRE_ASYNC_MODULE"];
30
+
31
+ var modules = null;
32
+ var loading = null;
33
+
34
+ function sourcePath(name) {
35
+ return path.join(SOURCE_DIR, FILES[name]);
36
+ }
37
+
38
+ function sourceUrl(name) {
39
+ return pathToFileURL(sourcePath(name)).href;
40
+ }
41
+
42
+ function keep(loaded) {
43
+ var out = {};
44
+ NAMES.forEach(function (name, i) { out[name] = loaded[i]; });
45
+ modules = out;
46
+ return out;
47
+ }
48
+
49
+ function failure(err) {
50
+ return new Error("prompt codecs could not be loaded from " + SOURCE_DIR + ": " + ((err && err.message) || err), { cause: err });
51
+ }
52
+
53
+ function loadOnce() {
54
+ try {
55
+ return Promise.resolve(keep(NAMES.map(function (name) { return require(sourcePath(name)); })));
56
+ } catch (err) {
57
+ if (NEEDS_IMPORT.indexOf(err && err.code) === -1) return Promise.reject(failure(err));
58
+ }
59
+ return Promise.all(NAMES.map(function (name) { return import(sourceUrl(name)); })).then(keep, function (err) {
60
+ throw failure(err);
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Load every shared module, once. Resolves to {askUser, elicitation,
66
+ * ownKey}; rejects, naming the directory, when any of them fails to load.
67
+ * @returns {Promise<object>}
68
+ */
69
+ function load() {
70
+ if (!loading) loading = loadOnce();
71
+ return loading;
72
+ }
73
+
74
+ function loaded(name) {
75
+ if (!modules) throw new Error("prompt codec " + FILES[name] + " used before load() finished");
76
+ return modules[name];
77
+ }
78
+
79
+ function askUser() { return loaded("askUser"); }
80
+ function elicitation() { return loaded("elicitation"); }
81
+ function ownKey() { return loaded("ownKey"); }
82
+
83
+ // The own-key lookups, called through so a caller can take them by name.
84
+ function hasOwnKey(map, key) { return ownKey().hasOwnKey(map, key); }
85
+ function ownValue(map, key) { return ownKey().ownValue(map, key); }
86
+ function putOwn(map, key, value) { return ownKey().putOwn(map, key, value); }
87
+
88
+ module.exports = {
89
+ load: load,
90
+ sourceUrl: sourceUrl,
91
+ askUser: askUser,
92
+ elicitation: elicitation,
93
+ ownKey: ownKey,
94
+ hasOwnKey: hasOwnKey,
95
+ ownValue: ownValue,
96
+ putOwn: putOwn,
97
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ // MCP elicitation (Claude's onElicitation and Codex's
4
+ // mcpServer/elicitation/request): the operator submits the requested form,
5
+ // approves the URL, or rejects. Submitted content is passed to the server but
6
+ // never recorded, since a form may carry secrets.
7
+ //
8
+ // What an answer to a requested schema is, and when a URL may be approved,
9
+ // is defined once, in the card's elicitation-codec.js (./codecs.js).
10
+
11
+ var codecs = require("./codecs");
12
+
13
+ module.exports = {
14
+ name: "elicitation",
15
+ scope: "session",
16
+ store: "pendingElicitations",
17
+ journal: true,
18
+
19
+ fields: function (req) {
20
+ return {
21
+ serverName: req.serverName,
22
+ message: req.message,
23
+ mode: req.mode || "form",
24
+ url: req.url || null,
25
+ elicitationId: req.elicitationId || null,
26
+ requestedSchema: req.requestedSchema || null,
27
+ };
28
+ },
29
+
30
+ requestFields: function (record) {
31
+ return {
32
+ serverName: record.serverName,
33
+ message: record.message,
34
+ mode: record.mode || "form",
35
+ url: record.url || null,
36
+ elicitationId: record.elicitationId || null,
37
+ requestedSchema: record.requestedSchema || null,
38
+ };
39
+ },
40
+
41
+ decisions: ["accept", "reject"],
42
+
43
+ // An acceptance that cannot stand - a URL approval for a URL that is not a
44
+ // web page, a form whose schema is outside the supported subset, or a form
45
+ // missing a required field - is invalid: the prompt stays pending, and
46
+ // nothing unchecked or incomplete reaches the MCP server. A form outside
47
+ // the subset can only be declined.
48
+ parse: function (msg, record) {
49
+ if (msg.action !== "accept") return { action: "reject" };
50
+ var codec = codecs.elicitation();
51
+ if (codec.requestMode(record) === "url") {
52
+ return codec.isOpenableUrl(record && record.url)
53
+ ? { action: "accept", content: {} }
54
+ : { invalid: "the URL is not a web address that can be opened" };
55
+ }
56
+ var problem = codec.schemaProblem(record && record.requestedSchema);
57
+ if (problem) return { invalid: "the requested form is outside the supported MCP elicitation schema (" + problem + "); it can only be declined" };
58
+ var held = codec.contentForSchema(record && record.requestedSchema, msg.content);
59
+ if (held.errors.length) return { invalid: held.errors.join("; ") };
60
+ return { action: "accept", content: held.content };
61
+ },
62
+
63
+ outcome: function (record, response) {
64
+ if (response.action === "accept") return { action: "accept", content: response.content };
65
+ return { action: "reject" };
66
+ },
67
+
68
+ grantsSession: function () { return false; },
69
+
70
+ resolvedFields: function (response) {
71
+ return { action: response.action };
72
+ },
73
+
74
+ cancelled: function () {
75
+ return { action: "reject" };
76
+ },
77
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ // A command sent to the operator's browser extension (tab context, console,
4
+ // screenshots). Answered by the extension rather than by a person, so it is
5
+ // never recorded, re-presented or notified, and it belongs to the project
6
+ // rather than to a session. It always runs under a timeout; a request that
7
+ // ends unanswered resolves to null, which callers treat as "no data".
8
+
9
+ module.exports = {
10
+ name: "extension",
11
+ scope: "project",
12
+ journal: false,
13
+ operatorAnswerable: false,
14
+ defaultTimeoutMs: 3000,
15
+
16
+ fields: function (req) {
17
+ return { command: req.command, args: req.args };
18
+ },
19
+
20
+ requestFields: function (record) {
21
+ return { command: record.command, args: record.args };
22
+ },
23
+
24
+ decisions: ["result"],
25
+
26
+ parse: function (msg) {
27
+ return { result: msg.result === undefined ? null : msg.result };
28
+ },
29
+
30
+ outcome: function (record, response) {
31
+ return response.result;
32
+ },
33
+
34
+ grantsSession: function () { return false; },
35
+
36
+ resolvedFields: function () { return {}; },
37
+
38
+ cancelled: function () { return null; },
39
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ // Every prompt kind the registry knows. A kind is an adapter: how a request
4
+ // is described on the wire, how a response is parsed and validated, what the
5
+ // vendor's callback receives for it, and what it receives when the prompt
6
+ // ends without an answer. A kind's parse() returns {invalid: reason} for an
7
+ // answer that cannot stand; the prompt then stays pending. Lifecycle,
8
+ // ownership and storage are the registry's (lib/prompt-registry.js).
9
+
10
+ var { ownValue } = require("./codecs");
11
+
12
+ var KINDS = {
13
+ permission: require("./permission"),
14
+ plan: require("./plan"),
15
+ ask_user: require("./ask-user"),
16
+ elicitation: require("./elicitation"),
17
+ extension: require("./extension"),
18
+ };
19
+
20
+ // Plan approval rides the tool-permission callback; it is its own kind
21
+ // because its decisions and their side effects differ.
22
+ function toolApprovalKind(toolName) {
23
+ return toolName === "ExitPlanMode" ? "plan" : "permission";
24
+ }
25
+
26
+ /**
27
+ * Whether an operator's answer may settle prompts of this kind. A browser
28
+ * extension's command is answered by the extension's own socket and no other
29
+ * (lib/extension-commands.js), so no operator-facing answer path reaches it.
30
+ * An unknown kind is not answerable.
31
+ */
32
+ function operatorMayAnswer(kindName) {
33
+ var kind = ownValue(KINDS, kindName);
34
+ return !!kind && kind.operatorAnswerable !== false;
35
+ }
36
+
37
+ function sessionStores() {
38
+ var seen = {};
39
+ var out = [];
40
+ Object.keys(KINDS).forEach(function (name) {
41
+ var kind = KINDS[name];
42
+ if (kind.scope !== "session" || seen[kind.store]) return;
43
+ seen[kind.store] = true;
44
+ out.push(kind.store);
45
+ });
46
+ return out;
47
+ }
48
+
49
+ /**
50
+ * The kind of a stored record. A record carries its kind from open(); one
51
+ * without (written before kinds existed) is classified by the store it sits
52
+ * in.
53
+ */
54
+ function kindOfRecord(record, store) {
55
+ var kind = record && ownValue(KINDS, record.kind);
56
+ if (kind) return kind;
57
+ if (store === "pendingAskUser") return KINDS.ask_user;
58
+ if (store === "pendingElicitations") return KINDS.elicitation;
59
+ return KINDS[toolApprovalKind(record && record.toolName)];
60
+ }
61
+
62
+ module.exports = {
63
+ KINDS: KINDS,
64
+ toolApprovalKind: toolApprovalKind,
65
+ operatorMayAnswer: operatorMayAnswer,
66
+ sessionStores: sessionStores,
67
+ kindOfRecord: kindOfRecord,
68
+ };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ // Tool-call approval: allow this call, allow the tool for the rest of the
4
+ // session, or deny. Codex command, file-change and MCP approvals arrive here
5
+ // through the same canUseTool callback as Claude's.
6
+ //
7
+ // The Claude Agent SDK may attach presentation hints to an ask, and the
8
+ // console holds to them wherever it shows or answers one:
9
+ // suppressAlwaysAllowRule the ask must not offer a persistent choice, so
10
+ // an Allow-for-session answer is refused here, not
11
+ // just left off the card;
12
+ // defaultToNo the ask must not open on an approve choice;
13
+ // matchedAskRule a user-written ask rule forced the prompt, so no
14
+ // host-side auto-approval may answer it.
15
+ // An ask without hints (Codex approvals, older CLIs) is unchanged.
16
+
17
+ var toolCall = require("./tool-call");
18
+ var { hasOwnKey } = require("./codecs");
19
+
20
+ var DECISIONS = { allow: true, allow_always: true, deny: true };
21
+
22
+ // A rule's source and text are authored outside the console and shown to the
23
+ // operator, so they are held to a bound and to strings.
24
+ var RULE_TEXT_MAX = 200;
25
+
26
+ function ruleText(value) {
27
+ return typeof value === "string" ? value.slice(0, RULE_TEXT_MAX) : "";
28
+ }
29
+
30
+ // A present rule that is not the expected shape is still a rule-forced ask:
31
+ // the hint fails closed.
32
+ function matchedRuleOf(raw) {
33
+ if (!raw) return undefined;
34
+ var rule = typeof raw === "object" ? raw : {};
35
+ var out = { source: ruleText(rule.source), toolName: ruleText(rule.toolName) };
36
+ if (typeof rule.ruleContent === "string") out.ruleContent = ruleText(rule.ruleContent);
37
+ return out;
38
+ }
39
+
40
+ // The hints present on a request or a stored record, normalized; absent ones
41
+ // are left out so an ask without hints is described exactly as before.
42
+ function hintsOf(source) {
43
+ var hints = {};
44
+ if (source.suppressAlwaysAllowRule === true) hints.suppressAlwaysAllowRule = true;
45
+ if (source.defaultToNo === true) hints.defaultToNo = true;
46
+ var rule = matchedRuleOf(source.matchedAskRule);
47
+ if (rule) hints.matchedAskRule = rule;
48
+ return hints;
49
+ }
50
+
51
+ module.exports = {
52
+ name: "permission",
53
+ scope: "session",
54
+ store: "pendingPermissions",
55
+ journal: true,
56
+
57
+ fields: function (req) {
58
+ return Object.assign({
59
+ toolName: req.toolName,
60
+ toolInput: req.toolInput,
61
+ decisionReason: req.decisionReason || "",
62
+ vendor: req.vendor,
63
+ }, hintsOf(req));
64
+ },
65
+
66
+ requestFields: function (record) {
67
+ return Object.assign({
68
+ toolName: record.toolName,
69
+ toolInput: record.toolInput,
70
+ decisionReason: record.decisionReason || "",
71
+ vendor: record.vendor,
72
+ }, hintsOf(record));
73
+ },
74
+
75
+ // What a banner needs to offer the same answers as the card.
76
+ notificationFields: function (record) {
77
+ var hints = hintsOf(record);
78
+ return {
79
+ suppressAlwaysAllowRule: hints.suppressAlwaysAllowRule,
80
+ defaultToNo: hints.defaultToNo,
81
+ };
82
+ },
83
+
84
+ decisions: Object.keys(DECISIONS),
85
+
86
+ // Anything but a known decision fails closed. An Allow-for-session answer to
87
+ // an ask that must not offer one settles nothing: the prompt stays pending
88
+ // and is offered again to the responder.
89
+ parse: function (msg, record) {
90
+ var decision = hasOwnKey(DECISIONS, msg.decision) ? msg.decision : "deny";
91
+ if (decision === "allow_always" && record && record.suppressAlwaysAllowRule === true) {
92
+ return { invalid: "always_allow_not_offered" };
93
+ }
94
+ return { decision: decision };
95
+ },
96
+
97
+ outcome: function (record, response, opts) {
98
+ if (response.decision === "deny") return toolCall.deny(opts.denyMessage || "User denied permission");
99
+ return toolCall.allow(record.toolInput);
100
+ },
101
+
102
+ grantsSession: function (response) {
103
+ return response.decision === "allow_always";
104
+ },
105
+
106
+ resolvedFields: function (response, record) {
107
+ var hints = record ? hintsOf(record) : {};
108
+ var fields = { decision: response.decision };
109
+ if (hints.matchedAskRule) fields.matchedAskRule = hints.matchedAskRule;
110
+ return fields;
111
+ },
112
+
113
+ cancelled: toolCall.cancelled,
114
+ };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ // Plan approval (ExitPlanMode): approve with or without auto-accepting edits,
4
+ // approve into a fresh context, reject, or reject with feedback. The session
5
+ // side effects of a decision (permission mode, the fresh session, the
6
+ // feedback message) belong to the WS handler; this adapter only decides what
7
+ // the vendor callback receives.
8
+
9
+ var toolCall = require("./tool-call");
10
+ var { hasOwnKey } = require("./codecs");
11
+
12
+ var DECISIONS = {
13
+ allow: true,
14
+ allow_accept_edits: true,
15
+ allow_clear_context: true,
16
+ deny: true,
17
+ deny_with_feedback: true,
18
+ };
19
+
20
+ module.exports = {
21
+ name: "plan",
22
+ scope: "session",
23
+ // Shares the tool-approval store: both kinds answer a canUseTool call.
24
+ store: "pendingPermissions",
25
+ journal: true,
26
+
27
+ fields: function (req) {
28
+ return {
29
+ toolName: req.toolName,
30
+ toolInput: req.toolInput,
31
+ decisionReason: req.decisionReason || "",
32
+ vendor: req.vendor,
33
+ };
34
+ },
35
+
36
+ requestFields: function (record) {
37
+ return {
38
+ toolName: record.toolName,
39
+ toolInput: record.toolInput,
40
+ decisionReason: record.decisionReason || "",
41
+ vendor: record.vendor,
42
+ };
43
+ },
44
+
45
+ decisions: Object.keys(DECISIONS),
46
+
47
+ parse: function (msg) {
48
+ // A page loaded before plan approval had its own kind offered "Allow for
49
+ // session" on every approval banner; for a plan that meant approve.
50
+ var requested = msg.decision === "allow_always" ? "allow" : msg.decision;
51
+ var decision = hasOwnKey(DECISIONS, requested) ? requested : "deny";
52
+ var out = { decision: decision };
53
+ if (decision === "deny_with_feedback") out.feedback = typeof msg.feedback === "string" ? msg.feedback : "";
54
+ if (decision === "allow_clear_context" && typeof msg.planContent === "string") out.planContent = msg.planContent;
55
+ return out;
56
+ },
57
+
58
+ outcome: function (record, response, opts) {
59
+ switch (response.decision) {
60
+ case "allow":
61
+ case "allow_accept_edits":
62
+ return toolCall.allow(record.toolInput);
63
+ case "allow_clear_context":
64
+ return toolCall.deny("User chose to clear context and restart");
65
+ case "deny_with_feedback":
66
+ return toolCall.deny(response.feedback || "User provided feedback");
67
+ default:
68
+ return toolCall.deny(opts.denyMessage || "User denied permission");
69
+ }
70
+ },
71
+
72
+ grantsSession: function () { return false; },
73
+
74
+ resolvedFields: function (response) {
75
+ return { decision: response.decision };
76
+ },
77
+
78
+ cancelled: toolCall.cancelled,
79
+ };