@clagentic/console 1.12.0-beta.1 → 1.12.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 (82) hide show
  1. package/README.md +1 -0
  2. package/bin/cli.js +2 -1
  3. package/lib/build-changes.js +8 -2
  4. package/lib/build-sha.json +2 -2
  5. package/lib/build-update-offer.js +31 -7
  6. package/lib/claude-settings-env.js +142 -0
  7. package/lib/cli/duration.js +27 -0
  8. package/lib/cli/schedule-input-subcommands.js +1 -22
  9. package/lib/cli/session-subcommands.js +38 -7
  10. package/lib/daemon.js +6 -0
  11. package/lib/notification-prefs.js +2 -0
  12. package/lib/notify/core.js +175 -0
  13. package/lib/notify/index.js +31 -0
  14. package/lib/notify/live-prompts.js +36 -0
  15. package/lib/notify/payload.js +63 -0
  16. package/lib/notify/target.js +5 -0
  17. package/lib/notify/type-registry.js +64 -0
  18. package/lib/notify/types.js +20 -0
  19. package/lib/open-sockets.js +27 -0
  20. package/lib/outbound-access.js +74 -0
  21. package/lib/outbound-entry.js +109 -0
  22. package/lib/outbound-ledger.js +306 -0
  23. package/lib/outbound-query.js +153 -0
  24. package/lib/pending-prompts.js +31 -16
  25. package/lib/project-connection.js +40 -1
  26. package/lib/project-filesystem.js +20 -5
  27. package/lib/project-http.js +9 -1
  28. package/lib/project-loop.js +22 -7
  29. package/lib/project-notifications.js +54 -32
  30. package/lib/project-prompt-responses.js +1 -1
  31. package/lib/project-sessions.js +2 -1
  32. package/lib/project.js +15 -1
  33. package/lib/prompt-registry.js +74 -24
  34. package/lib/prompt-reminders.js +38 -33
  35. package/lib/prompt-source.js +43 -8
  36. package/lib/public/app.js +1 -0
  37. package/lib/public/css/diagnostics.css +28 -0
  38. package/lib/public/css/home-hub.css +12 -0
  39. package/lib/public/css/icon-strip.css +9 -0
  40. package/lib/public/css/mobile-nav.css +11 -0
  41. package/lib/public/css/sidebar.css +7 -0
  42. package/lib/public/index.html +3 -0
  43. package/lib/public/modules/activity-state.js +20 -4
  44. package/lib/public/modules/app-connection.js +22 -5
  45. package/lib/public/modules/app-notifications.js +47 -48
  46. package/lib/public/modules/app-projects.js +3 -1
  47. package/lib/public/modules/app-rendering.js +10 -0
  48. package/lib/public/modules/build-update-sessions.js +81 -0
  49. package/lib/public/modules/diagnostics.js +9 -2
  50. package/lib/public/modules/env-shadow-notice.js +34 -0
  51. package/lib/public/modules/notify-client.js +153 -0
  52. package/lib/public/modules/project-settings.js +5 -0
  53. package/lib/public/modules/prompt-state.js +3 -3
  54. package/lib/public/modules/prompts.js +1 -1
  55. package/lib/public/modules/server-settings.js +3 -0
  56. package/lib/public/modules/terminal-links.js +175 -0
  57. package/lib/public/modules/terminal.js +19 -103
  58. package/lib/public/notify-sw-logic.js +300 -0
  59. package/lib/public/notify-target.js +97 -0
  60. package/lib/public/sw.js +15 -68
  61. package/lib/push.js +63 -19
  62. package/lib/runtime-env.js +1 -0
  63. package/lib/sdk-bridge.js +62 -30
  64. package/lib/sdk-message-processor.js +78 -37
  65. package/lib/server.js +34 -2
  66. package/lib/session-directory.js +6 -4
  67. package/lib/session-input-ipc.js +11 -1
  68. package/lib/session-input.js +89 -14
  69. package/lib/session-liveness.js +53 -0
  70. package/lib/session-reclaim.js +37 -2
  71. package/lib/sessions.js +31 -4
  72. package/lib/usage-store.js +29 -7
  73. package/lib/vendor-auth.js +33 -2
  74. package/lib/ws-schema.js +6 -1
  75. package/lib/yoke/adapters/claude-vendor.js +11 -1
  76. package/lib/yoke/adapters/claude.js +7 -0
  77. package/lib/yoke/auth-checks.js +17 -2
  78. package/lib/yoke/index.js +21 -3
  79. package/lib/yoke/provider-credentials.js +24 -0
  80. package/lib/yoke/registry.js +8 -1
  81. package/package.json +2 -2
  82. package/scripts/check-test-count.js +14 -0
@@ -9,7 +9,6 @@ import { store } from './store.js';
9
9
  import { loginCommandFor, defaultVendorId } from './vendor-registry.js';
10
10
  import { getWs } from './ws-ref.js';
11
11
  import { getCachedProjects } from './app-projects.js';
12
- import { switchProject } from './app-projects.js';
13
12
  import { userAvatarUrl } from './avatar.js';
14
13
  import { openTerminal } from './terminal.js';
15
14
  import { askWording } from './prompt-kinds/index.js';
@@ -17,10 +16,14 @@ import { wirePromptBanner, restoreUnconfirmedBanners, bannerActions } from './pr
17
16
  import { promptLabelHtml } from './prompt-label.js';
18
17
  import { isSurfaceWanted, shouldChimeForNotification } from './notification-prefs.js';
19
18
  import { playDoneSound, isNotifSoundEnabled } from './notifications.js';
19
+ import { initNotifyClient, noteNotificationsState, routeTo, takePendingSession } from './notify-client.js';
20
+ import '../notify-sw-logic.js';
20
21
 
21
22
  // The server dismisses a prompt's banner once the prompt settles, however it
22
23
  // was answered.
23
24
  var notifications = [];
25
+ // The notification behind each banner on screen, by id.
26
+ var shownNotifs = Object.create(null);
24
27
  var unreadCount = 0;
25
28
  var bannerContainer = null;
26
29
  var bellBtn = null;
@@ -47,6 +50,8 @@ export function initAppNotifications() {
47
50
  bannerContainer.className = "notif-banner-container";
48
51
  document.body.appendChild(bannerContainer);
49
52
 
53
+ initNotifyClient();
54
+
50
55
  if (bellBtn) {
51
56
  bellBtn.addEventListener("click", function (e) {
52
57
  e.stopPropagation();
@@ -106,6 +111,10 @@ function showBanner(notif, autoDismissMs) {
106
111
  banner.className = "notif-banner" + (isAuthRequired ? " notif-banner-update notif-banner-auth" : isPermission ? " notif-banner-permission" : isUserMention ? " notif-banner-user-mention" : isReminder ? " notif-banner-reminder" : "");
107
112
  if (!isEmpty) banner.setAttribute("data-notif-id", notif.id);
108
113
  if (!isEmpty && notif.type) banner.setAttribute("data-notif-type", notif.type);
114
+ if (!isEmpty && notif.liveInState === true) {
115
+ banner.setAttribute("data-live-in-state", "true");
116
+ shownNotifs[notif.id] = notif;
117
+ }
109
118
  if (isAuthRequired) banner.setAttribute("data-auth-banner", "true");
110
119
 
111
120
  var iconHtmlStr = userMentionAvatarSrc
@@ -322,6 +331,7 @@ export function showAuthRequiredBanner(msg) {
322
331
 
323
332
  function removeBanner(banner) {
324
333
  if (!banner || !banner.parentNode) return;
334
+ delete shownNotifs[banner.getAttribute("data-notif-id")];
325
335
  banner.classList.remove("show");
326
336
  banner.classList.add("hide");
327
337
  // Update the clear-all button right away so it disappears before the
@@ -408,42 +418,47 @@ export function handleNotificationsState(msg) {
408
418
  notifications = msg.notifications || [];
409
419
  unreadCount = msg.unreadCount || 0;
410
420
  updateBadge();
411
- dropBannersOfEndedPrompts();
421
+ dropBannersOfEndedPrompts(msg.livePrompts || null);
422
+ noteNotificationsState(notifications, msg.livePrompts);
412
423
 
413
- // Check for pending session navigation after project switch
414
- try {
415
- var pendingSession = sessionStorage.getItem("pending-notif-session");
416
- if (pendingSession) {
417
- sessionStorage.removeItem("pending-notif-session");
418
- var ws = getWs();
419
- if (ws && ws.readyState === 1) {
420
- ws.send(JSON.stringify({ type: "switch_session", id: parseInt(pendingSession, 10) }));
421
- }
422
- }
423
- } catch (e) {}
424
+ // A route waiting on the connection (a project switch, a deep link) opens
425
+ // its session now that this project's socket is up.
426
+ var ws = getWs();
427
+ if (ws && ws.readyState === 1) {
428
+ var pendingId = takePendingSession();
429
+ if (pendingId !== null) ws.send(JSON.stringify({ type: "switch_session", id: pendingId }));
430
+ }
424
431
  }
425
432
 
426
433
  // A prompt banner and a reminder are tied to a live prompt. The server's list
427
- // (sent on every connect) is the truth: after a daemon restart no prompt
428
- // survives, and the dismissals were sent to a connection that was gone, so
429
- // banners it no longer lists are removed.
430
- function dropBannersOfEndedPrompts() {
434
+ // (sent on every connect) and its live-prompt record are the truth: after a
435
+ // daemon restart no prompt survives, and the dismissals were sent to a
436
+ // connection that was gone. The check is the one the push reconcile uses
437
+ // (NotifySw.isBannerLive), for every banner the registry marks liveInState.
438
+ function dropBannersOfEndedPrompts(livePrompts) {
431
439
  if (!bannerContainer) return;
432
- var live = Object.create(null);
433
- notifications.forEach(function (n) { live[n.id] = true; });
434
- var banners = bannerContainer.querySelectorAll('.notif-banner[data-notif-type="permission_request"], .notif-banner[data-notif-type="permission_reminder"]');
440
+ var banners = bannerContainer.querySelectorAll('.notif-banner[data-live-in-state="true"]');
435
441
  for (var i = 0; i < banners.length; i++) {
436
- if (!live[banners[i].getAttribute("data-notif-id")]) removeBanner(banners[i]);
442
+ var notif = shownNotifs[banners[i].getAttribute("data-notif-id")];
443
+ if (notif && !globalThis.NotifySw.isBannerLive(notif, notifications, livePrompts)) removeBanner(banners[i]);
437
444
  }
438
445
  }
439
446
 
447
+ // Session local ids are unique only within a project, and the server sends a
448
+ // user's notifications to every project socket that user has open. A session
449
+ // id therefore names the viewed session only together with the project slug.
450
+ function isViewedProject(slug) {
451
+ return !!slug && slug === (store.get('currentSlug') || "");
452
+ }
453
+
440
454
  export function handleNotificationCreated(msg) {
441
455
  var notif = msg.notification;
442
456
 
443
457
  // Auto-dismiss if it's for the session the user is currently viewing
444
458
  var activeSession = store.get('activeSessionId') || null;
445
- console.log("[notif] created:", notif.type, "sessionId=" + notif.sessionId + "(" + typeof notif.sessionId + ")", "active=" + activeSession + "(" + typeof activeSession + ")", "match=" + (notif.sessionId == activeSession));
446
- if (notif.type !== "auth_required" && notif.sessionId && String(notif.sessionId) === String(activeSession)) {
459
+ var sameProject = isViewedProject(notif.slug);
460
+ console.log("[notif] created:", notif.type, "slug=" + notif.slug, "sessionId=" + notif.sessionId + "(" + typeof notif.sessionId + ")", "active=" + activeSession + "(" + typeof activeSession + ")", "match=" + (sameProject && notif.sessionId == activeSession));
461
+ if (notif.type !== "auth_required" && notif.sessionId && sameProject && String(notif.sessionId) === String(activeSession)) {
447
462
  dismissNotif(notif.id);
448
463
  return;
449
464
  }
@@ -452,16 +467,12 @@ export function handleNotificationCreated(msg) {
452
467
  unreadCount = msg.unreadCount;
453
468
  updateBadge();
454
469
 
455
- // user_mention banners are persistent (no auto-dismiss). They go away when:
456
- // 1. The user clicks the banner (which navigates to the session — see
457
- // banner click handler in showBanner / navigateToNotification), OR
458
- // 2. The user navigates to the target session by some other path, in which
459
- // case handleNotificationCreated above already dismissed the notif on
460
- // activeSessionId match, OR
461
- // 3. The user clicks the X close button.
462
- // Permission and auth banners are also persistent for the same UX reason.
463
- // A reminder stays until its prompt is answered, or the next one replaces it.
464
- var _autoDismiss = (notif.type === "permission_request" || notif.type === "permission_reminder" || notif.type === "auth_required" || notif.type === "user_mention") ? false : true;
470
+ // A banner stays until acted on when the type registry says so (the
471
+ // notification's persistent flag; lib/notify/types.js), or when it carries
472
+ // its own persistent marker in meta. It goes away when the user clicks it
473
+ // (which routes to its session), views the session some other way (handled
474
+ // above), closes it, or when its prompt resolves and the server dismisses it.
475
+ var _autoDismiss = !(notif.persistent === true || (notif.meta && notif.meta.persistent === true));
465
476
 
466
477
  // The user's per-type choices (lib/notification-prefs.js). A muted type has
467
478
  // still been added to the list and counted above: only the alert and the
@@ -510,22 +521,10 @@ function updateBadge() {
510
521
  // Navigation
511
522
  // ========================================================
512
523
 
524
+ // The one router (notify-client.js) opens the notification's project and
525
+ // session; the slug is part of the target, as session ids repeat across projects.
513
526
  function navigateToNotification(notif) {
514
- var currentSlug = store.get('currentSlug') || "";
515
- var needsProjectSwitch = notif.slug && notif.slug !== currentSlug;
516
-
517
- if (needsProjectSwitch) {
518
- // Store target session for after project switch
519
- if (notif.sessionId) {
520
- try { sessionStorage.setItem("pending-notif-session", notif.sessionId); } catch (e) {}
521
- }
522
- switchProject(notif.slug);
523
- } else if (notif.sessionId) {
524
- var ws = getWs();
525
- if (ws && ws.readyState === 1) {
526
- ws.send(JSON.stringify({ type: "switch_session", id: notif.sessionId }));
527
- }
528
- }
527
+ routeTo({ slug: notif.slug, sessionId: notif.sessionId, requestId: notif.meta && notif.meta.requestId });
529
528
  }
530
529
 
531
530
  // Build the sender avatar URL for a user_mention notification banner.
@@ -22,7 +22,7 @@ import { resetFileBrowser } from './filebrowser.js';
22
22
  import { closeArchive } from './sticky-notes.js';
23
23
  import { isSchedulerOpen, closeScheduler, resetScheduler } from './scheduler.js';
24
24
  import { connect, cancelReconnect, setStatus } from './app-connection.js';
25
- import { setTurnCounter, setPrependAnchor, setActivityEl, setIsUserScrolledUp, hideSuggestionChips, resetCurrentFullText } from './app-rendering.js';
25
+ import { setTurnCounter, setPrependAnchor, setActivityEl, setIsUserScrolledUp, hideSuggestionChips, resetCurrentFullText, resetStreamState } from './app-rendering.js';
26
26
  import { resetToolState, enableMainInput, resetTurnMetaCost, clearPromptStates } from './tools.js';
27
27
  import { clearPendingImages } from './input.js';
28
28
  import { clearAllMentionActive } from './sidebar-users.js';
@@ -404,6 +404,7 @@ export function resetClientState() {
404
404
  store.set({ currentMsgEl: null });
405
405
  store.set({ currentFullText: "" });
406
406
  resetCurrentFullText("");
407
+ resetStreamState();
407
408
  resetToolState();
408
409
  clearPromptStates();
409
410
  clearPendingImages();
@@ -506,6 +507,7 @@ export function switchProject(slug) {
506
507
  // session switch) where the session list must stay intact.
507
508
  if (typeof _onResetClientState === "function") _onResetClientState();
508
509
  resetClientState();
510
+ cancelReconnect();
509
511
  connect();
510
512
  }
511
513
 
@@ -37,6 +37,16 @@ var currentFullTextLocal = ""; // module-local accumulator — not in store duri
37
37
  export function resetCurrentFullText(v) {
38
38
  currentFullTextLocal = v || "";
39
39
  }
40
+
41
+ // Drops undrawn stream text and in-flight render bookkeeping. Without this a
42
+ // reset (reconnect, session or project switch) leaves buffered text that is
43
+ // then drawn in front of the next replayed block.
44
+ export function resetStreamState() {
45
+ if (streamDrainTimer) { cancelAnimationFrame(streamDrainTimer); streamDrainTimer = null; }
46
+ streamBuffer = "";
47
+ streamRenderPending = false;
48
+ streamRenderLen = 0;
49
+ }
40
50
  var isUserScrolledUp = false;
41
51
  var scrollThreshold = 150;
42
52
 
@@ -0,0 +1,81 @@
1
+ // build-update-sessions.js — the sessions a restart would end, as a count line
2
+ // with an expand control instead of one line each in the card's message. A
3
+ // card that lists every session grows with the session count until its
4
+ // action buttons leave the screen; collapsed by default, and bounded and
5
+ // scrolling when expanded, the list can never push them out. The card places
6
+ // this block above its actions, never around them. Every value is set with
7
+ // textContent: session titles are content, never markup.
8
+
9
+ function plural(n, word) {
10
+ return n + ' ' + word + (n === 1 ? '' : 's');
11
+ }
12
+
13
+ // The session lines the offer carries, or [] when it has none to set apart.
14
+ export function sessionLinesOf(offer) {
15
+ var i = offer && offer.interruptions;
16
+ if (!i || !Array.isArray(i.lines)) return [];
17
+ return i.lines.filter(function (l) { return typeof l === 'string' && l !== ''; });
18
+ }
19
+
20
+ /**
21
+ * The card's message without the per-session lines. Each line is dropped once,
22
+ * by exact match on the "- " form the daemon writes, so nothing else in the
23
+ * message can be mistaken for a session.
24
+ */
25
+ export function messageWithoutSessions(message, lines) {
26
+ if (lines.length === 0) return message;
27
+ var pending = lines.map(function (l) { return '- ' + l; });
28
+ return String(message).split('\n').filter(function (l) {
29
+ var at = pending.indexOf(l);
30
+ if (at === -1) return true;
31
+ pending.splice(at, 1);
32
+ return false;
33
+ }).join('\n');
34
+ }
35
+
36
+ /**
37
+ * @param {string[]} lines
38
+ * @param {{collapsed?: boolean}} [opts]
39
+ * @returns {?HTMLElement} null when there is no session to list
40
+ */
41
+ export function buildSessionsEl(lines, opts) {
42
+ if (!lines || lines.length === 0) return null;
43
+ var collapsed = !(opts && opts.collapsed === false);
44
+
45
+ var root = document.createElement('div');
46
+ root.className = 'build-update-sessions';
47
+
48
+ var head = document.createElement('div');
49
+ head.className = 'build-update-sessions-head';
50
+ var count = document.createElement('span');
51
+ count.className = 'build-update-sessions-count';
52
+ count.textContent = 'Ends ' + plural(lines.length, 'live session');
53
+ var toggle = document.createElement('button');
54
+ toggle.type = 'button';
55
+ toggle.className = 'collapsible-toggle build-update-sessions-toggle';
56
+ head.appendChild(count);
57
+ head.appendChild(toggle);
58
+
59
+ var list = document.createElement('ul');
60
+ list.className = 'build-update-session-list';
61
+ lines.forEach(function (l) {
62
+ var item = document.createElement('li');
63
+ item.textContent = l;
64
+ list.appendChild(item);
65
+ });
66
+
67
+ function apply() {
68
+ root.classList.toggle('is-collapsed', collapsed);
69
+ toggle.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
70
+ toggle.textContent = collapsed ? 'Expand' : 'Collapse';
71
+ }
72
+ toggle.addEventListener('click', function () {
73
+ collapsed = !collapsed;
74
+ apply();
75
+ });
76
+ apply();
77
+
78
+ root.appendChild(head);
79
+ root.appendChild(list);
80
+ return root;
81
+ }
@@ -27,6 +27,7 @@ import { iconHtml, refreshIcons } from './icons.js';
27
27
  import { formatDiagnosticSource as _formatSource } from './diagnostic-format.js';
28
28
  import { sendWs } from './ws-ref.js';
29
29
  import { buildUpdateDetailEl } from './build-update-detail.js';
30
+ import { sessionLinesOf, messageWithoutSessions, buildSessionsEl } from './build-update-sessions.js';
30
31
  import {
31
32
  BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION, noticeKeyOf, cooldownOf, createNoticeGate,
32
33
  } from './build-notice-gate.js';
@@ -477,10 +478,13 @@ function _showDiagnosticToast(entry) {
477
478
 
478
479
  var msgEl = document.createElement("div");
479
480
  msgEl.className = "toast-diagnostic-msg diagnostic-multiline";
480
- msgEl.textContent = entry.message;
481
+ var sessionLines = sessionLinesOf(entry.buildUpdate);
482
+ msgEl.textContent = messageWithoutSessions(entry.message, sessionLines);
481
483
 
482
484
  el.appendChild(headerEl);
483
485
  el.appendChild(msgEl);
486
+ var sessionsEl = buildSessionsEl(sessionLines);
487
+ if (sessionsEl) el.appendChild(sessionsEl);
484
488
  var hasAction = _appendToastActions(el, entry, function () {
485
489
  clearTimeout(timer);
486
490
  _removeDiagnosticToast(el);
@@ -587,10 +591,13 @@ function _appendEntry(entry) {
587
591
 
588
592
  var msgEl = document.createElement("div");
589
593
  msgEl.className = "diagnostics-message diagnostic-multiline";
590
- msgEl.textContent = entry.message;
594
+ var panelSessionLines = sessionLinesOf(entry.buildUpdate);
595
+ msgEl.textContent = messageWithoutSessions(entry.message, panelSessionLines);
591
596
 
592
597
  item.appendChild(meta);
593
598
  item.appendChild(msgEl);
599
+ var panelSessions = buildSessionsEl(panelSessionLines);
600
+ if (panelSessions) item.appendChild(panelSessions);
594
601
  var panelDetail = buildUpdateDetailEl(entry.buildUpdate);
595
602
  if (panelDetail) item.appendChild(panelDetail);
596
603
 
@@ -0,0 +1,34 @@
1
+ // env-shadow-notice.js - the warning shown under an environment editor when the
2
+ // Claude user settings file sets a variable the editor also sets. That file
3
+ // wins at the runtime, so the saved value has no effect for those names.
4
+
5
+ /**
6
+ * @param {string} elementId the notice element
7
+ * @param {?string[]} keys names set in both places (empty or absent hides it unless configDirNote is set)
8
+ * @param {boolean} [configDirNote] the edited text sets CLAUDE_CONFIG_DIR,
9
+ * which the console does not consult: say the check covers one file only
10
+ */
11
+ export function renderShadowNotice(elementId, keys, configDirNote) {
12
+ var el = document.getElementById(elementId);
13
+ if (!el) return;
14
+ var names = Array.isArray(keys) ? keys : [];
15
+ var scopeNote = "This check covers that user's Claude settings only; a CLAUDE_CONFIG_DIR set here is not consulted.";
16
+ // The scope note matters most when nothing overlaps: the admin would
17
+ // otherwise read the empty result as covering the directory they set.
18
+ if (names.length === 0 && configDirNote) {
19
+ el.textContent = scopeNote;
20
+ el.classList.remove("hidden");
21
+ return;
22
+ }
23
+ if (names.length === 0) {
24
+ el.textContent = "";
25
+ el.classList.add("hidden");
26
+ return;
27
+ }
28
+ el.textContent = (names.length === 1 ? "The variable " : "The variables ") + names.join(", ") +
29
+ (names.length === 1 ? " is" : " are") +
30
+ " also set in the Claude settings file of the user running Clagentic: Console. That file wins, so the value saved here has no effect for " +
31
+ (names.length === 1 ? "it." : "them.") +
32
+ (configDirNote ? " " + scopeNote : "");
33
+ el.classList.remove("hidden");
34
+ }
@@ -0,0 +1,153 @@
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
+
10
+ var Target = globalThis.NotifyTarget;
11
+ var PENDING_KEY = 'pending-notif-session';
12
+
13
+ export var urlForTarget = Target.urlForTarget;
14
+
15
+ var lastState = null;
16
+ var lastLivePrompts = null;
17
+
18
+ // The session a route is waiting to open once the connection is up. Held in
19
+ // memory as well as in sessionStorage: sessionStorage can be unavailable
20
+ // (private mode, quota), and the target must not depend on it.
21
+ var pendingSession = null;
22
+ // True while the deep link's query is still on the URL as the only durable
23
+ // copy of the target (sessionStorage refused it).
24
+ var queryHoldsTarget = false;
25
+
26
+ // Returns whether sessionStorage took the target. The in-memory copy is always
27
+ // kept, so a caller that sees false still has the route.
28
+ function rememberPendingSession(id) {
29
+ pendingSession = String(id);
30
+ try {
31
+ sessionStorage.setItem(PENDING_KEY, pendingSession);
32
+ return true;
33
+ } catch (e) {
34
+ console.debug('[notify] could not store the pending session:', e && e.message ? e.message : e);
35
+ return false;
36
+ }
37
+ }
38
+
39
+ function readStoredSession() {
40
+ try {
41
+ return sessionStorage.getItem(PENDING_KEY);
42
+ } catch (e) {
43
+ console.debug('[notify] could not read the pending session:', e && e.message ? e.message : e);
44
+ return null;
45
+ }
46
+ }
47
+
48
+ function clearStoredSession() {
49
+ try {
50
+ sessionStorage.removeItem(PENDING_KEY);
51
+ } catch (e) {
52
+ console.debug('[notify] could not clear the pending session:', e && e.message ? e.message : e);
53
+ }
54
+ }
55
+
56
+ function stripDeepLinkQuery() {
57
+ var params = new URLSearchParams(location.search);
58
+ params.delete('session');
59
+ params.delete('request');
60
+ var rest = params.toString();
61
+ history.replaceState(null, '', location.pathname + (rest ? '?' + rest : '') + location.hash);
62
+ }
63
+
64
+ /**
65
+ * The session a route is waiting to open, or null. Call it only once the
66
+ * connection can carry the switch: taking it ends the wait, and with it the
67
+ * deep link's query if that was the target's only copy.
68
+ * @returns {?number}
69
+ */
70
+ export function takePendingSession() {
71
+ var raw = pendingSession !== null ? pendingSession : readStoredSession();
72
+ pendingSession = null;
73
+ clearStoredSession();
74
+ if (queryHoldsTarget) {
75
+ queryHoldsTarget = false;
76
+ stripDeepLinkQuery();
77
+ }
78
+ return raw === null ? null : parseId(raw);
79
+ }
80
+
81
+ function parseId(id) {
82
+ var n = parseInt(id, 10);
83
+ return isNaN(n) ? null : n;
84
+ }
85
+
86
+ // Opens the target's project and session in this page. A different project is
87
+ // switched to first, and the session is picked up by handleNotificationsState
88
+ // through the pending key once that project's connection is up; the same
89
+ // project switches at once when its connection is open, else the same key
90
+ // carries it.
91
+ export function routeTo(target) {
92
+ var t = Target.makeTarget(target);
93
+ if (!t) return;
94
+ var current = store.get('currentSlug') || '';
95
+ var sessionId = parseId(t.sessionId);
96
+ if (t.slug && t.slug !== current) {
97
+ if (sessionId !== null) rememberPendingSession(sessionId);
98
+ switchProject(t.slug);
99
+ return;
100
+ }
101
+ if (sessionId === null) return;
102
+ var ws = getWs();
103
+ if (ws && ws.readyState === 1) {
104
+ ws.send(JSON.stringify({ type: 'switch_session', id: sessionId }));
105
+ } else {
106
+ rememberPendingSession(sessionId);
107
+ }
108
+ }
109
+
110
+ // The page was opened on a deep link (/p/<slug>/?session=<id>): route to the
111
+ // session once connected, then drop the query so a reload does not repeat it.
112
+ // When sessionStorage refused the target, the query stays until the route has
113
+ // been taken, so a reload still finds it.
114
+ function consumeDeepLink() {
115
+ var link = Target.parseDeepLink(location.search);
116
+ if (!link) return;
117
+ if (rememberPendingSession(link.sessionId)) stripDeepLinkQuery();
118
+ else queryHoldsTarget = true;
119
+ }
120
+
121
+ // Scoped to this page's own project: the live-prompt record names it, else
122
+ // the project the page is on.
123
+ function reconcile() {
124
+ if (lastState === null || document.visibilityState !== 'visible') return;
125
+ if (!navigator.serviceWorker || !globalThis.NotifySw) return;
126
+ var scope = {
127
+ slug: (lastLivePrompts && lastLivePrompts.slug) || store.get('currentSlug') || '',
128
+ livePrompts: lastLivePrompts,
129
+ };
130
+ navigator.serviceWorker.ready.then(function (reg) {
131
+ return globalThis.NotifySw.reconcileShown(reg, lastState, scope);
132
+ }).catch(function (e) {
133
+ console.debug('[notify] reconcile failed:', e && e.message ? e.message : e);
134
+ });
135
+ }
136
+
137
+ // Called with each notifications_state; reconciling waits for the first one so
138
+ // an empty list at boot never reads as "nothing is live".
139
+ export function noteNotificationsState(list, livePrompts) {
140
+ lastState = Array.isArray(list) ? list : [];
141
+ lastLivePrompts = livePrompts || null;
142
+ reconcile();
143
+ }
144
+
145
+ export function initNotifyClient() {
146
+ consumeDeepLink();
147
+ if (navigator.serviceWorker) {
148
+ navigator.serviceWorker.addEventListener('message', function (event) {
149
+ if (event.data && event.data.type === 'notify_route') routeTo(event.data.target);
150
+ });
151
+ }
152
+ document.addEventListener('visibilitychange', reconcile);
153
+ }
@@ -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) {
@@ -15,7 +15,7 @@
15
15
  /**
16
16
  * @typedef {{state: "pending"|"resolved"|"cancelled", decision?: ?string,
17
17
  * answers?: ?object, skipped?: boolean, action?: ?string,
18
- * reason?: ?string}} PromptState
18
+ * reason?: ?string, source?: ?string}} PromptState
19
19
  */
20
20
 
21
21
  var OUTCOME_FIELDS = ["decision", "answers", "skipped", "action"];
@@ -25,7 +25,7 @@ export function isTerminal(st) {
25
25
  }
26
26
 
27
27
  function normalizeState(next) {
28
- var out = { state: next.state, reason: next.reason || null };
28
+ var out = { state: next.state, reason: next.reason || null, source: next.source || null };
29
29
  OUTCOME_FIELDS.forEach(function (k) { out[k] = next[k] === undefined ? null : next[k]; });
30
30
  return out;
31
31
  }
@@ -135,7 +135,7 @@ export function normalizePromptMessage(msg) {
135
135
  return { phase: "cancel", requestId: msg.toolId, kind: "ask_user", fields: { reason: null }, serverState: null };
136
136
  case "prompt_cancel":
137
137
  case "permission_cancel":
138
- return { phase: "cancel", requestId: msg.requestId, kind: msg.kind || null, fields: { reason: msg.reason || null }, serverState: null };
138
+ return { phase: "cancel", requestId: msg.requestId, kind: msg.kind || null, fields: { reason: msg.reason || null, source: msg.source || null }, serverState: null };
139
139
  default:
140
140
  return null;
141
141
  }
@@ -115,7 +115,7 @@ export function createPromptController(host) {
115
115
  states.apply(n.requestId, Object.assign({ state: "resolved" }, n.fields));
116
116
  sync(n.requestId);
117
117
  } else {
118
- states.apply(n.requestId, { state: "cancelled", reason: n.fields.reason });
118
+ states.apply(n.requestId, { state: "cancelled", reason: n.fields.reason, source: n.fields.source });
119
119
  sync(n.requestId);
120
120
  }
121
121
  return states.get(n.requestId);
@@ -10,6 +10,7 @@ import { capabilitiesFor, defaultVendorId } from './vendor-registry.js';
10
10
  import { renderPermissionSettings } from './permission-settings.js';
11
11
  import { initCustomIconsSettings, initCustomIconsUpload, loadCustomIcons } from './custom-icons-settings.js';
12
12
  import { formatBytes } from './app-panels.js';
13
+ import { renderShadowNotice } from './env-shadow-notice.js';
13
14
  import { registerHandlers } from './app-messages.js';
14
15
 
15
16
  var ctx = null;
@@ -1225,6 +1226,7 @@ function loadSharedEnv() {
1225
1226
  }
1226
1227
 
1227
1228
  export function handleSharedEnv(msg) {
1229
+ renderShadowNotice("ss-env-shadow-notice", msg.shadowedKeys, msg.shadowConfigDirNote);
1228
1230
  var list = document.getElementById("ss-env-list");
1229
1231
  if (!list) return;
1230
1232
  list.innerHTML = "";
@@ -1237,6 +1239,7 @@ export function handleSharedEnv(msg) {
1237
1239
  }
1238
1240
 
1239
1241
  export function handleSharedEnvSaved(msg) {
1242
+ if (msg.ok) renderShadowNotice("ss-env-shadow-notice", msg.shadowedKeys, msg.shadowConfigDirNote);
1240
1243
  var saveStatus = document.getElementById("ss-env-save-status");
1241
1244
  if (!saveStatus) return;
1242
1245
  if (msg.ok) {