+
-
-
-
-
- {t("office:editOrgChartFromTheAgents")}
-
-
+
diff --git a/apps/web/app/office/agents/[id]/components/agent-overview-tab.tsx b/apps/web/app/office/agents/[id]/components/agent-overview-tab.tsx
deleted file mode 100644
index d054453161..0000000000
--- a/apps/web/app/office/agents/[id]/components/agent-overview-tab.tsx
+++ /dev/null
@@ -1,323 +0,0 @@
-"use client";
-
-import { useState, useCallback } from "react";
-import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card";
-import { Input } from "@kandev/ui/input";
-import { Label } from "@kandev/ui/label";
-import { Button } from "@kandev/ui/button";
-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select";
-import { IconRefresh } from "@tabler/icons-react";
-import { toast } from "@/lib/toast/sonner";
-import { useAppStore } from "@/components/state-provider";
-import { selectOfficeAgentProfiles } from "@/lib/state/slices/office/selectors";
-import { updateAgentProfile, getAgentUtilization } from "@/lib/api/domains/office-api";
-import type { AgentProfile, AgentRole, ProviderUsage } from "@/lib/state/slices/office/types";
-import { UtilizationBars } from "@/app/office/components/utilization-bars";
-import { useTranslation } from "react-i18next";
-
-type AgentOverviewTabProps = {
- agent: AgentProfile;
-};
-
-function IdentityCard({
- name,
- role,
- reportsToName,
- roles,
- onNameChange,
- onRoleChange,
-}: {
- name: string;
- role: AgentRole;
- reportsToName: string;
- roles: Array<{ id: string; label: string }>;
- onNameChange: (v: string) => void;
- onRoleChange: (v: AgentRole) => void;
-}) {
- const { t } = useTranslation();
- return (
-
-
- {t("office:identity")}
-
- {t("office:nameRoleAndReportingStructureFor")}
-
-
-
-
-
- onNameChange(e.target.value)} className="mt-1" />
-
-
-
-
-
-
-
-
-
-
-
-
-
- );
-}
-
-function ConfigurationCard({
- budget,
- maxConcurrent,
- executorType,
- executorTypes,
- onBudgetChange,
- onMaxConcurrentChange,
- onExecutorTypeChange,
-}: {
- budget: number;
- maxConcurrent: number;
- executorType: string;
- executorTypes: Array<{ id: string; label: string }>;
- onBudgetChange: (v: number) => void;
- onMaxConcurrentChange: (v: number) => void;
- onExecutorTypeChange: (v: string) => void;
-}) {
- const { t } = useTranslation();
- return (
-
-
- {t("office:configuration")}
-
- {t("office:budgetLimitsConcurrencyAndExecutionEnvironment")}
-
-
-
-
-
-
-
-
-
-
- );
-}
-
-function QuotaCard({
- agentId,
- initialUsage,
-}: {
- agentId: string;
- initialUsage: ProviderUsage | null | undefined;
-}) {
- const { t } = useTranslation();
- const [usage, setUsage] = useState
(initialUsage ?? null);
- const [refreshing, setRefreshing] = useState(false);
-
- const handleRefresh = useCallback(async () => {
- setRefreshing(true);
- try {
- const result = await getAgentUtilization(agentId);
- setUsage(result.utilization);
- } catch {
- toast.error(t("office:failedToRefreshUtilization"));
- } finally {
- setRefreshing(false);
- }
- }, [agentId]);
-
- return (
-
-
-
-
-
{t("office:subscriptionQuota")}
-
- {t("office:currentUtilizationOfSubscriptionRateLimit")}
-
-
-
-
-
-
- {usage ? (
-
- ) : (
-
- {t("office:noUtilizationDataClickRefreshTo")}
-
- )}
-
-
- );
-}
-
-// Catalog keys, not copy — module scope freezes a `t()` at the boot locale.
-// The `id`s are the wire role / executor-type values.
-const FALLBACK_ROLES = [
- { id: "ceo", labelKey: "office:roleCeo" },
- { id: "worker", labelKey: "office:roleWorker" },
- { id: "specialist", labelKey: "office:roleSpecialist" },
- { id: "assistant", labelKey: "office:roleAssistant" },
-];
-
-const FALLBACK_EXECUTOR_TYPES = [
- { id: "local_pc", labelKey: "office:localStandalone" },
- { id: "local_docker", labelKey: "office:localDocker" },
- { id: "sprites", labelKey: "office:spritesRemoteSandbox" },
-];
-
-export function AgentOverviewTab({ agent }: AgentOverviewTabProps) {
- const { t } = useTranslation();
- const agents = useAppStore(selectOfficeAgentProfiles);
- const meta = useAppStore((s) => s.office.meta);
- const updateStore = useAppStore((s) => s.updateOfficeAgentProfile);
-
- const roles =
- meta?.roles.map((r) => ({ id: r.id, label: r.label })) ??
- FALLBACK_ROLES.map((r) => ({ id: r.id, label: t(r.labelKey) }));
- const executorTypes =
- meta?.executorTypes.map((e) => ({ id: e.id, label: e.label })) ??
- FALLBACK_EXECUTOR_TYPES.map((e) => ({ id: e.id, label: t(e.labelKey) }));
-
- const [name, setName] = useState(agent.name);
- const [role, setRole] = useState(agent.role);
- const [budget, setBudget] = useState(agent.budgetMonthlyCents / 100);
- const [maxConcurrent, setMaxConcurrent] = useState(agent.maxConcurrentSessions);
- const [executorType, setExecutorType] = useState(agent.executorPreference?.type ?? "");
- const [saving, setSaving] = useState(false);
- const [dirty, setDirty] = useState(false);
-
- const markDirty = useCallback(() => setDirty(true), []);
-
- const handleSave = useCallback(async () => {
- setSaving(true);
- try {
- await updateAgentProfile(agent.id, {
- name,
- role,
- budgetMonthlyCents: Math.round(budget * 100),
- maxConcurrentSessions: maxConcurrent,
- executorPreference: executorType ? { type: executorType } : undefined,
- } as Partial);
- updateStore(agent.workspaceId, agent.id, {
- name,
- role,
- budgetMonthlyCents: Math.round(budget * 100),
- maxConcurrentSessions: maxConcurrent,
- executorPreference: executorType ? { type: executorType } : undefined,
- });
- setDirty(false);
- toast.success(t("office:agentUpdated"));
- } catch (err) {
- toast.error(err instanceof Error ? err.message : t("office:failedToUpdateAgent"));
- } finally {
- setSaving(false);
- }
- }, [agent.id, agent.workspaceId, name, role, budget, maxConcurrent, executorType, updateStore]);
-
- const reportsToAgent = agents.find((a) => a.id === agent.reportsTo);
-
- const isSubscription = agent.billingType === "subscription";
-
- return (
-
-
{
- setName(v);
- markDirty();
- }}
- onRoleChange={(v) => {
- setRole(v);
- markDirty();
- }}
- />
- {
- setBudget(v);
- markDirty();
- }}
- onMaxConcurrentChange={(v) => {
- setMaxConcurrent(v);
- markDirty();
- }}
- onExecutorTypeChange={(v) => {
- setExecutorType(v);
- markDirty();
- }}
- />
- {isSubscription && }
- {dirty && (
-
-
-
- )}
-
- );
-}
diff --git a/apps/web/app/office/agents/[id]/components/reports-to-options.test.ts b/apps/web/app/office/agents/[id]/components/reports-to-options.test.ts
new file mode 100644
index 0000000000..060ff195d0
--- /dev/null
+++ b/apps/web/app/office/agents/[id]/components/reports-to-options.test.ts
@@ -0,0 +1,66 @@
+import { describe, expect, it } from "vitest";
+import type { AgentProfile } from "@/lib/state/slices/office/types";
+import { collectDescendantIds, reportsToOptions } from "./reports-to-options";
+
+function agent(id: string, reportsTo?: string): AgentProfile {
+ return { id, name: id, reportsTo } as AgentProfile;
+}
+
+describe("collectDescendantIds", () => {
+ it("returns the direct child of the root", () => {
+ const agents = [agent("ceo"), agent("manager", "ceo")];
+ expect(collectDescendantIds(agents, "ceo")).toEqual(new Set(["manager"]));
+ });
+
+ it("returns a grandchild transitively", () => {
+ const agents = [agent("ceo"), agent("manager", "ceo"), agent("worker", "manager")];
+ expect(collectDescendantIds(agents, "ceo")).toEqual(new Set(["manager", "worker"]));
+ });
+
+ it("excludes unrelated agents", () => {
+ const agents = [agent("ceo"), agent("manager", "ceo"), agent("other")];
+ expect(collectDescendantIds(agents, "ceo")).toEqual(new Set(["manager"]));
+ });
+
+ it("does not loop on a chain with a missing parent", () => {
+ const agents = [agent("orphan", "does-not-exist")];
+ expect(collectDescendantIds(agents, "orphan")).toEqual(new Set());
+ });
+
+ it("returns an empty set for a leaf agent", () => {
+ const agents = [agent("ceo"), agent("worker", "ceo")];
+ expect(collectDescendantIds(agents, "worker")).toEqual(new Set());
+ });
+});
+
+describe("reportsToOptions", () => {
+ it("excludes the agent itself", () => {
+ const agents = [agent("ceo"), agent("worker", "ceo")];
+ const options = reportsToOptions(agents, "worker");
+ expect(options.map((o) => o.id)).not.toContain("worker");
+ });
+
+ it("excludes a direct child", () => {
+ const agents = [agent("ceo"), agent("manager", "ceo"), agent("worker", "manager")];
+ const options = reportsToOptions(agents, "ceo");
+ expect(options.map((o) => o.id)).not.toContain("manager");
+ });
+
+ it("excludes a grandchild", () => {
+ const agents = [agent("ceo"), agent("manager", "ceo"), agent("worker", "manager")];
+ const options = reportsToOptions(agents, "ceo");
+ expect(options.map((o) => o.id)).not.toContain("worker");
+ });
+
+ it("keeps an unrelated agent", () => {
+ const agents = [agent("ceo"), agent("manager", "ceo"), agent("other")];
+ const options = reportsToOptions(agents, "manager");
+ expect(options.map((o) => o.id)).toContain("other");
+ });
+
+ it("keeps an unrelated agent when a chain has a missing parent", () => {
+ const agents = [agent("orphan", "does-not-exist"), agent("other")];
+ const options = reportsToOptions(agents, "orphan");
+ expect(options.map((o) => o.id)).toEqual(["other"]);
+ });
+});
diff --git a/apps/web/app/office/agents/[id]/components/reports-to-options.ts b/apps/web/app/office/agents/[id]/components/reports-to-options.ts
new file mode 100644
index 0000000000..a6f47ebaa1
--- /dev/null
+++ b/apps/web/app/office/agents/[id]/components/reports-to-options.ts
@@ -0,0 +1,37 @@
+import type { AgentProfile } from "@/lib/state/slices/office/types";
+
+/**
+ * Every agent transitively managed by `rootId`, walking the `reportsTo` edges
+ * forward. Re-parenting `rootId` under one of its own descendants would form
+ * a cycle: `buildForest` (org-tree-layout.ts) treats a cyclic agent's parent
+ * as unresolved and drops the whole cycle from the org chart with no error.
+ */
+export function collectDescendantIds(agents: AgentProfile[], rootId: string): Set {
+ const childrenByParent = new Map();
+ for (const agent of agents) {
+ if (!agent.reportsTo) continue;
+ const siblings = childrenByParent.get(agent.reportsTo) ?? [];
+ siblings.push(agent.id);
+ childrenByParent.set(agent.reportsTo, siblings);
+ }
+
+ const descendants = new Set();
+ const queue = [...(childrenByParent.get(rootId) ?? [])];
+ while (queue.length > 0) {
+ const id = queue.pop()!;
+ if (descendants.has(id)) continue;
+ descendants.add(id);
+ queue.push(...(childrenByParent.get(id) ?? []));
+ }
+ return descendants;
+}
+
+/** Agents eligible as a manager for `agentId`: everyone except itself and its own descendants. */
+export function reportsToOptions(
+ agents: AgentProfile[],
+ agentId: string,
+): Array<{ id: string; name: string }> {
+ const excluded = collectDescendantIds(agents, agentId);
+ excluded.add(agentId);
+ return agents.filter((a) => !excluded.has(a.id)).map((a) => ({ id: a.id, name: a.name }));
+}
diff --git a/apps/web/app/office/workspace/org/org-node-card.tsx b/apps/web/app/office/workspace/org/org-node-card.tsx
index 2d85a9e59e..6c42afe1f5 100644
--- a/apps/web/app/office/workspace/org/org-node-card.tsx
+++ b/apps/web/app/office/workspace/org/org-node-card.tsx
@@ -47,6 +47,7 @@ export function OrgNodeCard({ node }: OrgNodeCardProps) {
return (
diff --git a/apps/web/e2e/tests/office/mobile-office-reparent.spec.ts b/apps/web/e2e/tests/office/mobile-office-reparent.spec.ts
new file mode 100644
index 0000000000..620b7bc8e1
--- /dev/null
+++ b/apps/web/e2e/tests/office/mobile-office-reparent.spec.ts
@@ -0,0 +1,45 @@
+import { expect, test } from "../../fixtures/office-fixture";
+import { waitForHttp } from "../../helpers/causal-waits";
+
+test.describe("Office manager reassignment on mobile", () => {
+ test("saves a manager change and renders the new parent-child link", async ({
+ testPage,
+ officeApi,
+ officeSeed,
+ }) => {
+ const worker = await officeApi.createAgent(officeSeed.workspaceId, {
+ name: "Mobile Org Chart Reparent Target",
+ role: "worker",
+ });
+ const workerId = worker.id as string;
+
+ await testPage.goto(`/office/agents/${workerId}/configuration`);
+ const reportsTo = testPage.getByRole("combobox", { name: "Reports to" });
+ await expect(reportsTo).toBeVisible();
+ const reportsToBox = await reportsTo.boundingBox();
+ expect(reportsToBox).not.toBeNull();
+ expect(reportsToBox!.height).toBeGreaterThanOrEqual(44);
+
+ await reportsTo.click();
+ const listbox = testPage.getByRole("listbox");
+ await expect(listbox).toBeVisible();
+ await listbox.getByRole("option", { name: "CEO" }).click();
+
+ const saved = waitForHttp(testPage, "PATCH", new RegExp(`/api/v1/office/agents/${workerId}$`));
+ await testPage.getByRole("button", { name: "Save Configuration" }).click();
+ await saved;
+
+ await testPage.getByTestId("app-nav-trigger").click();
+ await testPage
+ .getByTestId("app-nav-sheet")
+ .getByRole("link", { name: /Org chart/i })
+ .click();
+ await expect(testPage).toHaveURL(/\/office\/workspace\/org$/);
+ await expect(testPage.getByRole("heading", { name: /Org/i }).first()).toBeVisible({
+ timeout: 10_000,
+ });
+ await expect(
+ testPage.getByRole("link", { name: "Mobile Org Chart Reparent Target" }),
+ ).toHaveAttribute("data-reports-to", officeSeed.agentId);
+ });
+});
diff --git a/apps/web/e2e/tests/office/org-chart.spec.ts b/apps/web/e2e/tests/office/org-chart.spec.ts
index 1f8db69008..5163710fdd 100644
--- a/apps/web/e2e/tests/office/org-chart.spec.ts
+++ b/apps/web/e2e/tests/office/org-chart.spec.ts
@@ -1,4 +1,5 @@
import { test, expect } from "../../fixtures/office-fixture";
+import { waitForHttp } from "../../helpers/causal-waits";
test.describe("Org chart", () => {
test("org chart shows CEO agent node", async ({ testPage, officeSeed: _ }) => {
@@ -9,4 +10,45 @@ test.describe("Org chart", () => {
// CEO agent from onboarding should appear as a node
await expect(testPage.getByText("CEO").first()).toBeVisible({ timeout: 15_000 });
});
+
+ test("changing an agent's manager on the configuration tab re-parents it on the org chart", async ({
+ testPage,
+ officeApi,
+ officeSeed,
+ }) => {
+ const worker = await officeApi.createAgent(officeSeed.workspaceId, {
+ name: "Org Chart Reparent Target",
+ role: "worker",
+ });
+ const workerId = worker.id as string;
+
+ await testPage.goto("/office/workspace/org");
+ await expect(testPage.getByRole("heading", { name: /Org/i }).first()).toBeVisible({
+ timeout: 10_000,
+ });
+ const edgesBefore = await testPage.getByTestId("org-edge").count();
+
+ await testPage.goto(`/office/agents/${workerId}/configuration`);
+ await testPage.getByRole("combobox", { name: "Reports to" }).click();
+ const listbox = testPage.getByRole("listbox");
+ await expect(listbox).toBeVisible();
+ await listbox.getByRole("option", { name: "CEO" }).click();
+
+ const saved = waitForHttp(testPage, "PATCH", new RegExp(`/api/v1/office/agents/${workerId}$`));
+ await testPage.getByRole("button", { name: "Save Configuration" }).click();
+ await saved;
+
+ await testPage.getByRole("link", { name: /Agent topology/i }).click();
+ await expect(testPage.getByRole("heading", { name: /Org/i }).first()).toBeVisible({
+ timeout: 10_000,
+ });
+ const orgChart = testPage.getByTestId("org-chart-edges").locator("..");
+ await expect(orgChart.getByRole("link", { name: /Org Chart Reparent Target/ })).toHaveAttribute(
+ "data-reports-to",
+ officeSeed.agentId,
+ );
+ await expect(testPage.getByTestId("org-edge")).toHaveCount(edgesBefore + 1, {
+ timeout: 15_000,
+ });
+ });
});
diff --git a/apps/web/src/locales/en/office.json b/apps/web/src/locales/en/office.json
index a91d3b1044..ac902a3595 100644
--- a/apps/web/src/locales/en/office.json
+++ b/apps/web/src/locales/en/office.json
@@ -238,7 +238,6 @@
"dockerImageWithExample": "Docker image (e.g. node:20-slim)",
"duration": "Duration",
"editable": "Editable",
- "editOrgChartFromTheAgents": "Edit org chart from the agents list.",
"editRoutine": "Edit routine",
"effectiveActionsThisAgentCanRequest": "Effective actions this agent can request during Office runs.",
"eGCodeReview": "e.g. code-review",
diff --git a/apps/web/src/locales/pseudo/office.json b/apps/web/src/locales/pseudo/office.json
index ceae002d19..87fec4aa96 100644
--- a/apps/web/src/locales/pseudo/office.json
+++ b/apps/web/src/locales/pseudo/office.json
@@ -238,7 +238,6 @@
"dockerImageWithExample": "Ďōćķēŕ ĩḿàĝē (ē.ĝ. ńōďē:20-śĺĩḿ)",
"duration": "Ďũŕàţĩōń",
"editable": "Ēďĩţàƀĺē",
- "editOrgChartFromTheAgents": "Ēďĩţ ōŕĝ ćĥàŕţ ƒŕōḿ ţĥē àĝēńţś ĺĩśţ.",
"editRoutine": "Ēďĩţ ŕōũţĩńē",
"effectiveActionsThisAgentCanRequest": "Ēƒƒēćţĩvē àćţĩōńś ţĥĩś àĝēńţ ćàń ŕēqũēśţ ďũŕĩńĝ Ōƒƒĩćē ŕũńś.",
"eGCodeReview": "ē.ĝ. ćōďē-ŕēvĩēŵ",
diff --git a/apps/web/src/locales/pt-pt/office.json b/apps/web/src/locales/pt-pt/office.json
index aefcf44bb7..809721a97f 100644
--- a/apps/web/src/locales/pt-pt/office.json
+++ b/apps/web/src/locales/pt-pt/office.json
@@ -238,7 +238,6 @@
"dockerImageWithExample": "Imagem Docker (por exemplo, node:20-slim)",
"duration": "Duração",
"editable": "Editável",
- "editOrgChartFromTheAgents": "Edite o organograma a partir da lista de agentes.",
"editRoutine": "Editar rotina",
"effectiveActionsThisAgentCanRequest": "Ações efetivas que este agente pode pedir durante as execuções do Office.",
"eGCodeReview": "por exemplo, code-review",
diff --git a/apps/web/src/locales/zh-cn/office.json b/apps/web/src/locales/zh-cn/office.json
index 0119049a95..895d8bc83c 100644
--- a/apps/web/src/locales/zh-cn/office.json
+++ b/apps/web/src/locales/zh-cn/office.json
@@ -238,7 +238,6 @@
"dockerImageWithExample": "Docker 镜像(例如 node:20-slim)",
"duration": "时长",
"editable": "可编辑",
- "editOrgChartFromTheAgents": "从智能体列表编辑组织图。",
"editRoutine": "编辑例行程序",
"effectiveActionsThisAgentCanRequest": "此智能体在办公室运行期间可请求的有效操作。",
"eGCodeReview": "例如 code-review",
diff --git a/apps/web/src/locales/zh-hk/office.json b/apps/web/src/locales/zh-hk/office.json
index 002fc31414..f945a0ab25 100644
--- a/apps/web/src/locales/zh-hk/office.json
+++ b/apps/web/src/locales/zh-hk/office.json
@@ -238,7 +238,6 @@
"dockerImageWithExample": "Docker 鏡像(例如 node:20-slim)",
"duration": "時長",
"editable": "可編輯",
- "editOrgChartFromTheAgents": "從代理程式列表編輯組織圖。",
"editRoutine": "編輯例行程序",
"effectiveActionsThisAgentCanRequest": "此代理程式在辦公室執行期間可請求的有效操作。",
"eGCodeReview": "例如 code-review",
diff --git a/apps/web/src/locales/zh-tw/office.json b/apps/web/src/locales/zh-tw/office.json
index 2020857924..c65a385dd3 100644
--- a/apps/web/src/locales/zh-tw/office.json
+++ b/apps/web/src/locales/zh-tw/office.json
@@ -238,7 +238,6 @@
"dockerImageWithExample": "Docker 映象(例如 node:20-slim)",
"duration": "時長",
"editable": "可編輯",
- "editOrgChartFromTheAgents": "從代理程式清單編輯組織圖。",
"editRoutine": "編輯例行程式",
"effectiveActionsThisAgentCanRequest": "此代理程式在辦公室執行期間可請求的有效操作。",
"eGCodeReview": "例如 code-review",