⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix: the @ menu offers agents a mention would leave silent (#514)
Pasqual Troncone8d8761fc1fb4
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.tsindex a62a31cf..938c5466 100644--- a/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts+++ b/apps/api/src/modules/agents/core/__tests__/integration/ai-agents.test.ts@@ -386,6 +386,25 @@ describe('ai agents', () => {expect(upd.data).toMatchObject({ triggerOnMention: true, triggerOnAssign: true });});+ // The "@" menu reads this to leave out the agents a mention would not start.+ it("tells the project's assignees which agents answer a mention", async () => {+ const { asOwner } = await setup();+ await createAgent(asOwner, 'MKT', { name: 'Listens', username: 'listens', kind: 'internal' });+ await createAgent(asOwner, 'MKT', {+ name: 'Deaf',+ username: 'deaf',+ kind: 'internal',+ triggerOnMention: false,+ });++ const project = await asOwner.projects({ projectKey: 'MKT' }).get();+ const byHandle = new Map(project.data!.assignees.map((a) => [a.username, a]));++ expect(byHandle.get('listens')?.respondsToMention).toBe(true);+ expect(byHandle.get('deaf')?.respondsToMention).toBe(false);+ expect(project.data!.assignees.find((a) => a.kind === 'member')?.respondsToMention).toBeNull();+ });+it("attaches an agent to a project on the team's default role", async () => {const { asOwner } = await setup();const roles = await listProjectRoles(asOwner, 'MKT');diff --git a/apps/api/src/modules/members/service.ts b/apps/api/src/modules/members/service.tsindex b634517a..22fa8843 100644--- a/apps/api/src/modules/members/service.ts+++ b/apps/api/src/modules/members/service.ts@@ -191,6 +191,9 @@ export interface AssigneeCandidate {// The user an 'owner'-scoped external agent works for: only their runs reach its// runner, so delegating it to anyone else does nothing. Null for everyone else.restrictedToUserId: string | null;+ // Whether @-mentioning this agent starts a run. Null for a person, whom a mention+ // always reaches as a notification.+ respondsToMention: boolean | null;canReadWorkItems: boolean;}@@ -225,6 +228,7 @@ export async function listAssigneeCandidates(projectId: number): Promise<AssigneagentKind: aiAgent.kind,ownerUserId: aiAgent.ownerUserId,runnerScope: aiAgent.runnerScope,+ triggerOnMention: aiAgent.triggerOnMention,}).from(aiAgent).innerJoin(user, eq(user.id, aiAgent.userId))@@ -248,6 +252,7 @@ export async function listAssigneeCandidates(projectId: number): Promise<Assignerole: r.role as MemberRole,description: r.description,restrictedToUserId: null,+ respondsToMention: null,canReadWorkItems:context.role === 'owner' || hasPermission(context.permissions, 'work_items', 'read'),};@@ -263,6 +268,7 @@ export async function listAssigneeCandidates(projectId: number): Promise<Assignerole: null,description: null,restrictedToUserId: r.runnerScope === 'owner' ? r.ownerUserId : null,+ respondsToMention: r.triggerOnMention,canReadWorkItems: false,}));return [...members, ...agents].sort((a, b) => a.name.localeCompare(b.name));diff --git a/apps/api/src/modules/projects/model.ts b/apps/api/src/modules/projects/model.tsindex 7a310846..49fbb6a0 100644--- a/apps/api/src/modules/projects/model.ts+++ b/apps/api/src/modules/projects/model.ts@@ -166,6 +166,7 @@ const AssigneeCandidateResponse = t.Object({kind: t.Union([t.Literal('member'), t.Literal('agent')]),agentKind: t.Nullable(t.Union([t.Literal('external'), t.Literal('internal')])),restrictedToUserId: t.Nullable(t.String()),+ respondsToMention: t.Nullable(t.Boolean()),canReadWorkItems: t.Boolean(),});diff --git a/apps/web/src/hooks/useMentionCandidates.test.ts b/apps/web/src/hooks/useMentionCandidates.test.tsnew file mode 100644index 00000000..3d59bed9--- /dev/null+++ b/apps/web/src/hooks/useMentionCandidates.test.ts@@ -0,0 +1,51 @@+import assert from 'node:assert/strict';+import { describe, it } from 'node:test';+import type { Assignee } from '@/lib/api/endpoints/projects';+import { mentionCandidatesFrom } from './useMentionCandidates';++function assignee(over: Partial<Assignee>): Assignee {+ return {+ userId: over.username ?? 'u',+ name: over.username ?? 'u',+ email: '',+ username: null,+ image: null,+ kind: 'member',+ agentKind: null,+ restrictedToUserId: null,+ respondsToMention: null,+ canReadWorkItems: true,+ ...over,+ };+}++describe('mentionCandidatesFrom', () => {+ it('offers people and the agents a mention by this user would start', () => {+ const offered = mentionCandidatesFrom(+ [+ assignee({ username: 'ana' }),+ assignee({ username: 'refinar', kind: 'agent', respondsToMention: true }),+ assignee({ username: 'consultas', kind: 'agent', respondsToMention: false }),+ assignee({+ username: 'mine',+ kind: 'agent',+ respondsToMention: true,+ restrictedToUserId: 'me',+ }),+ assignee({+ username: 'theirs',+ kind: 'agent',+ respondsToMention: true,+ restrictedToUserId: 'someone-else',+ }),+ assignee({ username: null }),+ ],+ 'me',+ );++ assert.deepEqual(+ offered.map((c) => c.username),+ ['ana', 'refinar', 'mine'],+ );+ });+});diff --git a/apps/web/src/hooks/useMentionCandidates.ts b/apps/web/src/hooks/useMentionCandidates.tsindex 80377364..be2b5980 100644--- a/apps/web/src/hooks/useMentionCandidates.ts+++ b/apps/web/src/hooks/useMentionCandidates.ts@@ -1,17 +1,32 @@import { useContext, useMemo } from 'react';import { ShellCtx } from '@/context/shellContext';+import { useSession } from '@/lib/auth-client';+import type { Assignee } from '@/lib/api/endpoints/projects';import { type MentionCandidate } from '@/lib/tiptap-mention';+import { isForeignAgent } from '@/features/issue/utils/delegates';++// An agent is offered only when a mention by this user would start a run: one that+// does not answer mentions, or works only for another member, would stay silent.+export function mentionCandidatesFrom(+ assignees: Assignee[],+ currentUserId: string | null,+): MentionCandidate[] {+ return assignees.flatMap((a) => {+ if (!a.username) return [];+ if (a.kind === 'agent' && (!a.respondsToMention || isForeignAgent(a, currentUserId))) return [];+ return [{ userId: a.userId, name: a.name, username: a.username, kind: a.kind }];+ });+}// Who the editors offer after an "@": the active project's members and agents that// have a handle. Read from the payload the Shell loads, so an editor needs no props// for it. Empty outside a project (the public share pages), where nothing is written.export function useMentionCandidates(): MentionCandidate[] {const assignees = useContext(ShellCtx)?.project?.assignees;+ const { data: session } = useSession();+ const currentUserId = session?.user.id ?? null;return useMemo(- () =>- (assignees ?? []).flatMap((a) =>- a.username ? [{ userId: a.userId, name: a.name, username: a.username, kind: a.kind }] : [],- ),- [assignees],+ () => mentionCandidatesFrom(assignees ?? [], currentUserId),+ [assignees, currentUserId],);}diff --git a/apps/web/src/lib/api/endpoints/projects.ts b/apps/web/src/lib/api/endpoints/projects.tsindex e8fdac3f..6a7fd52b 100644--- a/apps/web/src/lib/api/endpoints/projects.ts+++ b/apps/web/src/lib/api/endpoints/projects.ts@@ -75,6 +75,8 @@ export interface Assignee {// The user an 'owner'-scoped agent works for: delegating it to anyone else queues a// run its runner never receives. Null for members and team-scoped agents.restrictedToUserId: string | null;+ // Whether @-mentioning this agent starts a run. Null for a person.+ respondsToMention: boolean | null;// Whether this person may read issues and can therefore receive watcher// notifications without leaking work-item content.canReadWorkItems: boolean;