Skip to content

Commit fe6d645

Browse files
committed
feat(workspaces): add targeted agent diagnostics
Generated by Coder Agents on behalf of @EhabY.
1 parent 8c35a91 commit fe6d645

20 files changed

Lines changed: 716 additions & 223 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
- The experimental Workspaces panel lists workspace agents, metadata and app
1313
status. Updated times expose the full date and time on hover or keyboard focus.
1414

15+
### Fixed
16+
17+
- Ping and speed test from an agent in the sidebar now target that agent
18+
instead of the workspace's first agent.
19+
1520
### Changed
1621

1722
- **Breaking:** the extension no longer follows a redirect to a different

‎packages/shared/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export type {
3232

3333
// Workspaces types and API
3434
export * from "./workspaces/types";
35+
export * from "./workspaces/diagnostics";
3536
export { WorkspacesApi } from "./workspaces/api";

‎packages/shared/src/workspaces/api.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { defineCommand, defineNotification } from "../ipc/protocol";
99

1010
import type {
11+
AgentDiagnosticParams,
1112
OpenWorkspaceParams,
1213
SetFilterParams,
1314
ViewInDashboardParams,
@@ -25,6 +26,8 @@ export const WorkspacesApi = {
2526
login: defineCommand<void>("login"),
2627
openWorkspace: defineCommand<OpenWorkspaceParams>("openWorkspace"),
2728
viewInDashboard: defineCommand<ViewInDashboardParams>("viewInDashboard"),
29+
runAgentDiagnostic:
30+
defineCommand<AgentDiagnosticParams>("runAgentDiagnostic"),
2831
refresh: defineCommand<void>("refresh"),
2932
setFilter: defineCommand<SetFilterParams>("setFilter"),
3033
/** Watch metadata for these agents only, so idle rows cost nothing */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { WorkspaceAgent } from "coder/site/src/api/typesGenerated";
2+
3+
export type AgentDiagnostic = "ping" | "speedTest" | "supportBundle";
4+
5+
export function agentDiagnostics(
6+
agent: WorkspaceAgent,
7+
): readonly AgentDiagnostic[] {
8+
if (agent.status === "connected") {
9+
return ["ping", "speedTest", "supportBundle"];
10+
}
11+
// A support bundle is still useful without a connection.
12+
return ["supportBundle"];
13+
}

‎packages/shared/src/workspaces/types.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type {
44
WorkspaceAgentMetadata,
55
} from "coder/site/src/api/typesGenerated";
66

7+
import type { AgentDiagnostic } from "./diagnostics";
8+
79
// Re-export SDK types for convenience
810
export type { Workspace, WorkspaceAgent, WorkspaceAgentMetadata };
911

@@ -67,6 +69,12 @@ export interface ViewInDashboardParams {
6769
readonly page: DashboardPage;
6870
}
6971

72+
export interface AgentDiagnosticParams {
73+
readonly workspaceId: string;
74+
readonly agentId: string;
75+
readonly diagnostic: AgentDiagnostic;
76+
}
77+
7078
export interface SetFilterParams {
7179
readonly filter: WorkspaceFilter;
7280
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
agentDiagnostics,
3+
type AgentDiagnostic,
4+
type WorkspaceAgent,
5+
} from "@repo/shared";
6+
import { Icon, MenuItem, type CodiconName } from "@repo/ui";
7+
8+
import { RowActions } from "./RowActions";
9+
10+
import type { WorkspaceCommands } from "./WorkspacesPanel";
11+
12+
interface MenuEntry {
13+
readonly label: string;
14+
readonly icon: CodiconName;
15+
}
16+
17+
const DIAGNOSTIC_ENTRIES: Readonly<Record<AgentDiagnostic, MenuEntry>> = {
18+
ping: { label: "Ping", icon: "pulse" },
19+
speedTest: { label: "Speed Test", icon: "dashboard" },
20+
supportBundle: { label: "Support Bundle", icon: "archive" },
21+
};
22+
23+
export function AgentActions({
24+
workspaceId,
25+
agent,
26+
api,
27+
}: {
28+
workspaceId: string;
29+
agent: WorkspaceAgent;
30+
api: WorkspaceCommands;
31+
}) {
32+
const target = { workspaceId, agentId: agent.id };
33+
return (
34+
<RowActions name={agent.name || "Unknown"} target={target} api={api}>
35+
{agentDiagnostics(agent).map((diagnostic) => {
36+
const { label, icon } = DIAGNOSTIC_ENTRIES[diagnostic];
37+
return (
38+
<MenuItem
39+
key={diagnostic}
40+
onClick={() => api.runAgentDiagnostic({ ...target, diagnostic })}
41+
>
42+
<Icon name={icon} />
43+
{label}
44+
</MenuItem>
45+
);
46+
})}
47+
</RowActions>
48+
);
49+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
DropdownMenu,
3+
DropdownMenuContent,
4+
DropdownMenuTrigger,
5+
IconButton,
6+
} from "@repo/ui";
7+
8+
import type { OpenWorkspaceParams } from "@repo/shared";
9+
import type { ReactNode } from "react";
10+
11+
import type { WorkspaceCommands } from "./WorkspacesPanel";
12+
13+
/** Open, dashboard and overflow menu buttons; `children` fill the menu. */
14+
export function RowActions({
15+
name,
16+
target,
17+
api,
18+
menuDescription,
19+
children,
20+
}: {
21+
name: string;
22+
target: OpenWorkspaceParams;
23+
api: Pick<WorkspaceCommands, "openWorkspace" | "viewInDashboard">;
24+
menuDescription?: string;
25+
children: ReactNode;
26+
}) {
27+
return (
28+
<>
29+
<IconButton
30+
icon="play"
31+
label={`Open ${name} in VS Code`}
32+
tooltip="Open in VS Code"
33+
onClick={() => api.openWorkspace(target)}
34+
/>
35+
<IconButton
36+
icon="link-external"
37+
label={`View ${name} in dashboard`}
38+
tooltip="View in Dashboard"
39+
onClick={() =>
40+
api.viewInDashboard({
41+
workspaceId: target.workspaceId,
42+
page: "workspace",
43+
})
44+
}
45+
/>
46+
<DropdownMenu>
47+
<DropdownMenuTrigger
48+
render={
49+
<IconButton
50+
icon="more"
51+
label={`More actions for ${name}`}
52+
tooltip="More Actions"
53+
/>
54+
}
55+
/>
56+
<DropdownMenuContent align="end" aria-description={menuDescription}>
57+
{children}
58+
</DropdownMenuContent>
59+
</DropdownMenu>
60+
</>
61+
);
62+
}
Lines changed: 61 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,73 @@
1-
import {
2-
DropdownMenu,
3-
DropdownMenuContent,
4-
DropdownMenuTrigger,
5-
Icon,
6-
IconButton,
7-
MenuItem,
8-
MenuSeparator,
9-
} from "@repo/ui";
1+
import { Icon, MenuItem, MenuSeparator, type CodiconName } from "@repo/ui";
2+
3+
import { RowActions } from "./RowActions";
104

115
import type { Workspace } from "@repo/shared";
6+
import type { WorkspaceStatus } from "coder/site/src/api/typesGenerated";
127

138
import type { WorkspaceCommands } from "./WorkspacesPanel";
149

10+
type LifecycleAction = "Start" | "Stop" | "Restart" | "Retry";
11+
12+
const LIFECYCLE_ICONS: Readonly<Record<LifecycleAction, CodiconName>> = {
13+
Start: "play",
14+
Stop: "primitive-square",
15+
Restart: "debug-restart",
16+
Retry: "debug-restart",
17+
};
18+
19+
function lifecycleActions(status: WorkspaceStatus): readonly LifecycleAction[] {
20+
switch (status) {
21+
case "running":
22+
return ["Stop", "Restart"];
23+
case "stopped":
24+
return ["Start"];
25+
case "failed":
26+
case "canceled":
27+
return ["Retry"];
28+
default:
29+
return [];
30+
}
31+
}
32+
1533
export function WorkspaceActions({
16-
workspaceId,
17-
name,
18-
agentId,
19-
status,
34+
workspace,
2035
api,
2136
}: {
22-
workspaceId: string;
23-
name: string;
24-
agentId?: string;
25-
status?: Workspace["latest_build"]["status"];
26-
api: Pick<WorkspaceCommands, "openWorkspace" | "viewInDashboard">;
37+
workspace: Workspace;
38+
api: WorkspaceCommands;
2739
}) {
28-
const lifecycleActions =
29-
status === "running"
30-
? ["Stop", "Restart"]
31-
: status === "stopped"
32-
? ["Start"]
33-
: status === "failed" || status === "canceled"
34-
? ["Retry"]
35-
: [];
40+
const workspaceId = workspace.id;
41+
const actions = lifecycleActions(workspace.latest_build.status);
3642
return (
37-
<>
38-
<IconButton
39-
icon="play"
40-
label={`Open ${name} in VS Code`}
41-
tooltip="Open in VS Code"
42-
onClick={() =>
43-
api.openWorkspace({ workspaceId, ...(agentId ? { agentId } : {}) })
44-
}
45-
/>
46-
<IconButton
47-
icon="link-external"
48-
label={`View ${name} in dashboard`}
49-
tooltip="View in Dashboard"
50-
onClick={() => api.viewInDashboard({ workspaceId, page: "workspace" })}
51-
/>
52-
{!agentId && (
53-
<DropdownMenu>
54-
<DropdownMenuTrigger
55-
render={
56-
<IconButton
57-
icon="more"
58-
label={`More actions for ${name}`}
59-
tooltip="More Actions"
60-
/>
61-
}
62-
/>
63-
<DropdownMenuContent
64-
align="end"
65-
aria-description="Disabled actions are not supported by this panel."
66-
>
67-
{lifecycleActions.map((label) => (
68-
<MenuItem key={label} disabled>
69-
<Icon
70-
name={
71-
label === "Start"
72-
? "play"
73-
: label === "Stop"
74-
? "primitive-square"
75-
: "debug-restart"
76-
}
77-
/>
78-
{label}
79-
</MenuItem>
80-
))}
81-
{lifecycleActions.length > 0 && <MenuSeparator />}
82-
<MenuItem disabled>
83-
<Icon name="share" />
84-
Share
85-
</MenuItem>
86-
<MenuItem
87-
onClick={() =>
88-
api.viewInDashboard({ workspaceId, page: "settings" })
89-
}
90-
>
91-
<Icon name="gear" />
92-
Settings
93-
</MenuItem>
94-
<MenuSeparator />
95-
<MenuItem disabled>
96-
<Icon name="pulse" />
97-
Ping
98-
</MenuItem>
99-
<MenuItem disabled>
100-
<Icon name="dashboard" />
101-
Speed Test
102-
</MenuItem>
103-
<MenuItem disabled>
104-
<Icon name="archive" />
105-
Support Bundle
106-
</MenuItem>
107-
<MenuSeparator />
108-
<MenuItem disabled className="workspace-delete">
109-
<Icon name="trash" />
110-
Delete...
111-
</MenuItem>
112-
</DropdownMenuContent>
113-
</DropdownMenu>
114-
)}
115-
</>
43+
<RowActions
44+
name={workspace.name || "Unknown"}
45+
target={{ workspaceId }}
46+
api={api}
47+
menuDescription="Disabled actions are not supported by this panel."
48+
>
49+
{actions.map((action) => (
50+
<MenuItem key={action} disabled>
51+
<Icon name={LIFECYCLE_ICONS[action]} />
52+
{action}
53+
</MenuItem>
54+
))}
55+
{actions.length > 0 && <MenuSeparator />}
56+
<MenuItem disabled>
57+
<Icon name="share" />
58+
Share
59+
</MenuItem>
60+
<MenuItem
61+
onClick={() => api.viewInDashboard({ workspaceId, page: "settings" })}
62+
>
63+
<Icon name="gear" />
64+
Settings
65+
</MenuItem>
66+
<MenuSeparator />
67+
<MenuItem disabled className="workspace-delete">
68+
<Icon name="trash" />
69+
Delete...
70+
</MenuItem>
71+
</RowActions>
11672
);
11773
}

‎packages/workspaces/src/components/WorkspacesPanel.stories.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const api = {
161161
login: fn(),
162162
openWorkspace: fn(),
163163
viewInDashboard: fn(),
164+
runAgentDiagnostic: fn(),
164165
refresh: fn(),
165166
setFilter: fn(),
166167
watchAgents: fn(),
@@ -222,6 +223,21 @@ export const MenuOpen: Story = {
222223
},
223224
};
224225

226+
export const AgentMenuOpen: Story = {
227+
play: async ({ canvasElement }) => {
228+
const canvas = within(canvasElement);
229+
await userEvent.click(
230+
canvas.getByRole("treeitem", { name: "frontend alice" }),
231+
);
232+
// Row actions stay hidden until the row is focused, selected or hovered.
233+
await userEvent.keyboard("{ArrowDown}");
234+
await userEvent.click(
235+
await canvas.findByRole("button", { name: "More actions for main" }),
236+
);
237+
await screen.findByRole("menuitem", { name: "Ping" });
238+
},
239+
};
240+
225241
export const FilterOpen: Story = {
226242
play: async ({ canvasElement }) => {
227243
await userEvent.click(

0 commit comments

Comments
 (0)