@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,136 @@
1
+ // The sign-in panel shown above a login terminal. The terminal stays the
2
+ // engine: the panel only offers the link the login printed, the code the login
3
+ // displayed, and a field that types the user's code back into that terminal.
4
+ //
5
+ // The URL and the code live only in this closure, and only while the panel is
6
+ // open. They are never logged, stored, or written to the page's persisted
7
+ // state, and remove() drops them.
8
+
9
+ import { displayHost } from './login-parser.js';
10
+
11
+ export var IDENTITY_NOTES = {
12
+ "os-users": "This sign-in applies to your own account on this host.",
13
+ "shared": "This sign-in applies to every user of this host.",
14
+ };
15
+
16
+ function el(tag, className, text) {
17
+ var node = document.createElement(tag);
18
+ if (className) node.className = className;
19
+ if (text !== undefined) node.textContent = text;
20
+ return node;
21
+ }
22
+
23
+ /**
24
+ * @param {object} opts
25
+ * @param {string} opts.vendorName agent display name, for the heading
26
+ * @param {string} [opts.identity] "os-users", "shared" or "" (no note)
27
+ * @param {function(string):void} opts.sendCode types text into the login terminal
28
+ * @param {function(string):void} opts.copy copies text to the clipboard
29
+ * @param {function(string):void} opts.openLink opens a URL in a new tab, noopener
30
+ * @param {function():void} opts.onDismiss user closed the panel
31
+ * @returns {{element: object, update: function, remove: function, setHidden: function, isOpen: function}}
32
+ */
33
+ export function createLoginPanel(opts) {
34
+ var url = "";
35
+ var userCode = "";
36
+ var open = true;
37
+
38
+ var root = el("div", "login-panel");
39
+ root.setAttribute("role", "region");
40
+ root.setAttribute("aria-label", "Sign in to " + opts.vendorName);
41
+
42
+ var head = el("div", "login-panel-head");
43
+ head.appendChild(el("span", "login-panel-title", "Sign in to " + opts.vendorName));
44
+ var dismissBtn = el("button", "login-panel-dismiss", "Dismiss");
45
+ dismissBtn.setAttribute("type", "button");
46
+ head.appendChild(dismissBtn);
47
+ root.appendChild(head);
48
+
49
+ var hostEl = el("div", "login-panel-host");
50
+ root.appendChild(hostEl);
51
+
52
+ var linkRow = el("div", "login-panel-row login-panel-links");
53
+ var openBtn = el("button", "login-panel-btn login-panel-open", "Open link");
54
+ openBtn.setAttribute("type", "button");
55
+ var copyBtn = el("button", "login-panel-btn login-panel-copy-link", "Copy link");
56
+ copyBtn.setAttribute("type", "button");
57
+ linkRow.appendChild(openBtn);
58
+ linkRow.appendChild(copyBtn);
59
+ root.appendChild(linkRow);
60
+
61
+ var shownRow = el("div", "login-panel-row login-panel-shown-code");
62
+ shownRow.style.display = "none";
63
+ shownRow.appendChild(el("span", "login-panel-label", "Your sign-in code"));
64
+ var shownValue = el("code", "login-panel-code-value");
65
+ shownRow.appendChild(shownValue);
66
+ var copyCodeBtn = el("button", "login-panel-btn login-panel-copy-code", "Copy code");
67
+ copyCodeBtn.setAttribute("type", "button");
68
+ shownRow.appendChild(copyCodeBtn);
69
+ root.appendChild(shownRow);
70
+
71
+ var entryRow = el("div", "login-panel-row login-panel-code-entry");
72
+ entryRow.style.display = "none";
73
+ var input = el("input", "login-panel-code-input");
74
+ input.setAttribute("type", "text");
75
+ input.setAttribute("autocomplete", "off");
76
+ input.setAttribute("autocapitalize", "off");
77
+ input.setAttribute("autocorrect", "off");
78
+ input.setAttribute("spellcheck", "false");
79
+ input.setAttribute("placeholder", "Code from the sign-in page");
80
+ input.setAttribute("aria-label", "Code from the sign-in page");
81
+ var submitBtn = el("button", "login-panel-btn login-panel-submit", "Submit code");
82
+ submitBtn.setAttribute("type", "button");
83
+ entryRow.appendChild(input);
84
+ entryRow.appendChild(submitBtn);
85
+ root.appendChild(entryRow);
86
+
87
+ if (opts.identity && IDENTITY_NOTES[opts.identity]) {
88
+ root.appendChild(el("div", "login-panel-identity", IDENTITY_NOTES[opts.identity]));
89
+ }
90
+
91
+ function submit() {
92
+ var code = String(input.value || "").trim();
93
+ if (!code || !open) return;
94
+ input.value = "";
95
+ opts.sendCode(code + "\n");
96
+ }
97
+
98
+ openBtn.addEventListener("click", function () { if (url) opts.openLink(url); });
99
+ copyBtn.addEventListener("click", function () { if (url) opts.copy(url); });
100
+ copyCodeBtn.addEventListener("click", function () { if (userCode) opts.copy(userCode); });
101
+ submitBtn.addEventListener("click", submit);
102
+ input.addEventListener("keydown", function (e) {
103
+ if (e && e.key === "Enter") submit();
104
+ });
105
+ dismissBtn.addEventListener("click", function () {
106
+ remove();
107
+ if (opts.onDismiss) opts.onDismiss();
108
+ });
109
+
110
+ function remove() {
111
+ open = false;
112
+ url = "";
113
+ userCode = "";
114
+ input.value = "";
115
+ shownValue.textContent = "";
116
+ hostEl.textContent = "";
117
+ root.remove();
118
+ }
119
+
120
+ return {
121
+ element: root,
122
+ isOpen: function () { return open; },
123
+ remove: remove,
124
+ /** @param {{url: string, codePrompt: boolean, userCode: string}} parsed */
125
+ update: function (parsed) {
126
+ if (!open || !parsed) return;
127
+ url = parsed.url;
128
+ userCode = parsed.userCode || "";
129
+ hostEl.textContent = displayHost(url);
130
+ shownValue.textContent = userCode;
131
+ shownRow.style.display = userCode ? "" : "none";
132
+ entryRow.style.display = parsed.codePrompt ? "" : "none";
133
+ },
134
+ setHidden: function (hidden) { root.style.display = hidden ? "none" : ""; },
135
+ };
136
+ }
@@ -0,0 +1,73 @@
1
+ // Reads a vendor login's terminal output for the sign-in URL and the code
2
+ // step. Pure: no DOM, no app imports. The patterns are declared per vendor
3
+ // beside its login command (the registry's loginPatterns) as regular
4
+ // expression sources; nothing here names a vendor.
5
+
6
+ function compile(source) {
7
+ if (typeof source !== "string" || !source) return null;
8
+ try {
9
+ return new RegExp(source);
10
+ } catch (e) {
11
+ return null;
12
+ }
13
+ }
14
+
15
+ /**
16
+ * @param {?{url: string, codePrompt?: string, userCode?: string}} patterns
17
+ * @returns {?{url: RegExp, codePrompt: ?RegExp, userCode: ?RegExp}} null when
18
+ * the vendor declares no usable URL pattern (it then shows no panel)
19
+ */
20
+ export function compileLoginPatterns(patterns) {
21
+ if (!patterns) return null;
22
+ var url = compile(patterns.url);
23
+ if (!url) return null;
24
+ return { url: url, codePrompt: compile(patterns.codePrompt), userCode: compile(patterns.userCode) };
25
+ }
26
+
27
+ // A sign-in URL is opened from the panel, so only a web URL is accepted
28
+ // whatever a pattern matched.
29
+ function isWebUrl(text) {
30
+ return /^https?:\/\/[^\s]+$/.test(text);
31
+ }
32
+
33
+ /**
34
+ * @param {string[]} lines logical lines, hard-wrapped URLs already joined
35
+ * @param {?object} compiled compileLoginPatterns result
36
+ * @returns {?{url: string, codePrompt: boolean, userCode: string}} null when
37
+ * no sign-in URL is present. The newest URL wins, so a retried login shows
38
+ * its current link.
39
+ */
40
+ export function parseLoginLines(lines, compiled) {
41
+ if (!compiled || !Array.isArray(lines)) return null;
42
+ var url = "";
43
+ var urlLine = -1;
44
+ for (var i = lines.length - 1; i >= 0 && !url; i--) {
45
+ var hit = compiled.url.exec(lines[i]);
46
+ if (hit && isWebUrl(hit[0])) { url = hit[0]; urlLine = i; }
47
+ }
48
+ if (!url) return null;
49
+
50
+ // The code and the prompt follow their URL on screen, so reading from the
51
+ // newest URL on keeps a retried link from pairing with an older attempt's
52
+ // dead code.
53
+ var text = lines.slice(urlLine).join("\n");
54
+ var userCode = "";
55
+ if (compiled.userCode) {
56
+ var codeHit = compiled.userCode.exec(text);
57
+ if (codeHit && codeHit[1]) userCode = codeHit[1];
58
+ }
59
+ return {
60
+ url: url,
61
+ codePrompt: !!compiled.codePrompt && compiled.codePrompt.test(text),
62
+ userCode: userCode,
63
+ };
64
+ }
65
+
66
+ /** The host of a URL for display, "" when it does not parse. Never the query. */
67
+ export function displayHost(url) {
68
+ try {
69
+ return new URL(url).host;
70
+ } catch (e) {
71
+ return "";
72
+ }
73
+ }
@@ -0,0 +1,66 @@
1
+ // Ties one login terminal to its sign-in panel. Only the terminal marked as a
2
+ // login tab gets one of these, so no other terminal's output is ever read for
3
+ // a URL or code. Parsing is client-side over the terminal's own buffer; the
4
+ // server sees nothing but the code the user types, through the same terminal
5
+ // input message as every other keystroke.
6
+
7
+ import { bufferLogicalLines } from './terminal-links.js';
8
+ import { compileLoginPatterns, parseLoginLines } from './login-parser.js';
9
+ import { createLoginPanel } from './login-panel.js';
10
+
11
+ // Rows of recent output read per update; a sign-in screen is a few lines.
12
+ var SCAN_ROWS = 200;
13
+
14
+ /**
15
+ * @param {object} opts
16
+ * @param {object} opts.patterns the vendor's loginPatterns (or null)
17
+ * @param {string} opts.vendorName
18
+ * @param {string} opts.identity "os-users", "shared" or ""
19
+ * @param {function(string):void} opts.sendCode types into this terminal only
20
+ * @param {function(object):void} opts.mount puts the panel element in the page
21
+ * @param {function(string):void} opts.copy
22
+ * @param {function(string):void} opts.openLink
23
+ * @returns {{feed: function, setActive: function, close: function}}
24
+ */
25
+ export function createLoginTab(opts) {
26
+ var compiled = compileLoginPatterns(opts.patterns);
27
+ var panel = null;
28
+ var dismissed = false;
29
+ var active = true;
30
+
31
+ function ensurePanel() {
32
+ if (panel || dismissed) return panel;
33
+ panel = createLoginPanel({
34
+ vendorName: opts.vendorName,
35
+ identity: opts.identity,
36
+ sendCode: opts.sendCode,
37
+ copy: opts.copy,
38
+ openLink: opts.openLink,
39
+ onDismiss: function () { dismissed = true; panel = null; },
40
+ });
41
+ opts.mount(panel.element);
42
+ panel.setHidden(!active);
43
+ return panel;
44
+ }
45
+
46
+ return {
47
+ /** Call after output was written to the terminal. */
48
+ feed: function (xterm) {
49
+ if (!compiled || dismissed || !xterm || !xterm.buffer) return;
50
+ var lines = bufferLogicalLines(xterm.buffer.active, xterm.cols, SCAN_ROWS);
51
+ var parsed = parseLoginLines(lines, compiled);
52
+ if (!parsed) return;
53
+ ensurePanel().update(parsed);
54
+ },
55
+ setActive: function (isActive) {
56
+ active = !!isActive;
57
+ if (panel) panel.setHidden(!active);
58
+ },
59
+ /** The terminal exited or closed: drop the panel and everything it held. */
60
+ close: function () {
61
+ if (panel) panel.remove();
62
+ panel = null;
63
+ dismissed = true;
64
+ },
65
+ };
66
+ }
@@ -1,5 +1,7 @@
1
1
  import { copyToClipboard, showToast } from './utils.js';
2
2
  import { iconHtml, refreshIcons } from './icons.js';
3
+ import { store } from './store.js';
4
+ import { routeTo } from './notify-client.js';
3
5
 
4
6
  var ctx;
5
7
  var basePath = "/";
@@ -50,14 +52,20 @@ export function showDoneNotification() {
50
52
  else sessionTitle = activeItem.textContent || "Claude";
51
53
  }
52
54
 
55
+ // The same target and tag the server's push for this turn carries (the
56
+ // response_done type collapses per session), so the page's notification and
57
+ // the push replace each other instead of showing twice, and a tap routes to
58
+ // the session through the one router.
59
+ var target = { slug: store.get('currentSlug'), sessionId: store.get('activeSessionId') };
53
60
  var n = new Notification(sessionTitle, {
54
61
  body: preview,
55
- tag: "claude-done",
62
+ tag: globalThis.NotifyTarget.tagFor("response_done", "session", target),
56
63
  });
57
64
 
58
65
  n.onclick = function() {
59
66
  window.focus();
60
67
  n.close();
68
+ routeTo(target);
61
69
  };
62
70
 
63
71
  setTimeout(function() { n.close(); }, 5000);
@@ -0,0 +1,246 @@
1
+ // The page side of notification routing: the one router a tap, a deep link and
2
+ // the service worker's route message all use, plus the reconcile that closes a
3
+ // shown notification whose prompt has ended.
4
+ import '../notify-target.js';
5
+ import '../notify-sw-logic.js';
6
+ import { store } from './store.js';
7
+ import { getWs } from './ws-ref.js';
8
+ import { switchProject } from './app-projects.js';
9
+ import { openDm } from './app-dm.js';
10
+
11
+ var Target = globalThis.NotifyTarget;
12
+ var PENDING_KEY = 'pending-notif-session';
13
+ var PENDING_PEER_KEY = 'pending-notif-dm';
14
+ var PENDING_PLACE_KEY = 'pending-notif-place';
15
+
16
+ export var urlForTarget = Target.urlForTarget;
17
+
18
+ var lastState = null;
19
+ var lastLivePrompts = null;
20
+
21
+ // The session a route is waiting to open once the connection is up. Held in
22
+ // memory as well as in sessionStorage: sessionStorage can be unavailable
23
+ // (private mode, quota), and the target must not depend on it.
24
+ var pendingSession = null;
25
+ // True while the deep link's query is still on the URL as the only durable
26
+ // copy of the target (sessionStorage refused it).
27
+ var queryHoldsTarget = false;
28
+ // The person whose conversation a route is waiting to open once connected.
29
+ // Held like the session: in memory, and in sessionStorage so a reload or a
30
+ // suspension before the connection is up keeps the destination.
31
+ var pendingPeer = null;
32
+ // True while the deep link's ?dm= is still on the URL as the only durable copy.
33
+ var peerQueryHoldsTarget = false;
34
+ // The system notification type a cold-start tap named (?notify=<type>), held
35
+ // like the peer so a reload before the connection keeps the destination.
36
+ var pendingPlace = null;
37
+ var placeQueryHoldsTarget = false;
38
+
39
+ // The places a system notification's action lives, by type: a system target
40
+ // names no project or session, so the type says where it opens. Registered by
41
+ // the module that owns the place; the router and the service worker carry no
42
+ // per-type branch.
43
+ var places = Object.create(null);
44
+
45
+ /**
46
+ * @param {string} type a notification type.
47
+ * @param {function(object): void} open opens the place; given the target.
48
+ */
49
+ export function registerPlace(type, open) {
50
+ places[type] = open;
51
+ }
52
+
53
+ /**
54
+ * The system notification type whose place a cold-start tap is waiting to open,
55
+ * or null; taking it ends the wait (and the query, if it was the only copy).
56
+ * @returns {?string}
57
+ */
58
+ export function takePendingPlace() {
59
+ var type = pendingPlace !== null ? pendingPlace : readStored(PENDING_PLACE_KEY);
60
+ pendingPlace = null;
61
+ clearStored(PENDING_PLACE_KEY);
62
+ if (placeQueryHoldsTarget) {
63
+ placeQueryHoldsTarget = false;
64
+ stripQuery(['notify']);
65
+ }
66
+ return type;
67
+ }
68
+
69
+ /**
70
+ * The conversation a route is waiting to open, or null; taking it ends the wait
71
+ * (and with it the deep link's query, if that was the target's only copy).
72
+ * @returns {?string} the other person's user id.
73
+ */
74
+ export function takePendingPeer() {
75
+ var peer = pendingPeer !== null ? pendingPeer : readStored(PENDING_PEER_KEY);
76
+ pendingPeer = null;
77
+ clearStored(PENDING_PEER_KEY);
78
+ if (peerQueryHoldsTarget) {
79
+ peerQueryHoldsTarget = false;
80
+ stripQuery(['dm']);
81
+ }
82
+ return peer;
83
+ }
84
+
85
+ // Returns whether sessionStorage took the target; the in-memory copy is kept
86
+ // either way.
87
+ function rememberPendingPeer(peer) {
88
+ pendingPeer = String(peer);
89
+ return storeValue(PENDING_PEER_KEY, pendingPeer);
90
+ }
91
+
92
+ function storeValue(key, value) {
93
+ try {
94
+ sessionStorage.setItem(key, value);
95
+ return true;
96
+ } catch (e) {
97
+ console.debug('[notify] could not store ' + key + ':', e && e.message ? e.message : e);
98
+ return false;
99
+ }
100
+ }
101
+
102
+ function readStored(key) {
103
+ try {
104
+ return sessionStorage.getItem(key);
105
+ } catch (e) {
106
+ console.debug('[notify] could not read ' + key + ':', e && e.message ? e.message : e);
107
+ return null;
108
+ }
109
+ }
110
+
111
+ function clearStored(key) {
112
+ try {
113
+ sessionStorage.removeItem(key);
114
+ } catch (e) {
115
+ console.debug('[notify] could not clear ' + key + ':', e && e.message ? e.message : e);
116
+ }
117
+ }
118
+
119
+ // Returns whether sessionStorage took the target. The in-memory copy is always
120
+ // kept, so a caller that sees false still has the route.
121
+ function rememberPendingSession(id) {
122
+ pendingSession = String(id);
123
+ return storeValue(PENDING_KEY, pendingSession);
124
+ }
125
+
126
+ function stripQuery(keys) {
127
+ var params = new URLSearchParams(location.search);
128
+ keys.forEach(function (k) { params.delete(k); });
129
+ var rest = params.toString();
130
+ history.replaceState(null, '', location.pathname + (rest ? '?' + rest : '') + location.hash);
131
+ }
132
+
133
+ /**
134
+ * The session a route is waiting to open, or null. Call it only once the
135
+ * connection can carry the switch: taking it ends the wait, and with it the
136
+ * deep link's query if that was the target's only copy.
137
+ * @returns {?number}
138
+ */
139
+ export function takePendingSession() {
140
+ var raw = pendingSession !== null ? pendingSession : readStored(PENDING_KEY);
141
+ pendingSession = null;
142
+ clearStored(PENDING_KEY);
143
+ if (queryHoldsTarget) {
144
+ queryHoldsTarget = false;
145
+ stripQuery(['session', 'request']);
146
+ }
147
+ return raw === null ? null : parseId(raw);
148
+ }
149
+
150
+ function parseId(id) {
151
+ var n = parseInt(id, 10);
152
+ return isNaN(n) ? null : n;
153
+ }
154
+
155
+ // Opens the target's project and session in this page. A different project is
156
+ // switched to first, and the session is picked up by handleNotificationsState
157
+ // through the pending key once that project's connection is up; the same
158
+ // project switches at once when its connection is open, else the same key
159
+ // carries it.
160
+ export function routeTo(target, type) {
161
+ var t = Target.makeTarget(target);
162
+ if (!t) return;
163
+ // A system notification's target names no place: its type does.
164
+ if (!t.peerId && !t.slug && !t.sessionId && type && places[type]) {
165
+ places[type](t);
166
+ return;
167
+ }
168
+ // A direct message opens the conversation with the other person; before the
169
+ // connection is up it waits for takePendingPeer.
170
+ if (t.peerId) {
171
+ var peerWs = getWs();
172
+ if (peerWs && peerWs.readyState === 1) openDm(t.peerId);
173
+ else rememberPendingPeer(t.peerId);
174
+ return;
175
+ }
176
+ var current = store.get('currentSlug') || '';
177
+ var sessionId = parseId(t.sessionId);
178
+ if (t.slug && t.slug !== current) {
179
+ if (sessionId !== null) rememberPendingSession(sessionId);
180
+ switchProject(t.slug);
181
+ return;
182
+ }
183
+ if (sessionId === null) return;
184
+ var ws = getWs();
185
+ if (ws && ws.readyState === 1) {
186
+ ws.send(JSON.stringify({ type: 'switch_session', id: sessionId }));
187
+ } else {
188
+ rememberPendingSession(sessionId);
189
+ }
190
+ }
191
+
192
+ // The page was opened on a deep link (/p/<slug>/?session=<id>): route to the
193
+ // session once connected, then drop the query so a reload does not repeat it.
194
+ // When sessionStorage refused the target, the query stays until the route has
195
+ // been taken, so a reload still finds it.
196
+ function consumeDeepLink() {
197
+ var peer = Target.parsePeerLink(location.search);
198
+ if (peer) {
199
+ if (rememberPendingPeer(peer)) stripQuery(['dm']);
200
+ else peerQueryHoldsTarget = true;
201
+ }
202
+ var place = Target.parsePlaceLink(location.search);
203
+ if (place) {
204
+ pendingPlace = place;
205
+ if (storeValue(PENDING_PLACE_KEY, place)) stripQuery(['notify']);
206
+ else placeQueryHoldsTarget = true;
207
+ }
208
+ var link = Target.parseDeepLink(location.search);
209
+ if (!link) return;
210
+ if (rememberPendingSession(link.sessionId)) stripQuery(['session', 'request']);
211
+ else queryHoldsTarget = true;
212
+ }
213
+
214
+ // Scoped to this page's own project: the live-prompt record names it, else
215
+ // the project the page is on.
216
+ function reconcile() {
217
+ if (lastState === null || document.visibilityState !== 'visible') return;
218
+ if (!navigator.serviceWorker || !globalThis.NotifySw) return;
219
+ var scope = {
220
+ slug: (lastLivePrompts && lastLivePrompts.slug) || store.get('currentSlug') || '',
221
+ livePrompts: lastLivePrompts,
222
+ };
223
+ navigator.serviceWorker.ready.then(function (reg) {
224
+ return globalThis.NotifySw.reconcileShown(reg, lastState, scope);
225
+ }).catch(function (e) {
226
+ console.debug('[notify] reconcile failed:', e && e.message ? e.message : e);
227
+ });
228
+ }
229
+
230
+ // Called with each notifications_state; reconciling waits for the first one so
231
+ // an empty list at boot never reads as "nothing is live".
232
+ export function noteNotificationsState(list, livePrompts) {
233
+ lastState = Array.isArray(list) ? list : [];
234
+ lastLivePrompts = livePrompts || null;
235
+ reconcile();
236
+ }
237
+
238
+ export function initNotifyClient() {
239
+ consumeDeepLink();
240
+ if (navigator.serviceWorker) {
241
+ navigator.serviceWorker.addEventListener('message', function (event) {
242
+ if (event.data && event.data.type === 'notify_route') routeTo(event.data.target, event.data.notifyType);
243
+ });
244
+ }
245
+ document.addEventListener('visibilitychange', reconcile);
246
+ }
@@ -0,0 +1,30 @@
1
+ // Ties a terminal the client asked for to the terminal the server reports
2
+ // back. A command queued for "the next terminal" would otherwise land in
3
+ // whichever terminal is created first, including one somebody else opened in
4
+ // the same window. The request id travels in term_create and returns in
5
+ // term_created; only the matching terminal takes the queued command.
6
+
7
+ var counter = 0;
8
+
9
+ /** @returns {string} a client-unique id for one term_create request */
10
+ export function newTermRequestId() {
11
+ counter += 1;
12
+ return "tq-" + Date.now().toString(36) + "-" + counter;
13
+ }
14
+
15
+ /**
16
+ * Takes the queued command and login vendor when this term_created answers the
17
+ * queued request; any other terminal leaves the slot alone.
18
+ * @param {{get: function(string): *, set: function(object)}} store
19
+ * @param {{requestId?: string}} msg the term_created message
20
+ * @returns {?{command: string, vendor: string}} null when nothing is queued or
21
+ * the terminal is not the one requested
22
+ */
23
+ export function consumePendingTerm(store, msg) {
24
+ var command = store.get("pendingTermCommand");
25
+ var requestId = store.get("pendingTermRequestId");
26
+ if (!command || !requestId || !msg || msg.requestId !== requestId) return null;
27
+ var vendor = store.get("pendingLoginVendor") || "";
28
+ store.set({ pendingTermCommand: null, pendingLoginVendor: "", pendingTermRequestId: "" });
29
+ return { command: command, vendor: vendor };
30
+ }
@@ -34,6 +34,26 @@ export function customIconSlug(iconStr) {
34
34
  return iconStr.slice(1, -1); // strip leading and trailing ":"
35
35
  }
36
36
 
37
+ /**
38
+ * The URL a custom-icon slug is served from (the global custom-icon store).
39
+ * Every place that draws a custom icon, project icons and agent avatars alike,
40
+ * builds its URL here.
41
+ * @param {string} slug A slug already validated against CUSTOM_ICON_RE's body.
42
+ * @returns {string}
43
+ */
44
+ export function customIconUrl(slug) {
45
+ return "/api/custom-emoji/" + encodeURIComponent(slug);
46
+ }
47
+
48
+ /**
49
+ * True when slug is a valid custom-icon slug ([a-z0-9_-]{1,64}).
50
+ * @param {unknown} slug
51
+ * @returns {boolean}
52
+ */
53
+ export function isCustomIconSlug(slug) {
54
+ return typeof slug === "string" && isCustomIcon(":" + slug + ":");
55
+ }
56
+
37
57
  // Minimal HTML-escape for the string-composition path (projectIconHtml).
38
58
  // Mirrors escapeHtml() from utils.js without importing it, so this module
39
59
  // stays DOM-free / Node-importable (see file header).
@@ -73,7 +93,7 @@ export function projectIconHtml(iconStr, fallbackHtml) {
73
93
  // (hide the broken image) since this string-built markup has no JS
74
94
  // event-listener wiring of its own. The handler is a fixed literal —
75
95
  // nothing from iconStr is interpolated into it.
76
- return '<img src="/api/custom-emoji/' + encodeURIComponent(slug) + '" alt=":' + slug + ':" class="project-emoji-img" onerror="this.style.display=&#39;none&#39;">';
96
+ return '<img src="' + customIconUrl(slug) + '" alt=":' + slug + ':" class="project-emoji-img" onerror="this.style.display=&#39;none&#39;">';
77
97
  }
78
98
  return escapeForHtml(iconStr);
79
99
  }
@@ -100,7 +120,7 @@ export function renderProjectIcon(iconStr, el, parseEmojisFn) {
100
120
  var slug = customIconSlug(iconStr);
101
121
  if (slug) {
102
122
  var img = document.createElement("img");
103
- img.src = "/api/custom-emoji/" + encodeURIComponent(slug);
123
+ img.src = customIconUrl(slug);
104
124
  img.alt = ":" + slug + ":";
105
125
  img.className = "project-emoji-img";
106
126
  // Graceful fallback: if the image 404s (deleted-in-use), show nothing
@@ -8,6 +8,7 @@ import { pushOverlayState, popOverlayState } from './overlay-history.js';
8
8
  import { closeFileViewer } from './filebrowser.js';
9
9
  import { renderModelList, renderModeList, renderEffortBar, renderThinkingBar, renderBetaCard } from './settings-defaults.js';
10
10
  import { capabilitiesFor, defaultVendorId } from './vendor-registry.js';
11
+ import { renderShadowNotice } from './env-shadow-notice.js';
11
12
 
12
13
  var ctx = null;
13
14
  var panelEl = null;
@@ -689,6 +690,7 @@ function loadEnvironment() {
689
690
  export function handleProjectEnv(msg) {
690
691
  var notice = document.getElementById("ps-env-override-notice");
691
692
  if (notice) notice.classList.toggle("hidden", !msg.hasEnvrc);
693
+ renderShadowNotice("ps-env-shadow-notice", msg.shadowedKeys, msg.shadowConfigDirNote);
692
694
 
693
695
  // Say whom these variables reach: in multi-user mode only the project owner's
694
696
  // sessions get them, so no one else's runtime can be changed from here.
@@ -858,6 +860,7 @@ function autoSaveEnv() {
858
860
  }
859
861
 
860
862
  export function handleProjectEnvSaved(msg) {
863
+ if (msg.ok) renderShadowNotice("ps-env-shadow-notice", msg.shadowedKeys, msg.shadowConfigDirNote);
861
864
  var saveStatus = document.getElementById("ps-env-save-status");
862
865
  if (!saveStatus) return;
863
866
  if (msg.ok) {
@@ -881,6 +884,7 @@ function loadSharedEnv() {
881
884
  }
882
885
 
883
886
  export function handleProjectSharedEnv(msg) {
887
+ renderShadowNotice("ps-shared-env-shadow-notice", msg.shadowedKeys, msg.shadowConfigDirNote);
884
888
  var list = document.getElementById("ps-shared-env-list");
885
889
  if (!list) return;
886
890
  list.innerHTML = "";
@@ -893,6 +897,7 @@ export function handleProjectSharedEnv(msg) {
893
897
  }
894
898
 
895
899
  export function handleProjectSharedEnvSaved(msg) {
900
+ if (msg.ok) renderShadowNotice("ps-shared-env-shadow-notice", msg.shadowedKeys, msg.shadowConfigDirNote);
896
901
  var saveStatus = document.getElementById("ps-shared-env-save-status");
897
902
  if (!saveStatus) return;
898
903
  if (msg.ok) {