@clagentic/console 1.12.0-beta.1 → 1.12.0-beta.3

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 (161) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/README.md +1 -0
  3. package/bin/cli.js +5 -2
  4. package/lib/agent-roster-ws.js +84 -0
  5. package/lib/agent-roster.js +312 -0
  6. package/lib/auth-required-notify.js +42 -0
  7. package/lib/build-changes.js +8 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-notify.js +45 -0
  10. package/lib/build-update-offer.js +34 -11
  11. package/lib/build-update-standing.js +34 -14
  12. package/lib/claude-settings-env.js +142 -0
  13. package/lib/cli/duration.js +27 -0
  14. package/lib/cli/schedule-input-subcommands.js +1 -22
  15. package/lib/cli/session-subcommands.js +60 -11
  16. package/lib/client-address.js +44 -0
  17. package/lib/daemon.js +31 -10
  18. package/lib/idle-compaction-setting.js +203 -0
  19. package/lib/mcp-bridge-credential.js +41 -0
  20. package/lib/notification-prefs.js +18 -22
  21. package/lib/notify/core.js +210 -0
  22. package/lib/notify/index.js +31 -0
  23. package/lib/notify/live-prompts.js +36 -0
  24. package/lib/notify/payload.js +62 -0
  25. package/lib/notify/target.js +5 -0
  26. package/lib/notify/type-registry.js +81 -0
  27. package/lib/notify/types.js +57 -0
  28. package/lib/open-sockets.js +27 -0
  29. package/lib/outbound-access.js +85 -0
  30. package/lib/outbound-entry.js +116 -0
  31. package/lib/outbound-ledger.js +306 -0
  32. package/lib/outbound-query.js +153 -0
  33. package/lib/pending-prompts.js +31 -16
  34. package/lib/project-connection.js +48 -8
  35. package/lib/project-filesystem.js +43 -5
  36. package/lib/project-http.js +9 -1
  37. package/lib/project-loop.js +38 -26
  38. package/lib/project-notifications.js +122 -39
  39. package/lib/project-prompt-responses.js +1 -1
  40. package/lib/project-sessions.js +11 -1
  41. package/lib/project-user-mention.js +22 -34
  42. package/lib/project-user-message.js +208 -4
  43. package/lib/project-user-shell.js +298 -0
  44. package/lib/project.js +41 -5
  45. package/lib/prompt-answer.js +145 -0
  46. package/lib/prompt-expiry.js +50 -0
  47. package/lib/prompt-registry.js +98 -25
  48. package/lib/prompt-reminders.js +38 -33
  49. package/lib/prompt-source.js +59 -8
  50. package/lib/public/app.js +32 -2
  51. package/lib/public/css/agent-messages.css +96 -0
  52. package/lib/public/css/agent-roster.css +93 -0
  53. package/lib/public/css/diagnostics.css +29 -1
  54. package/lib/public/css/home-hub.css +12 -0
  55. package/lib/public/css/icon-strip.css +9 -0
  56. package/lib/public/css/input.css +20 -141
  57. package/lib/public/css/login-panel.css +73 -0
  58. package/lib/public/css/menus.css +2 -2
  59. package/lib/public/css/mobile-nav.css +11 -0
  60. package/lib/public/css/sidebar.css +18 -0
  61. package/lib/public/css/team-panel.css +1 -6
  62. package/lib/public/css/team-view.css +101 -0
  63. package/lib/public/css/title-bar.css +10 -0
  64. package/lib/public/css/user-shell.css +144 -0
  65. package/lib/public/index.html +44 -7
  66. package/lib/public/modules/activity-state.js +20 -4
  67. package/lib/public/modules/agent-avatar-picker.js +162 -0
  68. package/lib/public/modules/agent-avatar.js +153 -0
  69. package/lib/public/modules/agent-messages.js +285 -0
  70. package/lib/public/modules/agent-roster.js +157 -0
  71. package/lib/public/modules/app-connection.js +34 -5
  72. package/lib/public/modules/app-messages.js +55 -16
  73. package/lib/public/modules/app-notifications.js +104 -75
  74. package/lib/public/modules/app-panels.js +26 -3
  75. package/lib/public/modules/app-projects.js +3 -1
  76. package/lib/public/modules/app-rate-limit.js +8 -165
  77. package/lib/public/modules/app-rendering.js +32 -7
  78. package/lib/public/modules/build-update-sessions.js +81 -0
  79. package/lib/public/modules/collapsible-text.js +33 -18
  80. package/lib/public/modules/compaction-state.js +34 -0
  81. package/lib/public/modules/custom-icons.js +23 -5
  82. package/lib/public/modules/diagnostics.js +61 -57
  83. package/lib/public/modules/env-shadow-notice.js +34 -0
  84. package/lib/public/modules/injected-identity.js +24 -21
  85. package/lib/public/modules/input.js +176 -15
  86. package/lib/public/modules/login-panel.js +136 -0
  87. package/lib/public/modules/login-parser.js +73 -0
  88. package/lib/public/modules/login-tab.js +66 -0
  89. package/lib/public/modules/notifications.js +9 -1
  90. package/lib/public/modules/notify-client.js +246 -0
  91. package/lib/public/modules/pending-term-request.js +30 -0
  92. package/lib/public/modules/project-icon.js +22 -2
  93. package/lib/public/modules/project-settings.js +5 -0
  94. package/lib/public/modules/prompt-state.js +3 -3
  95. package/lib/public/modules/prompts.js +1 -1
  96. package/lib/public/modules/queued-button.js +11 -0
  97. package/lib/public/modules/scheduled-input-actions.js +12 -4
  98. package/lib/public/modules/scheduled-outbox.js +230 -0
  99. package/lib/public/modules/send-now.js +200 -0
  100. package/lib/public/modules/server-settings.js +50 -1
  101. package/lib/public/modules/shell-card.js +76 -0
  102. package/lib/public/modules/shell-line.js +49 -0
  103. package/lib/public/modules/shell-queue.js +253 -0
  104. package/lib/public/modules/shell-settings-controls.js +76 -0
  105. package/lib/public/modules/sidebar-mobile.js +3 -3
  106. package/lib/public/modules/sidebar-sessions.js +8 -0
  107. package/lib/public/modules/sidebar-users.js +5 -7
  108. package/lib/public/modules/team-panel.js +30 -88
  109. package/lib/public/modules/team-view.js +211 -0
  110. package/lib/public/modules/terminal-links.js +193 -0
  111. package/lib/public/modules/terminal.js +84 -107
  112. package/lib/public/modules/tools.js +19 -0
  113. package/lib/public/modules/user-shell.js +824 -0
  114. package/lib/public/notify-sw-logic.js +252 -0
  115. package/lib/public/notify-target.js +157 -0
  116. package/lib/public/style.css +5 -0
  117. package/lib/public/sw.js +20 -69
  118. package/lib/push.js +63 -19
  119. package/lib/queued-chat.js +392 -0
  120. package/lib/runtime-env.js +1 -0
  121. package/lib/scheduled-input/ws.js +67 -9
  122. package/lib/sdk-bridge.js +184 -73
  123. package/lib/sdk-message-processor.js +124 -76
  124. package/lib/server-auth.js +6 -4
  125. package/lib/server-dm.js +11 -20
  126. package/lib/server-settings.js +39 -1
  127. package/lib/server.js +112 -16
  128. package/lib/session-directory.js +39 -12
  129. package/lib/session-end.js +97 -0
  130. package/lib/session-input-ipc.js +37 -1
  131. package/lib/session-input.js +263 -21
  132. package/lib/session-liveness.js +53 -0
  133. package/lib/session-reclaim.js +37 -2
  134. package/lib/session-resume.js +1 -0
  135. package/lib/session-settings-file.js +53 -0
  136. package/lib/sessions.js +80 -9
  137. package/lib/team-traffic-ws.js +68 -0
  138. package/lib/team-traffic.js +318 -0
  139. package/lib/usage-store.js +36 -7
  140. package/lib/user-shell-settings.js +105 -0
  141. package/lib/vendor-auth.js +33 -2
  142. package/lib/ws-schema.js +33 -5
  143. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  144. package/lib/yoke/adapters/claude-vendor.js +17 -1
  145. package/lib/yoke/adapters/claude-worker.js +39 -11
  146. package/lib/yoke/adapters/claude.js +225 -6
  147. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  148. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  149. package/lib/yoke/adapters/codex-vendor.js +7 -0
  150. package/lib/yoke/adapters/codex.js +186 -52
  151. package/lib/yoke/auth-checks.js +17 -2
  152. package/lib/yoke/codex-app-server.js +8 -2
  153. package/lib/yoke/index.js +21 -3
  154. package/lib/yoke/interface.js +54 -1
  155. package/lib/yoke/mcp-bridge-server.js +12 -8
  156. package/lib/yoke/provider-credentials.js +24 -0
  157. package/lib/yoke/registry.js +40 -1
  158. package/lib/yoke/user-shell.js +224 -0
  159. package/package.json +2 -2
  160. package/scripts/check-test-count.js +14 -0
  161. package/lib/public/modules/build-notice-gate.js +0 -73
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ // The record the page checks a shown prompt notification against: which
4
+ // prompts of a project await the operator right now, as seen by one viewer.
5
+ // Ids only, never prompt content. It is what makes every persistent
6
+ // close-on-resolve type verifiable on the page, including those with no banner
7
+ // (ask_user, elicitation).
8
+
9
+ var { audienceFor } = require("../push-audience");
10
+
11
+ /**
12
+ * @param {object} deps
13
+ * @param {string} deps.slug the project the sessions belong to.
14
+ * @param {{forEach: function}} deps.sessions the project's sessions.
15
+ * @param {{pendingInfo: function}} deps.prompts the project's prompt registry.
16
+ * @param {?string} deps.viewerId the connecting user, if any.
17
+ * @param {function(): boolean} [deps.isMultiUser] see push-audience.audienceFor.
18
+ * @param {function(): string[]} [deps.listAdmins] see push-audience.audienceFor.
19
+ * @returns {{slug: string, at: number, items: Array<{sessionId: string, requestId: string, toolUseId: ?string}>}}
20
+ * at is the server time of the snapshot: a notification sent after it is not
21
+ * judged by it.
22
+ */
23
+ function snapshotLivePrompts(deps) {
24
+ var items = [];
25
+ deps.sessions.forEach(function (session) {
26
+ // Only prompts the viewer would have been pushed.
27
+ var audience = audienceFor(session.ownerId || null, deps.isMultiUser, deps.listAdmins);
28
+ if (audience.kind !== "broadcast" && audience.userIds.indexOf(deps.viewerId) === -1) return;
29
+ deps.prompts.pendingInfo(session).forEach(function (info) {
30
+ items.push({ sessionId: String(session.localId), requestId: info.requestId, toolUseId: info.toolUseId || null });
31
+ });
32
+ });
33
+ return { slug: deps.slug, at: Date.now(), items: items };
34
+ }
35
+
36
+ module.exports = { snapshotLivePrompts: snapshotLivePrompts };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ // Builds the wire payloads. The tag is derived here and nowhere else: from the
4
+ // type's collapse rule and the target key, so two notifications for the same
5
+ // target share a tag (the platform replaces, never stacks) and different
6
+ // targets never do.
7
+
8
+ var target = require("./target");
9
+
10
+ // Marks a payload the generic service worker handles from its own fields. A
11
+ // payload without it is not shown.
12
+ var CORE_MARK = 1;
13
+ var CLOSE_TYPE = "notify_close";
14
+
15
+ function tagFor(type, t) {
16
+ return target.tagFor(type.name, type.collapse, t);
17
+ }
18
+
19
+ /**
20
+ * @param {object} type a registered type.
21
+ * @param {object} t a normalised target.
22
+ * @param {{title: string, body: string}} content
23
+ */
24
+ function buildPayload(type, t, content) {
25
+ var text = type.format(content || {});
26
+ return {
27
+ core: CORE_MARK,
28
+ type: type.name,
29
+ title: text.title,
30
+ body: text.body,
31
+ target: t,
32
+ tag: tagFor(type, t),
33
+ collapse: type.collapse,
34
+ url: target.urlForTarget(t),
35
+ requireInteraction: type.persistent,
36
+ renotify: type.renotify,
37
+ liveInState: type.liveInState,
38
+ // Server time of the send: the page's reconcile only judges a notification
39
+ // sent before the state snapshot it checks against.
40
+ sentAt: Date.now(),
41
+ };
42
+ }
43
+
44
+ /**
45
+ * The push that closes a shown notification. It names the type it closes so
46
+ * the push filter applies that type's preference: a device never told of the
47
+ * notification is not told of its closing.
48
+ * @param {object} type a type of the category being closed.
49
+ * @param {string|string[]} tags the tag or tags to close.
50
+ */
51
+ function buildClose(type, tags) {
52
+ return {
53
+ core: CORE_MARK,
54
+ type: CLOSE_TYPE,
55
+ closes: type.name,
56
+ tags: [].concat(tags),
57
+ title: "Clagentic: Console",
58
+ body: "No longer waiting for input",
59
+ };
60
+ }
61
+
62
+ module.exports = { tagFor: tagFor, buildPayload: buildPayload, buildClose: buildClose, CLOSE_TYPE: CLOSE_TYPE };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ // The target model is defined once, in the file the browser and the service
4
+ // worker load too, so the server and the client cannot disagree on identity.
5
+ module.exports = require("../public/notify-target.js");
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ // The notification types the core knows. A new type is one register() call:
4
+ // the core derives its tag, payload and close behaviour from what is declared
5
+ // here, so no emitter carries any of it.
6
+
7
+ var COLLAPSE = ["request", "session"];
8
+ // Who a type's notification reaches: "target" follows the owner the emitter
9
+ // names (the session's owner, a message's recipient); "admins" is fixed by the
10
+ // type, whatever the emitter passes.
11
+ var AUDIENCE = ["target", "admins"];
12
+
13
+ function defaultFormat(content) {
14
+ return { title: content.title, body: content.body };
15
+ }
16
+
17
+ function createTypeRegistry() {
18
+ var types = Object.create(null);
19
+
20
+ /**
21
+ * @param {string} name the push payload type.
22
+ * @param {object} def
23
+ * @param {string} def.category the notification-prefs category (documentation
24
+ * of what lib/notification-prefs.js filters the type under).
25
+ * @param {"request"|"session"} def.collapse "request": one notification per
26
+ * prompt; "session": one per session, a repeat replaces it.
27
+ * @param {boolean} def.persistent stays on screen until acted on.
28
+ * @param {boolean} [def.renotify] a replacement alerts again.
29
+ * @param {boolean} [def.closeOnResolve] the notification is closed when its
30
+ * target resolves (default true).
31
+ * @param {boolean} [def.banner] the type also shows as an in-app banner,
32
+ * closed with the notification (default false).
33
+ * @param {boolean} [def.liveInState] the page can verify the notification
34
+ * against notifications_state (default false).
35
+ * @param {boolean} [def.pushUnlessOnline] no push to a person who is online
36
+ * in the app: their banner already reaches them (default false).
37
+ * @param {"target"|"admins"} [def.audience] who receives it (default
38
+ * "target"). "admins": the admins in a multi-user install, the one person
39
+ * otherwise; the emitter cannot widen it.
40
+ * @param {boolean} [def.ephemeral] its banner does not outlive a daemon
41
+ * restart: what it announces is rebuilt from live state (default false).
42
+ * @param {function(object): {title: string, body: string}} [def.format]
43
+ */
44
+ function register(name, def) {
45
+ if (typeof name !== "string" || !name) throw new Error("notification type needs a name");
46
+ if (types[name]) throw new Error("notification type already registered: " + name);
47
+ if (!def || COLLAPSE.indexOf(def.collapse) === -1) {
48
+ throw new Error("notification type " + name + " needs collapse: request|session");
49
+ }
50
+ if (def.audience !== undefined && AUDIENCE.indexOf(def.audience) === -1) {
51
+ throw new Error("notification type " + name + " needs audience: target|admins");
52
+ }
53
+ types[name] = Object.freeze({
54
+ name: name,
55
+ category: def.category || null,
56
+ collapse: def.collapse,
57
+ persistent: def.persistent === true,
58
+ renotify: def.renotify === true,
59
+ closeOnResolve: def.closeOnResolve !== false,
60
+ banner: def.banner === true,
61
+ liveInState: def.liveInState === true,
62
+ pushUnlessOnline: def.pushUnlessOnline === true,
63
+ audience: def.audience || "target",
64
+ ephemeral: def.ephemeral === true,
65
+ format: typeof def.format === "function" ? def.format : defaultFormat,
66
+ });
67
+ return types[name];
68
+ }
69
+
70
+ function get(name) {
71
+ return typeof name === "string" && Object.prototype.hasOwnProperty.call(types, name) ? types[name] : null;
72
+ }
73
+
74
+ function names() {
75
+ return Object.keys(types);
76
+ }
77
+
78
+ return { register: register, get: get, names: names };
79
+ }
80
+
81
+ module.exports = { createTypeRegistry: createTypeRegistry, COLLAPSE: COLLAPSE };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ // The notification types registered with the core. Adding a type is adding an
4
+ // entry here; emitters then call notify()/resolve() with its name.
5
+
6
+ var PROMPT_TYPES = {
7
+ permission_request: { category: "approval", collapse: "request", persistent: true, banner: true, liveInState: true },
8
+ permission_reminder: { category: "approval_reminder", collapse: "session", persistent: true, renotify: true, banner: true, liveInState: true },
9
+ ask_user: { category: "approval", collapse: "request", persistent: true, liveInState: true },
10
+ elicitation: { category: "approval", collapse: "request", persistent: true, liveInState: true },
11
+ };
12
+
13
+ // What happened in a session, a loop or a conversation. Nothing waits on the
14
+ // person, so none is closed when a prompt resolves; a repeat for the same
15
+ // session replaces the earlier one.
16
+ var ACTIVITY_TYPES = {
17
+ response_done: { category: "turn_done", collapse: "session", renotify: true, banner: true, closeOnResolve: false },
18
+ loop_complete: { category: "loop", collapse: "session", renotify: true, banner: true, closeOnResolve: false },
19
+ loop_error: { category: "loop", collapse: "session", renotify: true, banner: true, closeOnResolve: false },
20
+ mate_dm: { category: "messages", collapse: "session", renotify: true, banner: true, closeOnResolve: false },
21
+ user_mention: { category: "messages", collapse: "session", renotify: true, banner: true, closeOnResolve: false, pushUnlessOnline: true },
22
+ };
23
+
24
+ // What the console itself needs the operator for. None is tied to a prompt, so
25
+ // a prompt resolving never closes one: each closes only by its own resolve
26
+ // (resolve(target, audience, { type })), whose tag derives from the target
27
+ // alone and so works from any process.
28
+ //
29
+ // The page does not reconcile these against its notification list (liveInState
30
+ // is off): the reconcile is scoped to the page's own project (see
31
+ // notify-client.js), and a system target has no project (slug null).
32
+ var SYSTEM_TYPES = {
33
+ // A sign-in is missing for a session's agent. Target: that session; owner only.
34
+ auth_required: { category: "system", collapse: "session", persistent: true, renotify: true, banner: true, closeOnResolve: false, audience: "target" },
35
+ // The installed build is newer than the running one. Target: the console
36
+ // itself (slug and session null). Only an admin can restart, so only admins
37
+ // are told. Closed when the build is adopted or the offer is declined.
38
+ build_update_offer: { category: "system", collapse: "session", persistent: true, banner: true, closeOnResolve: false, audience: "admins", ephemeral: true },
39
+ // A newer release exists. Target: the console itself; admins only. Ephemeral:
40
+ // after the update the banner would announce the version already running.
41
+ update_available: { category: "system", collapse: "session", banner: true, closeOnResolve: false, audience: "admins", ephemeral: true },
42
+ };
43
+
44
+ function registerBuiltins(registry) {
45
+ Object.keys(PROMPT_TYPES).forEach(function (name) {
46
+ registry.register(name, PROMPT_TYPES[name]);
47
+ });
48
+ Object.keys(ACTIVITY_TYPES).forEach(function (name) {
49
+ registry.register(name, ACTIVITY_TYPES[name]);
50
+ });
51
+ Object.keys(SYSTEM_TYPES).forEach(function (name) {
52
+ registry.register(name, SYSTEM_TYPES[name]);
53
+ });
54
+ return registry;
55
+ }
56
+
57
+ module.exports = { registerBuiltins: registerBuiltins, PROMPT_TYPES: PROMPT_TYPES, ACTIVITY_TYPES: ACTIVITY_TYPES, SYSTEM_TYPES: SYSTEM_TYPES };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ // Open browser sockets per project, for the activity diagnostics. A tab holds
4
+ // one socket, so a project showing more sockets than tabs is the sign of an
5
+ // orphaned connection. The count is the daemon's own and holds no connection
6
+ // detail: only the project slug and a number.
7
+
8
+ var counts = new Map();
9
+
10
+ function opened(slug) {
11
+ counts.set(slug, (counts.get(slug) || 0) + 1);
12
+ }
13
+
14
+ function closed(slug) {
15
+ var n = (counts.get(slug) || 0) - 1;
16
+ if (n > 0) counts.set(slug, n);
17
+ else counts.delete(slug);
18
+ }
19
+
20
+ // { slug: openSocketCount } for every project with at least one open socket.
21
+ function snapshot() {
22
+ var out = {};
23
+ counts.forEach(function (n, slug) { out[slug] = n; });
24
+ return out;
25
+ }
26
+
27
+ module.exports = { opened: opened, closed: closed, snapshot: snapshot };
@@ -0,0 +1,85 @@
1
+ // outbound-access.js - may this caller see the prompt text of an outbound-ledger
2
+ // entry? The prompt is also in the target session's history, so it is shown only
3
+ // to a caller who could read that session.
4
+ //
5
+ // The decision for a target that runs as another OS user is not made here. It is
6
+ // made when the entry is written (lib/outbound-entry.js): such an entry, and one
7
+ // that did not record the OS user of its target, stores no prompt and no context
8
+ // note, only metadata and the reason. No read path and no later mode can return
9
+ // text that was never stored, so this module has no os-users branch.
10
+ //
11
+ // The caller is one of two shapes:
12
+ // - the daemon-owner socket (the CLI verb) carries no user record; the OS
13
+ // gate on the socket proves the caller is the daemon's own OS user. It gets
14
+ // each entry as stored.
15
+ // - a caller that is a console user (a transport that authenticates one) is
16
+ // judged by canReadSession, which applies canAccessSession: project access,
17
+ // then owner, shared or private.
18
+ //
19
+ // Metadata is always shown. A text that is not shown is replaced by a stated
20
+ // reason, never silently dropped.
21
+
22
+ // deps:
23
+ // projectAccess lib/project-access.js createProjectAccess() result
24
+ // getProject(slug) -> project context | null
25
+ // caller: { user, authenticated } user is a user record or null
26
+ function createOutboundAccess(deps) {
27
+ var projectAccess = deps.projectAccess;
28
+ var getProject = deps.getProject;
29
+
30
+ // The session an entry's target names, or null. Only the vendor session id
31
+ // names a session for good. A console id is renumbered by a restart, so it
32
+ // never identifies a target here: an access decision that rested on it could
33
+ // hand the text of one session to the reader of another.
34
+ function findTarget(entry) {
35
+ var target = entry.target || {};
36
+ var project = target.project ? getProject(target.project) : null;
37
+ if (!project || !project.sm || !project.sm.sessions || !target.cliSessionId) return null;
38
+ var found = null;
39
+ project.sm.sessions.forEach(function (s) {
40
+ if (!found && s.cliSessionId === target.cliSessionId) found = s;
41
+ });
42
+ return found;
43
+ }
44
+
45
+ // Returns { allowed: true } or { allowed: false, reason }.
46
+ function canReadPrompt(entry, caller) {
47
+ caller = caller || {};
48
+ var principal = projectAccess.principalFor(caller.user || null, { authenticated: caller.authenticated === true });
49
+ if (!principal) {
50
+ if (!caller.user && caller.authenticated === true) return { allowed: true };
51
+ return { allowed: false, reason: "the caller is not authenticated; prompt text is shown only to a caller who can read the target session" };
52
+ }
53
+ // The single-user owner reads every session the console holds, so there is
54
+ // no session boundary to check, including for a target that is gone.
55
+ if (principal.implicit) return { allowed: true };
56
+
57
+ var target = entry.target || {};
58
+ if (!target.project || !projectAccess.canAccess(principal.id, target.project, { authenticated: true })) {
59
+ return { allowed: false, reason: "the caller cannot access the target project" };
60
+ }
61
+ var session = findTarget(entry);
62
+ if (!session) {
63
+ return { allowed: false, reason: "the target session is not held by the console, so access to it cannot be checked" };
64
+ }
65
+ if (!projectAccess.canReadSession(principal.user, session, { authenticated: true })) {
66
+ return { allowed: false, reason: "the caller cannot read the target session" };
67
+ }
68
+ return { allowed: true };
69
+ }
70
+
71
+ // May this caller see that something happened in `project`? The project-level
72
+ // half of canReadPrompt, for readers (the agent roster) that record where an
73
+ // identity was seen and not a session's text.
74
+ function canReadProject(project, caller) {
75
+ caller = caller || {};
76
+ var principal = projectAccess.principalFor(caller.user || null, { authenticated: caller.authenticated === true });
77
+ if (!principal) return false;
78
+ if (principal.implicit) return true;
79
+ return !!project && projectAccess.canAccess(principal.id, project, { authenticated: true });
80
+ }
81
+
82
+ return { canReadPrompt: canReadPrompt, canReadProject: canReadProject };
83
+ }
84
+
85
+ module.exports = { createOutboundAccess: createOutboundAccess };
@@ -0,0 +1,116 @@
1
+ // outbound-entry.js - builds one outbound-ledger entry (lib/outbound-ledger.js)
2
+ // from what session-input.js knows at the moment a request is answered.
3
+ //
4
+ // Pure: no clock, no I/O. The sender fields are the ones senderFields() in
5
+ // injected-sender.js produced for the history entry, so the ledger and the
6
+ // target's history can never name different senders.
7
+
8
+ var { SENDER_KIND } = require("./injected-sender");
9
+
10
+ var VERB = Object.freeze({ SEND_INPUT: "send_input", OPEN_SESSION: "open_session", END_SESSION: "end_session", ANSWER_PROMPT: "answer_prompt" });
11
+
12
+ // target.runsAs for a session that runs as the daemon's own OS user; any other
13
+ // value is the name of the OS user it runs as.
14
+ var RUNS_AS_DAEMON = "daemon";
15
+
16
+ function put(obj, key, value) {
17
+ if (value !== undefined && value !== null && value !== "") obj[key] = value;
18
+ }
19
+
20
+ // How far the sender can be trusted. "extracted" is derived from the console's
21
+ // own records for a process it started; a same-user process can copy that
22
+ // reference. Anything else is whatever the caller said about itself.
23
+ function attributionOf(senderKind) {
24
+ return senderKind === SENDER_KIND.EXTRACTED ? "extracted" : "unverified";
25
+ }
26
+
27
+ function senderOf(fields) {
28
+ var s = { kind: fields.senderKind || SENDER_KIND.UNDECLARED, attribution: attributionOf(fields.senderKind) };
29
+ put(s, "name", fields.fromName);
30
+ put(s, "project", fields.senderProject);
31
+ put(s, "sessionId", fields.senderSessionId);
32
+ put(s, "cliSessionId", fields.senderCliSessionId);
33
+ put(s, "agent", fields.senderAgent);
34
+ put(s, "vendor", fields.senderVendor);
35
+ put(s, "declaredName", fields.declaredName);
36
+ // Self-reported on a declared sender; the console's own record on an extracted one.
37
+ put(s, "fromSession", fields.fromSession);
38
+ return s;
39
+ }
40
+
41
+ // Why message text is not stored for a target, or null when it is stored. An
42
+ // absent runsAs is treated as another OS user: it cannot be shown to be the daemon's.
43
+ function withholdReasonFor(runsAs) {
44
+ if (runsAs === RUNS_AS_DAEMON) return null;
45
+ if (typeof runsAs === "string" && runsAs) return "the target session runs as another OS user";
46
+ return "the OS user the target session runs as was not recorded, so it cannot be established";
47
+ }
48
+
49
+ // args:
50
+ // verb VERB.*
51
+ // ts ISO time of the request's outcome
52
+ // req the request as the caller gave it
53
+ // out the result (absent for a delivery, recorded before it is built)
54
+ // initiator the resolved initiator, or null when it was refused
55
+ // messageId set for a delivery
56
+ // sender senderFields() output
57
+ // target { project, consoleSessionId, sessionId, agent, vendor, name, runsAs } of the
58
+ // session that took (or was meant to take) the prompt
59
+ function buildEntry(args) {
60
+ var req = args.req || {};
61
+ var out = args.out || {};
62
+ var entry = {
63
+ formatVersion: 1,
64
+ ts: args.ts,
65
+ verb: args.verb,
66
+ result: out.result || (args.verb === VERB.OPEN_SESSION ? "opened" : "delivered"),
67
+ };
68
+ put(entry, "reason", out.reason);
69
+ // An answer-prompt names the request and its kind, never the decision, which
70
+ // can be the text of an answer.
71
+ if (args.verb === VERB.ANSWER_PROMPT) {
72
+ put(entry, "requestId", out.requestId);
73
+ put(entry, "promptKind", out.kind);
74
+ }
75
+ if (out.retryable === true) entry.retryable = true;
76
+ if (Array.isArray(out.failures) && out.failures.length) entry.failures = out.failures;
77
+ put(entry, "messageId", args.messageId);
78
+ put(entry, "initiator", args.initiator);
79
+ entry.sender = senderOf(args.sender || {});
80
+
81
+ var t = args.target || {};
82
+ var target = {};
83
+ put(target, "project", t.project || req.projectSlug);
84
+ put(target, "sessionId", t.consoleSessionId);
85
+ put(target, "cliSessionId", t.sessionId);
86
+ put(target, "agent", t.agent);
87
+ put(target, "vendor", t.vendor);
88
+ put(target, "name", t.name);
89
+ // Recorded at write time: a console id is renumbered by a restart, so the
90
+ // reader cannot work out later which OS user the target ran as.
91
+ put(target, "runsAs", t.runsAs);
92
+ // What the caller asked for, kept when it differs from what it resolved to.
93
+ put(target, "address", typeof req.to === "string" ? req.to : undefined);
94
+ put(target, "requestedSessionId", typeof req.sessionId === "string" ? req.sessionId : undefined);
95
+ if (req.reply) target.reply = true;
96
+ entry.target = target;
97
+
98
+ // Message text (the prompt and the context note) is stored only for a target
99
+ // known to run as the daemon's OS user. For any other target, or one whose OS
100
+ // user was not recorded, it is never written: the access decision is made here,
101
+ // at write time, so no read path and no later mode can return it.
102
+ var withholdReason = withholdReasonFor(t.runsAs);
103
+ var hasPrompt = typeof req.prompt === "string" && req.prompt;
104
+ var hasNote = typeof req.contextNote === "string" && req.contextNote;
105
+ if (withholdReason) {
106
+ if (hasPrompt) entry.promptWithheld = true;
107
+ if (hasNote) entry.contextNoteWithheld = true;
108
+ if (hasPrompt || hasNote) entry.promptWithheldReason = withholdReason;
109
+ } else {
110
+ if (hasNote) entry.contextNote = req.contextNote;
111
+ if (hasPrompt) entry.prompt = req.prompt;
112
+ }
113
+ return entry;
114
+ }
115
+
116
+ module.exports = { VERB: VERB, RUNS_AS_DAEMON: RUNS_AS_DAEMON, buildEntry: buildEntry };