Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { useLingui } from "@lingui/react/macro";
import { formatCompactRelativeTime } from "@superset/i18n/format";
import { cn } from "@superset/ui/utils";
import { useNavigate } from "@tanstack/react-router";
import { useNow } from "renderer/hooks/useNow";
import { navigateToV2Workspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation";
import { getStatusTooltip } from "renderer/screens/main/components/StatusIndicator";
import type {
DashboardSidebarRunningAgent,
RunningAgentActivity,
RunningAgentStatus,
} from "../../../../hooks/useDashboardSidebarWorkspaceRunningAgents";
import { DashboardSidebarAgentAvatar } from "../DashboardSidebarAgentAvatar";
import {
type AgentActivityVerb,
describeAgentActivity,
} from "./utils/describeAgentActivity";

const STATUS_TEXT_CLASS: Record<RunningAgentStatus, string> = {
idle: "text-muted-foreground",
Expand Down Expand Up @@ -51,7 +58,12 @@ export function DashboardSidebarAgentHoverRow({
className="flex min-w-0 flex-1 items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
>
<DashboardSidebarAgentAvatar agent={agent} />
<span className="min-w-0 truncate text-xs">{agent.label}</span>
<span className="flex min-w-0 flex-1 flex-col">
<span className="min-w-0 truncate text-xs">{agent.label}</span>
{agent.activity ? (
<DashboardSidebarAgentActivityLine activity={agent.activity} />
) : null}
</span>
</button>
<span
className={cn("shrink-0 text-[10px]", STATUS_TEXT_CLASS[agent.status])}
Expand All @@ -61,3 +73,59 @@ export function DashboardSidebarAgentHoverRow({
</div>
);
}

/**
* One line for the agent's latest tool call: "Edit · src/a.ts · 3s ago".
* The elapsed time ticks while the card is open so a stale line reads as
* stale instead of live.
*/
function DashboardSidebarAgentActivityLine({
activity,
}: {
activity: RunningAgentActivity;
}) {
const { t } = useLingui();
const now = useNow();
const { verb, tool, detail } = describeAgentActivity(activity);

const verbLabels: Record<AgentActivityVerb, string> = {
edit: t({
id: "dashboard.sidebar.agentHoverRow.activity.edit",
message: "Edit",
}),
read: t({
id: "dashboard.sidebar.agentHoverRow.activity.read",
message: "Read",
}),
run: t({
id: "dashboard.sidebar.agentHoverRow.activity.run",
message: "Run",
}),
search: t({
id: "dashboard.sidebar.agentHoverRow.activity.search",
message: "Search",
}),
fetch: t({
id: "dashboard.sidebar.agentHoverRow.activity.fetch",
message: "Fetch",
}),
delegate: t({
id: "dashboard.sidebar.agentHoverRow.activity.delegate",
message: "Subagent",
}),
};
const label = verb ? verbLabels[verb] : tool;
const text = detail ? `${label} · ${detail}` : label;

return (
<span
className="flex min-w-0 items-baseline text-[10px] text-muted-foreground"
title={text}
>
<span className="min-w-0 truncate">{text}</span>
<span className="ml-1 shrink-0 text-muted-foreground/70">
· {formatCompactRelativeTime(activity.at, now)}
</span>
</span>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "bun:test";
import { describeAgentActivity } from "./describeAgentActivity";

describe("describeAgentActivity", () => {
it("maps known tools to a verb regardless of case", () => {
expect(describeAgentActivity({ tool: "Edit", detail: "a.ts" })).toEqual({
verb: "edit",
tool: "Edit",
detail: "a.ts",
});
expect(describeAgentActivity({ tool: "bash" }).verb).toBe("run");
expect(describeAgentActivity({ tool: "WebFetch" }).verb).toBe("fetch");
});

it("falls through to the raw tool name for unknown tools", () => {
expect(describeAgentActivity({ tool: "mcp__linear__get_issue" })).toEqual({
verb: null,
tool: "mcp__linear__get_issue",
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Coarse verb for an agent tool name. Tool names are the agent's own
* (Claude's `Edit`, Grok's `bash`, …); matching is case-insensitive and
* anything unrecognized falls through as the raw tool name.
*/
export type AgentActivityVerb =
| "edit"
| "read"
| "run"
| "search"
| "fetch"
| "delegate";

const VERB_BY_TOOL: Record<string, AgentActivityVerb> = {
edit: "edit",
multiedit: "edit",
write: "edit",
notebookedit: "edit",
apply_patch: "edit",
read: "read",
bash: "run",
shell: "run",
grep: "search",
glob: "search",
ls: "search",
webfetch: "fetch",
websearch: "fetch",
task: "delegate",
agent: "delegate",
};

export interface AgentActivityDescription {
/** Recognized verb, or null when the tool name should show as-is. */
verb: AgentActivityVerb | null;
tool: string;
detail?: string;
}

export function describeAgentActivity(activity: {
tool: string;
detail?: string;
}): AgentActivityDescription {
const verb = VERB_BY_TOOL[activity.tool.toLowerCase()] ?? null;
return {
verb,
tool: activity.tool,
...(activity.detail ? { detail: activity.detail } : {}),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./describeAgentActivity";
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {
type DashboardSidebarRunningAgent,
type RunningAgentActivity,
type RunningAgentStatus,
useDashboardSidebarWorkspaceRunningAgents,
} from "./useDashboardSidebarWorkspaceRunningAgents";
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type AgentIdentityId,
} from "@superset/shared/agent-catalog";
import { useMemo } from "react";
import type { TerminalAgentBinding } from "renderer/hooks/host-service/useTerminalAgentBindings";
import { useSidebarWorkspaceStatus } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarWorkspaceStatusProvider";
import type { V2NotificationSource } from "renderer/stores/v2-notifications";
import type { PaneStatus } from "shared/tabs-types";
Expand All @@ -13,6 +14,11 @@ import type { PaneStatus } from "shared/tabs-types";
*/
export type RunningAgentStatus = PaneStatus;

/** The agent's latest tool call, as reported by its hooks. */
export type RunningAgentActivity = NonNullable<
TerminalAgentBinding["activity"]
>;

export interface DashboardSidebarRunningAgent {
/** Stable key for React lists, derived from the notification source. */
sourceKey: string;
Expand All @@ -27,6 +33,8 @@ export interface DashboardSidebarRunningAgent {
startedAt: number;
/** Agent display name (e.g. "Claude"). */
label: string;
/** Latest tool call; absent for agents without tool hooks. */
activity?: RunningAgentActivity;
}

/**
Expand All @@ -53,6 +61,7 @@ export function useDashboardSidebarWorkspaceRunningAgents(
status: statuses.get(binding.terminalId) ?? "idle",
startedAt: binding.startedAt,
label: AGENT_IDENTITY_LABELS[binding.agentId] ?? binding.agentId,
...(binding.activity ? { activity: binding.activity } : {}),
});
}
agents.sort((a, b) => a.startedAt - b.startedAt);
Expand Down
89 changes: 86 additions & 3 deletions packages/agent-setup/src/notify-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ async function runNotifyHookAsync(

/** Fake host-service answering notifications.hook like the real router. */
function fakeHostService(ignored: boolean) {
const requests: Array<{ json: { terminalId?: string } }> = [];
const requests: Array<{
json: {
terminalId?: string;
eventType?: string;
activity?: { tool: string; detail: string };
};
}> = [];
const server = Bun.serve({
port: 0,
fetch: async (req) => {
Expand Down Expand Up @@ -104,7 +110,7 @@ function writeHookManifest(home: string, orgId: string, endpoint: string) {

describe("getNotifyScriptContent", () => {
it("bumps the notify hook marker when hook semantics change", () => {
expect(NOTIFY_SCRIPT_MARKER).toBe("# Superset agent notification hook v9");
expect(NOTIFY_SCRIPT_MARKER).toBe("# Superset agent notification hook v10");
});

it("ignores hooks fired inside a subagent (agent_id present)", () => {
Expand Down Expand Up @@ -144,7 +150,7 @@ describe("getNotifyScriptContent", () => {

expect(script).toContain('HOOK_SESSION_ID=$(echo "$INPUT"');
expect(script).toContain(
'PAYLOAD="{\\"json\\":{\\"terminalId\\":\\"$(json_escape "$SUPERSET_TERMINAL_ID")\\",\\"eventType\\":\\"$(json_escape "$EVENT_TYPE")\\",\\"agent\\":{\\"agentId\\":\\"$(json_escape "$SUPERSET_AGENT_ID")\\",\\"sessionId\\":\\"$(json_escape "$SESSION_ID")\\"}}}"',
'PAYLOAD="{\\"json\\":{\\"terminalId\\":\\"$(json_escape "$SUPERSET_TERMINAL_ID")\\",\\"eventType\\":\\"$(json_escape "$EVENT_TYPE")\\",\\"agent\\":{\\"agentId\\":\\"$(json_escape "$SUPERSET_AGENT_ID")\\",\\"sessionId\\":\\"$(json_escape "$SESSION_ID")\\"}$ACTIVITY_JSON}}"',
);
expect(script).toContain(
"event=$EVENT_TYPE terminalId=$SUPERSET_TERMINAL_ID agentId=$SUPERSET_AGENT_ID sessionId=$SESSION_ID hookSessionId=$HOOK_SESSION_ID resourceId=$RESOURCE_ID paneId=$SUPERSET_PANE_ID tabId=$SUPERSET_TAB_ID workspaceId=$SUPERSET_WORKSPACE_ID",
Expand Down Expand Up @@ -249,6 +255,83 @@ describe("getNotifyScriptContent", () => {
});
});

describe("tool activity", () => {
it("forwards the tool name and its main argument to the host", async () => {
const live = fakeHostService(false);
const home = mkdtempSync(path.join(tmpdir(), "notify-hook-home-"));
writeHookManifest(home, "org-a", live.url);
try {
const result = await runNotifyHookAsync(
{
hook_event_name: "PostToolUse",
session_id: "main-session",
tool_name: "Bash",
tool_input: {
command: 'echo "hi"\nbun test',
description: "Say hi",
},
tool_response: { stdout: "hi" },
},
{ SUPERSET_HOME_DIR: home },
);

expect(result.exitCode).toBe(0);
expect(live.requests).toHaveLength(1);
expect(live.requests[0]?.json.eventType).toBe("PostToolUse");
expect(live.requests[0]?.json.activity).toEqual({
tool: "Bash",
detail: 'echo "hi" bun test',
});
} finally {
live.stop();
}
});

it("prefers the file path over other arguments", async () => {
const live = fakeHostService(false);
const home = mkdtempSync(path.join(tmpdir(), "notify-hook-home-"));
writeHookManifest(home, "org-a", live.url);
try {
await runNotifyHookAsync(
{
hook_event_name: "PermissionRequest",
session_id: "main-session",
tool_name: "Write",
tool_input: {
content: '{"file_path":"decoy"}',
file_path: "/repo/src/a.ts",
},
},
{ SUPERSET_HOME_DIR: home },
);

expect(live.requests[0]?.json.activity).toEqual({
tool: "Write",
detail: "/repo/src/a.ts",
});
} finally {
live.stop();
}
});

it("sends no activity for events without a tool", async () => {
const live = fakeHostService(false);
const home = mkdtempSync(path.join(tmpdir(), "notify-hook-home-"));
writeHookManifest(home, "org-a", live.url);
try {
await runNotifyHookAsync(
{ hook_event_name: "Stop", session_id: "main-session" },
{ SUPERSET_HOME_DIR: home },
);

expect(live.requests).toHaveLength(1);
expect(live.requests[0]?.json).not.toHaveProperty("activity");
} finally {
live.stop();
}
});
});

describe("per-agent hook scripts dispatch to v2", () => {
const buildExpectedV2Payload = (agentIdVar: string) =>
`PAYLOAD="{\\"json\\":{\\"terminalId\\":\\"$(json_escape "$SUPERSET_TERMINAL_ID")\\",\\"eventType\\":\\"$(json_escape "$EVENT_TYPE")\\",\\"agent\\":{\\"agentId\\":\\"$(json_escape "$${agentIdVar}")\\",\\"sessionId\\":\\"$(json_escape "$HOOK_SESSION_ID")\\"}}}"`;
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-setup/src/notify-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getHooksDir } from "./paths";
import { writeFileIfChanged } from "./write-file-if-changed";

export const NOTIFY_SCRIPT_NAME = "notify.sh";
export const NOTIFY_SCRIPT_MARKER = "# Superset agent notification hook v9";
export const NOTIFY_SCRIPT_MARKER = "# Superset agent notification hook v10";

export function getNotifyScriptPath(): string {
return path.join(getHooksDir(), NOTIFY_SCRIPT_NAME);
Expand Down
25 changes: 24 additions & 1 deletion packages/agent-setup/templates/notify-hook.template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ fi
# a false completion notification.
[ -z "$EVENT_TYPE" ] && exit 0

# Tool activity for the sidebar's "what is it doing" line. Claude-schema
# agents put tool_name at the top level and the tool's arguments under
# tool_input; the first of these keys is the one worth showing. Values are
# JSON string literals: unescape, drop control characters, and cap the
# length so a heredoc command can't bloat the payload. Absent for agents
# without tool hooks — the host keeps the line blank for them.
json_string_field() {
printf '%s' "$INPUT" | grep -oE "\"$1\"[[:space:]]*:[[:space:]]*\"([^\"\\\\]|\\\\.)*\"" | head -1 | sed -e 's/^"[^"]*"[[:space:]]*:[[:space:]]*"//' -e 's/"$//'
}
TOOL_NAME=$(json_string_field tool_name)
TOOL_DETAIL=""
if [ -n "$TOOL_NAME" ]; then
for DETAIL_KEY in file_path command pattern url description; do
TOOL_DETAIL=$(json_string_field "$DETAIL_KEY")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a Claude tool response contains a matching file_path, command, pattern, url, or description, the hook can display that response metadata instead of the tool call detail. json_string_field scans all of $INPUT; scope extraction to tool_input before selecting the detail key.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/agent-setup/templates/notify-hook.template.sh, line 94:

<comment>When a Claude tool response contains a matching `file_path`, `command`, `pattern`, `url`, or `description`, the hook can display that response metadata instead of the tool call detail. `json_string_field` scans all of `$INPUT`; scope extraction to `tool_input` before selecting the detail key.</comment>

<file context>
@@ -78,6 +78,25 @@ fi
+TOOL_DETAIL=""
+if [ -n "$TOOL_NAME" ]; then
+  for DETAIL_KEY in file_path command pattern url description; do
+    TOOL_DETAIL=$(json_string_field "$DETAIL_KEY")
+    [ -n "$TOOL_DETAIL" ] && break
+  done
</file context>

[ -n "$TOOL_DETAIL" ] && break
done
TOOL_DETAIL=$(printf '%s' "$TOOL_DETAIL" | sed -e 's/\\[nrt]/ /g' -e 's/\\"/"/g' -e 's/\\\\/\\/g' | tr -d '\000-\037' | cut -c1-400)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a command contains a literal backslash sequence such as printf '\n', this pipeline treats the second backslash plus n as an encoded newline and corrupts the displayed command. Use an escape-aware JSON decoder so literal shell syntax is preserved.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/agent-setup/templates/notify-hook.template.sh, line 97:

<comment>When a command contains a literal backslash sequence such as `printf '\n'`, this pipeline treats the second backslash plus `n` as an encoded newline and corrupts the displayed command. Use an escape-aware JSON decoder so literal shell syntax is preserved.</comment>

<file context>
@@ -78,6 +78,25 @@ fi
+    TOOL_DETAIL=$(json_string_field "$DETAIL_KEY")
+    [ -n "$TOOL_DETAIL" ] && break
+  done
+  TOOL_DETAIL=$(printf '%s' "$TOOL_DETAIL" | sed -e 's/\\[nrt]/ /g' -e 's/\\"/"/g' -e 's/\\\\/\\/g' | tr -d '\000-\037' | cut -c1-400)
+fi
+
</file context>

fi

DEBUG_HOOKS_ENABLED="0"
if [ -n "$SUPERSET_DEBUG_HOOKS" ]; then
case "$SUPERSET_DEBUG_HOOKS" in
Expand Down Expand Up @@ -121,7 +140,11 @@ json_escape() {
# then every org manifest's endpoint. Only the host that owns this terminal
# answers "ignored":false; probing the other orgs' hosts is a harmless no-op.
if [ -n "$SUPERSET_TERMINAL_ID" ]; then
PAYLOAD="{\"json\":{\"terminalId\":\"$(json_escape "$SUPERSET_TERMINAL_ID")\",\"eventType\":\"$(json_escape "$EVENT_TYPE")\",\"agent\":{\"agentId\":\"$(json_escape "$SUPERSET_AGENT_ID")\",\"sessionId\":\"$(json_escape "$SESSION_ID")\"}}}"
ACTIVITY_JSON=""
if [ -n "$TOOL_NAME" ]; then
ACTIVITY_JSON=",\"activity\":{\"tool\":\"$(json_escape "$TOOL_NAME")\",\"detail\":\"$(json_escape "$TOOL_DETAIL")\"}"
fi
PAYLOAD="{\"json\":{\"terminalId\":\"$(json_escape "$SUPERSET_TERMINAL_ID")\",\"eventType\":\"$(json_escape "$EVENT_TYPE")\",\"agent\":{\"agentId\":\"$(json_escape "$SUPERSET_AGENT_ID")\",\"sessionId\":\"$(json_escape "$SESSION_ID")\"}$ACTIVITY_JSON}}"

HOOK_CANDIDATE_URLS="$SUPERSET_HOST_AGENT_HOOK_URL"
for MANIFEST_FILE in "${SUPERSET_HOME_DIR:-$HOME/.superset}"/host/*/manifest.json; do
Expand Down
Loading