@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,39 @@
1
+ 'use strict';
2
+
3
+ // supervisor.js — is a service manager responsible for this daemon's lifetime?
4
+ //
5
+ // Under systemd the unit restarts the daemon after it exits (Restart=always),
6
+ // and KillMode=mixed removes every other process in the unit's cgroup when the
7
+ // main process exits. A daemon that spawned its own replacement before exiting
8
+ // therefore had the replacement killed with the rest of the cgroup, and the
9
+ // restart worked only because the unit started another one. A supervised
10
+ // restart is an exit with RESTART_EXIT_CODE and nothing else.
11
+
12
+ // Also the code the dev watcher (lib/cli/daemon-launch.js) respawns on.
13
+ var RESTART_EXIT_CODE = 120;
14
+
15
+ // Set by systemd for every process it starts as part of a unit.
16
+ var SUPERVISOR_ENV = ['INVOCATION_ID', 'NOTIFY_SOCKET'];
17
+
18
+ function isSupervised(env) {
19
+ var e = env || process.env;
20
+ return SUPERVISOR_ENV.some(function (name) { return !!e[name]; });
21
+ }
22
+
23
+ /**
24
+ * The environment for a daemon this process starts itself (the CLI's detached
25
+ * start, a self-spawned replacement). That daemon is not the unit's main
26
+ * process, so it must not read the unit's variables, which it would inherit
27
+ * when the CLI itself was run from inside a service.
28
+ */
29
+ function unsupervisedEnv(env) {
30
+ var copy = Object.assign({}, env || process.env);
31
+ SUPERVISOR_ENV.forEach(function (name) { delete copy[name]; });
32
+ return copy;
33
+ }
34
+
35
+ module.exports = {
36
+ RESTART_EXIT_CODE: RESTART_EXIT_CODE,
37
+ isSupervised: isSupervised,
38
+ unsupervisedEnv: unsupervisedEnv,
39
+ };
@@ -0,0 +1,108 @@
1
+ // turn-initiator.js - who started a turn, carried per turn from the entry point
2
+ // that created it to the agent adapter that delivers it.
3
+ //
4
+ // The initiator is a property of ONE turn, never of a session: a session can
5
+ // take a typed turn, then a scheduled one, then a typed one again. Each entry
6
+ // point (the WebSocket "message" handler, the scheduled-message timer, a Ralph
7
+ // loop iteration, an external trigger) names its initiator and passes it with
8
+ // the turn; an adapter maps it to the vendor's own provenance field. A turn
9
+ // whose entry point names none is delivered unstamped.
10
+ //
11
+ // This module owns the console-side vocabulary and the Claude mapping. Where a
12
+ // vendor carries provenance in a different place (the Codex adapter), the
13
+ // adapter maps from the same vocabulary.
14
+
15
+ var pkg = require("../package.json");
16
+ var runtimeEnv = require("./runtime-env");
17
+
18
+ var INITIATORS = Object.freeze({
19
+ // Text a person typed into the console.
20
+ HUMAN: "human",
21
+ // A message the console sent at the time the person scheduled it.
22
+ SCHEDULED: "scheduled",
23
+ // A scheduled message the person chose to send now.
24
+ SCHEDULED_NOW: "scheduled-now",
25
+ // One iteration of an automated loop.
26
+ LOOP: "loop",
27
+ // A turn delivered by an external trigger.
28
+ TRIGGER: "trigger",
29
+ });
30
+
31
+ var KNOWN = Object.keys(INITIATORS).map(function (k) { return INITIATORS[k]; });
32
+
33
+ function isInitiator(value) {
34
+ return KNOWN.indexOf(value) !== -1;
35
+ }
36
+
37
+ // The Claude Agent SDK's SDKMessageOrigin for a turn. Undefined when the turn
38
+ // names no initiator: the SDK treats an absent origin as unattributed, so only
39
+ // a turn the console knows the source of is stamped.
40
+ function claudeOrigin(initiator) {
41
+ switch (initiator) {
42
+ case INITIATORS.HUMAN:
43
+ return { kind: "human" };
44
+ case INITIATORS.SCHEDULED:
45
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "scheduled" };
46
+ case INITIATORS.SCHEDULED_NOW:
47
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "manual" };
48
+ case INITIATORS.LOOP:
49
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "loop" };
50
+ case INITIATORS.TRIGGER:
51
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "trigger" };
52
+ default:
53
+ return undefined;
54
+ }
55
+ }
56
+
57
+ // Whether the CLI must deliver the turn's text as written (no @path expansion,
58
+ // no slash-command dispatch): true for every turn a person did not type.
59
+ function isClientComposed(initiator) {
60
+ return isInitiator(initiator) && initiator !== INITIATORS.HUMAN;
61
+ }
62
+
63
+ // The CLI keeps a host-declared origin only when it is human, or the
64
+ // scheduled-trigger kind in a process started with this variable. Every
65
+ // automated turn uses the latter, so a process whose first turn is anything but
66
+ // a typed one gets it.
67
+ function isScheduledInitiator(initiator) {
68
+ return isClientComposed(initiator);
69
+ }
70
+
71
+ // Identifies this product to the Claude Agent SDK ("<app>/<version>").
72
+ function clientAppId() {
73
+ return "clagentic-console/" + pkg.version;
74
+ }
75
+
76
+ // The environment additions the console always makes for a Claude process.
77
+ // Laid over the process's own environment by the caller, never in place of it.
78
+ function claudeHostEnv(initiator) {
79
+ var env = { CLAUDE_AGENT_SDK_CLIENT_APP: clientAppId() };
80
+ if (isScheduledInitiator(initiator)) env.CLAUDE_CODE_HOST_SCHEDULED_RUN = "1";
81
+ return env;
82
+ }
83
+
84
+ // The complete environment for a Claude process: the process's own, then the
85
+ // Settings overlay, then the console's additions. The SDK replaces the CLI's
86
+ // environment with options.env, so this is always the whole environment.
87
+ function claudeProcessEnv(base, overlay, initiator) {
88
+ return Object.assign(runtimeEnv.composeRuntimeEnv(base, overlay), claudeHostEnv(initiator));
89
+ }
90
+
91
+ // A streamed Claude user message for a turn, with its provenance stamped.
92
+ function stampClaudeUserMessage(message, initiator) {
93
+ var origin = claudeOrigin(initiator);
94
+ if (origin) message.origin = origin;
95
+ if (isClientComposed(initiator)) message.client_composed = true;
96
+ return message;
97
+ }
98
+
99
+ module.exports = {
100
+ INITIATORS: INITIATORS,
101
+ isInitiator: isInitiator,
102
+ claudeOrigin: claudeOrigin,
103
+ isClientComposed: isClientComposed,
104
+ clientAppId: clientAppId,
105
+ claudeHostEnv: claudeHostEnv,
106
+ claudeProcessEnv: claudeProcessEnv,
107
+ stampClaudeUserMessage: stampClaudeUserMessage,
108
+ };
@@ -65,16 +65,19 @@ function attachPermissions(deps) {
65
65
 
66
66
  function canAccessProject(userId, project) {
67
67
  if (!project) return false;
68
- // Public projects are accessible to all authenticated users
69
- if (!project.visibility || project.visibility === "public") return true;
70
- // Admin always has access
71
- var user = findUserById(userId);
72
- if (user && user.role === "admin") return true;
68
+ // Only an explicit "public" opens a project to every authenticated user.
69
+ // A record with no (or an unrecognised) visibility is treated as private
70
+ // so a missing field can never widen access.
71
+ if (project.visibility === "public") return true;
73
72
  // Owner always has access to their own project
74
73
  if (project.ownerId && project.ownerId === userId) return true;
75
74
  // Private project -- check allowedUsers
76
75
  var allowed = project.allowedUsers || [];
77
- return allowed.indexOf(userId) >= 0;
76
+ if (allowed.indexOf(userId) >= 0) return true;
77
+ // Admin always has access. Checked last: it reads the user store, and
78
+ // this runs for every message a connection sends.
79
+ var user = findUserById(userId);
80
+ return !!(user && user.role === "admin");
78
81
  }
79
82
 
80
83
  function getAccessibleProjects(userId, projects) {
package/lib/users.js CHANGED
@@ -140,6 +140,14 @@ function hasAdmin() {
140
140
  return !!findAdmin();
141
141
  }
142
142
 
143
+ // The daemon's mode, as stored with the users. An install that predates the
144
+ // flag, or whose file is absent, is multi-user (see loadUsers); only an
145
+ // explicit false marks a single-user install. A read error propagates so the
146
+ // caller can treat "mode unknown" as the stricter mode.
147
+ function isMultiUser() {
148
+ return loadUsers().multiUser !== false;
149
+ }
150
+
143
151
  function findUserById(id) {
144
152
  var data = loadUsers();
145
153
  for (var i = 0; i < data.users.length; i++) {
@@ -438,6 +446,7 @@ module.exports = {
438
446
  createAdmin: createAdmin,
439
447
  findAdmin: findAdmin,
440
448
  hasAdmin: hasAdmin,
449
+ isMultiUser: isMultiUser,
441
450
  findUserById: findUserById,
442
451
  findUserByEmail: findUserByEmail,
443
452
  authenticateUser: authenticateUser,
package/lib/utils.js CHANGED
@@ -67,10 +67,12 @@ function resolveEncodedFile(baseDir, cwd, ext) {
67
67
  *
68
68
  * Keeps only entries whose key is a string and whose value is strictly
69
69
  * boolean `true`; drops everything else. A non-object input (including
70
- * null/undefined/arrays) yields {} rather than throwing.
70
+ * null/undefined/arrays) yields an empty map rather than throwing. The map
71
+ * has no prototype: its keys are tool names, and a name like "constructor"
72
+ * must not be found as an inherited entry.
71
73
  */
72
74
  function sanitizeAllowedTools(value) {
73
- var out = {};
75
+ var out = Object.create(null);
74
76
  if (!value || typeof value !== "object" || Array.isArray(value)) return out;
75
77
  for (var key in value) {
76
78
  if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
@@ -0,0 +1,22 @@
1
+ // vendor-auth.js - the "not logged in" facts for one agent, read from the YOKE
2
+ // registry so the title and the login command are written once and every
3
+ // surface (chat message, notification, terminal launcher) agrees.
4
+
5
+ var registry = require("./yoke").registry;
6
+
7
+ /**
8
+ * @param {string} vendor a registered vendor id
9
+ * @returns {{vendor: string, displayName: string, title: string, loginCommand: string}}
10
+ * @throws {Error} code YOKE_UNKNOWN_VENDOR when the vendor is not registered
11
+ */
12
+ function authRequiredFacts(vendor) {
13
+ var descriptor = registry.get(vendor);
14
+ return {
15
+ vendor: descriptor.id,
16
+ displayName: descriptor.displayName,
17
+ title: descriptor.displayName + " is not logged in.",
18
+ loginCommand: descriptor.loginCommand,
19
+ };
20
+ }
21
+
22
+ module.exports = { authRequiredFacts: authRequiredFacts };
@@ -0,0 +1,66 @@
1
+ // vendor-registry-message.js - the agent registry as the browser receives it:
2
+ // every registered agent with its display data, whether it is installed, the
3
+ // login command and the capabilities its controls are gated on. The agent
4
+ // picker and every capability-gated control render from this message, so a
5
+ // newly registered agent appears without a front-end change.
6
+ //
7
+ // Install state belongs to an OS identity: what is on one user's PATH says
8
+ // nothing about another's. The session manager keeps it per identity
9
+ // (installStateByUser, keyed by Linux user name, "" for the daemon account).
10
+
11
+ var registry = require("./yoke").registry;
12
+
13
+ var DAEMON_IDENTITY_KEY = "";
14
+
15
+ /**
16
+ * Records what an install lookup found for one OS identity.
17
+ * @param {object} sm
18
+ * @param {?string} linuxUser null for the daemon's own account
19
+ * @param {{installed: string[], failures: object}} state
20
+ */
21
+ function recordInstallState(sm, linuxUser, state) {
22
+ sm.installStateByUser = sm.installStateByUser || {};
23
+ sm.installStateByUser[linuxUser || DAEMON_IDENTITY_KEY] = state;
24
+ if (!linuxUser) sm.installedVendors = state.installed;
25
+ }
26
+
27
+ /**
28
+ * What is known about installed agents for an OS identity. An identity not
29
+ * looked up yet gets the project-wide list from the last warm-up.
30
+ * @param {object} sm
31
+ * @param {?string} linuxUser
32
+ * @returns {{installed: string[], failures: object}}
33
+ */
34
+ function installStateFor(sm, linuxUser) {
35
+ var byUser = sm.installStateByUser || {};
36
+ var key = linuxUser || DAEMON_IDENTITY_KEY;
37
+ if (Object.prototype.hasOwnProperty.call(byUser, key)) return byUser[key];
38
+ return { installed: sm.installedVendors || [], failures: {} };
39
+ }
40
+
41
+ /**
42
+ * @param {object} sm the session manager (installedVendors, availableVendors,
43
+ * capabilitiesByVendor, installStateByUser)
44
+ * @param {?string} [linuxUser] the OS identity the message is for
45
+ * @returns {{type: string, vendors: object[], reasons: object}}
46
+ */
47
+ function buildVendorRegistryMessage(sm, linuxUser) {
48
+ var state = installStateFor(sm, linuxUser);
49
+ return {
50
+ type: "vendor_registry",
51
+ vendors: registry.describeForClient({
52
+ installed: state.installed,
53
+ probeFailures: state.failures,
54
+ details: state.details,
55
+ available: sm.availableVendors || [],
56
+ capabilities: sm.capabilitiesByVendor || {},
57
+ }),
58
+ reasons: registry.capabilityReasons(),
59
+ };
60
+ }
61
+
62
+ module.exports = {
63
+ buildVendorRegistryMessage: buildVendorRegistryMessage,
64
+ recordInstallState: recordInstallState,
65
+ installStateFor: installStateFor,
66
+ };
@@ -0,0 +1,99 @@
1
+ // WebSocket upgrade origin check (defence in depth against cross-site
2
+ // WebSocket hijacking; every upgrade must also carry a valid login).
3
+ //
4
+ // Rules:
5
+ // - No Origin header: a non-browser client (CLI, relay, MCP bridge). Allowed;
6
+ // the login still applies.
7
+ // - An Origin on the operator's allowedOrigins list: allowed.
8
+ // - Otherwise the Origin's host AND port must equal those of the request's
9
+ // Host header (or, only when the operator declared a trusted proxy, of its
10
+ // X-Forwarded-Host). A bare port match is not enough: a sibling
11
+ // subdomain that is served on the same port is a different origin.
12
+ // - Scheme is compared only where the daemon knows it: it terminates TLS
13
+ // itself (https required), or a trusted proxy reported it
14
+ // (X-Forwarded-Proto). Behind an unconfigured TLS-terminating proxy the
15
+ // scheme the daemon sees is not the browser's, so it is not compared; the
16
+ // origin's own scheme only supplies the default port.
17
+ // - Any Origin that is not a parsable http(s) origin (including "null" and
18
+ // extension origins such as chrome-extension://...) is refused unless it
19
+ // is on the allowed list.
20
+
21
+ function parseOrigin(value) {
22
+ try {
23
+ var url = new URL(value);
24
+ if (url.protocol !== "http:" && url.protocol !== "https:") return null;
25
+ return url;
26
+ } catch (e) {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ function defaultPort(protocol) {
32
+ return protocol === "https:" ? "443" : "80";
33
+ }
34
+
35
+ // "scheme://host:port" with the default port made explicit and the host
36
+ // lower-cased, or null when value is not an http(s) origin.
37
+ function normalizeOrigin(value) {
38
+ var url = parseOrigin(value);
39
+ if (!url) return null;
40
+ return url.protocol + "//" + url.hostname + ":" + (url.port || defaultPort(url.protocol));
41
+ }
42
+
43
+ function hostMatches(originUrl, hostHeader) {
44
+ if (!hostHeader) return false;
45
+ var hostUrl;
46
+ try {
47
+ hostUrl = new URL(originUrl.protocol + "//" + hostHeader);
48
+ } catch (e) {
49
+ return false;
50
+ }
51
+ var originPort = originUrl.port || defaultPort(originUrl.protocol);
52
+ var hostPort = hostUrl.port || defaultPort(originUrl.protocol);
53
+ return originUrl.hostname === hostUrl.hostname && originPort === hostPort;
54
+ }
55
+
56
+ function firstValue(header) {
57
+ if (typeof header !== "string") return "";
58
+ return header.split(",")[0].trim();
59
+ }
60
+
61
+ // o: { headers, tls, trustedProxy, allowedOrigins }
62
+ // Returns { ok: boolean, reason?: string }.
63
+ function checkWsOrigin(o) {
64
+ var headers = o.headers || {};
65
+ var origin = headers.origin;
66
+ if (origin === undefined || origin === "") return { ok: true };
67
+ if (typeof origin !== "string") return { ok: false, reason: "malformed origin" };
68
+
69
+ var allowed = Array.isArray(o.allowedOrigins) ? o.allowedOrigins : [];
70
+ var normalized = normalizeOrigin(origin);
71
+ for (var i = 0; i < allowed.length; i++) {
72
+ if (typeof allowed[i] !== "string") continue;
73
+ // Non-http(s) entries (extension origins) are compared as written.
74
+ if (allowed[i] === origin) return { ok: true };
75
+ if (normalized && normalizeOrigin(allowed[i]) === normalized) return { ok: true };
76
+ }
77
+
78
+ var originUrl = parseOrigin(origin);
79
+ if (!originUrl) return { ok: false, reason: "origin is not an http(s) origin" };
80
+
81
+ var hostOk = hostMatches(originUrl, headers.host);
82
+ if (!hostOk && o.trustedProxy) {
83
+ hostOk = hostMatches(originUrl, firstValue(headers["x-forwarded-host"]));
84
+ }
85
+ if (!hostOk) return { ok: false, reason: "origin host does not match the request host" };
86
+
87
+ var knownScheme = null;
88
+ if (o.tls) knownScheme = "https:";
89
+ else if (o.trustedProxy) {
90
+ var forwardedProto = firstValue(headers["x-forwarded-proto"]).toLowerCase();
91
+ if (forwardedProto === "https" || forwardedProto === "http") knownScheme = forwardedProto + ":";
92
+ }
93
+ if (knownScheme && originUrl.protocol !== knownScheme) {
94
+ return { ok: false, reason: "origin scheme does not match the connection" };
95
+ }
96
+ return { ok: true };
97
+ }
98
+
99
+ module.exports = { checkWsOrigin: checkWsOrigin };
package/lib/ws-schema.js CHANGED
@@ -78,7 +78,9 @@ var schema = {
78
78
  // were live, sent types with no documentation entry.
79
79
  "plan_content": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Plan-mode content for the plan card" },
80
80
  "sdk_notification": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Informational notification surfaced from the vendor SDK" },
81
- "diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings)" },
81
+ "diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings). A message with refresh:true updates the entry the client already holds for the same source and action, and is ignored when the client holds none" },
82
+
83
+ "diagnostic_retract": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Withdraws every diagnostic of one source (source) because its condition no longer holds; sent when the installed build is adopted while an update offer is shown, and to a client that connects while no offer stands" },
82
84
 
83
85
  // -----------------------------------------------------------------------
84
86
  // Thinking
@@ -113,27 +115,36 @@ var schema = {
113
115
  "task_updated": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Background task status/description patch" },
114
116
 
115
117
  // -----------------------------------------------------------------------
116
- // Permissions
117
- // -----------------------------------------------------------------------
118
- "permission_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Tool permission request from assistant" },
119
- "permission_request_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Permission request that was pending when client connected" },
120
- "permission_response": { direction: "c2s", handler: "lib/project-sessions.js", description: "User response to a permission request" },
121
- "permission_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Permission request resolved" },
122
- "permission_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Permission request cancelled (e.g. interrupted)" },
123
-
124
- // -----------------------------------------------------------------------
125
- // Ask user (interactive input)
126
- // -----------------------------------------------------------------------
118
+ // Operator prompts: one shape for every kind (lib/prompt-registry.js).
119
+ // kind is permission, plan, ask_user or elicitation; the kind's own fields
120
+ // ride flat on the message (permission/plan: toolName, toolInput,
121
+ // decisionReason, vendor, and for permission the SDK's hints when set:
122
+ // suppressAlwaysAllowRule, defaultToNo, matchedAskRule; ask_user: input; elicitation: serverName,
123
+ // message, mode, url, elicitationId, requestedSchema).
124
+ // -----------------------------------------------------------------------
125
+ "prompt_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt awaits the operator: {requestId, kind, toolUseId, ...kind fields}. On history replay it carries promptState {state: pending|resolved|cancelled, decision|answers|skipped|action, reason}, the server's authoritative state for the prompt at replay time" },
126
+ "prompt_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt still awaiting the operator, re-presented on connect and session switch; same fields as prompt_request" },
127
+ "prompt_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "The operator's answer: {requestId, kind, ...} with decision (+ feedback, planContent) for permission/plan, answers or decision:\"skip\" for ask_user (answers keyed by question index; each a label or text, or for a multi-select question the list of chosen labels), action (+ content, held to the requested schema) for elicitation. The kind is required and must match the prompt's. Decision allow_always to a permission prompt that carries suppressAlwaysAllowRule settles nothing: the prompt is sent again as prompt_pending. A prompt of the extension kind is never answered this way" },
128
+ "prompt_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt was answered: {requestId, kind, decision|answers|skipped|action}; a permission prompt forced by a user ask rule also carries matchedAskRule" },
129
+ "prompt_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt ended without an answer: {requestId, kind, reason}; reason is aborted, expired, turn_ended, query_ended, rewind, cleared or shutdown. Reason \"stale\" is sent only to a client whose prompt_response named a prompt the server no longer holds, and is not recorded in history" },
130
+
131
+ // Aliases kept for compatibility: the s2c types appear in history recorded
132
+ // before prompts had one shape (the client maps them onto the prompt_*
133
+ // handlers), and the c2s types are still accepted from a page loaded
134
+ // before an upgrade. Nothing records or sends the s2c aliases any more,
135
+ // except permission_cancel {reason: "stale"} in reply to a
136
+ // permission_response.
137
+ "permission_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_request (kind permission or plan); history carries permissionState or promptState" },
138
+ "permission_request_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_pending (kind permission or plan)" },
139
+ "permission_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "Alias of prompt_response for kinds permission and plan: {requestId, decision, feedback, planContent}" },
140
+ "permission_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_resolved (kind permission or plan)" },
141
+ "permission_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_cancel (kind permission or plan); the stale reply to a permission_response" },
127
142
  "ask_user": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Assistant is requesting user input via ask_user tool" },
128
- "ask_user_response": { direction: "c2s", handler: "lib/project-sessions.js", description: "User reply to an ask_user request" },
129
- "ask_user_answered": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Confirmation that ask_user was answered" },
130
-
131
- // -----------------------------------------------------------------------
132
- // Elicitation
133
- // -----------------------------------------------------------------------
134
- "elicitation_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Structured form elicitation request from assistant" },
135
- "elicitation_response": { direction: "c2s", handler: "lib/project-sessions.js", description: "User response to an elicitation form" },
136
- "elicitation_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Elicitation request resolved" },
143
+ "ask_user_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "Alias of prompt_response for kind ask_user: {toolId, answers}; toolId is the prompt's requestId" },
144
+ "ask_user_answered": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_resolved (kind ask_user) keyed by toolId; without answers, the question ended unanswered" },
145
+ "elicitation_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_request (kind elicitation)" },
146
+ "elicitation_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "Alias of prompt_response for kind elicitation: {requestId, action, content}" },
147
+ "elicitation_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_resolved (kind elicitation)" },
137
148
 
138
149
  // -----------------------------------------------------------------------
139
150
  // Stop / control
@@ -186,6 +197,8 @@ var schema = {
186
197
  "set_project_default_betas": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set and persist the project default beta flags" },
187
198
  "set_thinking": { direction: "c2s", handler: "lib/project-sessions.js", description: "Set thinking mode and budget" },
188
199
  "model_info": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Current model and available models list" },
200
+ "vendor_registry": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Every registered agent with display data, install state, login command and capabilities; the agent picker and capability-gated controls render from it" },
201
+ "recheck_vendors": { direction: "c2s", handler: "lib/project-sessions.js", description: "Look again for installed agents and broadcast the vendor registry" },
189
202
  "config_state": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Full config state: model, mode, effort, betas, thinking" },
190
203
  "slash_commands": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Available slash commands list" },
191
204
  "fast_mode_state": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Fast mode toggle state" },
@@ -375,8 +388,8 @@ var schema = {
375
388
  // Browser extension
376
389
  // -----------------------------------------------------------------------
377
390
  "browser_tab_list": { direction: "c2s", handler: "lib/project-user-message.js", description: "Provide browser tab list from the extension" },
378
- "extension_result": { direction: "c2s", handler: "lib/project-user-message.js", description: "Result from a browser extension command" },
379
- "extension_command": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Command for the browser extension to execute" },
391
+ "extension_result": { direction: "c2s", handler: "lib/project-user-message.js", description: "Result from a browser extension command; answers the extension-kind prompt named by requestId (lib/prompt-registry.js)" },
392
+ "extension_command": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Command for the browser extension to execute; an unanswered command resolves to null after its timeout" },
380
393
  "clay_ext_tab_list": { direction: "s2c", handler: "lib/public/modules/app-misc.js", description: "Browser tab list from the extension (broadcast)" },
381
394
  "clay_ext_result": { direction: "s2c", handler: "lib/public/modules/app-misc.js", description: "Browser extension command result (broadcast)" },
382
395
  "clay_ext_command": { direction: "c2s", handler: "lib/public/modules/app-misc.js", description: "Send a command to the browser extension" },
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ // What a Claude session can do, as the client sees it (sent with
4
+ // session_switched), and the declaration the Claude adapter registers. Every
5
+ // key is one of the YOKE capability ledger (lib/yoke/interface.js).
6
+ // permissionModes names the SDK permission modes the session accepts through
7
+ // setPermissionMode: the mode picker offers dontAsk and auto only for a vendor
8
+ // that lists them, so a vendor that cannot run one never shows it.
9
+
10
+ var PERMISSION_MODES = ["default", "plan", "acceptEdits", "dontAsk", "auto"];
11
+
12
+ function claudeCapabilities() {
13
+ return {
14
+ thinking: true,
15
+ betas: true,
16
+ effort: true,
17
+ rewind: true,
18
+ fork: true,
19
+ rollback: false,
20
+ sessionResume: true,
21
+ sessionList: true,
22
+ sessionRename: true,
23
+ sessionArchive: false,
24
+ promptSuggestions: true,
25
+ elicitation: true,
26
+ fileCheckpointing: true,
27
+ contextCompacting: true,
28
+ mcpPanel: true,
29
+ backgroundTasks: true,
30
+ steering: true,
31
+ agentInjection: true,
32
+ executionPolicy: false,
33
+ toolPolicy: ["ask", "allow-all"],
34
+ permissionModes: PERMISSION_MODES.slice(),
35
+ };
36
+ }
37
+
38
+ module.exports = { claudeCapabilities: claudeCapabilities, PERMISSION_MODES: PERMISSION_MODES };
@@ -0,0 +1,34 @@
1
+ // Registers the Claude Code vendor with the YOKE registry.
2
+ //
3
+ // Kept apart from claude.js on purpose: that module does work when it is first
4
+ // loaded (it opens up the package directory for OS-user workers), so merely
5
+ // asking the registry which agents exist must not load it. The adapter module is
6
+ // required only when an adapter is actually created.
7
+
8
+ var registry = require("../registry");
9
+ var authChecks = require("../auth-checks");
10
+ var providerCredentials = require("../provider-credentials");
11
+ var claudeCapabilities = require("./claude-capabilities").claudeCapabilities;
12
+
13
+ registry.register({
14
+ id: "claude",
15
+ displayName: "Claude Code",
16
+ icon: "/claude-code-avatar.png",
17
+ priority: 10,
18
+ binaryNames: ["claude"],
19
+ probeInstalled: function(ctx) { return ctx.lookupBinary("claude"); },
20
+ checkAuth: authChecks.checkClaudeAuth,
21
+ installHint: "Install Claude Code (npm install -g @anthropic-ai/claude-code), then sign in.",
22
+ loginCommand: "claude login",
23
+ osUsersSupported: true,
24
+ needsRuntimeEnv: false,
25
+ perProjectRuntime: false,
26
+ activityTokens: false,
27
+ ownedEnvNames: ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN"].concat(providerCredentials.allCredentialNames()),
28
+ ownedEnvPrefixes: providerCredentials.allCredentialPrefixes(),
29
+ credentialGroups: providerCredentials.CREDENTIAL_GROUPS,
30
+ nativeInstructionFiles: ["CLAUDE.md"],
31
+ interruptMessage: "Interrupted · What should Claude do instead?",
32
+ capabilities: claudeCapabilities(),
33
+ createAdapter: function(opts) { return require("./claude").createClaudeAdapter(opts); },
34
+ });