feat: comments marked as decisions, on top of the ticket and searchable

Whoever can change the ticket flags a comment as a decision (new event
CommentDecisionMarkedEvent on the comment). The ticket page lists its
decisions above the description, with a link to the comment in the
conversation (`?comment=<id>` scrolls to it and points at it), and the
search palette finds them by their text across my projects.

API: markDecision / PUT-DELETE /api/comments/{id}/decision; Issue.decisions
and GET /api/issues/{issue}/decisions; decisions(projectId?, search) and
GET /api/projects/{project}/decisions, GET /api/me/decisions. MCP:
mark_decision, search_decisions, and get_issue includes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 11:32:07 +02:00
parent 8f83fdefb6
commit 70e4fbd399
45 changed files with 2515 additions and 84 deletions

View File

@@ -0,0 +1,112 @@
import { IQueryHandler, Query, QueryHandler } from '@nestjs/cqrs';
import {
CommentReadModel,
DecisionReadModel,
} from '@task-stream/api/tracker/domain';
import { FindCommentsRepository } from '../ports/find-comments.repository';
import { FindIssuesRepository } from '../ports/find-issues.repository';
import { FindProjectsRepository } from '../ports/find-projects.repository';
import { ReadAccess } from './read-access';
/** The decisions of a ticket, oldest first (shown above its conversation). */
export class GetIssueDecisionsQuery extends Query<CommentReadModel[]> {
constructor(
/** Null: anonymous (public projects only). */
public readonly viewerId: string | null,
public readonly issueId: string,
) {
super();
}
}
/**
* Decisions by their text, most recently decided first: of one project, or
* (without one) of every project the viewer belongs to.
*/
export class SearchDecisionsQuery extends Query<DecisionReadModel[]> {
constructor(
public readonly viewerId: string | null,
public readonly filter: {
projectId?: string;
search?: string;
limit: number;
},
) {
super();
}
}
@QueryHandler(GetIssueDecisionsQuery)
export class GetIssueDecisionsQueryHandler
implements IQueryHandler<GetIssueDecisionsQuery, CommentReadModel[]>
{
constructor(
private readonly findIssues: FindIssuesRepository,
private readonly findComments: FindCommentsRepository,
private readonly access: ReadAccess,
) {}
async execute(query: GetIssueDecisionsQuery): Promise<CommentReadModel[]> {
const issue = this.access.assertFound(
await this.findIssues.findById(query.issueId),
'Issue',
query.issueId,
);
await this.access.assertCanViewIssue(issue, query.viewerId);
return this.findComments.findDecisions({ issueId: issue.id, limit: 50 });
}
}
@QueryHandler(SearchDecisionsQuery)
export class SearchDecisionsQueryHandler
implements IQueryHandler<SearchDecisionsQuery, DecisionReadModel[]>
{
constructor(
private readonly findProjects: FindProjectsRepository,
private readonly findIssues: FindIssuesRepository,
private readonly findComments: FindCommentsRepository,
private readonly access: ReadAccess,
) {}
async execute(query: SearchDecisionsQuery): Promise<DecisionReadModel[]> {
const { filter, viewerId } = query;
let projectIds: string[];
if (filter.projectId) {
await this.access.assertCanView(filter.projectId, viewerId);
projectIds = [filter.projectId];
} else {
if (!viewerId) return [];
projectIds = (await this.findProjects.findByMember(viewerId)).map(
(p) => p.id,
);
}
if (projectIds.length === 0) return [];
const limit = Math.min(filter.limit, 100);
// Read a few more: some may sit in the trash or, for a guest, in
// tickets they do not take part in.
const comments = await this.findComments.findDecisions({
projectIds,
search: filter.search?.trim().slice(0, 200) || undefined,
limit: limit * 2,
});
const issues = new Map(
(
await this.findIssues.findByIds([
...new Set(comments.map((c) => c.issueId)),
])
).map((issue) => [issue.id, issue]),
);
const found: DecisionReadModel[] = [];
for (const comment of comments) {
const issue = issues.get(comment.issueId);
if (!issue || issue.trashedAt) continue;
if (!(await this.access.canViewIssue(issue, viewerId))) continue;
found.push({
comment,
issue: { id: issue.id, key: issue.key, title: issue.title },
});
if (found.length === limit) break;
}
return found;
}
}

View File

@@ -26,6 +26,10 @@ import { GetReleaseNotesDraftQueryHandler } from './get-release-notes-draft.quer
import { GetTrashQueryHandler } from './get-trash.query';
import { GetShowcaseQueryHandler } from './get-showcase.query';
import { SearchMyIssuesQueryHandler } from './search-my-issues.query-handler';
import {
GetIssueDecisionsQueryHandler,
SearchDecisionsQueryHandler,
} from './decisions.query';
export const QUERY_HANDLERS = [
GetPublicProjectsQueryHandler,
@@ -33,6 +37,8 @@ export const QUERY_HANDLERS = [
GetActivityQueryHandler,
GetBoardQueryHandler,
GetCommentsQueryHandler,
GetIssueDecisionsQueryHandler,
SearchDecisionsQueryHandler,
GetIssueQueryHandler,
GetIssuesByIdsQueryHandler,
GetMyProjectsQueryHandler,