From 00d9c2b5b51d47949c81d3d72ead1a451204b1a6 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Mon, 19 Oct 2026 02:11:37 +0000 Subject: [PATCH] feat(timeline): edit your comments and resolve threads from the timeline Edit on your own comment opens its text in place (Enter saves, Escape cancels). Resolve the thread and Reopen the thread sit on a thread's first comment for those who may, and a resolved thread says who resolved it. Uses the existing PATCH /activities/{id}/comments/{cid}. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Ln25ykE6uBDqx21WBU94SX --- changelog.d/timeline-comment-edit.md | 2 + docs/requirements.md | 2 +- docs/timeline.md | 4 +- .../__tests__/timeline-ui.test.tsx | 48 +++++++++ .../components/timeline/social.tsx | 101 ++++++++++++++---- .../components/timeline/use-social.ts | 11 +- 6 files changed, 144 insertions(+), 24 deletions(-) create mode 100644 changelog.d/timeline-comment-edit.md diff --git a/changelog.d/timeline-comment-edit.md b/changelog.d/timeline-comment-edit.md new file mode 100644 index 000000000..215be3876 --- /dev/null +++ b/changelog.d/timeline-comment-edit.md @@ -0,0 +1,2 @@ +Comments on the timeline can be edited in place (Enter saves, Escape cancels), and a thread can be resolved or +reopened there, as on an asset's page. diff --git a/docs/requirements.md b/docs/requirements.md index 1656e6e16..c9d90fbea 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -260,7 +260,7 @@ request, to another check that proves the same thing; loosening a requirement or | Everything that happens is kept as W3C Activity Streams activities, read by agents through the API, MCP and the assistant | [test_events.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_events.py) `test_activities_have_one_shape`; [test_activities.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_activities.py) `test_the_timeline_lists_new_assets_newest_first`, `test_agents_read_the_timeline_too`; [test_news_feed_source.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_news_feed_source.py) `test_a_news_feed_as_a_source` | | Ask the assistant about a timeline item from the item (its button, or `a` on its line), in the chat beside the page, with the item's id, line and fields as what the question is about | [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `asking about an item hands the page chat its id, line and fields, by button or the a key`; [page-chat.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/page-chat.test.tsx) `opens with what a page's own Ask about this hands it, and sends it as the highlighted part` | | The Timeline page and Latest on Home, marking what you've seen | [test_timeline_marks.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_marks.py) `test_marks_are_set_cleared_and_filter_the_timeline`; [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `Home's Latest card lists what you haven't reviewed` | -| Reactions and comments on timeline activities, shared by everyone who sees them, each reaction saying who gave it, through the API, MCP and the page | [test_timeline_social.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_social.py) `test_reactions_are_shared_counted_and_taken_back`, `test_comments_on_an_activity_are_a_thread_everyone_who_sees_it_joins`, `test_comments_on_a_logged_activity_follow_its_audience`, `test_agents_react_and_comment_too`, `test_a_reaction_names_who_else_gave_it_earliest_first_up_to_five`; [timeline-social-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-social-model.test.ts) `a reaction's hover says who gave it: you first, then up to five names, then how many more`; [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `reactions and comments: a line sums its items', a 👍 goes to the server, and Enter sends a comment` | +| Reactions and comments on timeline activities, shared by everyone who sees them, each reaction saying who gave it, comments edited and threads resolved in place, through the API, MCP and the page | [test_timeline_social.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_social.py) `test_reactions_are_shared_counted_and_taken_back`, `test_comments_on_an_activity_are_a_thread_everyone_who_sees_it_joins`, `test_comments_on_a_logged_activity_follow_its_audience`, `test_agents_react_and_comment_too`, `test_a_reaction_names_who_else_gave_it_earliest_first_up_to_five`; [timeline-social-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-social-model.test.ts) `a reaction's hover says who gave it: you first, then up to five names, then how many more`; [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `reactions and comments: a line sums its items', a 👍 goes to the server, and Enter sends a comment`, `your comment is edited in place, and a thread you can resolve is resolved and reopened from the timeline` | | Tagging @lens in a comment on the timeline or an asset gets the agent's answer in the thread, as the person who tagged it, with every change waiting for their approval, off with `ai.answer_comments` | [test_comment_agent.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_comment_agent.py) `test_the_agent_answers_a_tagged_comment_in_the_thread`, `test_without_a_model_or_within_a_used_up_budget_the_reply_says_so`; [timeline-social-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-social-model.test.ts) `the agent's reply links its addresses` | | Automations act on the stream, on a schedule, at a time or when their own webhook is called | [test_automation_runs.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_automation_runs.py) `test_each_new_activity_runs_each_automation_it_matches_once`, `test_a_schedule_runs_its_automation_when_its_timer_fires`, `test_a_call_to_a_webhook_runs_its_automation`; [test_timer_triggers.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_timer_triggers.py) `test_an_at_trigger_fires_once_then_reads_done` | | They test conditions, then tell you, ask the model or the agent, use a tool, call a web address with sealed credentials, run Lens work, or change assets and notes | [test_automation_runs.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_automation_runs.py) `test_the_if_limits_and_dry_runs`; [test_actions_messages.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_actions_messages.py) `test_notify_tells_me_in_my_chat_app`; [test_actions_ai.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_actions_ai.py) `test_ask_model_answers_in_text_or_as_the_fields_a_schema_names`, `test_ask_agent_works_on_what_happened_and_saves_the_conversation`, `test_call_tool_reads_as_the_person_and_changes_only_by_asking_them`; [test_actions_web.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_actions_web.py) `test_credentials_in_headers_are_sealed_to_the_automation_and_the_host_and_never_shown`; [test_actions_run.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_actions_run.py) `test_run_workflow_queues_it_on_the_asset_as_the_automation`, `test_run_pipeline_processes_the_asset_again`; [test_actions_lens.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_actions_lens.py) `test_set_field_is_kept_in_the_assets_history_by_the_automation`, `test_write_note_writes_a_page_adds_to_a_things_page_or_notes_an_asset` | diff --git a/docs/timeline.md b/docs/timeline.md index 5c314904a..23e46ac4c 100644 --- a/docs/timeline.md +++ b/docs/timeline.md @@ -100,6 +100,9 @@ them, and each one is an activity of its own, so an automation (or an agent) can - **Comments** open from the comment count on an opened item (or **Comment** when there are none): the threads with who wrote each and when, **Reply** on a thread, and a box where Enter sends (Shift+Enter makes a new line). Anyone who sees the activity can comment, up to 1,000 each; its writer, or an owner of the namespace, deletes a comment. + **Edit** on your own comment opens its text in the box (Enter saves, Escape leaves it as it was), and it then says + "edited". **Resolve the thread** (on its first comment, for whoever started it or an editor of the namespace) + marks it "Resolved by Sam", and **Reopen the thread** takes that back; a resolved thread stays in place, dimmed. Each comment is a `comment.added` activity. A comment on an asset's arrival (`create-recording-`) is a comment on the asset itself: the same thread shows on the asset's page and here, and a comment made on the page shows here. - Comments and reactions on an activity meant for one person (`lens.audience` owner) stay with that person, as the @@ -259,6 +262,5 @@ per source page; they go when the person is removed. Nothing of this costs a mod - Saved filter views. - Marks on activities whose rows are gone (an event log entry past `events.keep_days`, a deleted asset) stay until the person is removed; a tidy could drop them. Reactions and comments on such activities likewise. -- Editing and resolving comments from the timeline (the API has both). - The agent's reply in a thread is plain text with links; the answer's excerpts could open at their moment, as in chat. Tagging a namespace's own assistant by its name, with its memory. diff --git a/nextjs-frontend/__tests__/timeline-ui.test.tsx b/nextjs-frontend/__tests__/timeline-ui.test.tsx index 68666570f..7df1359c2 100644 --- a/nextjs-frontend/__tests__/timeline-ui.test.tsx +++ b/nextjs-frontend/__tests__/timeline-ui.test.tsx @@ -20,6 +20,7 @@ jest.mock("@/app/openapi-client", () => ({ listActivityComments: jest.fn(), commentOnActivity: jest.fn(), deleteActivityComment: jest.fn(), + updateActivityComment: jest.fn(), listActivityMutes: jest.fn(), muteActivities: jest.fn(), activityCaused: jest.fn(), @@ -215,6 +216,53 @@ test("reactions and comments: a line sums its items', a 👍 goes to the server, ); }); +test("your comment is edited in place, and a thread you can resolve is resolved and reopened from the timeline", async () => { + const mineC = { ...COMMENT, mine: true, can_resolve: true, can_delete: true }; + m(Activities.listActivityComments).mockReturnValue(ok([mineC])); + m(Activities.updateActivityComment).mockImplementation(({ body }) => ok({ ...mineC, ...body })); + wrap(); + const rows = within(await screen.findByRole("list", { name: "Timeline" })).getAllByTestId("timeline-row"); + fireEvent.click(within(rows[1]).getByRole("button", { name: "Show details" })); + fireEvent.click(within(rows[1]).getByRole("button", { name: "1 comment" })); + await within(rows[1]).findByText("Nice one"); + // Edit opens the text in a box; Enter saves it + fireEvent.click(within(rows[1]).getByRole("button", { name: "Edit" })); + const box = within(rows[1]).getByRole("textbox", { name: "Save" }); + expect(box).toHaveValue("Nice one"); + fireEvent.change(box, { target: { value: "Nice one, thanks" } }); + fireEvent.keyDown(box, { key: "Enter" }); + await waitFor(() => + expect(m(Activities.updateActivityComment)).toHaveBeenCalledWith( + expect.objectContaining({ path: { activity_id: "u1", cid: 7 }, body: { text: "Nice one, thanks" } }), + ), + ); + await waitFor(() => expect(within(rows[1]).queryByRole("textbox", { name: "Save" })).not.toBeInTheDocument()); + // Escape leaves an edit without saving + fireEvent.click(within(rows[1]).getByRole("button", { name: "Edit" })); + fireEvent.keyDown(within(rows[1]).getByRole("textbox", { name: "Save" }), { key: "Escape" }); + expect(within(rows[1]).queryByRole("textbox", { name: "Save" })).not.toBeInTheDocument(); + expect(m(Activities.updateActivityComment)).toHaveBeenCalledTimes(1); + // resolve, then the thread says so and offers Reopen + m(Activities.listActivityComments).mockReturnValue( + ok([{ ...mineC, resolved: true, resolved_by_name: "Adeel", resolved_at: new Date(NOW).toISOString() }]), + ); + fireEvent.click(within(rows[1]).getByRole("button", { name: "Resolve the thread" })); + await waitFor(() => + expect(m(Activities.updateActivityComment)).toHaveBeenLastCalledWith( + expect.objectContaining({ path: { activity_id: "u1", cid: 7 }, body: { resolved: true } }), + ), + ); + expect(await within(rows[1]).findByRole("listitem", { name: "Resolved thread" })).toHaveTextContent( + "Resolved by Adeel", + ); + fireEvent.click(within(rows[1]).getByRole("button", { name: "Reopen the thread" })); + await waitFor(() => + expect(m(Activities.updateActivityComment)).toHaveBeenLastCalledWith( + expect.objectContaining({ body: { resolved: false } }), + ), + ); +}); + test("the list groups a run of emails into one line that opens to its items, and shows what you reviewed", async () => { wrap(); const list = await screen.findByRole("list", { name: "Timeline" }); diff --git a/nextjs-frontend/components/timeline/social.tsx b/nextjs-frontend/components/timeline/social.tsx index 14fb23580..d1b05861b 100644 --- a/nextjs-frontend/components/timeline/social.tsx +++ b/nextjs-frontend/components/timeline/social.tsx @@ -1,10 +1,10 @@ "use client"; -import { MessageSquare, Reply, SmilePlus, Sparkles, Trash2 } from "lucide-react"; +import { Check, MessageSquare, Pencil, Reply, RotateCcw, SmilePlus, Sparkles, Trash2 } from "lucide-react"; import { useState, type KeyboardEvent } from "react"; import type { Comment, Reaction } from "@/app/openapi-client/types.gen"; -import { threads, type Thread } from "@/components/recording/comments-model"; +import { resolvedBy, threads, type Thread } from "@/components/recording/comments-model"; import { writer } from "@/components/recording/notes-model"; import type { Activity } from "@/components/timeline/model"; import { EMOJIS, EMOJI_LABEL, commentsLabel, linked, reactedBy } from "@/components/timeline/social-model"; @@ -134,6 +134,7 @@ function Composer({ placeholder, pending, autoFocus, + initial = "", onSend, onCancel, }: { @@ -141,10 +142,11 @@ function Composer({ placeholder: string; pending: boolean; autoFocus?: boolean; + initial?: string; onSend: (text: string) => Promise; onCancel?: () => void; }) { - const [text, setText] = useState(""); + const [text, setText] = useState(initial); const send = () => { if (!text.trim() || pending) return; void onSend(text.trim()).then(() => setText("")); @@ -181,12 +183,19 @@ function CommentLine({ replies, onReply, onDelete, + onEdit, + onResolve, + pending, }: { c: Comment; replies: number; onReply?: () => void; onDelete: () => void; + onEdit: (text: string) => Promise; + onResolve?: (resolved: boolean) => void; + pending: boolean; }) { + const [editing, setEditing] = useState(false); return (
  • @@ -197,6 +206,20 @@ function CommentLine({ {relative(c.created_at)} {c.edited_at && · edited} + {onResolve && c.can_resolve && ( + onResolve(!c.resolved)} + > + {c.resolved ? : } + + )} + {c.mine && !c.by_agent && ( + setEditing(true)}> + + + )} {onReply && ( @@ -213,19 +236,31 @@ function CommentLine({ )} -

    - {c.by_agent - ? linked(c.text).map((part, i) => - part.url ? ( - - {part.text} - - ) : ( - {part.text} - ), - ) - : c.text} -

    + {editing ? ( + (text === c.text ? Promise.resolve() : onEdit(text)).then(() => setEditing(false))} + onCancel={() => setEditing(false)} + /> + ) : ( +

    + {c.by_agent + ? linked(c.text).map((part, i) => + part.url ? ( + + {part.text} + + ) : ( + {part.text} + ), + ) + : c.text} +

    + )}
  • ); } @@ -234,6 +269,8 @@ function ThreadView({ t, onReply, onDelete, + onEdit, + onResolve, replying, setReplying, pending, @@ -241,23 +278,45 @@ function ThreadView({ t: Thread; onReply: (text: string, parent: number) => Promise; onDelete: (c: Comment, replies: number) => void; + onEdit: (c: Comment, text: string) => Promise; + onResolve: (c: Comment, resolved: boolean) => void; replying: boolean; setReplying: (on: boolean) => void; pending: boolean; }) { + const done = resolvedBy(t.root); return ( -
  • +
    • setReplying(true)} onDelete={() => onDelete(t.root, t.replies.length)} + onEdit={(text) => onEdit(t.root, text)} + onResolve={(on) => onResolve(t.root, on)} + pending={pending} /> {t.replies.map((r) => ( - onDelete(r, 0)} /> + onDelete(r, 0)} + onEdit={(text) => onEdit(r, text)} + pending={pending} + /> ))}
    + {done && ( + + {done} + {t.root.resolved_at ? ` · ${relative(t.root.resolved_at)}` : ""} + + )} {replying && (
    void }) { const q = useActivityComments(a.id, true); - const { create, remove } = useActivityCommentActions(a.id, bump); + const { create, remove, update } = useActivityCommentActions(a.id, bump); const [replying, setReplying] = useState(null); const list = q.data ?? []; const all = threads(list); - const pending = create.isPending; + const pending = create.isPending || update.isPending; const send = (text: string, parent?: number) => create.mutateAsync({ text, parent: parent ?? null }); return (
    @@ -299,6 +358,8 @@ export function CommentThread({ a, bump }: { a: Activity; bump: (id: string, by: t={t} onReply={send} onDelete={(c, replies) => remove.mutate({ cid: c.id, replies })} + onEdit={(c, text) => update.mutateAsync({ cid: c.id, text })} + onResolve={(c, resolved) => update.mutate({ cid: c.id, resolved })} replying={replying === t.root.id} setReplying={(on) => setReplying(on ? t.root.id : null)} pending={pending} diff --git a/nextjs-frontend/components/timeline/use-social.ts b/nextjs-frontend/components/timeline/use-social.ts index d11bf8681..d8c49831a 100644 --- a/nextjs-frontend/components/timeline/use-social.ts +++ b/nextjs-frontend/components/timeline/use-social.ts @@ -63,7 +63,8 @@ export function useActivityComments(id: string, enabled: boolean) { }); } -/** Comment or reply on an activity, and delete a comment; each refreshes the thread and moves the line's count. */ +/** Comment or reply on an activity, edit or delete a comment, and resolve or reopen a thread; each refreshes the + * thread, and adding or deleting moves the line's count. */ export function useActivityCommentActions(id: string, bump: (id: string, by: number) => void) { const client = useApiClient(); const qc = useQueryClient(); @@ -90,5 +91,11 @@ export function useActivityCommentActions(id: string, bump: (id: string, by: num }, onError: fail("Couldn’t delete the comment"), }); - return { create, remove }; + const update = useMutation({ + mutationFn: ({ cid, ...body }: { cid: number; text?: string; resolved?: boolean }) => + data(Activities.updateActivityComment({ client, path: { activity_id: id, cid }, body })) as Promise, + onSuccess: () => void refresh(), + onError: fail("Couldn’t save the comment"), + }); + return { create, remove, update }; }