diff --git a/dashboard/e2e/chat.spec.ts b/dashboard/e2e/chat.spec.ts index f84e48f5..51eb24d7 100644 --- a/dashboard/e2e/chat.spec.ts +++ b/dashboard/e2e/chat.spec.ts @@ -76,6 +76,8 @@ interface Backend { uploads: number; /** The saved answer's text. */ answerText: string; + /** The saved answer's steps, when not the default three. */ + answerUsed?: unknown[]; } const ev = (type: string, data: unknown) => `event: ${type}\ndata: ${JSON.stringify(data)}\n\n`; @@ -167,7 +169,7 @@ async function mockApi(page: Page, init: Partial = {}): Promise { await askIt(page, "Why is this waiting?"); await expect.poll(() => db.asks.length).toBe(1); expect(db.asks[0].mentions).toEqual([{ kind: "run", id: "01RUNACME" }]); + // Under the question it reads as what it's about, not a place it's "only in". + await expect(page.getByTestId("question").last().getByTestId("question-scope")).toHaveText("About “Add a Heading component”"); // Removable before asking. await page.goto("/chat?run=01RUNACME&title=Add%20a%20Heading%20component"); await page.getByRole("button", { name: /Stop pointing at Run: Add a Heading component/ }).click(); @@ -667,7 +671,31 @@ test.describe("chat: the chat list", () => { await expect(page.getByTestId("mention-chip")).toHaveCount(0); }); - test("“What needs my answer?” sends the waiting runs with it", async ({ page }) => { + test("“What needs my answer?” asks about everything waiting, with no scope line and a step that says what it checked", async ({ page }) => { + const db = await mockApi(page, { + starters: [ + { question: "What needs my answer?", why: "Runs, tickets and pull requests waiting on you", sources: { ...NONE, work: true }, mentions: [] }, + ...STARTERS.slice(0, 3), + ] as typeof STARTERS, + answerText: "6 things need you: 2 now, 3 today, 1 when you can [S1].", + answerUsed: [ + { kind: "work", name: "work_needs_me", label: "Checked what's waiting on you", summary: "6 items" }, + { kind: "data_sources", name: "api_get", label: "Read /v1/orders/42 from Orders API", summary: "1 result" }, + ], + }); + await page.goto("/chat"); + await page.getByTestId("starter").filter({ hasText: "What needs my answer?" }).click(); + await expect.poll(() => db.asks.length).toBe(1); + expect(db.asks[0].mentions).toEqual([]); + const answer = page.getByTestId("answer").last(); + await expect(answer.getByTestId("activity-summary")).toHaveText("Checked what's waiting on you, read /v1/orders/42 from Orders API"); + await expect(answer).not.toContainText("api get"); + await answer.getByTestId("activity-toggle").click(); + await expect(answer.getByTestId("step-group").first()).toContainText("Waiting on you"); + await expect(page.getByTestId("question").last().getByTestId("question-scope")).toHaveCount(0); + }); + + test("a question an older starter sent with waiting runs says it's about them, never “Only in A run”", async ({ page }) => { const db = await mockApi(page, { starters: [ { question: "What needs my answer?", why: "2 runs are waiting on an answer", sources: NONE, mentions: [{ kind: "run", id: "01R1" }, { kind: "run", id: "01R2" }] }, @@ -677,7 +705,9 @@ test.describe("chat: the chat list", () => { await page.goto("/chat"); await page.getByTestId("starter").filter({ hasText: "What needs my answer?" }).click(); await expect.poll(() => db.asks.length).toBe(1); - expect(db.asks[0].mentions).toEqual([{ kind: "run", id: "01R1" }, { kind: "run", id: "01R2" }]); + const scope = page.getByTestId("question").last().getByTestId("question-scope"); + await expect(scope).toHaveText("About 2 runs"); + await expect(page.getByTestId("question").last()).not.toContainText("Only in"); }); test("⌘J opens Chat from any page", async ({ page }) => { diff --git a/dashboard/src/app/chat/page.tsx b/dashboard/src/app/chat/page.tsx index d4912e15..fb610b91 100644 --- a/dashboard/src/app/chat/page.tsx +++ b/dashboard/src/app/chat/page.tsx @@ -22,6 +22,8 @@ import { askBrain, brainApi, MAX_BULK_DELETE, + NEEDS_ME, + scopeNote, uploadProblem, uploadToSignedUrl, type BrainMessage, @@ -128,6 +130,10 @@ function Chat() { // as a chip the asker can remove. const fromRun = /^[A-Za-z0-9_-]{1,64}$/.test(params.get("run") ?? "") ? params.get("run")! : ""; const fromRunTitle = (params.get("title") ?? "").slice(0, 120); + // Run titles this page was opened with, kept after the address moves to + // the new chat, so the question still says which run it was about. + const runTitles = useRef>({}); + if (fromRun && fromRunTitle) runTitles.current[fromRun] = fromRunTitle; // Asking is the brain_ask capability; managing knowledge is knowledge_manage. const { can, ready: capsReady } = useCan(); @@ -703,8 +709,13 @@ function Chat() { ); const noData = !!sources && !!starters && starters.length === 0 && sources.knowledge.length === 0 && sources.repos.length === 0; - const mentionName = (m: Mention) => - mentionOptions.find((o) => o.kind === m.kind && o.id === m.id)?.label ?? (m.kind === "run" ? "A run" : m.id.split("/").pop() ?? m.id); + // What a mention is called under its question: a run by its title when + // the page knows it, else counted ("About 2 runs"); a repository or base + // by its name. + const mentionName = (m: Mention): { kind: string; label?: string } => + m.kind === "run" + ? { kind: "run", label: runTitles.current[m.id] } + : { kind: m.kind, label: mentionOptions.find((o) => o.kind === m.kind && o.id === m.id)?.label ?? m.id.split("/").pop() ?? m.id }; // One list for saved turns and the live one, keyed by position: when the // answer ends and its saved copy arrives, the same blocks stay mounted @@ -908,14 +919,19 @@ function starterKind(s: Starter): string { return "code"; } -function Question({ text, attachments, mentions, anchor }: { text: string; attachments: string[]; mentions: string[]; anchor?: string }) { +function Question({ text, attachments, mentions, anchor }: { text: string; attachments: string[]; mentions: { kind: string; label?: string }[]; anchor?: string }) { + const scope = scopeNote(mentions); return (

{text}

{attachments.length > 0 &&

Attached: {attachments.join(", ")}

}
- {mentions.length > 0 &&

Only in {mentions.join(", ")}

} + {scope && ( +

+ {scope} +

+ )}
); } @@ -937,6 +953,14 @@ function startLabel(name: string): string { return "Searching knowledge"; case "search_memories": return "Checking past work"; + case NEEDS_ME: + return "Checking what's waiting on you"; + case "api_get": + return "Reading the team's API"; + case "db_query": + return "Querying a database"; + case "logs_search": + return "Searching the logs"; default: return name.startsWith("graph_") ? "Checking the code graph" : "Looking it up"; } diff --git a/dashboard/src/lib/brain.ts b/dashboard/src/lib/brain.ts index e6a4052f..3e0db279 100644 --- a/dashboard/src/lib/brain.ts +++ b/dashboard/src/lib/brain.ts @@ -452,10 +452,11 @@ export function activitySummary(steps: { name?: string; label: string; repo?: st if (count(isSearch)) parts.push("searched the code"); if (count((n) => n === "search_knowledge")) parts.push("searched knowledge"); if (count((n) => n === "search_memories")) parts.push("checked past work"); + if (count((n) => n === NEEDS_ME)) parts.push("checked what's waiting on you"); // The team's records, by what was looked up: "looked up tickets, pull requests and runs". const work = [...new Set(done.map((s) => WORK_NOUN[s.name ?? ""]).filter(Boolean))]; if (work.length) parts.push(`looked up ${andList(work)}`); - const known = (n: string) => isRead(n) || isOverview(n) || isSearch(n) || n === "search_knowledge" || n === "search_memories" || n === "github__list_repos" || n in WORK_NOUN; + const known = (n: string) => isRead(n) || isOverview(n) || isSearch(n) || n === "search_knowledge" || n === "search_memories" || n === "github__list_repos" || n === NEEDS_ME || n in WORK_NOUN; const other = done.filter((s) => !known(s.name ?? "") && !s.label.startsWith("Looked further")); if (other.length === 1) parts.push(other[0].label.charAt(0).toLowerCase() + other[0].label.slice(1)); else if (other.length > 1) parts.push(`${other.length} other lookups`); @@ -464,6 +465,9 @@ export function activitySummary(steps: { name?: string; label: string; repo?: st return text.charAt(0).toUpperCase() + text.slice(1); } +/** The lookup that gathers everything waiting on the asker (runs, approvals, Jira, GitHub). */ +export const NEEDS_ME = "work_needs_me"; + /** What each work lookup reads, in the summary's words. */ const WORK_NOUN: Record = { work_tickets: "tickets", @@ -484,6 +488,7 @@ export function stepSource(name?: string): { key: string; label: string } { if (n.startsWith("github__") || n.startsWith("graph_")) return { key: "code", label: "Code" }; if (n === "search_knowledge") return { key: "knowledge", label: "Knowledge" }; if (n === "search_memories") return { key: "memories", label: "Past work" }; + if (n === NEEDS_ME) return { key: n, label: "Waiting on you" }; if (WORK_NOUN[n]) { const w = WORK_NOUN[n]; return { key: n, label: w.charAt(0).toUpperCase() + w.slice(1) }; @@ -515,6 +520,25 @@ export function unavailableNote(steps: { name?: string; status?: string }[]): st return gone.length ? `${andList(gone)} couldn't be read` : ""; } +/** + * The line under a question that says what it was pointed at. Repositories + * and knowledge bases narrow what Chat reads ("Only in api"); a run only goes + * with the question as context ("About “Add a Heading”", "About 2 runs"), so + * it never reads as a place. + */ +export function scopeNote(mentions: { kind: string; label?: string }[]): string { + const narrow = mentions.filter((m) => m.kind !== "run" && m.label).map((m) => m.label!); + const runs = mentions.filter((m) => m.kind === "run"); + const named = runs.map((m) => m.label).filter((l): l is string => !!l); + const parts: string[] = []; + if (narrow.length) parts.push(`Only in ${narrow.join(", ")}`); + if (runs.length) { + if (named.length === runs.length) parts.push(`About ${named.map((l) => `“${l}”`).join(", ")}`); + else parts.push(runs.length === 1 ? "About a run" : `About ${runs.length} runs`); + } + return parts.join(" · "); +} + /** An answer's text without its `[S1]` markers, for copying. */ export function withoutCitations(text: string): string { return text diff --git a/docs/content/docs/concepts/chat.mdx b/docs/content/docs/concepts/chat.mdx index 4cd9b8b6..9d94806d 100644 --- a/docs/content/docs/concepts/chat.mdx +++ b/docs/content/docs/concepts/chat.mdx @@ -22,6 +22,16 @@ Chat works like a teammate who opens the code: it looks a repository over (its R Besides code and knowledge, Chat looks up your team's work directly: Jira tickets by key or words, pull requests and CoderHelm's branches, runs (what is running now, why one stopped, what it waits on), security and infrastructure findings, quarantined tests, reviews, alerts, log findings, plans, and AWS resources from the daily read of your connected accounts. It reads through the team's [built-in bases](/concepts/knowledge#the-teams-built-in-bases), so a base that isn't open to you is left out. When a source it needed couldn't be read, the answer says so. Your [AI tools](/mcp) use the same lookups. +### What needs you + +Ask **What needs my answer?** (it's the first suggested question), or say it your way: "what's on my plate", "anything waiting on me", "my reviews". Chat checks everything waiting on you in one step: + +- **CoderHelm:** questions runs stopped on, with the answers they found; runs waiting on a change outside their repository; CoderHelm's open pull requests on your tickets; and, for admins, tool calls waiting for a yes. +- **Jira:** open tickets assigned to you, and tickets where someone mentioned you after your last comment. Tickets nobody touched in 60 days are left out unless they're urgent. +- **GitHub:** pull requests asking for your review, your pull requests with changes asked for, failing checks or ready to merge, and comments that mention you that you haven't answered, in your team's repositories. + +The answer starts with a count, then lists the items by how soon they need you, each on one line with a link and what to do. When a source can't be read (Jira isn't connected, or your sign-in isn't linked to GitHub), the answer says so. Chat finds you by your sign-in email, your GitHub login and the Jira account CoderHelm has seen with your email; it reads your team only. + 1. You ask a question, and can attach files.