From bfaa49a2d6001d49e6b6406baac29a90d6a74808 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 18 Oct 2026 06:04:33 +0000 Subject: [PATCH 1/2] test(clicks): a deep research journey, and the switch keeps the cursor in the box The survey's stand-in model answers a deep research plan, the chat-research journey plans, approves and saves a report as a note, and the page survey finds navigation links by where they go (a note the assistant wrote has more in its name than its title) and visits each kind of page once. The composer's Deep research switch puts the cursor back in the question box. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01HXPWXcSCQb9hWPr7xkZu7B --- ci/clicks/fake-model.mjs | 28 ++++++++++++++++--- ci/clicks/journeys.mjs | 27 ++++++++++++++++++ ci/clicks/survey.mjs | 7 +++-- docs/assistant.md | 9 +++--- docs/requirements.md | 1 + .../__tests__/chat-research.test.tsx | 2 ++ nextjs-frontend/components/chat/composer.tsx | 9 ++++-- 7 files changed, 71 insertions(+), 12 deletions(-) diff --git a/ci/clicks/fake-model.mjs b/ci/clicks/fake-model.mjs index adbaf51b8..3a27e9c53 100644 --- a/ci/clicks/fake-model.mjs +++ b/ci/clicks/fake-model.mjs @@ -1,7 +1,8 @@ // A stand-in OpenAI-compatible model server, so the journeys that need a model (the install wizard finding one, the // setup wizard testing one, the assistant answering) run without a real one. Every answer is the same short reply, -// except that the assistant asked the same again (an answer regenerated) says which version it's writing, and a -// conversation's title (asked for after its first answer) is its first question's words, as a real model's would be. +// except that the assistant asked the same again (an answer regenerated) says which version it's writing, a +// conversation's title (asked for after its first answer) is its first question's words, as a real model's would be, +// and deep research gets a plan for its goal. import http from "node:http"; const REPLY = "This is the survey's stand-in model answering."; @@ -20,6 +21,26 @@ function title(payload) { return question.trim().replace(/[?.!]+$/, "").split(/\s+/).slice(0, 8).join(" ") || "A conversation"; } +/** Structured output: a research plan for a deep research goal ("Goal: ..."), with no questions to answer first, so + * it can be approved as it is; an empty object for anything else, which satisfies most schemas' optional fields. */ +function structured(payload) { + const system = (payload.messages ?? []).find((m) => m.role === "system")?.content; + if (typeof system !== "string" || !system.startsWith("You plan deep research")) return "{}"; + const said = String((payload.messages ?? []).find((m) => m.role === "user")?.content ?? ""); + const goal = said.match(/^Goal: (.*)$/m)?.[1]?.trim() || "Research"; + return JSON.stringify({ + questions: [], + plan: { + title: goal.replace(/[?.!]+$/, ""), + goal, + sub_questions: ["What was said about it?", "Who said it?", "What is still open?"], + sources: ["archive"], + max_tool_calls: 3, + report_outline: ["What was said", "What is still open"], + }, + }); +} + function reply(payload) { const system = (payload.messages ?? []).find((m) => m.role === "system")?.content; if (typeof system === "string" && system.startsWith("You title conversations")) return title(payload); @@ -72,8 +93,7 @@ export function startFakeModel(port) { res.write(chunk({}, "stop")); return res.end("data: [DONE]\n\n"); } - // structured output: an empty object satisfies most schemas' optional fields - const content = payload.response_format ? "{}" : reply(payload); + const content = payload.response_format ? structured(payload) : reply(payload); return json(200, { id: "survey", object: "chat.completion", diff --git a/ci/clicks/journeys.mjs b/ci/clicks/journeys.mjs index e02862d04..5241e8e2a 100644 --- a/ci/clicks/journeys.mjs +++ b/ci/clicks/journeys.mjs @@ -795,6 +795,33 @@ export const JOURNEYS = [ await page.getByRole("button", { name: /^Tools: \d+ picked · 10 calls\. / }).waitFor(); }, }, + { + id: "chat-research", + ns: "podcasts", + module: "Chat", + feature: "Research a goal, approve its plan and save the report as a note", + note: "A new conversation in one namespace: the Deep research switch beside the composer, the goal and Enter; the plan comes back as a card to approve (Approve, or Enter in it), then the run's progress, then the cited report with Save as note. The stand-in model plans three sub-questions without asking anything first.", + from: "/", + async run(ctx) { + const { page, meter } = ctx; + await go(ctx, "Chat"); + const question = page.getByRole("textbox", { name: "Your question" }); + // A phone's Chat opens on the list of conversations once there is one + if (!(await question.waitFor({ timeout: 3000 }).then(() => true, () => false))) + await meter.click(page.getByRole("button", { name: "New conversation" }), "New conversation"); + await meter.click(page.getByRole("button", { name: "Deep research", exact: true }), "Deep research"); + await meter.type(question, "What was said about Raspberry Pi?", "the goal"); + await meter.press("Enter", "Enter to plan it"); + const plan = page.getByRole("form", { name: "Research plan" }); + await plan.waitFor({ timeout: 60000 }); + await meter.click(plan.getByRole("button", { name: "Approve", exact: true }), "Approve"); + // it runs in the background: the progress card, then the report and what can be done with it + const actions = page.getByRole("group", { name: "Report actions" }); + await actions.waitFor({ timeout: 120000 }); + await meter.click(actions.getByRole("button", { name: "Save as note" }), "Save as note"); + await page.getByText("Saved as a note in podcasts").first().waitFor(); + }, + }, { // Last: it points Lens at a cloud model, which the stand-in model behind the journeys above isn't id: "cloud-model", diff --git a/ci/clicks/survey.mjs b/ci/clicks/survey.mjs index 41338213b..02d1fbc93 100644 --- a/ci/clicks/survey.mjs +++ b/ci/clicks/survey.mjs @@ -144,11 +144,14 @@ async function surveyPages(page, base, phone) { // On a phone the navigation sits behind the menu button: one more tap to reach every page const menu = phone ? 1 : 0; for (const item of items) { + // one of each kind of page: the notes in the navigation are one page, whichever notes the journeys left there + if (item.href && pages.some((p) => p.page === pageKey(base + item.href))) continue; await page.goto(base + "/", { waitUntil: "domcontentloaded" }); await settle(); if (phone) await page.getByRole("button", { name: "Open navigation" }).tap(); - const name = new RegExp(`^${item.label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}( \\d+)?$`); - const link = page.getByRole("navigation", { name: "Primary" }).getByRole("link", { name }).first(); + // found by where it goes: a link's name can carry more than its label (a note the assistant wrote is "Written by + // the assistant" and its title) + const link = page.getByRole("navigation", { name: "Primary" }).locator(`a[href="${item.href}"]`).first(); await (phone ? link.tap() : link.click()); await page.waitForLoadState("domcontentloaded"); await settle(); diff --git a/docs/assistant.md b/docs/assistant.md index 5f34f04cf..d4ade7afe 100644 --- a/docs/assistant.md +++ b/docs/assistant.md @@ -503,8 +503,8 @@ Built: the web app, the API, MCP, chat rooms and the assistant's tools. Give the assistant a goal that needs many look-ups, and it comes back with a plan; once you approve it, the research runs in the background and a cited report comes back in the conversation. -- **Asking.** Turn on the composer's Deep research switch (the telescope) and type the goal, start a question with - `/research` (`/research what changed in the capsid work this year?`), send it with +- **Asking.** Turn on the composer's Deep research switch (the telescope; the cursor stays in the box) and type the + goal, start a question with `/research` (`/research what changed in the capsid work this year?`), send it with `research: true` (`POST /api/v1/chats//messages`), call `POST /api/v1/chats//research {goal}`, or ask the assistant for research: its `start_research` tool (the `research` [tool group](#choosing-tools-namespaces-and-a-limit)) works from chat, voice and [chat rooms](chat-rooms.md). It needs a language model that uses tools. @@ -571,8 +571,9 @@ runs in the background and a cited report comes back in the conversation. checking are two or three calls. Every call is in the activity ledger for the conversation and `research:`. Refine later: sub-questions in parallel, research on a schedule, sharing a report with a namespace's members, research -as an automation action, a report template people can edit, and the report posted back into the chat room it was -asked in (today the room gets the plan, and the report is in the conversation in Lens). +as an automation action, a report template people can edit, the report posted back into the chat room it was asked +in (today the room gets the plan, and the report is in the conversation in Lens), and one way to read a report aloud +(today its Read aloud and the answer's speaker button both do). ## Third-party content and prompt injection diff --git a/docs/requirements.md b/docs/requirements.md index 7a4214b31..97c15b2b4 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -80,6 +80,7 @@ request, to another check that proves the same thing; loosening a requirement or | It acts with tools, and changes wait for approval | [test_chats.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_chats.py) `test_tools_approvals_and_checking`; [test_approvals.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_approvals.py) `test_the_assistant_lists_and_declines_but_never_approves` | | Web search and reading pages, cited like the archive, off until an admin turns it on | [test_web_search.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_web_search.py) `test_an_answer_cites_the_web_and_the_conversation_keeps_it`, `test_reading_pages_and_pdfs`; [chat-web-citations.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/chat-web-citations.test.tsx) | | Python and bash in a sandbox of each conversation's own, off until an admin turns it on | [test_sandbox.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_sandbox.py) `test_python_and_bash_share_one_sandbox_per_conversation`, `test_the_sandbox_is_off_until_an_admin_turns_it_on_for_the_people_it_names` | +| Deep research: a goal gets a plan to approve, runs in the background and comes back as a cited report, saved as a note or a podcast episode | [test_research.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_research.py) `test_a_goal_gets_a_plan_that_waits_for_approval_and_can_be_revised`, `test_an_approved_plan_runs_and_its_report_comes_back_checked`, `test_a_report_becomes_a_note_and_a_podcast`; [chat-research.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/chat-research.test.tsx) `approves the plan with Enter, sending the edits`, `saves it as a note, asking where when it could go in several namespaces`, `turns the next message into a research goal, and says when it can't`; [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `chat-research`; [baseline.json](https://github.com/adeelahmad/lense/blob/main/ci/clicks/baseline.json) `chat-research` ≤ 4 clicks | | Regenerating an answer or editing a question makes a new version beside the old one | [test_chat_versions.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_chat_versions.py) `test_regenerate_edit_switch_and_go_on`; [chat-versions.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/chat-versions.test.tsx) `regenerating an answer`, `the version switch`; [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `chat-regenerate`; [baseline.json](https://github.com/adeelahmad/lense/blob/main/ci/clicks/baseline.json) `chat-regenerate` ≤ 4 clicks | | Each answer keeps a record of what produced it: the model, its tools, how long it took and what it cost | [test_chat_records.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_chat_records.py) `test_an_answer_records_what_produced_it`, `test_a_regenerated_answer_has_its_own_record`; [chat-details.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/chat-details.test.tsx) `says what produced it: model and host, scope, tools, use, tokens, cost, time and how it ended` | | Answers read aloud by a speech provider, macOS `say` or StyleTTS2 (opt-in) | [test_voice.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_voice.py) `test_answers_are_read_aloud_by_a_speech_model`; [test_speech.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_speech.py) `test_macos_say_reads_aloud_on_a_mac`, `test_styletts2_reads_aloud_from_its_own_service`; [styletts2.yml](https://github.com/adeelahmad/lense/blob/main/.github/workflows/styletts2.yml) `Read a sentence aloud` | diff --git a/nextjs-frontend/__tests__/chat-research.test.tsx b/nextjs-frontend/__tests__/chat-research.test.tsx index ce5cf6cfd..b6e9b5a3a 100644 --- a/nextjs-frontend/__tests__/chat-research.test.tsx +++ b/nextjs-frontend/__tests__/chat-research.test.tsx @@ -294,6 +294,8 @@ describe("the Deep research switch", () => { ); fireEvent.click(screen.getByRole("button", { name: "Deep research" })); expect(onToggle).toHaveBeenCalled(); + // the goal is typed next, without a click into the box + expect(screen.getByRole("textbox", { name: "Your question" })).toHaveFocus(); rerender( void; off?: string | null }; }) { const ref = useRef(null); + // the switch hands the cursor back to the box, so the goal (or the question) is typed next without a click + const toggleResearch = () => { + research?.onToggle(); + ref.current?.focus(); + }; const [over, setOver] = useState(false); useEffect(() => { const el = ref.current; @@ -529,7 +534,7 @@ export function Composer({ Deep research: you approve a plan first