This repository was archived by the owner on Sep 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Mention tasks in any chat surface #93
Open
vincelwt
wants to merge
1
commit into
main
Choose a base branch
from
feat/mention-tasks-in-chat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { TASK_KEY, matchTasks } from "./mentions.ts"; | ||
| import type { Task, TaskStatus } from "./types.ts"; | ||
|
|
||
| const task = (key: string, title: string, status: TaskStatus, updated: number) => | ||
| ({ | ||
| id: `id-${key}`, | ||
| key, | ||
| title, | ||
| outcome: "", | ||
| status, | ||
| discussion_channel_id: "c1", | ||
| created_by: "u1", | ||
| created_at: 0, | ||
| updated_at: updated, | ||
| position: 0, | ||
| }) as Task; | ||
|
|
||
| const tasks = [ | ||
| task("PW-1", "Ship the relay", "done", 300), | ||
| task("PW-42", "Allow mentioning tasks", "planned", 100), | ||
| task("ACME-7", "Cache the pricing endpoint", "running", 200), | ||
| ]; | ||
|
|
||
| test("open work is offered before finished work, newest first", () => { | ||
| assert.deepEqual( | ||
| matchTasks(tasks, "").map((found) => found.key), | ||
| ["ACME-7", "PW-42", "PW-1"], | ||
| ); | ||
| }); | ||
|
|
||
| test("a key or a word from the title finds the task", () => { | ||
| assert.deepEqual( | ||
| matchTasks(tasks, "pw-4").map((found) => found.key), | ||
| ["PW-42"], | ||
| ); | ||
| assert.deepEqual( | ||
| matchTasks(tasks, "pricing").map((found) => found.key), | ||
| ["ACME-7"], | ||
| ); | ||
| assert.deepEqual(matchTasks(tasks, "nothing here"), []); | ||
| }); | ||
|
|
||
| test("a key is recognised in prose but not inside a longer token", () => { | ||
| const find = (text: string) => text.match(new RegExp(TASK_KEY.source))?.[1]; | ||
| assert.equal(find("landed in PW-42, see above"), "PW-42"); | ||
| assert.equal(find("ACME-7"), "ACME-7"); | ||
| assert.equal(find("v2-1024-beta"), undefined); | ||
| assert.equal(find("plain words"), undefined); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Mentioning a task is just writing its key. `PW-42` in a message is the same | ||
| // reference everywhere — typed by a person, printed by an agent, or copied out | ||
| // of the CLI — so the composer only has to help find the key, and the renderer | ||
| // only has to recognise the keys that name a real task. | ||
|
|
||
| import type { Task } from "./types"; | ||
|
|
||
| /// The shape of a key: the workspace prefix is configurable, so this matches | ||
| /// `ACME-7` as readily as `PW-42` and the caller decides which keys are real. | ||
| export const TASK_KEY = /(?<![\w-])([A-Za-z][A-Za-z0-9]*-\d+)(?![\w-])/; | ||
|
|
||
| const finished = (task: Task) => task.status === "done" || task.status === "canceled"; | ||
|
|
||
| /// Tasks worth offering for what has been typed after `#`, open work first and | ||
| /// most recently touched before the rest. | ||
| export function matchTasks(tasks: Task[], query: string, limit = 6): Task[] { | ||
| const needle = query.trim().toLowerCase(); | ||
| return tasks | ||
| .filter( | ||
| (task) => | ||
| task.key.toLowerCase().includes(needle) || | ||
| task.title.toLowerCase().includes(needle), | ||
| ) | ||
| .sort( | ||
| (a, b) => | ||
| Number(finished(a)) - Number(finished(b)) || b.updated_at - a.updated_at, | ||
| ) | ||
| .slice(0, limit); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| // table has to render as something calm rather than flickering into garbage. | ||
|
|
||
| import type { ReactNode } from "react"; | ||
| import { TASK_KEY } from "@client/mentions"; | ||
|
|
||
| // --- blocks ----------------------------------------------------------------- | ||
|
|
||
|
|
@@ -346,6 +347,9 @@ export interface InlineOptions { | |
| /// Handles that resolve to a real member, so `@nobody` stays plain text. | ||
| handles?: Set<string>; | ||
| onMention?: (handle: string) => void; | ||
| /// Uppercased task keys to task ids, so `PW-999` stays plain text. | ||
| tasks?: Map<string, string>; | ||
| onTask?: (taskId: string) => void; | ||
| } | ||
|
|
||
| /// Only schemes that can't execute anything. A `javascript:` href in an agent's | ||
|
|
@@ -371,6 +375,7 @@ const INLINE = new RegExp( | |
| "<(https?://[^>\\s]+)>", // autolink | ||
| "(?<![\\w/])(https?://[^\\s<>()\\[\\]]+[^\\s<>()\\[\\].,;:!?'\"])", // bare url | ||
| "@([a-z0-9][\\w-]*)", // mention | ||
| TASK_KEY.source, // task mention: PW-42 | ||
| ].join("|"), | ||
| "gi", | ||
| ); | ||
|
|
@@ -423,6 +428,7 @@ export function renderInline( | |
| autolink, | ||
| bareUrl, | ||
| mention, | ||
| taskKey, | ||
| ] = match; | ||
|
|
||
| if (code !== undefined) { | ||
|
|
@@ -484,6 +490,26 @@ export function renderInline( | |
| <span key={k}>@{mention}</span> | ||
| ), | ||
| ); | ||
| } else if (taskKey !== undefined) { | ||
| // Every surface writes the key the same way, so recognising it here makes | ||
| // a task someone typed and a task an agent cited the same live reference. | ||
| const taskId = options.tasks?.get(taskKey.toUpperCase()); | ||
| push( | ||
| taskId ? ( | ||
| <span | ||
| key={k} | ||
| className="mention task" | ||
| onClick={(event) => { | ||
| event.stopPropagation(); | ||
| options.onTask?.(taskId); | ||
|
Comment on lines
+502
to
+504
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a known task key is used as an explicit Markdown link label, such as Useful? React with 👍 / 👎. |
||
| }} | ||
| > | ||
| {taskKey.toUpperCase()} | ||
| </span> | ||
| ) : ( | ||
| <span key={k}>{taskKey}</span> | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workspaces can validly configure a task prefix beginning with a digit because
update_workspaceretains any nonempty ASCII-alphanumeric prefix, producing keys such as2FA-1or123-4. This pattern requires the first character to be a letter, so those real tasks can be selected by the new composer menu but remain plain text in desktop messages. Match an alphanumeric leading character or tighten the server-side prefix validation consistently.Useful? React with 👍 / 👎.