Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(show-pages): fail closed on access refresh

Maxeea6c945115d
diff --git a/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx b/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx
index 7ac3d5227..c8dde128c 100644
--- a/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx
+++ b/ui/src/components/workbench/ChatArchivedReadOnly.test.tsx
@@ -304,6 +304,11 @@ describe('read-only header withdraws the Show Page controls', () => {
expect(isShowPageActive(true, false)).toBe(false);
});
+ it('withdraws an active Show Page frame on a definitive access denial', () => {
+ expect(isShowPageActive(false, true, false)).toBe(true);
+ expect(isShowPageActive(false, true, true)).toBe(false);
+ });
+
it('renders an archived header with the title and badge but no Show Page button', () => {
// Only the read-only header is reachable here: the live one renders
// AgentRoutePicker, which calls useApi() and throws without an ApiProvider.
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 2464b0763..9a054c333 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -293,7 +293,8 @@ export const ChatPage: React.FC = () => {
// Derived rather than an effect on purpose: the fallback lands in the SAME
// render that flips ``readOnly``. An effect would first commit one frame with
// the chat surface still hidden and the iframe already gone — a blank chat.
- const showPageActive = isShowPageActive(readOnly, showPageMode);
+ const showPageAccessDenied = showPageRestoreAccess === 'deny';
+ const showPageActive = isShowPageActive(readOnly, showPageMode, showPageAccessDenied);
// True while the share popover is open. The popover floats over the Show Page
// iframe; making the iframe inert lets an outside tap there reach the parent
// document so the (non-modal) popover dismisses, without modal-blocking the
@@ -310,6 +311,16 @@ export const ChatPage: React.FC = () => {
// show the stale enabled/mode and could send control messages to the freshly
// remounted overlay before it rebroadcasts. Re-points reset via the URL change.
const annotation = useShowPageAnnotation(showPageActive ? showPageUrl : null);
+ useEffect(() => {
+ const sid = sessionId;
+ if (!sid || !showPageAccessDenied) return;
+ // The derived showPageActive value already withdrew the iframe in this
+ // render. Persist the fallback and invalidate any in-flight ensure so a
+ // late response cannot re-open content after access was revoked.
+ showPageRestoreAttemptRef.current = sid;
+ selectChatView(sid, true);
+ setShowPageUrl(null);
+ }, [selectChatView, sessionId, showPageAccessDenied]);
const probeShowPageAccess = useCallback(async (targetSessionId: string) => {
const generation = ++showPageAccessProbeGenerationRef.current;
try {
@@ -2226,6 +2237,7 @@ export const ChatPage: React.FC = () => {
showPageAccess={showPageAccess}
canOpenShowPage={canOpenShowPage}
canManageShowPage={canManageShowPage}
+ canManageInstance={capabilities.can_manage_instance}
sessionActions={sessionActions}
titleFieldRef={titleFieldRef}
/>
@@ -2809,6 +2821,7 @@ interface ChatHeaderBarProps {
showPageAccess?: ShowPageAccess | null;
canOpenShowPage?: boolean;
canManageShowPage?: boolean;
+ canManageInstance?: boolean;
// Shared session actions, rendered behind the mobile-only ⋯ at the far right.
// Empty (or absent) withdraws the trigger — which is what a read-only session
// yields, since every one of those writes is refused.
@@ -2821,7 +2834,7 @@ interface ChatHeaderBarProps {
// which renders the header alone rather than mounting the whole page. Note the
// live (non-readOnly) header pulls in AgentRoutePicker → useApi, so only the
// read-only rendering is reachable without an ApiProvider.
-export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack, working, showPageMode, showPageBusy, onToggleShowPage, onPrepareShowPageLaunch, onShowPageVisibilityChange, onShareOpenChange, annotation, onAnnotateOpenChange, readOnlyReason, writable = readOnlyReason === null, showPageAccess = null, canOpenShowPage = true, canManageShowPage = true, sessionActions, titleFieldRef }) => {
+export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack, working, showPageMode, showPageBusy, onToggleShowPage, onPrepareShowPageLaunch, onShowPageVisibilityChange, onShareOpenChange, annotation, onAnnotateOpenChange, readOnlyReason, writable = readOnlyReason === null, showPageAccess = null, canOpenShowPage = true, canManageShowPage = true, canManageInstance = false, sessionActions, titleFieldRef }) => {
const { t } = useTranslation();
const readOnly = !writable;
const sessionReadOnly = readOnlyReason !== null;
@@ -2972,6 +2985,7 @@ export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, d
key={session.id}
sessionId={session.id}
initialAccess={showPageAccess}
+ canManageInstance={canManageInstance}
onPayloadChange={onShowPageVisibilityChange}
onOpenChange={onShareOpenChange}
/>
diff --git a/ui/src/components/workbench/ShowPageShareControl.tsx b/ui/src/components/workbench/ShowPageShareControl.tsx
index 492cd1d60..046591db0 100644
--- a/ui/src/components/workbench/ShowPageShareControl.tsx
+++ b/ui/src/components/workbench/ShowPageShareControl.tsx
@@ -38,6 +38,8 @@ type ShowPagePayload = ShowPageLinkInfo & {
export const ShowPageShareControl: React.FC<{
sessionId: string;
initialAccess?: ShowPageAccess | null;
+ // Dock mutations use Instance authority, not Show Page resource authority.
+ canManageInstance?: boolean;
// Lets the chat view re-point the iframe at the route that now serves the
// page when visibility flips (private↔public swap the serving route).
onPayloadChange?: (payload: ShowPageLinkInfo) => void;
@@ -45,7 +47,13 @@ export const ShowPageShareControl: React.FC<{
// inert while it is open so an outside tap there falls through to the parent
// document and Radix can dismiss (a tap inside an iframe never reaches us).
onOpenChange?: (open: boolean) => void;
-}> = ({ sessionId, initialAccess = null, onPayloadChange, onOpenChange }) => {
+}> = ({
+ sessionId,
+ initialAccess = null,
+ canManageInstance = false,
+ onPayloadChange,
+ onOpenChange,
+}) => {
const { t } = useTranslation();
const api = useApi();
const dock = useDock();
@@ -76,9 +84,12 @@ export const ShowPageShareControl: React.FC<{
const [loading, setLoading] = useState(false);
const [accessLoading, setAccessLoading] = useState(false);
const [access, setAccess] = useState<ShowPageAccess | null>(initialAccess);
- const shareCapabilities = showPageShareCapabilities(access);
- const payload = shareCapabilities.canReadPayload ? candidatePayload : null;
const [accessError, setAccessError] = useState(false);
+ const shareCapabilities = showPageShareCapabilities(access, {
+ accessInvalid: accessError,
+ canManageInstance,
+ });
+ const payload = shareCapabilities.canReadPayload ? candidatePayload : null;
const [busy, setBusy] = useState(false);
const [copied, setCopied] = useState(false);
// A visibility mutation is authoritative: it always applies its result and
@@ -137,7 +148,7 @@ export const ShowPageShareControl: React.FC<{
// refreshing so reopening doesn't flash a spinner.
const refresh = () => {
const seq = ++reqSeq.current;
- const canLoadPayload = access?.can_use !== false;
+ const canLoadPayload = canManageInstance || access?.can_use === true;
setLoading(canLoadPayload && !payload);
setAccessLoading(!access);
setAccessError(false);
@@ -164,6 +175,10 @@ export const ShowPageShareControl: React.FC<{
setAccess(nextAccess);
} catch {
if (seq !== reqSeq.current) return;
+ // A failed refresh cannot leave the previous authority actionable. The
+ // payload stays cached for a later successful refresh, but is withdrawn
+ // while accessError invalidates this control's authorization state.
+ setAccess(null);
setAccessError(true);
} finally {
setAccessLoading(false);
@@ -479,8 +494,8 @@ export const ShowPageShareControl: React.FC<{
{/* Pin to Dock — records the session's Show Page as a Dock app. Deliberately
OUTSIDE the visibility branches: pinning is independent of public/private
(a private page can be pinned) and never changes visibility or deletes the
- page. Shown whenever the page exists (the popover ensured it on open). */}
- {payload && (
+ page. Shown only when the page exists and the caller can manage the Instance. */}
+ {payload && shareCapabilities.canManageDock && (
<div className="border-t border-border pt-3">
<div className="flex items-center gap-3">
<span className="grid size-9 shrink-0 place-items-center rounded-lg border border-border bg-foreground/[0.03] text-cyan">
diff --git a/ui/src/components/workbench/sessionArchived.ts b/ui/src/components/workbench/sessionArchived.ts
index 0e77b6eca..686f946dc 100644
--- a/ui/src/components/workbench/sessionArchived.ts
+++ b/ui/src/components/workbench/sessionArchived.ts
@@ -130,9 +130,14 @@ export const transcriptSelectionActions = (
* a page it cannot leave and that archive already forced offline. Answering
* ``false`` here puts it back on the transcript. ChatPage derives this rather
* than resetting ``showPageMode`` from an effect, so the fallback lands in the
- * same render that flips ``readOnly``. */
-export const isShowPageActive = (readOnly: boolean, showPageMode: boolean): boolean =>
- showPageMode && !readOnly;
+ * same render that flips ``readOnly``. A definitive page-access denial follows
+ * the same rule: the already-rendered private frame must disappear in the render
+ * that observes the denial, before the state-reset effect persists Chat mode. */
+export const isShowPageActive = (
+ readOnly: boolean,
+ showPageMode: boolean,
+ accessDenied = false,
+): boolean => showPageMode && !readOnly && !accessDenied;
/** Which Show Page controls the chat header offers.
*
diff --git a/ui/src/lib/showPageAccess.test.ts b/ui/src/lib/showPageAccess.test.ts
index 1a01e45c8..2fa096bd0 100644
--- a/ui/src/lib/showPageAccess.test.ts
+++ b/ui/src/lib/showPageAccess.test.ts
@@ -81,11 +81,34 @@ describe('Show Page access policy helpers', () => {
expect(showPageShareCapabilities(manager)).toEqual({
canReadPayload: false,
canRevokePublicLinkWithoutPayload: true,
+ canManageDock: false,
});
expect(canChangeShowPagePublicLink(manager, false)).toBe(true);
expect(canChangeShowPagePublicLink(manager, true)).toBe(false);
});
+ it('fails closed after an access refresh error and keeps Dock authority separate', () => {
+ const manager = access({
+ can_use: false,
+ can_publish_public: false,
+ public_link_enabled: true,
+ });
+
+ expect(showPageShareCapabilities(manager, { accessInvalid: true })).toEqual({
+ canReadPayload: false,
+ canRevokePublicLinkWithoutPayload: false,
+ canManageDock: false,
+ });
+ expect(showPageShareCapabilities(null)).toEqual({
+ canReadPayload: false,
+ canRevokePublicLinkWithoutPayload: false,
+ canManageDock: false,
+ });
+ expect(showPageShareCapabilities(null, { canManageInstance: true }).canReadPayload).toBe(true);
+ expect(showPageShareCapabilities(access(), { canManageInstance: false }).canManageDock).toBe(false);
+ expect(showPageShareCapabilities(access(), { canManageInstance: true }).canManageDock).toBe(true);
+ });
+
it('separates page use from page-specific access management in the chat header', () => {
expect(showPageHeaderAccess(false, access({ can_use: true, can_manage: false }))).toEqual({
canOpen: true,
diff --git a/ui/src/lib/showPageAccess.ts b/ui/src/lib/showPageAccess.ts
index d4dc62710..d1e75a9aa 100644
--- a/ui/src/lib/showPageAccess.ts
+++ b/ui/src/lib/showPageAccess.ts
@@ -123,18 +123,31 @@ export function canChangeShowPagePublicLink(
return nextEnabled ? access.can_publish_public : access.can_manage;
}
-export function showPageShareCapabilities(access: ShowPageAccess | null): {
+export function showPageShareCapabilities(
+ access: ShowPageAccess | null,
+ options: {
+ accessInvalid?: boolean;
+ canManageInstance?: boolean;
+ } = {},
+): {
canReadPayload: boolean;
canRevokePublicLinkWithoutPayload: boolean;
+ canManageDock: boolean;
} {
+ const accessValid = options.accessInvalid !== true;
+ const canManageInstance = options.canManageInstance === true;
return {
- canReadPayload: access?.can_use !== false,
+ canReadPayload: accessValid && (canManageInstance || access?.can_use === true),
canRevokePublicLinkWithoutPayload: Boolean(
- access
+ accessValid
+ && access
&& !access.can_use
&& access.can_manage
&& access.public_link_enabled,
),
+ // Dock writes remain Instance-owner operations. Page-level use/manage
+ // authority deliberately does not inherit this independent capability.
+ canManageDock: canManageInstance,
};
}