synabun 2.2.1 → 2.2.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 (149) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +1 -1
  3. package/hooks/claude-code/pre-websearch.mjs +4 -1
  4. package/hooks/claude-code/prompt-submit.mjs +7 -0
  5. package/lib/release-scan.mjs +23 -10
  6. package/lib/virustotal.mjs +143 -39
  7. package/mcp-server/dist/http.d.ts +19 -0
  8. package/mcp-server/dist/http.d.ts.map +1 -1
  9. package/mcp-server/dist/http.js +55 -13
  10. package/mcp-server/dist/http.js.map +1 -1
  11. package/mcp-server/dist/index.d.ts.map +1 -1
  12. package/mcp-server/dist/index.js +14 -9
  13. package/mcp-server/dist/index.js.map +1 -1
  14. package/mcp-server/dist/services/browser-route-flow.d.ts +118 -0
  15. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -0
  16. package/mcp-server/dist/services/browser-route-flow.js +339 -0
  17. package/mcp-server/dist/services/browser-route-flow.js.map +1 -0
  18. package/mcp-server/dist/services/desktop-client.js +2 -2
  19. package/mcp-server/dist/services/desktop-client.js.map +1 -1
  20. package/mcp-server/dist/services/identity.d.ts +66 -3
  21. package/mcp-server/dist/services/identity.d.ts.map +1 -1
  22. package/mcp-server/dist/services/identity.js +61 -4
  23. package/mcp-server/dist/services/identity.js.map +1 -1
  24. package/mcp-server/dist/services/neural-interface.d.ts +112 -1
  25. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  26. package/mcp-server/dist/services/neural-interface.js +555 -61
  27. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  28. package/mcp-server/dist/tools/bluesky.d.ts +20 -7
  29. package/mcp-server/dist/tools/bluesky.d.ts.map +1 -1
  30. package/mcp-server/dist/tools/bluesky.js +147 -45
  31. package/mcp-server/dist/tools/bluesky.js.map +1 -1
  32. package/mcp-server/dist/tools/browser-advanced.d.ts +11 -2
  33. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  34. package/mcp-server/dist/tools/browser-advanced.js +131 -18
  35. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  36. package/mcp-server/dist/tools/browser-cheatsheet.d.ts +2 -0
  37. package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
  38. package/mcp-server/dist/tools/browser-cheatsheet.js +3 -0
  39. package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
  40. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  41. package/mcp-server/dist/tools/morelogin.js +4 -2
  42. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  43. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  44. package/mcp-server/dist/tools/youtube/helpers.d.ts +1 -0
  45. package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
  46. package/mcp-server/dist/tools/youtube/helpers.js +1 -1
  47. package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
  48. package/mcp-server/package-lock.json +2 -2
  49. package/mcp-server/package.json +1 -1
  50. package/mcp-server/src/http.ts +58 -12
  51. package/mcp-server/src/index.ts +15 -9
  52. package/mcp-server/src/services/browser-route-flow.ts +402 -0
  53. package/mcp-server/src/services/desktop-client.ts +2 -2
  54. package/mcp-server/src/services/identity.ts +80 -4
  55. package/mcp-server/src/services/neural-interface.ts +572 -70
  56. package/mcp-server/src/tools/bluesky.ts +164 -51
  57. package/mcp-server/src/tools/browser-advanced.ts +121 -17
  58. package/mcp-server/src/tools/browser-cheatsheet.ts +3 -0
  59. package/mcp-server/src/tools/morelogin.ts +4 -2
  60. package/mcp-server/src/tools/youtube/helpers.ts +2 -2
  61. package/neural-interface/i18n/en.json +24 -0
  62. package/neural-interface/i18n/pt-BR.json +24 -0
  63. package/neural-interface/lib/assistant-api.js +64 -23
  64. package/neural-interface/lib/assistant-catalog.js +20 -2
  65. package/neural-interface/lib/assistant-dispatch.js +27 -1
  66. package/neural-interface/lib/assistant-persona.js +1 -0
  67. package/neural-interface/lib/assistant-runtime.js +15 -1
  68. package/neural-interface/lib/assistant-tools.js +10 -1
  69. package/neural-interface/lib/browser-automation-routes.js +84 -0
  70. package/neural-interface/lib/browser-execution.js +16 -3
  71. package/neural-interface/lib/browser-owner.js +48 -0
  72. package/neural-interface/lib/browser-session-close.js +84 -0
  73. package/neural-interface/lib/browser-start-handoff.js +202 -0
  74. package/neural-interface/lib/browser-tool-policy.js +21 -4
  75. package/neural-interface/lib/browser-wedge-retire.js +64 -0
  76. package/neural-interface/lib/claude-agent-bridge.js +36 -1
  77. package/neural-interface/lib/claude-background-hold.js +239 -0
  78. package/neural-interface/lib/exec-loop-command.js +8 -0
  79. package/neural-interface/lib/http-guards.js +11 -6
  80. package/neural-interface/lib/loop-logger.js +6 -1
  81. package/neural-interface/lib/mcp-external-servers.js +37 -10
  82. package/neural-interface/lib/native-loop-providers.js +121 -10
  83. package/neural-interface/lib/native-loop-runtime.js +112 -11
  84. package/neural-interface/lib/owner-authority.js +113 -37
  85. package/neural-interface/lib/page-session.js +81 -23
  86. package/neural-interface/lib/peer-identity.js +263 -43
  87. package/neural-interface/lib/provider-panel-api-key-auth.js +7 -2
  88. package/neural-interface/lib/pty-host/core.js +36 -0
  89. package/neural-interface/lib/pty-host/protocol.js +2 -0
  90. package/neural-interface/lib/skills/api-v2.js +13 -2
  91. package/neural-interface/lib/skills/creation-api.js +3 -1
  92. package/neural-interface/lib/skills/evals-api.js +5 -1
  93. package/neural-interface/lib/social-write-pacing.js +151 -0
  94. package/neural-interface/lib/terminal-token-redaction.js +293 -0
  95. package/neural-interface/lib/terminal-tokens.js +359 -0
  96. package/neural-interface/lib/worker-mcp-channel.js +45 -10
  97. package/neural-interface/package-lock.json +2 -2
  98. package/neural-interface/package.json +1 -1
  99. package/neural-interface/public/shared/agy/agy-render.js +41 -1
  100. package/neural-interface/public/shared/agy/agy-styles.js +5 -0
  101. package/neural-interface/public/shared/api.js +1 -0
  102. package/neural-interface/public/shared/assistant/asst-computer.js +47 -2
  103. package/neural-interface/public/shared/assistant/asst-limit-wait.js +3 -1
  104. package/neural-interface/public/shared/assistant/asst-panel.js +7 -3
  105. package/neural-interface/public/shared/assistant/asst-render.js +10 -4
  106. package/neural-interface/public/shared/assistant/asst-styles.js +2 -1
  107. package/neural-interface/public/shared/cdx/cdx-render.js +73 -7
  108. package/neural-interface/public/shared/cdx/cdx-tabs.js +3 -3
  109. package/neural-interface/public/shared/cp/cp-agents.js +8 -0
  110. package/neural-interface/public/shared/cp/cp-permissions.js +6 -2
  111. package/neural-interface/public/shared/cp/cp-rehydrate.js +25 -1
  112. package/neural-interface/public/shared/cp/cp-tasks-model.js +33 -0
  113. package/neural-interface/public/shared/judgments-log-origins.js +29 -0
  114. package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +23 -0
  115. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +13 -0
  116. package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +3 -1
  117. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +4 -2
  118. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +6 -86
  119. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +5 -2
  120. package/neural-interface/public/shared/owner-access.js +134 -0
  121. package/neural-interface/public/shared/owner-authority-view.js +92 -0
  122. package/neural-interface/public/shared/page-session.js +143 -14
  123. package/neural-interface/public/shared/poll-backoff.js +59 -0
  124. package/neural-interface/public/shared/settings/settings-data.js +6 -1
  125. package/neural-interface/public/shared/settings/settings-kit.js +11 -3
  126. package/neural-interface/public/shared/settings/settings-shell.js +7 -0
  127. package/neural-interface/public/shared/shown-children.js +72 -0
  128. package/neural-interface/public/shared/static-bg-state.js +22 -0
  129. package/neural-interface/public/shared/styles.css +101 -7
  130. package/neural-interface/public/shared/synabun-tools.js +173 -0
  131. package/neural-interface/public/shared/tool-heartbeat.js +43 -0
  132. package/neural-interface/public/shared/tool-list-picker.js +3 -1
  133. package/neural-interface/public/shared/tool-list-view.js +23 -4
  134. package/neural-interface/public/shared/ui-automation-studio.js +8 -1
  135. package/neural-interface/public/shared/ui-claude-panel.js +159 -29
  136. package/neural-interface/public/shared/ui-judgments.js +37 -10
  137. package/neural-interface/public/shared/ui-navbar.js +6 -0
  138. package/neural-interface/public/shared/ui-owner-access.js +191 -0
  139. package/neural-interface/public/shared/ui-owner-authority.js +162 -0
  140. package/neural-interface/public/shared/ui-sessions.js +45 -16
  141. package/neural-interface/public/shared/ui-settings.js +86 -15
  142. package/neural-interface/public/shared/ui-terminal.js +15 -7
  143. package/neural-interface/public/shared/ui-tutorial-preview.js +4 -0
  144. package/neural-interface/public/shared/ui-update.js +3 -0
  145. package/neural-interface/public/shared/ui-whiteboard.js +4 -0
  146. package/neural-interface/public/shared/window-keys.js +38 -0
  147. package/neural-interface/server.js +1160 -205
  148. package/npm-shrinkwrap.json +2 -2
  149. package/package.json +1 -1
@@ -0,0 +1,191 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Neural Interface — a page without the owner's access: the page side
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // When the server refuses this page the owner's access (SynaBun's automation browser opened it: 403 WORKER_BROWSER;
6
+ // or a refusal the page secret's recovery could not cure: PAGE_SECRET_REQUIRED, OWNER_ROUTE), the page says so in one
7
+ // way everywhere instead of showing a refused read as an empty list or default values:
8
+ // • one banner at the top centre (the owner-authority banner's glass and warning tint, styles.css
9
+ // .owner-authority-notice), with Reload and Dismiss; never on an invite guest's page;
10
+ // • `markNoAccess(container)` in a panel whose data was refused: a "No access" block on top, its Save and actions
11
+ // disabled (`noAccessHTML()` for a list that draws its own empty state);
12
+ // • `ownerAccessRefused()` / `onOwnerAccessChange(fn)` for a poller that should stop (asst-computer.js).
13
+ // What it knows comes from page-session.js (the page's fetch tells every final refusal, and a refresh that got this
14
+ // boot's page secret); a page that becomes visible again while refused asks for the secret once more (one request).
15
+ // The words are owner-access.js (DOM-free, tested under node), `ownerAccess.*` in i18n.
16
+
17
+ import { on } from './state.js';
18
+ import { t } from './i18n.js';
19
+ import { isGuest } from './ui-sync.js';
20
+ import { OWNER_ACCESS_REFUSED_EVENT, OWNER_ACCESS_RESTORED_EVENT, refreshPageSession } from './page-session.js';
21
+ import { createOwnerAccessState, ownerAccessNoticeView, ownerAccessSayer, refusalOfError, refusalOfResponse } from './owner-access.js';
22
+
23
+ export { refusalOfError, refusalOfResponse };
24
+
25
+ const NOTICE_ID = 'owner-access-notice';
26
+ /** What markNoAccess disables: every control but a section's own disclosure (its header). */
27
+ const CONTROLS = 'button, input, textarea, select, .cc-dropdown-trigger';
28
+
29
+ const access = createOwnerAccessState();
30
+ const say = ownerAccessSayer((key, params) => t(`ownerAccess.${key}`, params));
31
+
32
+ let _wired = false;
33
+ let _guest = false;
34
+ let _current = null; // { key, el }
35
+ let _dismissed = null; // the key this page dismissed
36
+ let _rechecking = null;
37
+
38
+ const guestPage = () => { try { return _guest || isGuest(); } catch { return _guest; } };
39
+
40
+ function esc(value) {
41
+ return String(value ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
42
+ }
43
+
44
+ /** What the page knows about its own access: null, or { code, reason: 'automation'|'owner', url, at }. */
45
+ export function ownerAccessRefused() { return access.current(); }
46
+
47
+ /** Told every change of what the page knows (fn(current)); returns the unsubscribe. */
48
+ export function onOwnerAccessChange(fn) { return access.subscribe(fn); }
49
+
50
+ /** A refusal seen through a path page-session.js does not wrap (a refusal, an error or an event's detail). */
51
+ export function noteOwnerAccessRefusal(detail) {
52
+ const changed = access.note(detail);
53
+ if (changed) presentOwnerAccess();
54
+ return changed;
55
+ }
56
+
57
+ /** The page is the owner's again (it got this boot's page secret). */
58
+ export function clearOwnerAccessRefusal() {
59
+ if (access.clear()) presentOwnerAccess();
60
+ }
61
+
62
+ /** A sentence of the "No access" state, in the page's language. */
63
+ export function ownerAccessSay(key, params) { return say(key, params); }
64
+
65
+ /** The "No access" block a panel draws in place of its empty state or its fields. */
66
+ export function noAccessHTML({ id = '', compact = false } = {}) {
67
+ return `<div class="owner-no-access${compact ? ' owner-no-access--compact' : ''}" role="status" data-owner-access="refused"${id ? ` id="${esc(id)}"` : ''}>
68
+ <div class="owner-no-access-icon" aria-hidden="true">!</div>
69
+ <div class="owner-no-access-body">
70
+ <div class="owner-no-access-title">${esc(say('panelTitle'))}</div>
71
+ <div class="owner-no-access-desc">${esc(say('panelBody'))}</div>
72
+ </div>
73
+ </div>`;
74
+ }
75
+
76
+ /**
77
+ * A panel whose data was refused: the "No access" block at its top (once) and its controls disabled (Save, Reset,
78
+ * fields, dropdowns; a section's header still opens and closes). Returns the container (or null).
79
+ */
80
+ export function markNoAccess(container, { controls = CONTROLS, keep = null } = {}) {
81
+ if (!container || typeof container.querySelector !== 'function') return null;
82
+ container.dataset.ownerAccess = 'refused';
83
+ if (!container.querySelector(':scope > .owner-no-access')) container.insertAdjacentHTML('afterbegin', noAccessHTML());
84
+ const why = say('actionDisabled');
85
+ container.querySelectorAll(controls).forEach((node) => {
86
+ if (node.closest('.owner-no-access') || node.hasAttribute('aria-expanded')) return;
87
+ if (keep && node.matches(keep)) return;
88
+ if ('disabled' in node) node.disabled = true;
89
+ node.setAttribute('aria-disabled', 'true');
90
+ node.classList.add('owner-access-disabled');
91
+ if (!node.getAttribute('title')) node.setAttribute('title', why);
92
+ });
93
+ return container;
94
+ }
95
+
96
+ // ── The banner ──
97
+
98
+ function hide() {
99
+ const current = _current;
100
+ _current = null;
101
+ if (!current) return;
102
+ current.el.classList.remove('show');
103
+ setTimeout(() => current.el.remove(), 250);
104
+ }
105
+
106
+ /** The loading screen covers the page while it starts: the banner waits for it to go. */
107
+ function whenPageShown(run) {
108
+ const overlay = document.getElementById('loading-overlay');
109
+ if (!overlay || overlay.classList.contains('hidden') || typeof MutationObserver === 'undefined') { run(); return; }
110
+ const watch = new MutationObserver(() => {
111
+ if (!overlay.classList.contains('hidden')) return;
112
+ watch.disconnect();
113
+ run();
114
+ });
115
+ watch.observe(overlay, { attributes: true, attributeFilter: ['class'] });
116
+ }
117
+
118
+ function draw(view) {
119
+ document.querySelectorAll(`#${NOTICE_ID}`).forEach((el) => el.remove());
120
+ const el = document.createElement('div');
121
+ el.className = 'owner-authority-notice owner-access-notice';
122
+ el.id = NOTICE_ID;
123
+ el.setAttribute('role', 'status');
124
+ el.setAttribute('aria-live', 'polite');
125
+ el.setAttribute('aria-label', view.label);
126
+ el.dataset.noticeKey = view.key;
127
+ const buttons = view.actions.map((item) => `<button class="action-btn ${item.id === 'reload' ? 'action-btn--primary' : 'action-btn--ghost'} owner-authority-btn" type="button" data-owner-access-action="${esc(item.id)}" id="owner-access-${esc(item.id)}">${esc(item.label)}</button>`).join('');
128
+ el.innerHTML = `
129
+ <div class="owner-authority-icon" aria-hidden="true">!</div>
130
+ <div class="owner-authority-body">
131
+ <div class="owner-authority-title" id="owner-access-title">${esc(view.title)}</div>
132
+ <div class="owner-authority-sub" id="owner-access-text">${esc(view.body)}</div>
133
+ <div class="update-notice-actions">${buttons}</div>
134
+ </div>`;
135
+ el.querySelectorAll('[data-owner-access-action]').forEach((btn) => {
136
+ btn.addEventListener('click', (event) => {
137
+ event.stopPropagation();
138
+ if (btn.dataset.ownerAccessAction === 'reload') {
139
+ try { window.location.reload(); } catch { /* nothing to reload */ }
140
+ } else {
141
+ _dismissed = view.key;
142
+ hide();
143
+ }
144
+ });
145
+ });
146
+ document.body.appendChild(el);
147
+ requestAnimationFrame(() => el.classList.add('show'));
148
+ _current = { key: view.key, el };
149
+ }
150
+
151
+ /** Draw (or take away) the banner for what the page knows now. */
152
+ function presentOwnerAccess() {
153
+ if (!_wired) return null;
154
+ const view = ownerAccessNoticeView(access.current(), { t: (key, params) => t(`ownerAccess.${key}`, params) });
155
+ if (!view || guestPage()) { hide(); if (!view) _dismissed = null; return null; }
156
+ if (_current && !_current.el.isConnected) _current = null;
157
+ if (_dismissed === view.key || _current?.key === view.key) return view;
158
+ whenPageShown(() => {
159
+ if (guestPage() || _dismissed === view.key || _current?.key === view.key) return;
160
+ if (!access.current()) return;
161
+ draw(view);
162
+ });
163
+ return view;
164
+ }
165
+
166
+ /** A refused page that becomes visible again asks for the page secret once (it may be the owner's window now). */
167
+ function recheck() {
168
+ if (!access.current() || _rechecking) return _rechecking;
169
+ _rechecking = refreshPageSession(window).then((ok) => { if (ok) clearOwnerAccessRefusal(); return ok; }).finally(() => { _rechecking = null; });
170
+ return _rechecking;
171
+ }
172
+
173
+ /** Wire the banner once: every final refusal, every restore, the guest flag, and a recheck when the page shows again. */
174
+ export function initOwnerAccessNotice() {
175
+ if (_wired || typeof window === 'undefined') return;
176
+ _wired = true;
177
+ on('session:info', (info) => {
178
+ _guest = !!info?.isGuest;
179
+ if (_guest) hide(); else presentOwnerAccess();
180
+ });
181
+ document.addEventListener('visibilitychange', () => { if (!document.hidden) recheck(); });
182
+ presentOwnerAccess();
183
+ }
184
+
185
+ // What the page knows is kept from the first refusal on, whoever draws it: page-session.js keeps the last one it told
186
+ // on the window (a refusal before this module loaded), and every later one comes as an event.
187
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
188
+ if (window.__synabunOwnerAccessRefused) access.note(window.__synabunOwnerAccessRefused);
189
+ window.addEventListener(OWNER_ACCESS_REFUSED_EVENT, (event) => { noteOwnerAccessRefusal(event?.detail); });
190
+ window.addEventListener(OWNER_ACCESS_RESTORED_EVENT, () => { clearOwnerAccessRefusal(); });
191
+ }
@@ -0,0 +1,162 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Neural Interface — the banner of a degraded owner authority: the page side
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // When the server cannot identify the program calling it (macOS, lib/peer-identity.js: netstat or ps missing,
6
+ // denied, slow past their cap), it pauses the owner's actions (503 PEER_UNAVAILABLE). This banner says so, with the
7
+ // reason and Reload to retry, in the update toast's glass at the top centre of the page (styles.css .owner-authority-notice):
8
+ // non-modal, nothing behind it is blocked. It shows when
9
+ // • GET /api/health says `ownerAuthority.state: 'degraded'` (asked when the page starts and every time the sync
10
+ // socket connects: a page that was open through a restart is not reloaded), or
11
+ // • a request of the page got 503 PEER_UNAVAILABLE (public/shared/page-session.js dispatches
12
+ // `synabun:peer-unavailable` on the window).
13
+ // While it shows, /api/health is asked again now and then, and the banner goes once the state is ok again (the
14
+ // page's next write then gets this boot's page secret by itself). Dismiss hides it until another reason comes. Never
15
+ // on an invite guest's page (the owner's authority is not a guest's concern). What it says is
16
+ // owner-authority-view.js (DOM-free, tested under node).
17
+
18
+ import { on } from './state.js';
19
+ import { t } from './i18n.js';
20
+ import { isGuest } from './ui-sync.js';
21
+ import { PEER_UNAVAILABLE_EVENT } from './page-session.js';
22
+ import { ownerAuthorityNoticeView, readOwnerAuthority, unavailableAuthority } from './owner-authority-view.js';
23
+
24
+ const HEALTH_URL = '/api/health';
25
+ const NOTICE_ID = 'owner-authority-notice';
26
+ /** How often /api/health is asked again while the banner shows. */
27
+ export const RECHECK_MS = 15_000;
28
+
29
+ const translate = (key, params) => t(`ownerAuthorityNotice.${key}`, params);
30
+
31
+ let _wired = false;
32
+ let _guest = false;
33
+ let _asking = null;
34
+ let _current = null; // { key, el }
35
+ let _dismissed = null; // the key this page dismissed
36
+ let _recheck = null;
37
+
38
+ const guestPage = () => _guest || isGuest();
39
+
40
+ function esc(value) {
41
+ return String(value ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
42
+ }
43
+
44
+ function stopRecheck() {
45
+ if (_recheck) { clearInterval(_recheck); _recheck = null; }
46
+ }
47
+ function startRecheck() {
48
+ if (_recheck) return;
49
+ _recheck = setInterval(() => { checkOwnerAuthority(); }, RECHECK_MS);
50
+ _recheck.unref?.();
51
+ }
52
+
53
+ function hide() {
54
+ stopRecheck();
55
+ const current = _current;
56
+ _current = null;
57
+ if (!current) return;
58
+ current.el.classList.remove('show');
59
+ setTimeout(() => current.el.remove(), 250);
60
+ }
61
+
62
+ /** The loading screen covers the page while it starts: the banner waits for it to go. */
63
+ function whenPageShown(run) {
64
+ const overlay = document.getElementById('loading-overlay');
65
+ if (!overlay || overlay.classList.contains('hidden') || typeof MutationObserver === 'undefined') { run(); return; }
66
+ const watch = new MutationObserver(() => {
67
+ if (!overlay.classList.contains('hidden')) return;
68
+ watch.disconnect();
69
+ run();
70
+ });
71
+ watch.observe(overlay, { attributes: true, attributeFilter: ['class'] });
72
+ }
73
+
74
+ function draw(view) {
75
+ document.querySelectorAll(`#${NOTICE_ID}`).forEach((el) => el.remove());
76
+ const el = document.createElement('div');
77
+ el.className = 'owner-authority-notice';
78
+ el.id = NOTICE_ID;
79
+ el.setAttribute('role', 'status');
80
+ el.setAttribute('aria-live', 'polite');
81
+ el.setAttribute('aria-label', view.label);
82
+ el.dataset.noticeKey = view.key;
83
+ const buttons = view.actions.map((item) => `<button class="action-btn ${item.id === 'reload' ? 'action-btn--primary' : 'action-btn--ghost'} owner-authority-btn" type="button" data-owner-action="${esc(item.id)}" id="owner-authority-${esc(item.id)}">${esc(item.label)}</button>`).join('');
84
+ el.innerHTML = `
85
+ <div class="owner-authority-icon" aria-hidden="true">!</div>
86
+ <div class="owner-authority-body">
87
+ <div class="owner-authority-title" id="owner-authority-title">${esc(view.title)}</div>
88
+ <div class="owner-authority-sub" id="owner-authority-text">${esc(view.body)}</div>
89
+ ${view.reason ? `<div class="owner-authority-sub owner-authority-reason" id="owner-authority-reason">${esc(view.reason)}</div>` : ''}
90
+ ${view.hint ? `<div class="owner-authority-hint" id="owner-authority-hint">${esc(view.hint)}</div>` : ''}
91
+ <div class="update-notice-actions">${buttons}</div>
92
+ </div>`;
93
+ el.querySelectorAll('[data-owner-action]').forEach((btn) => {
94
+ btn.addEventListener('click', (event) => {
95
+ event.stopPropagation();
96
+ if (btn.dataset.ownerAction === 'reload') reloadPage();
97
+ else if (btn.dataset.ownerAction === 'dismiss') dismiss(view.key);
98
+ });
99
+ });
100
+ document.body.appendChild(el);
101
+ requestAnimationFrame(() => el.classList.add('show'));
102
+ _current = { key: view.key, el };
103
+ startRecheck();
104
+ }
105
+
106
+ /** Reload to retry: the page asks for everything again, the page secret included (a lookup that works hands it out). */
107
+ function reloadPage() {
108
+ try { (typeof window !== 'undefined' && window.location ? window.location : globalThis.location).reload(); } catch { /* nothing to reload */ }
109
+ }
110
+
111
+ function dismiss(key) {
112
+ _dismissed = key;
113
+ hide();
114
+ }
115
+
116
+ /** Show the banner for this owner authority (or none): never on a guest's page, never one this page dismissed. */
117
+ export function presentOwnerAuthority(authority) {
118
+ const view = ownerAuthorityNoticeView(authority, { t: translate });
119
+ if (!view || guestPage()) { hide(); if (!view) _dismissed = null; return null; }
120
+ // A banner something else took off the page is drawn again.
121
+ if (_current && !_current.el.isConnected) _current = null;
122
+ if (_dismissed === view.key) return null;
123
+ if (_current?.key === view.key) return view;
124
+ whenPageShown(() => {
125
+ if (guestPage() || _dismissed === view.key || _current?.key === view.key) return;
126
+ draw(view);
127
+ });
128
+ return view;
129
+ }
130
+
131
+ /** Ask GET /api/health; an older server (no `ownerAuthority`) or a failed request changes nothing. */
132
+ export function checkOwnerAuthority() {
133
+ if (guestPage()) return Promise.resolve(null);
134
+ if (_asking) return _asking;
135
+ _asking = (async () => {
136
+ try {
137
+ const res = await fetch(HEALTH_URL, { headers: { Accept: 'application/json' }, cache: 'no-store' });
138
+ if (!res.ok) return null;
139
+ const authority = readOwnerAuthority(await res.json());
140
+ if (authority) presentOwnerAuthority(authority);
141
+ return authority;
142
+ } catch {
143
+ return null;
144
+ }
145
+ })().finally(() => { _asking = null; });
146
+ return _asking;
147
+ }
148
+
149
+ /** Wire the banner once: ask now, again whenever the sync socket connects, and on every 503 PEER_UNAVAILABLE. */
150
+ export function initOwnerAuthorityNotice() {
151
+ if (_wired) return;
152
+ _wired = true;
153
+ on('session:info', (info) => {
154
+ _guest = !!info?.isGuest;
155
+ if (_guest) hide();
156
+ else checkOwnerAuthority();
157
+ });
158
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
159
+ window.addEventListener(PEER_UNAVAILABLE_EVENT, (event) => { presentOwnerAuthority(unavailableAuthority(event?.detail)); });
160
+ }
161
+ checkOwnerAuthority();
162
+ }
@@ -20,6 +20,7 @@ import { openAntigravityWithPrompt } from './ui-antigravity-panel.js';
20
20
  import { dropdownHTML, wireDropdowns } from './cc-dropdown.js';
21
21
  import { fetchRulesStatus, installAllRules, ackRulesNotice } from './api.js';
22
22
  import { centeredInFrame } from './app-frame.js';
23
+ import { noAccessHTML, refusalOfResponse } from './ui-owner-access.js';
23
24
 
24
25
  // ── State ──
25
26
  let ws = null;
@@ -29,6 +30,9 @@ let leaks = [];
29
30
  let agents = [];
30
31
  let loops = [];
31
32
  let staleLoopCount = 0;
33
+ // A list whose read the server refused this page (it has no owner access: SynaBun's automation browser opened it):
34
+ // its tab says "No access", never "No loops" (ui-owner-access.js). null while the last read answered.
35
+ const _refused = { sessions: null, leaks: null, agents: null, loops: null };
32
36
  let _panel = null;
33
37
  let _backdrop = null;
34
38
  let _activeTab = 'updates'; // 'updates' | 'sessions' | 'agents' | 'loops' | 'leaks'
@@ -468,6 +472,7 @@ function renderUpdateCard(item, idx) {
468
472
  // ── Tab renderers ──
469
473
 
470
474
  function renderSessionsTab() {
475
+ if (_refused.sessions) return noAccessHTML({ compact: true });
471
476
  if (sessions.length === 0) {
472
477
  return `<div class="sm-empty-state">
473
478
  <div class="sm-empty-icon">${ICON_SESSIONS}</div>
@@ -513,6 +518,7 @@ function renderAgentsTab() {
513
518
  const runningAgents = agents.filter(a => a.status === 'running');
514
519
  const finishedAgents = agents.filter(a => a.status !== 'running');
515
520
 
521
+ if (_refused.agents) return noAccessHTML({ compact: true });
516
522
  if (agents.length === 0) {
517
523
  return `<div class="sm-empty-state">
518
524
  <div class="sm-empty-icon">${ICON_AGENT}</div>
@@ -573,6 +579,7 @@ function renderAgentCard(a) {
573
579
  }
574
580
 
575
581
  function renderLeaksTab() {
582
+ if (_refused.leaks) return noAccessHTML({ compact: true });
576
583
  const criticalLeaks = leaks.filter(l => l.severity === 'critical');
577
584
  const warningLeaks = leaks.filter(l => l.severity === 'warning');
578
585
  const infoLeaks = leaks.filter(l => l.severity === 'info');
@@ -659,6 +666,7 @@ function renderLeakCard(l) {
659
666
  }
660
667
 
661
668
  function renderLoopsTab() {
669
+ if (_refused.loops) return noAccessHTML({ compact: true });
662
670
  if (loops.length === 0) {
663
671
  return `<div class="sm-empty-state">
664
672
  <div class="sm-empty-icon">${ICON_LOOP}</div>
@@ -887,20 +895,41 @@ function stopStalledTicker() {
887
895
 
888
896
  // ── Actions ──
889
897
 
898
+ /**
899
+ * One list's read: { body } when it answered, { refusal } when the server refused this page the owner's access
900
+ * (the list then says "No access" and keeps what it had), {} when it failed otherwise.
901
+ */
902
+ async function readList(url) {
903
+ try {
904
+ const res = await fetch(url);
905
+ const refusal = await refusalOfResponse(res);
906
+ if (refusal) return { refusal };
907
+ if (!res.ok) return {};
908
+ return { body: await res.json() };
909
+ } catch { return {}; }
910
+ }
911
+
890
912
  async function refreshSessions() {
891
913
  try {
892
914
  const [sessRes, leakRes, agentRes, loopRes] = await Promise.all([
893
- fetch('/api/sessions/active').then(r => r.json()),
894
- fetch('/api/sessions/leaks').then(r => r.json()),
895
- fetch('/api/agents').then(r => r.json()).catch(() => ({ agents: [] })),
896
- fetch('/api/loop/list').then(r => r.json()).catch(() => ({ loops: [], staleCount: 0 })),
915
+ readList('/api/sessions/active'),
916
+ readList('/api/sessions/leaks'),
917
+ readList('/api/agents'),
918
+ readList('/api/loop/list'),
897
919
  ]);
898
- sessions = sessRes.sessions || [];
899
- leaks = leakRes.leaks || [];
900
- agents = agentRes.agents || [];
901
- const fetchedAt = Date.now();
902
- loops = (loopRes.loops || []).map(l => ({ ...l, _fetchedAt: fetchedAt }));
903
- staleLoopCount = loopRes.staleCount || 0;
920
+ _refused.sessions = sessRes.refusal || null;
921
+ _refused.leaks = leakRes.refusal || null;
922
+ _refused.agents = agentRes.refusal || null;
923
+ _refused.loops = loopRes.refusal || null;
924
+ // A list that failed keeps what it had (Sessions, Health) or is empty (Agents, Loops), as before.
925
+ if (sessRes.body) sessions = sessRes.body.sessions || [];
926
+ if (leakRes.body) leaks = leakRes.body.leaks || [];
927
+ if (agentRes.body || !agentRes.refusal) agents = agentRes.body?.agents || [];
928
+ if (loopRes.body || !loopRes.refusal) {
929
+ const fetchedAt = Date.now();
930
+ loops = (loopRes.body?.loops || []).map(l => ({ ...l, _fetchedAt: fetchedAt }));
931
+ staleLoopCount = loopRes.body?.staleCount || 0;
932
+ }
904
933
  _sessionsLoaded = true;
905
934
  emitLoopsUpdate();
906
935
  // Refresh notification feed alongside session/loop data
@@ -1277,12 +1306,12 @@ export function openLoopsTab() {
1277
1306
  // drawer. Called from ui-navbar.js on init so the alert dot can show on app
1278
1307
  // load.
1279
1308
  export async function fetchLoopsForBadge() {
1280
- try {
1281
- const res = await fetch('/api/loop/list').then(r => r.json());
1282
- loops = res.loops || [];
1283
- staleLoopCount = res.staleCount || 0;
1284
- emitLoopsUpdate();
1285
- } catch {}
1309
+ const read = await readList('/api/loop/list');
1310
+ _refused.loops = read.refusal || null;
1311
+ if (!read.body) return; // refused or failed: the badge keeps what the sync socket said
1312
+ loops = read.body.loops || [];
1313
+ staleLoopCount = read.body.staleCount || 0;
1314
+ emitLoopsUpdate();
1286
1315
  }
1287
1316
 
1288
1317
  // Bootstrap fetch for Updates badge — reads the rules status and emits the