diff --git a/desktop/playwright.config.ts b/desktop/playwright.config.ts
index 3b5f35d990..0234916738 100644
--- a/desktop/playwright.config.ts
+++ b/desktop/playwright.config.ts
@@ -36,6 +36,7 @@ export default defineConfig({
"**/profile-active-turn.spec.ts",
"**/config-bridge-screenshots.spec.ts",
"**/observer-feed-screenshots.spec.ts",
+ "**/activity-scope-label-screenshots.spec.ts",
"**/file-attachment.spec.ts",
"**/image-attachment-gallery.spec.ts",
"**/video-attachment.spec.ts",
diff --git a/desktop/src/app/navigation/useAppNavigation.ts b/desktop/src/app/navigation/useAppNavigation.ts
index 3b40eeab49..820e9f046a 100644
--- a/desktop/src/app/navigation/useAppNavigation.ts
+++ b/desktop/src/app/navigation/useAppNavigation.ts
@@ -145,6 +145,8 @@ export function useAppNavigation() {
(
channelId: string,
options?: {
+ /** Open the agent activity pane for this agent pubkey on arrival. */
+ agentSession?: string;
messageId?: string;
replace?: boolean;
threadRootId?: string | null;
@@ -156,12 +158,17 @@ export function useAppNavigation() {
params: {
channelId,
},
- search: options?.messageId
- ? {
- messageId: options.messageId,
- threadRootId: options.threadRootId ?? undefined,
- }
- : {},
+ search: {
+ ...(options?.messageId
+ ? {
+ messageId: options.messageId,
+ threadRootId: options.threadRootId ?? undefined,
+ }
+ : {}),
+ ...(options?.agentSession
+ ? { agentSession: options.agentSession }
+ : {}),
+ },
},
{
replace: options?.replace,
diff --git a/desktop/src/features/agents/ui/ManagedAgentRow.tsx b/desktop/src/features/agents/ui/ManagedAgentRow.tsx
index f065e3c88c..aaa07a8317 100644
--- a/desktop/src/features/agents/ui/ManagedAgentRow.tsx
+++ b/desktop/src/features/agents/ui/ManagedAgentRow.tsx
@@ -7,6 +7,7 @@ import { PresenceDot } from "@/features/presence/ui/PresenceBadge";
import { Badge } from "@/shared/ui/badge";
import { AgentStatusBadge } from "@/features/agents/ui/AgentStatusBadge";
import { useAgentWorking } from "@/features/agents/agentWorkingSignal";
+import { useOpenAgentActivity } from "@/features/agents/useOpenAgentActivity";
import { formatElapsed } from "@/features/agents/ui/agentSessionUtils";
import { useNow } from "@/shared/lib/useNow";
import type {
@@ -202,6 +203,7 @@ function AgentSummary({
presenceStatus: PresenceStatus | undefined;
}) {
const { goChannel } = useAppNavigation();
+ const { openAgentActivity } = useOpenAgentActivity();
return (
@@ -275,7 +277,11 @@ function AgentSummary({
channelId={channel.id}
name={channel.name}
anchorAt={channel.anchorAt}
- onNavigate={goChannel}
+ // Deep-link straight into the agent's activity pane in the
+ // working channel, not just the channel timeline.
+ onNavigate={(channelId) =>
+ openAgentActivity(agent.pubkey, { channelId })
+ }
/>
))}
diff --git a/desktop/src/features/agents/useOpenAgentActivity.test.mjs b/desktop/src/features/agents/useOpenAgentActivity.test.mjs
new file mode 100644
index 0000000000..503566de90
--- /dev/null
+++ b/desktop/src/features/agents/useOpenAgentActivity.test.mjs
@@ -0,0 +1,84 @@
+import assert from "node:assert/strict";
+import { describe, it } from "node:test";
+
+import {
+ isChannelOpenable,
+ resolveOpenableActivityChannelId,
+} from "./useOpenAgentActivity.ts";
+
+describe("isChannelOpenable", () => {
+ it("allows joined channels regardless of visibility", () => {
+ assert.equal(
+ isChannelOpenable({ isMember: true, visibility: "private" }),
+ true,
+ );
+ assert.equal(
+ isChannelOpenable({ isMember: true, visibility: "open" }),
+ true,
+ );
+ });
+
+ it("allows open channels the viewer hasn't joined (read-only)", () => {
+ assert.equal(
+ isChannelOpenable({ isMember: false, visibility: "open" }),
+ true,
+ );
+ });
+
+ it("rejects private channels the viewer hasn't joined", () => {
+ assert.equal(
+ isChannelOpenable({ isMember: false, visibility: "private" }),
+ false,
+ );
+ });
+
+ it("rejects channels missing from the viewer's channel list", () => {
+ assert.equal(isChannelOpenable(undefined), false);
+ });
+});
+
+describe("resolveOpenableActivityChannelId", () => {
+ it("prefers the first openable working channel", () => {
+ assert.equal(
+ resolveOpenableActivityChannelId({
+ agentChannelIds: ["member-1"],
+ openableChannelIds: new Set(["working-2", "member-1"]),
+ workingChannelIds: ["working-1", "working-2"],
+ }),
+ "working-2",
+ );
+ });
+
+ it("falls back to the agent's first openable member channel", () => {
+ assert.equal(
+ resolveOpenableActivityChannelId({
+ agentChannelIds: ["hidden-2", "member-1"],
+ openableChannelIds: new Set(["member-1"]),
+ workingChannelIds: ["hidden-1"],
+ }),
+ "member-1",
+ );
+ });
+
+ it("returns null when the agent is only active in inaccessible rooms", () => {
+ assert.equal(
+ resolveOpenableActivityChannelId({
+ agentChannelIds: ["hidden-2"],
+ openableChannelIds: new Set(["unrelated"]),
+ workingChannelIds: ["hidden-1"],
+ }),
+ null,
+ );
+ });
+
+ it("returns null with no candidate channels at all", () => {
+ assert.equal(
+ resolveOpenableActivityChannelId({
+ agentChannelIds: [],
+ openableChannelIds: new Set(),
+ workingChannelIds: [],
+ }),
+ null,
+ );
+ });
+});
diff --git a/desktop/src/features/agents/useOpenAgentActivity.ts b/desktop/src/features/agents/useOpenAgentActivity.ts
new file mode 100644
index 0000000000..050a9ac1d8
--- /dev/null
+++ b/desktop/src/features/agents/useOpenAgentActivity.ts
@@ -0,0 +1,161 @@
+import * as React from "react";
+import { toast } from "sonner";
+
+import { useAppNavigation } from "@/app/navigation/useAppNavigation";
+import { useChannelsQuery } from "@/features/channels/hooks";
+import { useAgentSession } from "@/shared/context/AgentSessionContext";
+import type { Channel } from "@/shared/api/types";
+import { normalizePubkey } from "@/shared/lib/pubkey";
+import { getAgentWorkingState } from "./agentWorkingSignal";
+import { useRelayAgentsQuery } from "./hooks";
+
+const INACCESSIBLE_ACTIVITY_MESSAGE =
+ "This agent is active in a channel you haven't joined, so its activity can't be opened from here.";
+
+/**
+ * Can the viewer actually open this channel? Joined channels always;
+ * open-visibility channels are readable without joining. Channels missing
+ * from the viewer's channel list (e.g. private rooms they aren't in) are
+ * not navigable destinations.
+ */
+export function isChannelOpenable(
+ channel: Pick | undefined,
+): boolean {
+ return (
+ channel !== undefined && (channel.isMember || channel.visibility === "open")
+ );
+}
+
+/**
+ * Pick the channel to land in when opening an agent's activity from a
+ * non-channel route: the agent's first working channel the viewer can open,
+ * else the agent's first member channel the viewer can open, else null.
+ */
+export function resolveOpenableActivityChannelId({
+ agentChannelIds,
+ openableChannelIds,
+ workingChannelIds,
+}: {
+ agentChannelIds: readonly string[];
+ openableChannelIds: ReadonlySet;
+ workingChannelIds: readonly string[];
+}): string | null {
+ for (const channelId of workingChannelIds) {
+ if (openableChannelIds.has(channelId)) {
+ return channelId;
+ }
+ }
+ for (const channelId of agentChannelIds) {
+ if (openableChannelIds.has(channelId)) {
+ return channelId;
+ }
+ }
+ return null;
+}
+
+/**
+ * Universal ingress for opening an agent's activity pane.
+ *
+ * Inside a channel screen the AgentSessionContext handler opens the pane in
+ * place. Everywhere else (agents page, home profile panel, popovers reached
+ * from non-channel routes) there is no provider, so we navigate to a channel
+ * with the `agentSession` search param instead — preferring a channel the
+ * agent is currently working in (unified working signal), then falling back
+ * to the first channel the agent is a member of.
+ *
+ * Navigation only ever targets channels the viewer can actually open
+ * (joined, or open visibility). Owner-global ingestion means the working
+ * signal can report activity in rooms the viewer can't access; deep-linking
+ * there would land on a screen they can't read. In that case we surface a
+ * safe warning instead of navigating — no channel content, no trap-door.
+ *
+ * This replaces the old behavior where "View activity log" silently
+ * disappeared on routes without an AgentSessionProvider.
+ */
+export function useOpenAgentActivity() {
+ const { onOpenAgentSession } = useAgentSession();
+ const { goChannel } = useAppNavigation();
+ const relayAgentsQuery = useRelayAgentsQuery();
+ const relayAgents = relayAgentsQuery.data;
+ const channelsQuery = useChannelsQuery();
+ const channels = channelsQuery.data;
+
+ const findOpenableChannel = React.useCallback(
+ (channelId: string): boolean =>
+ isChannelOpenable(channels?.find((entry) => entry.id === channelId)),
+ [channels],
+ );
+
+ const resolveChannelId = React.useCallback(
+ (pubkey: string): string | null => {
+ const key = normalizePubkey(pubkey);
+ const relayAgent = relayAgents?.find(
+ (agent) => normalizePubkey(agent.pubkey) === key,
+ );
+ const openableChannelIds = new Set(
+ (channels ?? [])
+ .filter((channel) => isChannelOpenable(channel))
+ .map((channel) => channel.id),
+ );
+ return resolveOpenableActivityChannelId({
+ agentChannelIds: relayAgent?.channelIds ?? [],
+ openableChannelIds,
+ workingChannelIds: getAgentWorkingState(pubkey).channels.map(
+ (working) => working.channelId,
+ ),
+ });
+ },
+ [channels, relayAgents],
+ );
+
+ const canOpenAgentActivity = React.useCallback(
+ (pubkey: string | null | undefined): boolean => {
+ if (!pubkey) {
+ return false;
+ }
+ return Boolean(onOpenAgentSession) || resolveChannelId(pubkey) !== null;
+ },
+ [onOpenAgentSession, resolveChannelId],
+ );
+
+ const openAgentActivity = React.useCallback(
+ (pubkey: string, options?: { channelId?: string | null }): boolean => {
+ // An explicit channel target (e.g. clicking a "Working in #channel"
+ // badge) navigates so the pane opens scoped to that channel — but only
+ // when the viewer can actually open that channel. Scoping the pane to
+ // an inaccessible room (in place or via navigation) would expose that
+ // room's activity content, so we warn and stop instead.
+ if (options?.channelId) {
+ if (!findOpenableChannel(options.channelId)) {
+ toast.warning(INACCESSIBLE_ACTIVITY_MESSAGE);
+ return false;
+ }
+ if (!onOpenAgentSession) {
+ void goChannel(options.channelId, { agentSession: pubkey });
+ return true;
+ }
+ onOpenAgentSession(pubkey, options.channelId);
+ return true;
+ }
+ if (onOpenAgentSession) {
+ onOpenAgentSession(pubkey);
+ return true;
+ }
+ const channelId = resolveChannelId(pubkey);
+ if (channelId) {
+ void goChannel(channelId, { agentSession: pubkey });
+ return true;
+ }
+ // The agent may be working somewhere, just nowhere the viewer can open.
+ // Say so plainly rather than failing silently — without leaking which
+ // room, or navigating into it.
+ if (getAgentWorkingState(pubkey).channels.length > 0) {
+ toast.warning(INACCESSIBLE_ACTIVITY_MESSAGE);
+ }
+ return false;
+ },
+ [findOpenableChannel, goChannel, onOpenAgentSession, resolveChannelId],
+ );
+
+ return { canOpenAgentActivity, openAgentActivity };
+}
diff --git a/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx b/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx
index c7df35405e..13930c7ec8 100644
--- a/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx
+++ b/desktop/src/features/channels/ui/AgentSessionThreadPanel.tsx
@@ -43,6 +43,7 @@ import {
useTranscriptAnimationEnabled,
} from "@/features/agents/ui/transcriptAnimationPreference";
import type { ChannelAgentSessionAgent } from "./useChannelAgentSessions";
+import { useChannelsQuery } from "@/features/channels/hooks";
type AgentSessionThreadPanelProps = {
agent: ChannelAgentSessionAgent;
@@ -109,6 +110,29 @@ export function AgentSessionThreadPanel({
? undefined
: `Last updated ${new Date(latestActivityAt).toLocaleString()}`;
const rawFeedScopeKey = `${agent.pubkey}:${sessionChannelId ?? "all"}`;
+ // Scope label input: prefer the passed channel's name; when the pane is
+ // channel-scoped without a full Channel object (#1380's channelId prop),
+ // resolve the name from the channels cache.
+ const channelsQuery = useChannelsQuery({
+ enabled: Boolean(sessionChannelId),
+ });
+ const scopeChannelName = React.useMemo(() => {
+ if (!sessionChannelId) {
+ return null;
+ }
+ if (channel && channel.id === sessionChannelId) {
+ return channel.name;
+ }
+ return (
+ channelsQuery.data?.find((entry) => entry.id === sessionChannelId)
+ ?.name ?? null
+ );
+ }, [channel, channelsQuery.data, sessionChannelId]);
+ const scopeLabel = sessionChannelId
+ ? scopeChannelName
+ ? `#${scopeChannelName}`
+ : "1 channel"
+ : "All channels";
const [rawFeedState, setRawFeedState] = React.useState(() => ({
scopeKey: rawFeedScopeKey,
show: false,
@@ -282,6 +306,14 @@ export function AgentSessionThreadPanel({
subtitleTitle={lastUpdatedTitle}
title={showRawFeed ? "Raw ACP Activity" : "Activity"}
/>
+ {/* Scope label: makes channel-targeted vs all-channels state obvious
+ (an all-channels pane can look "wrong" without it). */}
+
+ {scopeLabel}
+
{agentHeaderActions}
>
diff --git a/desktop/src/features/profile/ui/UserProfilePanel.tsx b/desktop/src/features/profile/ui/UserProfilePanel.tsx
index 9bdd0fb2fa..4c4d8b068e 100644
--- a/desktop/src/features/profile/ui/UserProfilePanel.tsx
+++ b/desktop/src/features/profile/ui/UserProfilePanel.tsx
@@ -80,7 +80,7 @@ import {
} from "@/features/profile/ui/UserProfilePanelUtils";
import { useProfileDmAction } from "@/features/profile/ui/useProfileDmAction";
import { useUserStatusQuery } from "@/features/user-status/hooks";
-import { useAgentSession } from "@/shared/context/AgentSessionContext";
+import { useOpenAgentActivity } from "@/features/agents/useOpenAgentActivity";
import { useEscapeKey } from "@/shared/hooks/useEscapeKey";
import { useIsThreadPanelOverlay } from "@/shared/hooks/use-mobile";
import { AuxiliaryPanelBody } from "@/shared/layout/AuxiliaryPanel";
@@ -229,7 +229,7 @@ export function UserProfilePanel({
const contactListQuery = useContactListQuery(currentPubkey);
const followMutation = useFollowMutation(currentPubkey);
const unfollowMutation = useUnfollowMutation(currentPubkey);
- const { onOpenAgentSession } = useAgentSession();
+ const { canOpenAgentActivity, openAgentActivity } = useOpenAgentActivity();
const { goChannel } = useAppNavigation();
const profile = resolvePanelProfile({
managedAgent,
@@ -301,7 +301,9 @@ export function UserProfilePanel({
pubkeyLower.length > 0 &&
pubkeyLower === currentPubkey.toLowerCase();
const canViewActivity =
- viewerIsOwner && Boolean(onOpenAgentSession) && Boolean(effectivePubkey);
+ viewerIsOwner &&
+ Boolean(effectivePubkey) &&
+ canOpenAgentActivity(effectivePubkey);
const canOpenAgentLogs =
isOwner === true && managedAgent?.backend.type === "local";
const canInstantiateAgent =
@@ -662,9 +664,9 @@ export function UserProfilePanel({
const handleOpenActivity = React.useCallback(
(channelId?: string | null) => {
if (!effectivePubkey) return;
- onOpenAgentSession?.(effectivePubkey, channelId ?? null);
+ openAgentActivity(effectivePubkey, { channelId: channelId ?? null });
},
- [effectivePubkey, onOpenAgentSession],
+ [effectivePubkey, openAgentActivity],
);
const handleOpenChannel = React.useCallback(
diff --git a/desktop/src/features/profile/ui/UserProfilePopover.tsx b/desktop/src/features/profile/ui/UserProfilePopover.tsx
index 4203e390ae..f038d41482 100644
--- a/desktop/src/features/profile/ui/UserProfilePopover.tsx
+++ b/desktop/src/features/profile/ui/UserProfilePopover.tsx
@@ -37,7 +37,7 @@ import {
mergeTimelineCacheMessages,
} from "@/features/messages/hooks";
import { buildWaveMessageContent } from "@/features/messages/lib/waveMessage";
-import { useAgentSession } from "@/shared/context/AgentSessionContext";
+import { useOpenAgentActivity } from "@/features/agents/useOpenAgentActivity";
import { useProfilePanel } from "@/shared/context/ProfilePanelContext";
import { sendChannelMessage } from "@/shared/api/tauri";
import type { Channel, RelayEvent } from "@/shared/api/types";
@@ -200,7 +200,7 @@ export function UserProfilePopover({
});
const userStatusQuery = useUserStatusQuery(open ? [pubkey] : []);
- const { onOpenAgentSession } = useAgentSession();
+ const { canOpenAgentActivity, openAgentActivity } = useOpenAgentActivity();
const { openProfilePanel } = useProfilePanel();
const canOpenProfilePanel = enableProfilePanel && Boolean(openProfilePanel);
const relayAgent = relayAgentsQuery.data?.find((a) => a.pubkey === pubkey);
@@ -245,7 +245,7 @@ export function UserProfilePopover({
const isCurrentUserOwner = ownsAuthorAgent(profile, currentPubkey);
const viewerIsOwner = isCurrentUserOwner || isOwner === true;
const canViewActivity =
- isBotProfile && viewerIsOwner && Boolean(onOpenAgentSession);
+ isBotProfile && viewerIsOwner && canOpenAgentActivity(pubkey);
const presenceStatus = presenceQuery.data?.[pubkey.toLowerCase()];
const userStatus = userStatusQuery.data?.[pubkey.toLowerCase()];
const userStatusText = userStatus?.text.trim() ?? "";
@@ -609,7 +609,7 @@ export function UserProfilePopover({
data-testid={`user-profile-view-activity-${pubkey}`}
onClick={() => {
setOpen(false);
- onOpenAgentSession?.(pubkey);
+ openAgentActivity(pubkey);
}}
type="button"
>
diff --git a/desktop/tests/e2e/activity-scope-label-screenshots.spec.ts b/desktop/tests/e2e/activity-scope-label-screenshots.spec.ts
new file mode 100644
index 0000000000..0fee5ebf9d
--- /dev/null
+++ b/desktop/tests/e2e/activity-scope-label-screenshots.spec.ts
@@ -0,0 +1,100 @@
+import { expect, test } from "@playwright/test";
+
+import { waitForAnimations } from "../helpers/animations";
+import { installMockBridge, TEST_IDENTITIES } from "../helpers/bridge";
+
+const SHOTS = "test-results/activity-scope-label";
+
+const AGENT_PUBKEY = TEST_IDENTITIES.tyler.pubkey;
+const AGENTS_CHANNEL_ID = "94a444a4-c0a3-5966-ab05-530c6ddc2301"; // #agents
+
+// Open the activity pane via profile → "View activity" (same ingress the
+// observer-feed screenshot spec uses).
+async function openActivityFromChannel(
+ page: import("@playwright/test").Page,
+ channelTestId: string,
+ channelTitle: string,
+) {
+ await page.goto("/", { waitUntil: "domcontentloaded" });
+ await page.getByTestId(channelTestId).click();
+ await expect(page.getByTestId("chat-title")).toHaveText(channelTitle);
+
+ const messageRow = page
+ .getByTestId("message-row")
+ .filter({ has: page.getByText("Observer Agent", { exact: false }) });
+ await expect(messageRow.first()).toBeVisible({ timeout: 8_000 });
+ await messageRow.first().getByRole("button").first().click();
+
+ const profilePanel = page.getByTestId("user-profile-panel");
+ await expect(profilePanel).toBeVisible({ timeout: 10_000 });
+
+ const activityBtn = page.getByTestId(
+ `user-profile-view-activity-${AGENT_PUBKEY}`,
+ );
+ await expect(activityBtn).toBeVisible({ timeout: 5_000 });
+ await activityBtn.click();
+
+ const panel = page.getByTestId("agent-session-thread-panel");
+ await expect(panel).toBeVisible({ timeout: 10_000 });
+ return panel;
+}
+
+test.describe("activity panel scope label", () => {
+ test("channel-targeted pane shows the channel name", async ({ page }) => {
+ await installMockBridge(page, {
+ managedAgents: [
+ {
+ pubkey: AGENT_PUBKEY,
+ name: "Observer Agent",
+ status: "running" as const,
+ channelNames: ["agents"],
+ },
+ ],
+ });
+
+ const panel = await openActivityFromChannel(
+ page,
+ "channel-agents",
+ "agents",
+ );
+ await expect(page.getByTestId("agent-session-scope-label")).toHaveText(
+ "#agents",
+ );
+
+ await waitForAnimations(page);
+ await panel.screenshot({ path: `${SHOTS}/01-channel-scoped.png` });
+ });
+
+ test("unscoped pane shows All channels", async ({ page }) => {
+ // The agent lives in #random only. Restoring an agentSession URL on
+ // #agents (where the agent is not in the activity list) puts the pane in
+ // all-channels scope — the state that looked silently broken before the
+ // scope label existed. The app uses a hash router, so the deep link goes
+ // in the hash.
+ await installMockBridge(page, {
+ managedAgents: [
+ {
+ pubkey: AGENT_PUBKEY,
+ name: "Observer Agent",
+ status: "running" as const,
+ channelNames: ["random"],
+ },
+ ],
+ });
+
+ await page.goto(
+ `/#/channels/${AGENTS_CHANNEL_ID}?agentSession=${AGENT_PUBKEY}`,
+ { waitUntil: "domcontentloaded" },
+ );
+ await expect(page.getByTestId("chat-title")).toHaveText("agents");
+
+ const panel = page.getByTestId("agent-session-thread-panel");
+ await expect(panel).toBeVisible({ timeout: 10_000 });
+ await expect(page.getByTestId("agent-session-scope-label")).toHaveText(
+ "All channels",
+ );
+
+ await waitForAnimations(page);
+ await panel.screenshot({ path: `${SHOTS}/02-all-channels.png` });
+ });
+});