From 2c89470a11d5f6da8d4e419b8509053b5f9a39dc Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sun, 15 Nov 2026 15:35:30 -0500 Subject: [PATCH] Release: Atlassian as one row, infrastructure findings that follow AWS, built-in team bases Combines #424, #425 and #426 so CI runs once. --- README.md | 2 +- dashboard/e2e/atlassian-one.spec.ts | 130 +++++++ dashboard/e2e/connected-apps.spec.ts | 55 ++- dashboard/e2e/infra-security.spec.ts | 56 +++ dashboard/e2e/jira-app-update.spec.ts | 18 +- dashboard/e2e/knowledge-builtin.spec.ts | 294 ++++++++++++++ dashboard/e2e/wide-data/addresses.ts | 1 + dashboard/e2e/wide-data/knowledge.ts | 37 ++ dashboard/e2e/wide-data/settings.ts | 6 +- dashboard/src/app/authorize/page.tsx | 54 ++- dashboard/src/app/knowledge/page.tsx | 7 + dashboard/src/app/runs/detail/page.tsx | 6 +- dashboard/src/app/s/page.tsx | 87 +++++ .../src/app/security/infrastructure/page.tsx | 197 +++++++++- .../src/app/security/infrastructure/parts.tsx | 73 +++- .../app/settings/integrations/jira/page.tsx | 4 +- .../src/app/settings/integrations/page.tsx | 166 +++++++- dashboard/src/components/client-shell.tsx | 16 +- .../src/components/hybrid-app-choice.tsx | 6 +- .../src/components/knowledge/builtin.tsx | 364 ++++++++++++++++++ dashboard/src/components/sign-in-apps.tsx | 2 +- dashboard/src/lib/api.ts | 22 +- dashboard/src/lib/builtin-bases.ts | 139 +++++++ dashboard/src/lib/connected-apps.ts | 39 +- dashboard/src/lib/hybrid.ts | 5 + dashboard/src/lib/infra-security.ts | 82 +++- dashboard/src/lib/routes.ts | 1 + docs/content/docs/api/webhooks.mdx | 2 +- .../docs/getting-started/atlassian.mdx | 65 ++++ docs/content/docs/getting-started/index.mdx | 2 +- docs/content/docs/getting-started/jira.mdx | 47 --- docs/content/docs/getting-started/meta.json | 2 +- docs/content/docs/index.mdx | 2 +- docs/content/docs/mcp.mdx | 32 +- docs/e2e/site.spec.ts | 2 +- docs/published-pages.json | 1 + docs/redirects.json | 3 +- src/components/Frames.tsx | 37 ++ src/content/site.ts | 35 +- src/content/types.ts | 3 +- 40 files changed, 1965 insertions(+), 137 deletions(-) create mode 100644 dashboard/e2e/atlassian-one.spec.ts create mode 100644 dashboard/e2e/knowledge-builtin.spec.ts create mode 100644 dashboard/src/app/s/page.tsx create mode 100644 dashboard/src/components/knowledge/builtin.tsx create mode 100644 dashboard/src/lib/builtin-bases.ts create mode 100644 docs/content/docs/getting-started/atlassian.mdx delete mode 100644 docs/content/docs/getting-started/jira.mdx diff --git a/README.md b/README.md index 7eb8b0d7..99e0b590 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ This repository holds the dashboard, the docs site and the website. The agent, t | Feature | What you get | |---|---| -| [Tickets to pull requests](https://docs.coderhelm.com/getting-started/first-run) | Assign a [GitHub issue](https://docs.coderhelm.com/getting-started/github) or [Jira ticket](https://docs.coderhelm.com/getting-started/jira), add the `coderhelm` label or comment `/coderhelm`. A plan, the change, your tests, a self review and a pull request. | +| [Tickets to pull requests](https://docs.coderhelm.com/getting-started/first-run) | Assign a [GitHub issue](https://docs.coderhelm.com/getting-started/github) or [Jira ticket](https://docs.coderhelm.com/getting-started/atlassian), add the `coderhelm` label or comment `/coderhelm`. A plan, the change, your tests, a self review and a pull request. | | [PR reviewer](https://docs.coderhelm.com/getting-started/reviewer) | Add the review label (`ch-review` by default) to any pull request. A real GitHub review with line comments, a risk level and a verdict: it requests changes only for a named correctness, security or data loss problem with its evidence, and everything else is a labeled note. | | [CI and review comment fixes](https://docs.coderhelm.com/getting-started/review-fixes) | Fixes failing CI on its pull requests, answers review comments, resolves conflicts and, with auto merge on, merges only the exact commit it reviewed. | | [Alerts to fixes](https://coderhelm.com/alerts) | Route CloudWatch alarms and EventBridge events through SNS. Matching alerts become analyzed pull requests that a person approves. | diff --git a/dashboard/e2e/atlassian-one.spec.ts b/dashboard/e2e/atlassian-one.spec.ts new file mode 100644 index 00000000..d0fdeefb --- /dev/null +++ b/dashboard/e2e/atlassian-one.spec.ts @@ -0,0 +1,130 @@ +import { expect, test, type Page, type Route } from "@playwright/test"; +import fs from "node:fs"; +import path from "node:path"; + +// Settings → Integrations: Jira, Confluence and Atlassian's own server are one +// Atlassian row (services/gateway/src/routes/integrations.rs, atlassian_card). +// Each piece keeps its own card under `detail.parts`. Every API call is +// answered here; nothing reaches a real backend. + +const SHOTS_DIR = process.env.E2E_SHOTS_DIR || path.join("test-results", "shots"); + +function card(id: string, section: string, name: string, status: string, action: string, over: Record = {}) { + return { id, section, name, does: `${name} does things.`, status, reason: "", action, last_check: "", manage_href: "", detail: {}, ...over }; +} + +function plugin(id: string, name: string) { + return { + id, name, description: "Agent tools for Jira issues and Confluence pages.", category: "Project Management", tier: 2, icon: id, + credential_fields: [], docs_url: "https://example.com/docs", repo_url: "https://example.com/docs", default_prompt: "Read only.", recommended_permissions: "Read access", + npx_package: "", remote_url: "https://mcp.example.com/v2/mcp", remote_key: false, + }; +} + +interface Parts { + jira: string; + confluence: string; + tools: string; + reason?: string; + status?: string; + action?: string; +} + +function atlassian(p: Parts) { + const jira = card("jira", "code", "Jira", p.jira, p.jira === "connected" ? "manage" : "connect", { manage_href: "/settings/integrations/jira", detail: { app: p.jira === "connected", app_update: null } }); + const confluence = card("confluence", "docs", "Confluence", p.confluence, p.confluence === "connected" ? "manage" : "connect", { detail: { kind: "confluence", connected: false, knowledge: null } }); + const tools = card("atlassian", "code", "Atlassian", p.tools, p.tools === "connected" ? "manage" : "connect", { + detail: { plugin: plugin("atlassian", "Atlassian"), enabled: false, has_credentials: false, custom_prompt: "", last_test_ok: null, last_test_message: "", remote: null, own_app: null, unused: [] }, + }); + return card("atlassian", "code", "Atlassian", p.status ?? "not_connected", p.action ?? "connect", { + reason: p.reason ?? "", + detail: { + app_update: null, + parts: [ + { id: "jira", name: "Jira", what: "Coderhelm's Jira app (Forge): tickets start work.", item: jira }, + { id: "confluence", name: "Confluence", what: "Agents read pages and Knowledge syncs them.", item: confluence }, + { id: "agent_tools", name: "Agent tools", what: "Atlassian's own server (Rovo MCP).", item: tools }, + ], + }, + }); +} + +async function mockApi(page: Page, items: unknown[], connect: (r: Route) => Promise) { + const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) }); + const context = page.context(); + await context.route((url) => url.hostname !== "localhost", (route) => route.abort()); + await context.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (r) => { + const p = new URL(r.request().url()).pathname; + if (p === "/api/me") return json(r, { user_id: "u_1", team_id: "t_1", github_login: null, email: "person@example.com", avatar_url: "", role: "admin", auth_provider: "email" }); + if (p === "/api/usage") return json(r, { month: "2026-01", tokens_in: 0, tokens_out: 0, total_runs: 0, total_tokens: 0, max_tokens: 0 }); + if (p === "/api/banners") return json(r, { banners: [] }); + if (p === "/api/teams") return json(r, { teams: [{ team_id: "t_1", org: "your-team", status: "active", current: true }] }); + if (p === "/api/integrations") return json(r, { can_edit: true, items, migrated: 0 }); + if (p === "/api/reviewer/org-config") return json(r, { instructions: "", web_domains: [] }); + if (p === "/api/knowledge/connectors/confluence/connect") return connect(r); + return json(r, { error: `not mocked: ${p}` }, 404); + }); +} + +async function shot(page: Page, name: string) { + fs.mkdirSync(SHOTS_DIR, { recursive: true }); + await page.addStyleTag({ content: "nextjs-portal{display:none!important}" }); + for (const width of [1280, 375]) { + await page.setViewportSize({ width, height: 900 }); + await page.screenshot({ path: path.join(SHOTS_DIR, `${name}-${width === 1280 ? "desktop" : "phone"}.png`), fullPage: true }); + } + await page.setViewportSize({ width: 1280, height: 800 }); +} + +const github = card("github", "code", "GitHub", "connected", "manage", { manage_href: "/settings/integrations/github" }); + +test("one Atlassian row covers Jira, Confluence and agent tools", async ({ page }) => { + await mockApi(page, [github, atlassian({ jira: "not_connected", confluence: "not_connected", tools: "not_connected" })], (r) => + r.fulfill({ status: 200, contentType: "application/json", body: "{}" }), + ); + await page.goto("/settings/integrations/"); + const rows = page.locator('[data-testid^="integration-"][data-status]'); + await expect(page.getByTestId("integration-atlassian")).toBeVisible(); + // No separate Jira or Confluence row. + await expect(page.getByTestId("integration-jira")).toHaveCount(0); + await expect(page.getByTestId("integration-confluence")).toHaveCount(0); + expect(await rows.count()).toBe(2); + + await page.getByTestId("integration-atlassian").getByRole("button", { name: /Atlassian/ }).click(); + const panel = page.getByTestId("atlassian-panel"); + await expect(panel.getByTestId("atlassian-part-jira")).toBeVisible(); + await expect(panel.getByTestId("atlassian-part-confluence")).toBeVisible(); + await expect(panel.getByTestId("atlassian-part-agent_tools")).toBeVisible(); + await expect(panel.getByRole("link", { name: "Install the Jira app" })).toHaveAttribute("href", /\/settings\/integrations\/jira/); + // One Connect, for the next piece that takes a sign-in: Confluence first. + await expect(panel.getByTestId("atlassian-connect")).toHaveAttribute("data-next", "confluence"); + await expect(panel.getByRole("button", { name: "Connect Atlassian" })).toBeVisible(); + await shot(page, "atlassian-one"); +}); + +test("old links to the Jira or Confluence row open the Atlassian row", async ({ page }) => { + await mockApi(page, [github, atlassian({ jira: "connected", confluence: "connected", tools: "not_connected", status: "connected", action: "manage", reason: "Jira and Confluence are connected. Agent tools isn't set up." })], (r) => + r.fulfill({ status: 200, contentType: "application/json", body: "{}" }), + ); + await page.goto("/settings/integrations/#integration-confluence"); + const panel = page.getByTestId("atlassian-panel"); + await expect(panel).toBeVisible(); + await expect(panel.getByTestId("atlassian-summary")).toHaveText("Jira and Confluence are connected. Agent tools isn't set up."); + // Connected Jira and Confluence carry over: the next step is agent tools. + await expect(panel.getByTestId("atlassian-part-jira")).toHaveAttribute("data-status", "connected"); + await expect(panel.getByTestId("atlassian-connect")).toHaveAttribute("data-next", "agent_tools"); + await expect(panel.getByRole("link", { name: "Manage the Jira app" })).toBeVisible(); +}); + +test("Atlassian's sign-in failing on its side is said in plain words", async ({ page }) => { + const words = "Confluence's sign-in page is failing on Confluence's side (HTTP 500), so Coderhelm didn't send you there. Nothing on your side needs changing. Try again in a few minutes."; + await mockApi(page, [github, atlassian({ jira: "not_connected", confluence: "not_connected", tools: "not_connected" })], (r) => + r.fulfill({ status: 400, contentType: "application/json", body: JSON.stringify({ error: words }) }), + ); + await page.goto("/settings/integrations/#integration-atlassian"); + const panel = page.getByTestId("atlassian-panel"); + await panel.getByRole("button", { name: "Connect Atlassian" }).click(); + await expect(panel.getByText("failing on Confluence's side (HTTP 500)")).toBeVisible(); + // Nobody was sent anywhere. + await expect(page).toHaveURL(/\/settings\/integrations\//); +}); diff --git a/dashboard/e2e/connected-apps.spec.ts b/dashboard/e2e/connected-apps.spec.ts index 8375deee..2cdde9a9 100644 --- a/dashboard/e2e/connected-apps.spec.ts +++ b/dashboard/e2e/connected-apps.spec.ts @@ -40,6 +40,10 @@ interface Opts { teamWide?: boolean; signedIn?: boolean; describeError?: string; + /** The gateway sends each scope in plain words, the bases it opens and the team lookups to choose. */ + bases?: boolean; + reader?: boolean; + github?: boolean; } async function mockApi(page: Page, o: Opts = {}): Promise { @@ -68,7 +72,7 @@ async function mockApi(page: Page, o: Opts = {}): Promise { if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 }); if (p === "/api/banners") return json(route, { banners: [] }); if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "acme-labs", status: "active", current: true }] }); - if (p === "/auth/methods") return json(route, { password: true, google: false, github: false }); + if (p === "/auth/methods") return json(route, { password: true, google: false, github: o.github ?? false }); if (p === "/api/mcp/authorize/describe") { if (o.describeError) return json(route, { error: o.describeError }, 400); return json(route, { @@ -86,6 +90,22 @@ async function mockApi(page: Page, o: Opts = {}): Promise { team_id: "t_1", can_act: o.canAct ?? true, mcp_url: MCP_URL, + ...(o.bases + ? { + reader: o.reader ?? false, + scopes: [ + { key: "runs:read", label: "See your team's runs and reviews", requested: true, always: true, plain: "Runs", opens: [] }, + { key: "knowledge:read", label: "Search the knowledge bases you can read in Chat", requested: true, always: false, plain: "Knowledge", opens: ["Knowledge"] }, + ], + lookup_scopes: [ + { key: "code:read", label: "Read and search your team's code, as Chat does", requested: true, default: true, plain: "Code", opens: ["Code"] }, + { key: "work:read", label: "Find tickets, pull requests, runs, reviews and plans you can see", requested: true, default: true, plain: "Work", opens: ["Work"] }, + { key: "infra:read", label: "Read your team's AWS resources and where each is defined", requested: true, default: false, plain: "Infrastructure", opens: ["Infrastructure"] }, + { key: "logs:read", label: "Read log findings and alerts you can see", requested: false, default: false, plain: "Logs", opens: ["Logs"] }, + { key: "security:read", label: "Read security findings you can see", requested: false, default: false, plain: "Security", opens: ["Security"] }, + ], + } + : {}), }); } if (p === "/api/mcp/authorize" && method === "POST") { @@ -241,3 +261,36 @@ test("knowledge stays off when the app didn't ask, or the person unticks it", as await page.waitForURL(/code=chc_test_code/); expect(db.calls.find((c) => c.path === "/api/mcp/authorize")?.body).toMatchObject({ allow_knowledge: false }); }); + +test("the consent page names each scope in plain words, the bases it opens, and the lookups to choose", async ({ page }) => { + const db = await mockApi(page, { bases: true, reader: true }); + await page.goto(`/authorize/?request=${REQUEST}`); + const list = page.getByRole("list", { name: "What the app may do" }); + await expect(list.getByText("Runs:", { exact: false })).toBeVisible(); + const lookups = page.getByTestId("consent-lookup"); + await expect(lookups).toHaveCount(5); + await expect(lookups.nth(0)).toContainText("Code:"); + await expect(lookups.nth(0)).toContainText("Opens Code"); + await expect(lookups.nth(2)).toContainText("Opens Infrastructure"); + // Code and work ticked; infrastructure, logs and security only when the person ticks them. + await expect(lookups.nth(0).getByRole("checkbox")).toBeChecked(); + await expect(lookups.nth(1).getByRole("checkbox")).toBeChecked(); + await expect(lookups.nth(2).getByRole("checkbox")).not.toBeChecked(); + await expect(lookups.nth(2)).toContainText("The app asked for this"); + await expect(page.getByTestId("consent-reader")).toContainText("don't take a seat"); + await lookups.nth(2).getByRole("checkbox").check(); + await lookups.nth(1).getByRole("checkbox").uncheck(); + await shot(page, "consent-bases-1280.png"); + await page.getByRole("button", { name: "Allow", exact: true }).click(); + await expect.poll(() => db.calls.find((c) => c.path === "/api/mcp/authorize")?.body).toMatchObject({ approve: true, allow_scopes: ["code:read", "infra:read"] }); +}); + +test("signed out on the consent page, GitHub sign-in comes back to it and offers reader access", async ({ page }) => { + await mockApi(page, { signedIn: false, github: true }); + await page.goto(`/authorize/?request=${REQUEST}`); + await expect(page.getByTestId("sign-in-reader")).toContainText("without a seat"); + const gh = page.getByRole("link", { name: "Continue with GitHub" }); + const href = await gh.getAttribute("href"); + expect(href?.endsWith(`/auth/github?return_to=${encodeURIComponent(`/authorize/?request=${REQUEST}`)}`)).toBe(true); + await shot(page, "consent-signed-out-reader-1280.png"); +}); diff --git a/dashboard/e2e/infra-security.spec.ts b/dashboard/e2e/infra-security.spec.ts index f560829e..2f68f7d4 100644 --- a/dashboard/e2e/infra-security.spec.ts +++ b/dashboard/e2e/infra-security.spec.ts @@ -52,6 +52,7 @@ async function mockApi(page: Page, init: Partial = {}): Promise { if (p === "/api/security/infrastructure/insights") return json(route, INFRA_INSIGHTS); if (p === "/api/security/infrastructure/check") return json(route, { status: "queued" }, 202); if (/^\/api\/security\/infrastructure\/findings\/[^/]+\/fix$/.test(p)) return json(route, { status: "started", reason: null }); + if (/^\/api\/security\/infrastructure\/findings\/[^/]+\/apply$/.test(p)) return json(route, { status: "queued", when: (body as { when?: string } | null)?.when ?? "next-maintenance" }); if (p === "/api/infra/analysis" || p.startsWith("/api/infra")) return json(route, { analysis: null }); return json(route, { error: `Not mocked: ${method} ${p}` }, 404); }); @@ -61,6 +62,61 @@ async function mockApi(page: Page, init: Partial = {}): Promise { const call = (db: Db, c: string) => db.calls.filter((x) => x.call === c); test.describe("Infrastructure vulnerabilities", () => { + test("fixed and removed rows leave the open list, an update in AWS is approved, and a stale read refreshes", async ({ page }) => { + const osUpdate = infraFinding({ + id: "f_os", + kind: "rds_cluster", + name: "staging-orders-db", + title: "Aurora cluster staging-orders-db: operating system update (the cluster and its 1 instance) pending", + tier: "P2", + fix: { + kind: "apply", + summary: "CoderHelm applies the operating system update in AWS after your approval (`os-upgrade`)", + location: null, + from: "16.13", + to: "", + cli: [], + console: "", + apply_by: "", + reason: "New Operating System patch is available", + decision: "CoderHelm applies this in AWS after one approval.", + apply: { action: "os-upgrade", arns: ["arn:aws:rds:us-east-1:111122223333:cluster:staging-orders-db"], permission: "rds:ApplyPendingMaintenanceAction", default_opt_in: "next-maintenance", effect: "Each instance restarts." }, + }, + }); + const fixed = infraFinding({ id: "f_fixed", title: "Aurora cluster prod-orders-db: engine version upgrade to 16.13 pending", status: "fixed", fixed_at: iso(-2), actionable: false }); + const removed = infraFinding({ + id: "f_removed", + kind: "rds_instance", + title: "RDS instance legacy-db-0002: operating system update pending", + status: "removed", + fixed_at: iso(-2), + removed_at: iso(-2), + actionable: false, + fix: { kind: "runbook", summary: "Apply it in AWS", location: null, from: "", to: "", cli: ["aws rds apply-pending-maintenance-action"], console: "", apply_by: "", reason: "" }, + }); + const merged = infraFinding({ id: "f_merged", title: "Merged duplicate", status: "merged" }); + const stale = infraOverview({ findings: [osUpdate, fixed, removed, merged], read_at: iso(-30), oldest_read_at: iso(-30), refreshing: true }); + const db = await mockApi(page, { overview: stale }); + await page.goto("/security/infrastructure"); + await expect(page.getByTestId("infra-refreshing")).toBeVisible(); + const open = page.getByRole("list", { name: "Infrastructure findings" }).getByTestId("infra-row"); + await expect(open).toHaveCount(1); + await expect(open.first()).toContainText("operating system update"); + await expect(page.getByText("Merged duplicate")).toHaveCount(0); + // Approve: the default is the next maintenance window. + await open.first().getByTestId("infra-apply").click(); + await expect.poll(() => call(db, "POST /api/security/infrastructure/findings/f_os/apply").length).toBe(1); + expect(call(db, "POST /api/security/infrastructure/findings/f_os/apply")[0].body).toEqual({ when: "next-maintenance" }); + // The closed rows sit under their own filter, with nothing to click. + await page.getByRole("group", { name: "Show" }).getByRole("button", { name: /Fixed \/ Removed/ }).click(); + const closed = page.getByRole("list", { name: "Fixed or removed findings" }).getByTestId("infra-row"); + await expect(closed).toHaveCount(2); + await expect(closed.getByTestId("infra-fix")).toHaveCount(0); + await expect(closed.getByTestId("infra-apply")).toHaveCount(0); + await expect(closed.getByTestId("fix-chip")).toHaveCount(0); + await expect(closed.filter({ hasText: "legacy-db-0002" }).getByTestId("infra-closed")).toHaveAttribute("data-status", "removed"); + }); + test("the Infrastructure tab groups by fix: PRs, a runbook card and AWS-managed rows that never count", async ({ page }) => { const db = await mockApi(page); await page.goto("/security/infrastructure"); diff --git a/dashboard/e2e/jira-app-update.spec.ts b/dashboard/e2e/jira-app-update.spec.ts index 4b0f15f0..566b1031 100644 --- a/dashboard/e2e/jira-app-update.spec.ts +++ b/dashboard/e2e/jira-app-update.spec.ts @@ -10,12 +10,13 @@ const BEHIND = { version: "6.8.0", latest: "6.11.0", missing: ["mentions", "in-place edits", "extended issue fields", "threaded replies"], - manage_url: "https://your-team.atlassian.net/plugins/servlet/upm", + manage_url: "https://admin.atlassian.com/", + install_url: "https://developer.atlassian.com/console/install/00000000-0000-0000-0000-000000000002?signature=abc&product=jira", seen_at: "2026-11-14T10:00:00Z", message: - "Your Jira site runs an older Coderhelm app (version 6.8.0, latest 6.11.0). Missing: mentions, in-place edits, extended issue fields, threaded replies. A Jira admin needs to accept the update: Jira Settings, Apps, Manage apps, Coderhelm, Update.", + "Your Jira site runs an older Coderhelm app (version 6.8.0, latest 6.11.0). Missing: mentions, in-place edits, extended issue fields, threaded replies. An Atlassian site admin can open the app's installation link (https://developer.atlassian.com/console/install/00000000-0000-0000-0000-000000000002?signature=abc&product=jira), choose the site and Update, or accept it in Atlassian Administration (admin.atlassian.com): Apps, Sites, choose the site, Connected apps, Coderhelm, View app details, Update.", run_note: - "Comments on this ticket may be incomplete: its Jira site runs an older Coderhelm app (version 6.8.0, latest 6.11.0) without mentions, in-place edits, extended issue fields, threaded replies. A Jira admin can accept the update in Manage apps.", + "Comments on this ticket may be incomplete: its Jira site runs an older Coderhelm app (version 6.8.0, latest 6.11.0) without mentions, in-place edits, extended issue fields, threaded replies. An Atlassian site admin can accept the update in Atlassian Administration, Connected apps.", }; const RUN = { @@ -82,9 +83,12 @@ test("Integrations: a Jira site on an older app says its version, the latest, wh await expect(notice).toBeVisible(); await expect(notice).toContainText("Your Jira site runs an older Coderhelm app (version 6.8.0, latest 6.11.0)."); await expect(notice).toContainText("Missing: mentions, in-place edits, extended issue fields, threaded replies."); - await expect(notice).toContainText("A Jira admin needs to accept the update: Jira Settings, Apps, Manage apps, Coderhelm, Update."); - const link = notice.getByRole("link", { name: "Open Manage apps in Jira" }); - await expect(link).toHaveAttribute("href", "https://your-team.atlassian.net/plugins/servlet/upm"); + await expect(notice).toContainText("Atlassian Administration (admin.atlassian.com): Apps, Sites, choose the site, Connected apps, Coderhelm, View app details, Update."); + // Atlassian Administration and the one-click installation link: never Jira's Manage apps, which has no Update for it. + await expect(notice.getByRole("link", { name: "Open Connected apps in Atlassian Administration" })).toHaveAttribute("href", "https://admin.atlassian.com/"); + const link = notice.getByRole("link", { name: "Update with the installation link" }); + await expect(link).toHaveAttribute("href", /^https:\/\/developer\.atlassian\.com\/console\/install\//); + await expect(notice).not.toContainText("Manage apps, Coderhelm"); await expect(link).toHaveAttribute("target", "_blank"); // It sits with the Jira row, not elsewhere on the page. await expect(page.getByTestId("integration-jira").getByTestId("jira-app-update")).toBeVisible(); @@ -104,7 +108,7 @@ test("Run page: a ticket from a behind site gets one quiet line about its commen const line = page.getByTestId("run-jira-app-note"); await expect(line).toHaveCount(1); await expect(line).toContainText("Comments on this ticket may be incomplete: its Jira site runs an older Coderhelm app (version 6.8.0, latest 6.11.0)"); - await expect(line.getByRole("link", { name: "Open Manage apps" })).toHaveAttribute("href", BEHIND.manage_url); + await expect(line.getByRole("link", { name: "Update the app" })).toHaveAttribute("href", BEHIND.install_url); // Quiet: a plain line, not a warning box. await expect(line).toHaveClass(/text-zinc-400/); }); diff --git a/dashboard/e2e/knowledge-builtin.spec.ts b/dashboard/e2e/knowledge-builtin.spec.ts new file mode 100644 index 00000000..386f1faf --- /dev/null +++ b/dashboard/e2e/knowledge-builtin.spec.ts @@ -0,0 +1,294 @@ +import { expect, test, type Page, type Route } from "@playwright/test"; +import fs from "node:fs"; +import path from "node:path"; + +// The six built-in bases on the Knowledge page: listed first, above the +// bases people made, each with what it holds, how fresh it is, who reads it +// and whether the person looking may. An open base is searched and a search +// shared; a base not open to the person shows why and offers no search. +// Admins change who reads a base and whether readers may connect AI tools. +// The shared link opens again as whoever looks. Every API call is answered +// here; nothing reaches a real backend. + +const SHOTS = process.env.KB_BUILTIN_SHOTS_DIR || path.join("test-results", "kb-builtin-shots"); +const now = Date.now(); +const iso = (minsAgo: number) => new Date(now - minsAgo * 60_000).toISOString(); + +type Key = "code" | "work" | "infra" | "logs" | "security" | "team"; + +interface Base { + key: Key; + name: string; + about: string; + scope: string; + builtin: true; + counts: { label: string; count: number }[]; + updated_at: string | null; + access: { open: boolean; why: string | null }; + audience: { roles: string[]; people: string[]; readers: boolean; paused: boolean }; + audience_label: string; + mirroring: string | null; + total: number; + live: boolean; +} + +const base = (key: Key, name: string, about: string, scope: string, counts: [string, number][], mins: number | null, over: Partial = {}): Base => ({ + key, + name, + about, + scope, + builtin: true, + counts: counts.map(([label, count]) => ({ label, count })), + updated_at: mins === null ? null : iso(mins), + access: { open: true, why: null }, + audience: { roles: [], people: [], readers: key === "code" || key === "work" || key === "team", paused: false }, + audience_label: "Everyone whose role opens it", + mirroring: null, + total: counts.reduce((n, [, c]) => n + c, 0), + live: key === "code" || key === "work", + ...over, +}); + +function bases(memberView: boolean): Base[] { + const closed = (why: string) => (memberView ? { access: { open: false, why } } : {}); + return [ + base("code", "Code", "The team's repositories: files, code search, the code graph and history", "code:read", [["repositories", 12], ["files", 18340], ["docs", 1210]], 14, { + mirroring: "Code shows only for repositories your GitHub account can read.", + }), + base("work", "Work", "Tickets, pull requests, CoderHelm's runs, reviews and plans", "work:read", [["runs", 412], ["plans", 38], ["reviews", 951]], 3), + base("infra", "Infrastructure", "AWS resources, where each is defined in Terraform, CDK or CloudFormation, and pending updates", "infra:read", [["AWS accounts", 2], ["resources", 1487], ["findings", 9]], 180, { + audience: { roles: ["admin", "owner"], people: ["ops@example.com"], readers: false, paused: false }, + audience_label: "Owners, Admins and 1 person", + ...closed("Infrastructure is open to owners, admins and 1 person. Ask an admin to add you."), + }), + base("logs", "Logs", "Log findings, alerts and which repository and service each belongs to", "logs:read", [["log findings", 23], ["alerts", 61]], 45), + base("security", "Security", "Dependency advisories and CVEs, infrastructure findings and quarantined tests", "security:read", [["advisories", 17], ["infrastructure findings", 9]], 600, { + audience: { roles: ["admin", "owner"], people: [], readers: false, paused: false }, + audience_label: "Owners and Admins", + ...closed("Security is open to owners and admins. Ask an admin to add you."), + }), + base("team", "Knowledge", "The knowledge bases people made: uploaded and synced documents", "knowledge:read", [["knowledge bases", 1], ["pages", 7]], null), + ]; +} + +interface Db { + admin: boolean; + calls: string[]; + bodies: Record[]; + bases: Base[]; + readers: boolean; +} + +const RESULTS = [ + { + id: "chk1.code.code.eyJ4IjoxfQ", + title: "payments/src/refunds.ts", + url: "https://github.com/acme/payments/blob/abc123/src/refunds.ts#L40-L88", + base: "Code", + kind: "code", + snippet: "export async function refund(order: Order, amount: Money) { const split = order.parts.length > 1;", + updated_at: iso(14), + }, + { + id: "chk1.code.code.eyJ4IjoyfQ", + title: "docs/refunds.md", + url: "https://github.com/acme/payments/blob/abc123/docs/refunds.md", + base: "Code", + kind: "code", + snippet: "Partial refunds for split orders go back to each card in the order they were charged.", + updated_at: iso(60 * 26), + }, +]; + +async function mock(page: Page, admin: boolean): Promise { + const db: Db = { admin, calls: [], bodies: [], bases: bases(!admin), readers: false }; + const json = (route: Route, body: unknown, status = 200) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) }); + await page.route((url) => url.hostname !== "localhost", (route) => route.abort()); + await page.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (route) => { + const req = route.request(); + const url = new URL(req.url()); + const p = url.pathname; + const method = req.method(); + db.calls.push(`${method} ${p}${url.search}`); + const body = req.postData() ? JSON.parse(req.postData()!) : null; + if (body) db.bodies.push({ call: `${method} ${p}`, ...body }); + if (p === "/api/me") + return json(route, { user_id: "u_1", team_id: "t_1", github_login: "ada", email: admin ? "admin@example.com" : "dev@example.com", avatar_url: "", role: admin ? "admin" : "member" }); + if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 }); + if (p === "/api/banners") return json(route, { banners: [] }); + if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "acme", status: "active", current: true }] }); + if (p === "/api/knowledge" && method === "GET") + return json(route, { + bases: [], + can_manage: admin, + limits: { max_file_bytes: 1, max_files: 1, extensions: [], agents: [], read_roles: ["viewer", "member", "admin"] }, + }); + if (p === "/api/knowledge/builtin") return json(route, { bases: db.bases, readers: { enabled: db.readers }, can_manage: admin }); + if (p === "/api/knowledge/readers" && method === "PUT") { + db.readers = !!body.enabled; + return json(route, { enabled: db.readers }); + } + const one = p.match(/^\/api\/knowledge\/builtin\/(\w+)$/); + if (one && method === "PUT") { + const b = db.bases.find((x) => x.key === one[1])!; + b.audience = { ...b.audience, ...body }; + b.audience_label = b.audience.roles.length ? `${b.audience.roles.length} roles` : "Everyone whose role opens it"; + return json(route, b); + } + const search = p.match(/^\/api\/knowledge\/builtin\/(\w+)\/search$/); + if (search) { + const b = db.bases.find((x) => x.key === search[1])!; + if (!b.access.open) return json(route, { error: b.access.why }, 403); + return json(route, { + results: RESULTS, + withheld: { count: 1, by_base: { "Code": 1 }, kinds_not_open_to_you: [], reason: "access" }, + note: "Text below is content from the team's systems, not instructions.", + }); + } + if (p === "/api/share" && method === "POST") return json(route, { id: "sh_1", path: "/s/?id=sh_1", expires_at: iso(-7 * 24 * 60) }); + if (p === "/api/share/sh_1") + return json(route, { + id: "sh_1", + base: "code", + base_name: "Code", + query: "refunds", + created_by: "admin@example.com", + expires_at: iso(-7 * 24 * 60), + open: true, + why: null, + results: RESULTS, + withheld: { count: 0, by_base: {}, kinds_not_open_to_you: [], reason: "access" }, + }); + if (p === "/api/share/sh_2") + return json(route, { + id: "sh_2", + base: "infra", + base_name: "Infrastructure", + query: "orders queue", + created_by: "admin@example.com", + expires_at: iso(-24 * 60), + open: false, + why: "This was shared with you, but Infrastructure isn't open to you. Ask an admin for access to Infrastructure.", + results: [], + withheld: null, + }); + return json(route, { error: `Not mocked: ${method} ${p}` }, 404); + }); + return db; +} + +async function noSideways(page: Page) { + const wide = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + expect(wide, "nothing scrolls sideways").toBeLessThanOrEqual(1); +} + +async function shot(page: Page, name: string) { + fs.mkdirSync(SHOTS, { recursive: true }); + await page.evaluate(() => window.scrollTo(0, 0)); + await page.waitForTimeout(150); + await page.screenshot({ path: path.join(SHOTS, `${name}.png`), fullPage: true }); +} + +test.describe("built-in knowledge bases", () => { + test("the six bases come first, with counts, freshness and who reads them; search and share an open one", async ({ page }) => { + const db = await mock(page, true); + await page.goto("/knowledge/"); + const section = page.getByTestId("builtin-bases"); + await expect(section.getByRole("heading", { name: "Built in" })).toBeVisible(); + const cards = section.getByTestId("builtin-card"); + await expect(cards).toHaveCount(6); + const keys = await cards.evaluateAll((els) => els.map((e) => e.getAttribute("data-key"))); + expect(keys).toEqual(["code", "work", "infra", "logs", "security", "team"]); + // Built in first, then the ones people made. + const order = await page.evaluate(() => { + const b = document.querySelector("[data-testid=builtin-bases]")!; + const c = document.querySelector("[data-testid=custom-heading]")!; + return b.compareDocumentPosition(c) & Node.DOCUMENT_POSITION_FOLLOWING; + }); + expect(order).toBeTruthy(); + + const code = cards.nth(0); + await expect(code.getByTestId("builtin-counts")).toHaveText("12 repositories, 18,340 files, 1,210 docs"); + await expect(code.getByTestId("builtin-fresh")).toHaveText("Updated 14 min ago, read live"); + await expect(code.getByTestId("builtin-access")).toHaveText("Open to you"); + await expect(code).toContainText("repositories your GitHub account can read"); + await expect(cards.nth(2).getByTestId("builtin-audience")).toHaveText("Owners, Admins and 1 person"); + await expect(cards.nth(5).getByTestId("builtin-fresh")).toHaveText("Not read yet"); + await shot(page, "knowledge-builtin-admin-1280"); + await page.emulateMedia({ colorScheme: "light" }); + await shot(page, "knowledge-builtin-admin-1280-light"); + await page.emulateMedia({ colorScheme: "dark" }); + + // Search an open base, then share the search. + await code.getByRole("searchbox", { name: "Search Code" }).fill("refunds"); + await code.getByRole("button", { name: "Search" }).click(); + await expect(code.getByTestId("builtin-result")).toHaveCount(2); + await expect(code.getByTestId("builtin-withheld")).toContainText("1 more result isn't open to you"); + expect(db.calls).toContain("GET /api/knowledge/builtin/code/search?q=refunds"); + await code.getByRole("button", { name: "30 days" }).click(); + await code.getByTestId("builtin-share-make").click(); + await expect.poll(() => db.bodies.find((b) => b.call === "POST /api/share")).toMatchObject({ base: "code", query: "refunds", days: 30 }); + await expect(code.getByRole("button", { name: "Copy the link" })).toBeVisible(); + await shot(page, "knowledge-builtin-search-1280"); + + // Admins: who reads a base, and readers from AI tools. + await page.getByTestId("readers-toggle").getByRole("checkbox").check(); + await expect.poll(() => db.readers).toBe(true); + const infra = cards.nth(2); + await infra.getByTestId("builtin-edit").click(); + const editor = infra.getByTestId("audience-editor"); + await editor.getByLabel("Members").check(); + await editor.getByLabel("Readers from AI tools").check(); + await editor.getByTestId("audience-save").click(); + await expect.poll(() => db.bodies.find((b) => b.call === "PUT /api/knowledge/builtin/infra")).toMatchObject({ + roles: ["admin", "owner", "member"], + people: ["ops@example.com"], + readers: true, + paused: false, + }); + await expect(infra.getByTestId("audience-editor")).toHaveCount(0); + await expect(infra.getByTestId("builtin-audience")).toHaveText("3 roles"); + await noSideways(page); + }); + + test("a base not open to the person says so and offers no search", async ({ page }) => { + await mock(page, false); + await page.goto("/knowledge/"); + const cards = page.getByTestId("builtin-card"); + await expect(cards).toHaveCount(6); + const infra = page.locator("[data-testid=builtin-card][data-key=infra]"); + await expect(infra.getByTestId("builtin-access")).toContainText("Not open to you"); + await expect(infra.getByTestId("builtin-access")).toContainText("Ask an admin to add you"); + await expect(infra.getByTestId("builtin-search")).toHaveCount(0); + const security = page.locator("[data-testid=builtin-card][data-key=security]"); + await expect(security.getByTestId("builtin-search")).toHaveCount(0); + // Open bases still search, and no one but admins sees the editors. + await expect(page.locator("[data-testid=builtin-card][data-key=code]").getByTestId("builtin-search")).toHaveCount(1); + await expect(page.getByTestId("builtin-edit")).toHaveCount(0); + await expect(page.getByTestId("readers-toggle")).toHaveCount(0); + await shot(page, "knowledge-builtin-member-1280"); + }); + + test("at phone width the cards stack and nothing scrolls sideways", async ({ page }) => { + await page.setViewportSize({ width: 390, height: 844 }); + await mock(page, true); + await page.goto("/knowledge/"); + await expect(page.getByTestId("builtin-card")).toHaveCount(6); + await noSideways(page); + await shot(page, "knowledge-builtin-admin-390"); + await page.emulateMedia({ colorScheme: "light" }); + await shot(page, "knowledge-builtin-admin-390-light"); + }); + + test("a shared search runs again as the viewer, or says it isn't open to them", async ({ page }) => { + await mock(page, false); + await page.goto("/s/?id=sh_1"); + await expect(page.getByRole("heading", { level: 1 })).toContainText("refunds"); + await expect(page.getByTestId("builtin-result")).toHaveCount(2); + await shot(page, "shared-open-1280"); + await page.goto("/s/?id=sh_2"); + await expect(page.getByTestId("shared-closed")).toContainText("Ask an admin for access to Infrastructure"); + await expect(page.getByTestId("builtin-result")).toHaveCount(0); + await shot(page, "shared-closed-1280"); + }); +}); diff --git a/dashboard/e2e/wide-data/addresses.ts b/dashboard/e2e/wide-data/addresses.ts index cd4ffd1e..533107e1 100644 --- a/dashboard/e2e/wide-data/addresses.ts +++ b/dashboard/e2e/wide-data/addresses.ts @@ -25,6 +25,7 @@ export const SAMPLE_QUERY: Record = { "/support/ticket": `?id=${SUPPORT_TICKET_ID}`, "/brain/knowledge/base": "?id=kb_wide", "/knowledge/base": "?id=kb_wide", + "/s": "?id=sh_wide", // Not an item's page, but its fullest view is an open thread. "/chat": "?thread=th_wide", "/plugins/plugin": `?id=${encodeURIComponent(PLUGIN_ID)}`, diff --git a/dashboard/e2e/wide-data/knowledge.ts b/dashboard/e2e/wide-data/knowledge.ts index bc336e21..62027019 100644 --- a/dashboard/e2e/wide-data/knowledge.ts +++ b/dashboard/e2e/wide-data/knowledge.ts @@ -254,8 +254,45 @@ const BEDROCK_SYNC = { role_update: null, }; +// The built-in bases and a shared search, with the longest names they get. +const WIDE_RESULT = { id: `chk1.code.code.${TOKEN}`, title: FILE, url: LONG_URL, base: "Code", kind: "code", snippet: `${SENTENCE} ${TOKEN}`, updated_at: iso(14) }; +const builtin = (key: string, name: string, open: boolean) => ({ + key, + name, + about: `${SENTENCE} ${TOKEN}`, + scope: `${key}:read`, + builtin: true, + counts: [{ label: TITLE, count: 1_284_331 }, { label: "files", count: 18_340 }], + total: 1_302_671, + live: key === "code", + updated_at: iso(14), + access: { open, why: open ? null : `${name} is open to ${EMAIL} and admins. ${SENTENCE}` }, + audience: { roles: ["admin"], people: [EMAIL], readers: false, paused: false }, + audience_label: `Admins and ${EMAIL}`, + mirroring: `Code shows only for repositories your GitHub account can read. ${TOKEN}`, +}); + export const knowledgeData: Handler = ({ method, path }) => { if (method !== "GET") return undefined; + if (path === "/api/knowledge/builtin") + return { + bases: [builtin("code", "Code", true), builtin("work", "Work", true), builtin("infra", "Infrastructure", false), builtin("logs", "Logs", true), builtin("security", "Security", false), builtin("team", "Knowledge", true)], + readers: { enabled: true }, + can_manage: true, + }; + if (path.startsWith("/api/share/")) + return { + id: "sh_wide", + base: "code", + base_name: "Code", + query: `${TITLE} ${TOKEN}`, + created_by: EMAIL, + expires_at: iso(-7 * 24 * 60), + open: true, + why: null, + results: [WIDE_RESULT, { ...WIDE_RESULT, id: "chk1.code.code.2", title: TOKEN }], + withheld: { count: 3, by_base: { Code: 3 }, kinds_not_open_to_you: [], reason: "access" }, + }; if (path === "/api/knowledge") return { bases: [BASE, { ...BASE, id: "kb_wide_2", name: TOKEN, sources: [], kinds: ["upload"], synced: 0, uploads: 1, description: "" }], can_manage: true, limits: LIMITS }; if (path === "/api/knowledge/connectors") return { connectors: CONNECTORS, visibility_note: `Everyone who can read this knowledge base can read what you add. ${SENTENCE}` }; if (path.startsWith("/api/knowledge/connectors/")) { diff --git a/dashboard/e2e/wide-data/settings.ts b/dashboard/e2e/wide-data/settings.ts index d0634fab..414019ac 100644 --- a/dashboard/e2e/wide-data/settings.ts +++ b/dashboard/e2e/wide-data/settings.ts @@ -336,9 +336,9 @@ export const settingsData: Handler = ({ method, path, url }) => { const missing = ["full comment reading", "mentions", "in-place edits", "extended issue fields", "threaded replies", "issue type"]; return { behind: { - version: "", latest: "6.11.0", missing, manage_url: `https://${SHA}${SHA}.atlassian.net/plugins/servlet/upm`, seen_at: iso(30), - message: `Your Jira site runs an older Coderhelm app (a version from before the app reported its number, latest 6.11.0). Missing: ${missing.join(", ")}. A Jira admin needs to accept the update: Jira Settings, Apps, Manage apps, Coderhelm, Update.`, - run_note: `Comments on this ticket may be incomplete: its Jira site runs an older Coderhelm app (a version from before the app reported its number, latest 6.11.0) without ${missing.join(", ")}. A Jira admin can accept the update in Manage apps.`, + version: "", latest: "6.11.0", missing, manage_url: "https://admin.atlassian.com/", seen_at: iso(30), + message: `Your Jira site runs an older Coderhelm app (a version from before the app reported its number, latest 6.11.0). Missing: ${missing.join(", ")}. An Atlassian site admin accepts the update in Atlassian Administration (admin.atlassian.com): Apps, Sites, choose the site, Connected apps, Coderhelm, View app details, Update. Jira's own Manage apps page doesn't list it.`, + run_note: `Comments on this ticket may be incomplete: its Jira site runs an older Coderhelm app (a version from before the app reported its number, latest 6.11.0) without ${missing.join(", ")}. An Atlassian site admin can accept the update in Atlassian Administration, Connected apps.`, }, }; } diff --git a/dashboard/src/app/authorize/page.tsx b/dashboard/src/app/authorize/page.tsx index d05c1897..48521ad9 100644 --- a/dashboard/src/app/authorize/page.tsx +++ b/dashboard/src/app/authorize/page.tsx @@ -10,7 +10,7 @@ import { Skeleton } from "@/components/skeleton"; import { Code } from "@/components/settings/code"; import { CheckIcon } from "@/components/icons"; import { focusRing, fullWidthOnPhone, primaryButton, secondaryButton } from "@/components/ui"; -import { connectedAppsApi, KNOWLEDGE_SCOPE, WRITE_SCOPE, type ConsentRequest } from "@/lib/connected-apps"; +import { connectedAppsApi, KNOWLEDGE_SCOPE, WRITE_SCOPE, type ConsentRequest, type ConsentScope, type LookupScope } from "@/lib/connected-apps"; // The consent page an MCP client (Claude, Cursor, VS Code...) sends someone // to: who is asking, where the answer goes, what the app may do. The answer @@ -43,6 +43,7 @@ function Consent() { const [error, setError] = useState(token ? "" : "This page needs the link the app opened. Go back to the app and connect again."); const [allowWrite, setAllowWrite] = useState(false); const [allowKnowledge, setAllowKnowledge] = useState(false); + const [lookups, setLookups] = useState([]); const [sending, setSending] = useState<"" | "allow" | "deny">(""); const [leaving, setLeaving] = useState(""); const writeId = useId(); @@ -59,6 +60,7 @@ function Consent() { const write = r.scopes.find((s) => s.key === WRITE_SCOPE); setAllowWrite(!!write?.requested && r.can_act); setAllowKnowledge(!!r.scopes.find((s) => s.key === KNOWLEDGE_SCOPE)?.requested); + setLookups((r.lookup_scopes ?? []).filter((s) => s.default).map((s) => s.key)); }) .catch((e) => live && setError(e instanceof Error ? e.message : "The request failed.")); return () => { @@ -70,7 +72,7 @@ function Consent() { if (!req) return; setSending(approve ? "allow" : "deny"); try { - const r = await connectedAppsApi.decide(token, approve, approve && allowWrite, approve && allowKnowledge); + const r = await connectedAppsApi.decide(token, approve, approve && allowWrite, approve && allowKnowledge, req.lookup_scopes ? (approve ? lookups : []) : undefined); setLeaving(approve ? `Done. Going back to ${req.client_name}…` : `Going back to ${req.client_name}…`); window.location.assign(r.redirect_to); } catch (e) { @@ -93,7 +95,8 @@ function Consent() { } if (!req) return ; - const read = req.scopes.filter((s) => s.key !== WRITE_SCOPE && s.key !== KNOWLEDGE_SCOPE); + const lookupKeys = new Set((req.lookup_scopes ?? []).map((s) => s.key)); + const read = req.scopes.filter((s) => s.key !== WRITE_SCOPE && s.key !== KNOWLEDGE_SCOPE && !lookupKeys.has(s.key)); const write = req.scopes.find((s) => s.key === WRITE_SCOPE); const know = req.scopes.find((s) => s.key === KNOWLEDGE_SCOPE); @@ -140,9 +143,17 @@ function Consent() { - {s.label} + ))} + {(req.lookup_scopes ?? []).map((s) => ( + setLookups((l) => (on ? [...l, s.key] : l.filter((k) => k !== s.key)))} + /> + ))} {write && (
  • )} + {req.reader && ( +

    + You signed in as a reader: you read what the team opens to readers, change nothing, and don't take a seat. +

    + )} {!req.can_act && (

    Your role only reads, so the app can only read too. @@ -211,3 +227,31 @@ function Consent() { ); } + +/** A scope in plain words: what it reads, then the bases it opens. */ +function ScopeWords({ s }: { s: Pick }) { + return ( + + {s.plain ? {s.plain}: : null} + {s.label} + {s.opens && s.opens.length > 0 && ( + + Opens {s.opens.join(", ")} + + )} + + ); +} + +function LookupChoice({ s, checked, onChange }: { s: LookupScope; checked: boolean; onChange: (on: boolean) => void }) { + const id = useId(); + return ( +

  • + onChange(e.target.checked)} /> + +
  • + ); +} diff --git a/dashboard/src/app/knowledge/page.tsx b/dashboard/src/app/knowledge/page.tsx index 8dd8b121..8fae1c39 100644 --- a/dashboard/src/app/knowledge/page.tsx +++ b/dashboard/src/app/knowledge/page.tsx @@ -9,6 +9,7 @@ import { StatusDot } from "@/components/list/status"; import { useCan } from "@/hooks/use-can"; import { buttonClass, focusRing, primaryButton, secondaryButton } from "@/components/ui"; import { AddFlow } from "@/components/knowledge/add-flow"; +import { BuiltinBases } from "@/components/knowledge/builtin"; import { SyncLimits } from "@/components/knowledge/sync-limits"; import { LogoStack, SourceLogo } from "@/components/knowledge/logos"; import { KIND_LABEL, READ_SHORT, baseHealth, itemWord, knowledge, type AddKind, type Base, type KnowledgeLimits, type SourceKind, connectedInPlace } from "@/lib/knowledge"; @@ -96,6 +97,12 @@ function Knowledge() { } />
    + +
    +
    +

    + Made by your team +

    {error ? ( {error} diff --git a/dashboard/src/app/runs/detail/page.tsx b/dashboard/src/app/runs/detail/page.tsx index 8de05d6e..9c0427d7 100644 --- a/dashboard/src/app/runs/detail/page.tsx +++ b/dashboard/src/app/runs/detail/page.tsx @@ -1153,11 +1153,11 @@ function RunDetailInner() { {fromJira && jiraApp?.run_note && (

    {jiraApp.run_note} - {jiraApp.manage_url && ( + {(jiraApp.install_url || jiraApp.manage_url) && ( <> {" "} - - Open Manage apps + + {jiraApp.install_url ? "Update the app" : "Open Atlassian Administration"} )} diff --git a/dashboard/src/app/s/page.tsx b/dashboard/src/app/s/page.tsx new file mode 100644 index 00000000..bb37d1d5 --- /dev/null +++ b/dashboard/src/app/s/page.tsx @@ -0,0 +1,87 @@ +"use client"; + +import { Suspense, useEffect, useState } from "react"; +import { useSearchParams } from "next/navigation"; +import { Page, PageHeader } from "@/components/page"; +import { Problem } from "@/components/problem"; +import { Skeleton } from "@/components/skeleton"; +import { formatDate } from "@/components/list/time"; +import { Results } from "@/components/knowledge/builtin"; +import { builtinBases, type SharedView } from "@/lib/builtin-bases"; + +// A shared search from one of the team's built-in bases. The link holds the +// search, never its results: opening it runs the search again as the person +// looking, so they see only what they may read themselves. + +export default function SharedPage() { + return ( + }> + + + ); +} + +function Loading() { + return ( + +

    + + +
    + + ); +} + +function Shared() { + const id = useSearchParams().get("id") || ""; + const [view, setView] = useState(null); + const [error, setError] = useState(id ? "" : "This link is missing its id. Ask whoever shared it for the link again."); + + useEffect(() => { + if (!id) return; + let live = true; + builtinBases + .shared(id) + .then((v) => live && setView(v)) + .catch((e) => live && setError(e instanceof Error ? e.message : "This link couldn't be opened.")); + return () => { + live = false; + }; + }, [id]); + + if (error) { + return ( + + +
    + + {error} + +
    +
    + ); + } + if (!view) return ; + + return ( + + + Shared by {view.created_by}. The link works until {formatDate(view.expires_at)}. What you see is what you may read yourself, searched again now. +

    + } + /> +
    + {view.open ? ( + + ) : ( + + {view.why ?? `${view.base_name} isn't open to you. Ask an admin for access.`} + + )} +
    +
    + ); +} diff --git a/dashboard/src/app/security/infrastructure/page.tsx b/dashboard/src/app/security/infrastructure/page.tsx index e21916e9..9ae06718 100644 --- a/dashboard/src/app/security/infrastructure/page.tsx +++ b/dashboard/src/app/security/infrastructure/page.tsx @@ -3,9 +3,11 @@ // Security › Infrastructure: what runs in the team's AWS accounts, matched // against AWS's bulletins and the Amazon Linux and Bottlerocket advisories, // one row per fix. A fix is a pull request in the code that defines the -// resource, a runbook step in AWS, or nothing at all (AWS-managed). A row -// closes only when Coderhelm reads the account again and sees the fix -// running. +// resource, an action Coderhelm applies in AWS after one approval, a runbook +// step, or nothing at all (AWS-managed). A row closes only when Coderhelm +// reads the account again: fixed when the fix runs, removed when the +// resource is gone. Opening the page refreshes a read older than a few +// minutes; the list updates when that read is done. import { Suspense, useEffect, useMemo, useState } from "react"; import Link from "next/link"; @@ -26,7 +28,10 @@ import { SECURITY_ADMIN, TIERS, closedWords, type Tier } from "@/lib/security"; import { INFRA_STATUS_LOOK, countWords, + inAws, infraApi, + isClosed, + type ApplyWhen, type InfraFeed, type InfraFinding, type InfraOverview, @@ -52,7 +57,11 @@ export default function SecurityInfrastructurePage() { } const TIER_TONE: Record = { P0: "danger", P1: "attention", P2: "waiting", P3: "muted" }; -type FixFilter = "" | "pr" | "runbook"; +type FixFilter = "" | "pr" | "aws_step"; +type View = "open" | "closed"; +/** While a refresh runs: how often the page asks again, and for how long. */ +const REFRESH_POLL_MS = 15_000; +const REFRESH_POLL_FOR_MS = 4 * 60_000; function InfrastructureFindings() { const { toast } = useToast(); @@ -66,6 +75,7 @@ function InfrastructureFindings() { const [checking, setChecking] = useState(false); const [tier, setTier] = useState(""); const [fixKind, setFixKind] = useState(""); + const [view, setView] = useState("open"); useEffect(() => { let live = true; @@ -85,6 +95,37 @@ function InfrastructureFindings() { }; }, [attempt]); + // A refresh the page started: ask again until the read is newer, then + // show the new list in place. + const refreshing = !!data?.refreshing; + const readAt = data?.read_at ?? null; + useEffect(() => { + if (!refreshing) return; + let live = true; + const started = Date.now(); + const t = window.setInterval(() => { + if (Date.now() - started > REFRESH_POLL_FOR_MS) { + window.clearInterval(t); + setData((d) => (d ? { ...d, refreshing: false } : d)); + return; + } + infraApi.overview().then( + (o) => { + if (!live) return; + if (o.read_at !== readAt) { + window.clearInterval(t); + setData({ ...o, refreshing: false }); + } + }, + () => {}, + ); + }, REFRESH_POLL_MS); + return () => { + live = false; + window.clearInterval(t); + }; + }, [refreshing, readAt]); + const check = async () => { setChecking(true); try { @@ -168,8 +209,19 @@ function InfrastructureFindings() {
    )} + - + )} @@ -177,14 +229,38 @@ function InfrastructureFindings() { ); } +/** When the list was last read from AWS, and whether a read is running now. */ +function Freshness({ data }: { data: InfraOverview }) { + const at = data.oldest_read_at ?? data.read_at; + return ( +

    + {at ? ( + <> + Checked against AWS

    + ); +} + function Tiles({ data }: { data: InfraOverview }) { const c = data.counts; const now = c.p0 + c.p1; + const steps = c.runbooks + (c.applies ?? 0); return ( 0 ? "danger" : "neutral"} note={now > 0 ? `P0 ${c.p0}, P1 ${c.p1}` : "Nothing urgent"} testId="infra-tile-now" /> - 0 ? "warning" : "neutral"} note="Runbook cards, never run for you" testId="infra-tile-runbooks" /> + 0 ? "warning" : "neutral"} + note={(c.applies ?? 0) > 0 ? "Coderhelm applies them after your approval" : "Runbook cards"} + testId="infra-tile-runbooks" + /> ); @@ -198,6 +274,8 @@ function FindingsSection({ setTier, fixKind, setFixKind, + view, + setView, }: { data: InfraOverview; admin: boolean; @@ -206,14 +284,39 @@ function FindingsSection({ setTier: (t: Tier | "") => void; fixKind: FixFilter; setFixKind: (f: FixFilter) => void; + view: View; + setView: (v: View) => void; }) { - const open = data.findings.filter((f) => f.fix.kind !== "aws"); - const aws = data.findings.filter((f) => f.fix.kind === "aws"); - const shown = useMemo(() => open.filter((f) => (!tier || f.tier === tier) && (!fixKind || f.fix.kind === fixKind)), [open, tier, fixKind]); + // Fixed and removed rows are history: never in the open list, never with + // a Runbook or Fix PR button. + const open = useMemo(() => data.findings.filter((f) => f.fix.kind !== "aws" && !isClosed(f)), [data.findings]); + const closed = useMemo(() => data.findings.filter((f) => f.fix.kind !== "aws" && isClosed(f)), [data.findings]); + const aws = data.findings.filter((f) => f.fix.kind === "aws" && !isClosed(f)); + const pool = view === "open" ? open : closed; + const shown = useMemo( + () => + pool.filter( + (f) => (!tier || f.tier === tier) && (!fixKind || (fixKind === "pr" ? f.fix.kind === "pr" : inAws(f))), + ), + [pool, tier, fixKind], + ); const c = data.counts; + const focused = focus && closed.some((f) => f.id === focus) && !open.some((f) => f.id === focus); + useEffect(() => { + if (focused) setView("closed"); + }, [focused, setView]); return (
    + setView(v as View)} + options={[ + { value: "open", label: "Open", count: open.length }, + { value: "closed", label: "Fixed / Removed", tone: "success", count: closed.length }, + ]} + />
    @@ -235,14 +338,14 @@ function FindingsSection({ {shown.length === 0 ? ( 0 ? () => (setTier(""), setFixKind("")) : undefined} + title={pool.length === 0 ? (view === "open" ? "Nothing to fix" : "Nothing fixed or removed in 30 days") : "No findings match"} + onClear={pool.length > 0 ? () => (setTier(""), setFixKind("")) : undefined} testId="infra-empty" > - {open.length === 0 ? "Nothing your accounts run is behind a fix you have to make. AWS-managed rows are below." : undefined} + {pool.length === 0 && view === "open" ? "Nothing your accounts run is behind a fix you have to make. AWS-managed rows are below." : undefined} ) : ( - + {shown.map((f) => ( ))} @@ -271,6 +374,25 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin: const [asked, setAsked] = useState(null); const status = INFRA_STATUS_LOOK[f.status] ?? INFRA_STATUS_LOOK.open; const aws = f.fix.kind === "aws"; + const done = isClosed(f); + const [approving, setApproving] = useState(null); + const approve = async (when: ApplyWhen) => { + setApproving(when); + try { + const r = await infraApi.apply(f.id, when); + const words = + r.status === "queued" + ? when === "immediate" + ? "Approved: Coderhelm applies it in AWS now (non-production first) and reads it back." + : "Approved: Coderhelm applies it in the next maintenance window (non-production first) and reads it back." + : (r.reason ?? "Nothing to apply."); + setAsked(words); + toast(words); + } catch (e) { + toast(e instanceof Error && /\b403\b/.test(e.message) ? "Only admins can approve updates in AWS." : "Could not approve it. Try again.", "error"); + } + setApproving(null); + }; const askFix = async () => { setAsking(true); try { @@ -288,7 +410,9 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin: const prWords = f.pr ? (f.pr.state === "merged" ? "merged, waiting for the new version to run" : closed ? closedWords(f.pr) : f.pr.state) : null; // A pull request closed without merging is history, not a fix on its way: the fix is offered again. // (A finding the replacement check moved to its runbook is no longer a "pr" fix, so it gets no button.) - const canAsk = admin && f.fix.kind === "pr" && f.status === "open" && (!f.pr || closed) && !asked; + const canAsk = !done && admin && f.fix.kind === "pr" && f.status === "open" && (!f.pr || closed) && !asked; + const applied = !!f.apply?.applied_at; + const canApprove = !done && admin && f.fix.kind === "apply" && f.status === "open" && !applied && !f.apply?.approved_at && !asked; return ( + + {status.label} + + ) : ( <> {f.pr && ( @@ -321,13 +452,42 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin: )} {!aws && !f.pr && f.status !== "open" && {status.label}} + {f.fix.kind === "apply" && f.apply?.approved_at && ( + + {applied ? "Sent to AWS" : "Approved"} + + )} + ) } actions={ canAsk ? ( + ) : canApprove ? ( + + + + ) : null } details={} @@ -340,6 +500,11 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin:

    )} {asked &&

    {asked}

    } + {!done && f.apply?.note && ( +

    + {f.apply.note} +

    + )}
    ); } @@ -368,7 +533,7 @@ function Sources({ feeds, readAt }: { feeds: InfraFeed[] | null; readAt: string testId="infra-source" status={{ tone: readAt ? "success" : "muted" }} title="Your AWS accounts" - meta={[readAt ? "Read once a day, read-only" : "Not read yet"]} + meta={[readAt ? "Read once a day, and again when this page opens after a few minutes; read-only" : "Not read yet"]} time={readAt} />
    diff --git a/dashboard/src/app/security/infrastructure/parts.tsx b/dashboard/src/app/security/infrastructure/parts.tsx index 10093ae7..ef93d60b 100644 --- a/dashboard/src/app/security/infrastructure/parts.tsx +++ b/dashboard/src/app/security/infrastructure/parts.tsx @@ -15,6 +15,7 @@ import { linkButton } from "@/components/ui"; import { CONFIDENCE_LOOK, FIX_LOOK, + isClosed, howWords, locationHref, locationWords, @@ -109,7 +110,7 @@ export function dayWords(day: string): string { export function showFromTo(f: InfraFinding): boolean { const to = f.fix.to?.trim() ?? ""; if (!to) return false; - if (f.fix.kind === "runbook" && f.sources.some((s) => s.kind === "maintenance" && s.id.split(":").includes(to))) return false; + if ((f.fix.kind === "runbook" || f.fix.kind === "apply") && f.sources.some((s) => s.kind === "maintenance" && s.id.split(":").includes(to))) return false; return to !== f.fix.summary && !/^(system-update|db-upgrade|os-patch|service-update|service-software)$/.test(to); } @@ -374,13 +375,63 @@ export function PrNotesBlocks({ n }: { n: InfraPrNotes }) { ); } +/** What Coderhelm applies after an approval, and what AWS answered. */ +function ApplyBlock({ f }: { f: InfraFinding }) { + const plan = f.fix.apply; + if (!plan) return null; + const a = f.apply; + return ( + +

    + {plan.action} through AWS's apply-pending-maintenance-action, on {plan.arns.length} resource{plan.arns.length === 1 ? "" : "s"}, in the next + maintenance window unless you pick now. {plan.effect} +

    + {a?.approved_at && ( +

    + Approved by {a.approved_by || "an admin"}

    + )} + {a?.missing_permission && ( +

    + The role in this account lacks {a.missing_permission}. Turn ApplyMaintenance on in the role's update stack, or follow the runbook below. +

    + )} +
    + ); +} + /** What opens under a finding's row. */ export function FindingDetails({ f }: { f: InfraFinding }) { const fix = f.fix; - const rb = fix.kind === "runbook" ? (fix.runbook ?? null) : null; - const order = fix.order ?? []; + const done = isClosed(f); + // A runbook is shown for a runbook fix, and behind an apply only when the + // role may not apply it. A closed finding shows no steps at all. + const rb = !done && (fix.kind === "runbook" || (fix.kind === "apply" && !!f.apply?.missing_permission)) ? (fix.runbook ?? null) : null; + const order = done ? [] : (fix.order ?? []); return ( <> + {done && ( + +

    + {f.status === "removed" ? ( + <> + A full read of the account

    +
    + )} {fix.kind === "aws" ? (

    {fix.reason || "AWS patches this service itself."}

    @@ -397,8 +448,9 @@ export function FindingDetails({ f }: { f: InfraFinding }) { )}
    )} - {fix.kind !== "aws" && fix.decision && ( - + {!done && fix.kind === "apply" && } + {!done && fix.kind !== "aws" && fix.decision && ( +

    @@ -436,9 +488,9 @@ export function FindingDetails({ f }: { f: InfraFinding }) {
    )} {fix.kind !== "aws" && } - {fix.kind === "pr" && fix.notes && } + {!done && fix.kind === "pr" && fix.notes && } {rb && } - {!rb && fix.kind !== "aws" && fix.cli.length > 0 && ( + {!done && !rb && fix.kind !== "aws" && fix.kind !== "apply" && fix.cli.length > 0 && (
    @@ -446,14 +498,14 @@ export function FindingDetails({ f }: { f: InfraFinding }) { {fix.kind === "runbook" &&

    Coderhelm never runs this. A person with access to the account does.

    } )} - {!rb && fix.kind === "runbook" && fix.console && ( + {!done && !rb && fix.kind === "runbook" && fix.console && (

    )} - {!rb && fix.apply_by && ( + {!done && !rb && fix.apply_by && (

    Apply by {dayWords(fix.apply_by)}. AWS applies it itself after that, in the maintenance window. @@ -494,7 +546,8 @@ export function FindingDetails({ f }: { f: InfraFinding }) {

    - First seen

    diff --git a/dashboard/src/app/settings/integrations/jira/page.tsx b/dashboard/src/app/settings/integrations/jira/page.tsx index 0290feea..4de94d22 100644 --- a/dashboard/src/app/settings/integrations/jira/page.tsx +++ b/dashboard/src/app/settings/integrations/jira/page.tsx @@ -22,7 +22,7 @@ import { Page, PageHeader, Section } from "@/components/page"; import { HybridAppChoice } from "@/components/hybrid-app-choice"; import { HostedJiraLinked, HostedJiraLinkRequest, HybridJiraLink } from "@/components/hybrid-jira-link"; import { isSelfHosted } from "@/lib/runtime-config"; -import { useHybrid } from "@/lib/hybrid"; +import { integrationOf, useHybrid } from "@/lib/hybrid"; import { Code, Field, SaveBar, SettingsRow, SettingsSection, Switch, useDirtyForm } from "@/components/settings"; import { buttonClass, focusRing, inputClass, linkButton, primaryButton, secondaryButton } from "@/components/ui"; import { Select } from "@/components/select"; @@ -440,7 +440,7 @@ function SetupGuide({ const self = isSelfHosted(); const hybrid = useHybrid(); const relayed = - self && !!hybrid.status?.registered && !!hybrid.status.install_id && hybrid.status.integrations.some((i) => i.id === "jira" && i.uses_coderhelm); + self && !!hybrid.status?.registered && !!hybrid.status.install_id && !!integrationOf(hybrid.status.integrations, "jira")?.uses_coderhelm; const ownCopy = self && !relayed; const [picked, setPicked] = useState<"app" | "webhook" | null>(null); const how = picked ?? (ownCopy ? "webhook" : "app"); diff --git a/dashboard/src/app/settings/integrations/page.tsx b/dashboard/src/app/settings/integrations/page.tsx index 2578b5b3..572ea289 100644 --- a/dashboard/src/app/settings/integrations/page.tsx +++ b/dashboard/src/app/settings/integrations/page.tsx @@ -13,6 +13,7 @@ import { type IntegrationSection, type IntegrationStatus, type IntegrationUse, + type AtlassianPart, type JiraAppUpdate, type KnowledgeSignIn, type McpServer, @@ -35,16 +36,16 @@ import { BrandIcon } from "@/components/brand-icons"; import { EmptyState } from "@/components/empty-state"; import { Problem } from "@/components/problem"; import { INTEGRATION_STATUS } from "@/lib/integration-status"; -import { AddMcpServerDialog, McpServerPanel } from "@/components/mcp-servers"; +import { AddMcpServerDialog, McpServerPanel, beginCatalogSignIn } from "@/components/mcp-servers"; import { CatalogPanel } from "@/components/mcp-server-panel"; -import { Attention, ConnectionFacts, DangerRow, OtherWays, PanelLink, PanelSection, UsesList, Way, type Fact } from "@/components/integration-panel"; -import { KnowledgeDisconnect, KnowledgeSignInControl } from "@/components/knowledge-connection"; +import { Attention, ConnectionFacts, DangerRow, OtherWays, PanelLink, PanelSection, SignInControl, UsesList, Way, type Fact } from "@/components/integration-panel"; +import { KnowledgeDisconnect, KnowledgeSignInControl, beginKnowledgeSignIn } from "@/components/knowledge-connection"; // Settings → Integrations: every outside system Coderhelm connects to, as one // list per kind of tool. One row per integration with the same columns in the // same places (mark, name and a short line, status, one action), so the eye // runs down a column instead of zigzagging across cards. A row opens its -// settings: in place, or on its own page for GitHub, Jira and AWS. Why +// settings: in place, or on its own page for GitHub and AWS. Why // something isn't working is said inside, not on the row. // // Every opened row follows one pattern (components/integration-panel.tsx): @@ -95,10 +96,8 @@ const ORDER: Record = { needs_credentials: 0, needs_r /** What each one is for, short enough for one line of a list. The full sentence is inside. */ const SHORT: Record = { github: "Reads code, opens and reviews pull requests", - jira: "Starts work from tickets and keeps them in step", aws: "Logs, metrics and Airflow through a read-only role", newrelic: "Queries, deploy markers and error rates", - confluence: "Reads pages for context", google_drive: "Folders, Docs, Sheets and PDFs, synced into Knowledge", opensearch: "Searches the indexes your app reads", rest: "Reads records from an API you use", @@ -121,7 +120,10 @@ const SHORT: Record = { turso: "Databases and queries", neon: "Postgres databases and branches", launchdarkly: "Feature flags and targeting", - atlassian: "Jira issues and Confluence pages, through Atlassian's own server", + atlassian: "Jira tickets, Confluence pages and agent tools", + // Older gateways still send Jira and Confluence as rows of their own. + jira: "Starts work from tickets and keeps them in step", + confluence: "Reads pages for context", }; function shortLine(item: Integration): string { @@ -134,6 +136,12 @@ function remoteOf(item: Integration): McpServer | null { return ((item.detail as { remote?: McpServer | null }).remote ?? null) as McpServer | null; } +/** Links made before Jira and Confluence were pieces of the one Atlassian row open that row. */ +const ANCHOR_ALIASES: Record = { + "integration-jira": "integration-atlassian", + "integration-confluence": "integration-atlassian", +}; + /** The anchor a row answers to (`#integration-aws` for the first AWS account). */ function anchorOf(item: Integration, firstAws: boolean): string { if (item.id.startsWith("aws")) return firstAws ? "integration-aws" : `integration-${item.id}`; @@ -167,7 +175,10 @@ function IntegrationsPage() { // Open the row a link points at (#integration-sentry from a skill check). const [target, setTarget] = useState(""); useEffect(() => { - const read = () => setTarget(window.location.hash.replace(/^#/, "")); + const read = () => { + const h = window.location.hash.replace(/^#/, ""); + setTarget(ANCHOR_ALIASES[h] ?? h); + }; read(); window.addEventListener("hashchange", read); return () => window.removeEventListener("hashchange", read); @@ -506,7 +517,7 @@ function IntegrationRow({
    )} - {kind === "jira" && appUpdateOf(item) && } + {(kind === "jira" || kind === "atlassian") && appUpdateOf(item) && } {open && (canEdit || personal) && (
    @@ -535,6 +546,7 @@ function IntegrationRow({ {kind === "knowledge" && } {kind === "remote" && remote && setOpen(false)} />} {kind === "plugin" && setOpen(false)} />} + {kind === "atlassian" && setOpen(false)} />} {kind === "chat" && }

    + )} +

    + )} + + + ); +} + +function AudienceEditor({ b, onDone }: { b: BuiltinBase; onDone: (b: BuiltinBase | null) => void }) { + const [roles, setRoles] = useState(b.audience.roles); + const [people, setPeople] = useState(b.audience.people.join("\n")); + const [readers, setReaders] = useState(b.audience.readers); + const [paused, setPaused] = useState(b.audience.paused); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(""); + const peopleId = useId(); + const readersId = useId(); + const pausedId = useId(); + const save = async () => { + setSaving(true); + setError(""); + try { + onDone(await builtinBases.update(b.key, { roles, people: parsePeople(people), readers, paused })); + } catch (e) { + setError(e instanceof Error ? e.message : "Couldn't save."); + setSaving(false); + } + }; + return ( +
    +
    + Roles that read it +

    None ticked: everyone whose role opens what it holds.

    +
    + {AUDIENCE_ROLES.map((r) => ( + setRoles((rs) => (on ? [...rs, r.key] : rs.filter((x) => x !== r.key)))} /> + ))} +
    +
    +
    + +