**Taking: `engine/triage.ts`, `engine/pr-comment-handler.ts`, `engine/eval-followups.ts`, `cli/commands/task.ts`, `cli/extension.ts`** (write class — no collision with the comparison backlog). ## A class the census does not count The 48-guard work list tracks `=== "triage"` **comparisons**. These are `column: "triage"` **writes** — and post-#2515 every one creates a card directly into the state STALL 3 was about, except **manufactured continuously** rather than left behind by the upgrade. ## Why they bite `createTaskImpl` resolves the column as: ```ts column: input.column || options?.resolvedEntryColumn || fallbackIntakeColumn || "triage" ``` `input.column` **wins**, so an explicit `column: "triage"` overrides the workflow's resolved intake column entirely. `store-create-intake-column.test.ts` already pins that a create with **no** column lands in the default workflow's intake (now `todo`) — these callers opted out of it. The sharpest is `triage.ts`'s `fn_task_create` agent tool: it passed `workflowId: params.workflow_id` **and** `column: "triage"` in the same call. The caller chose a workflow and the column ignored it — a Coding (Ideas) create landed in `triage` instead of `ideas`. ## Counts **Comparison guards: unchanged by this PR.** This is the write class; conflating the two would misreport convergence toward the zero bar. | file | `column: "triage"` writes before | after | |---|---:|---:| | `packages/engine/src/triage.ts` | 1 | **0** | | `packages/engine/src/pr-comment-handler.ts` | 1 | **0** | | `packages/engine/src/eval-followups.ts` | 1 | **0** | | `packages/cli/src/commands/task.ts` | 3 | **0** | | `packages/cli/src/extension.ts` | 3 | **0** | | **total** | **9** | **0** | ## A test that pinned the defect `pr-comment-handler.test.ts` asserted `column: "triage"` in the createTask call — so it would have **failed the fix and passed the bug**. Rewritten to assert the invariant (the caller passes no column, so the workflow's intake wins) plus an explicit `Object.hasOwn(arg, "column") === false`, which is what actually catches a reintroduction. ## Interaction with #2591 My merged #2591 rescues these cards once created — they sit on a legacy planner id their workflow doesn't declare and are still in planning stage. So this isn't a *visible* stall today; the rescue absorbs it. **That's the reason to fix it rather than leave it:** a self-healing path silently absorbing a steady stream of malformed creates is exactly how the underlying defect stays invisible. ## Deliberately not touched - `{ id: "start", kind: "start", column: "triage" }` in the builtin coding / PR / lead-generation IRs — workflow-internal **node declarations** for workflows that still legitimately declare a `triage` column, not lifecycle writes. - Left for their owners: `core/task-store/project-store-ops.ts:210`, `core/task-store/update-task-deps.ts:111` (main worker), `dashboard/src/routes/register-gitlab.ts:108` (u12). Same defect, same one-line shape. ## Verification - 304 engine/CLI tests green across the affected suites - merge gate green (482 + 132 + 10), engine + CLI tsc clean, lint clean No changeset: `@fusion/engine` and `@fusion/core` are private; the CLI change is a bug fix with no user-facing API change — happy to add one if you'd rather it appear in release notes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
347 lines
11 KiB
TypeScript
347 lines
11 KiB
TypeScript
import type { TaskStore } from "@fusion/core";
|
|
import type { PrInfo } from "@fusion/core";
|
|
import { prMonitorLog } from "./logger.js";
|
|
|
|
/*
|
|
FNXC:PullRequestReview 2026-07-26-00:00:
|
|
The PR-feedback follow-up card is a real product feature, but it used to borrow the shared automated-recovery follow-up engine (`createAutomatedFollowup` in verification-followup-dedup.ts) purely for its dedup pass. That engine was deleted along with the recovery follow-up cards it existed to file, so the one dedup rule this feature needs is inlined below: never file a second card for the same PR number under the same parent while one is still open. Closed columns (done/archived) are excluded so a later close/reopen of the same PR can legitimately file a fresh card.
|
|
*/
|
|
const CLOSED_FOLLOWUP_COLUMNS = new Set(["done", "archived"]);
|
|
|
|
interface PrComment {
|
|
id: number;
|
|
body: string;
|
|
user: { login: string };
|
|
created_at: string;
|
|
updated_at: string;
|
|
html_url: string;
|
|
}
|
|
|
|
/**
|
|
* Analyzes PR comments for actionable feedback and creates
|
|
* steering comments or follow-up tasks.
|
|
*/
|
|
export class PrCommentHandler {
|
|
// Keywords that suggest actionable feedback
|
|
private readonly ACTION_KEYWORDS = [
|
|
"fix",
|
|
"change",
|
|
"update",
|
|
"remove",
|
|
"add",
|
|
"should",
|
|
"need to",
|
|
"needs to",
|
|
"please",
|
|
"consider",
|
|
"suggest",
|
|
"recommend",
|
|
];
|
|
|
|
// Non-actionable patterns to filter out
|
|
private readonly NON_ACTIONABLE_PATTERNS = [
|
|
/^\s*lgtm\s*$/i,
|
|
/^\s*looks? good\s*$/i,
|
|
/^\s*thanks?\s*$/i,
|
|
/^\s*thank you\s*$/i,
|
|
/^\s*nice\s*$/i,
|
|
/^\s*great\s*$/i,
|
|
/^\s*awesome\s*$/i,
|
|
/^\s*👍\s*$/,
|
|
/^\s*✅\s*$/,
|
|
];
|
|
|
|
constructor(private store: TaskStore) {}
|
|
|
|
/**
|
|
* Process new PR comments for a task.
|
|
* Called by PrMonitor when new comments are detected.
|
|
*/
|
|
async handleNewComments(
|
|
taskId: string,
|
|
prInfo: PrInfo,
|
|
comments: PrComment[]
|
|
): Promise<void> {
|
|
for (const comment of comments) {
|
|
await this.processComment(taskId, prInfo, comment);
|
|
}
|
|
}
|
|
|
|
private async processComment(
|
|
taskId: string,
|
|
prInfo: PrInfo,
|
|
comment: PrComment
|
|
): Promise<void> {
|
|
// Skip non-actionable comments
|
|
if (this.isNonActionable(comment.body)) {
|
|
prMonitorLog.log(`Skipping non-actionable comment #${comment.id}`);
|
|
return;
|
|
}
|
|
|
|
// Check if comment contains actionable feedback
|
|
const isActionable = this.isActionable(comment.body);
|
|
const hasCodeSuggestions = this.hasCodeBlock(comment.body);
|
|
|
|
if (!isActionable && !hasCodeSuggestions) {
|
|
prMonitorLog.log(`Comment #${comment.id} does not contain actionable feedback`);
|
|
return;
|
|
}
|
|
|
|
// Build comment text
|
|
const text = this.buildCommentText(prInfo, comment, hasCodeSuggestions);
|
|
|
|
try {
|
|
await this.store.addTaskComment(taskId, text, "agent");
|
|
await this.upsertReviewItem(taskId, prInfo, comment, "queued");
|
|
prMonitorLog.log(`Added comment for PR review #${comment.id}`);
|
|
} catch (err) {
|
|
prMonitorLog.error(`Failed to add comment for ${taskId}:`, err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if a comment is non-actionable (LGTM, thanks, etc.)
|
|
*/
|
|
private isNonActionable(body: string): boolean {
|
|
const trimmed = body.trim();
|
|
return this.NON_ACTIONABLE_PATTERNS.some((pattern) => pattern.test(trimmed));
|
|
}
|
|
|
|
/**
|
|
* Check if a comment contains actionable feedback keywords.
|
|
*/
|
|
private isActionable(body: string): boolean {
|
|
const lowerBody = body.toLowerCase();
|
|
return this.ACTION_KEYWORDS.some((keyword) => lowerBody.includes(keyword));
|
|
}
|
|
|
|
/**
|
|
* Check if a comment contains code blocks suggesting changes.
|
|
*/
|
|
private hasCodeBlock(body: string): boolean {
|
|
// Look for code blocks (``` or `code`)
|
|
return /```[\s\S]*?```/.test(body) || /`[^`]+`/.test(body);
|
|
}
|
|
|
|
/**
|
|
* Build comment text from PR review comment.
|
|
*/
|
|
private buildCommentText(
|
|
prInfo: PrInfo,
|
|
comment: PrComment,
|
|
hasCodeSuggestions: boolean
|
|
): string {
|
|
const lines: string[] = [];
|
|
|
|
lines.push(`**PR Review Feedback** from @${comment.user.login}`);
|
|
lines.push(`**PR:** #${prInfo.number} (${prInfo.status})`);
|
|
if (prInfo.status !== "open") {
|
|
lines.push(`**Note:** This PR is already ${prInfo.status}. Treat the feedback as follow-up work.`);
|
|
}
|
|
lines.push("");
|
|
|
|
// Truncate comment body if too long
|
|
const maxBodyLength = 500;
|
|
let body = comment.body.trim();
|
|
if (body.length > maxBodyLength) {
|
|
body = body.slice(0, maxBodyLength) + "...";
|
|
}
|
|
lines.push(body);
|
|
lines.push("");
|
|
|
|
if (hasCodeSuggestions) {
|
|
lines.push("💡 This comment contains code suggestions. Please review and apply if appropriate.");
|
|
}
|
|
|
|
lines.push(`[View on GitHub](${comment.html_url})`);
|
|
|
|
return lines.join("\n");
|
|
}
|
|
|
|
/**
|
|
* Handle "changes requested" PR review state.
|
|
* Moves the task back to in-progress with reviewer feedback as a steering comment,
|
|
* closing the feedback loop so the agent can address the requested changes.
|
|
*/
|
|
async handleChangesRequested(
|
|
taskId: string,
|
|
prInfo: PrInfo,
|
|
reviewerLogin: string,
|
|
reviewBody: string,
|
|
): Promise<void> {
|
|
try {
|
|
const task = await this.store.getTask(taskId);
|
|
if (task.column !== "in-review") {
|
|
prMonitorLog.log(`Task ${taskId} not in-review (${task.column}), skipping changes-requested handling`);
|
|
return;
|
|
}
|
|
|
|
// Add reviewer feedback as a steering comment
|
|
const feedbackText = [
|
|
`**Changes Requested** by @${reviewerLogin} on PR #${prInfo.number}`,
|
|
"",
|
|
reviewBody ? reviewBody.slice(0, 800) : "(no review body)",
|
|
"",
|
|
"Please address the requested changes and update the PR.",
|
|
].join("\n");
|
|
|
|
await this.store.addTaskComment(taskId, feedbackText, "agent");
|
|
await this.upsertReviewItem(
|
|
taskId,
|
|
prInfo,
|
|
{
|
|
id: Date.now(),
|
|
body: reviewBody || "(no review body)",
|
|
user: { login: reviewerLogin },
|
|
created_at: new Date().toISOString(),
|
|
updated_at: new Date().toISOString(),
|
|
html_url: prInfo.url,
|
|
},
|
|
"queued",
|
|
);
|
|
await this.store.moveTask(taskId, "in-progress");
|
|
await this.store.logEntry(
|
|
taskId,
|
|
`PR #${prInfo.number}: changes requested by @${reviewerLogin} — moved back to in-progress`,
|
|
);
|
|
prMonitorLog.log(`Task ${taskId} moved to in-progress after changes requested on PR #${prInfo.number}`);
|
|
} catch (err) {
|
|
prMonitorLog.error(`Failed to handle changes-requested for ${taskId}:`, err);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create a follow-up task when a PR is closed with unaddressed feedback.
|
|
* This is called when a PR is merged or closed.
|
|
*/
|
|
async createFollowUpTask(
|
|
originalTaskId: string,
|
|
prInfo: PrInfo,
|
|
unaddressedComments: PrComment[]
|
|
): Promise<void> {
|
|
if (unaddressedComments.length === 0) return;
|
|
|
|
const summary = unaddressedComments
|
|
.map((c) => `- @${c.user.login}: ${c.body.slice(0, 100).trim()}${c.body.length > 100 ? "..." : ""}`)
|
|
.join("\n");
|
|
|
|
const description = `Follow-up for ${originalTaskId}
|
|
|
|
PR #${prInfo.number} was ${prInfo.status} with unaddressed feedback:
|
|
|
|
${summary}
|
|
|
|
Please review the PR comments and address any remaining issues.`;
|
|
|
|
try {
|
|
const openTasks = await this.store.listTasks({ slim: true }).catch(() => []);
|
|
const existing = openTasks.find(
|
|
(task) =>
|
|
task.id !== originalTaskId &&
|
|
!CLOSED_FOLLOWUP_COLUMNS.has(task.column) &&
|
|
task.sourceParentTaskId === originalTaskId &&
|
|
task.sourceMetadata?.prNumber === prInfo.number,
|
|
);
|
|
|
|
if (existing) {
|
|
prMonitorLog.log(`Reused follow-up task ${existing.id} for PR #${prInfo.number}`);
|
|
return;
|
|
}
|
|
|
|
const task = await this.store.createTask({
|
|
title: `Follow-up: Address PR #${prInfo.number} feedback`,
|
|
description,
|
|
/* FNXC:WorkflowLifecycleColumns 2026-07-29-20:15 (U11): no explicit column —
|
|
`createTaskImpl` resolves the WORKFLOW'S intake column, and `input.column` would
|
|
override it. Hard-coding `"triage"` created the card in a column the default
|
|
lineage no longer declares (#2515), i.e. straight into the stranded state. */
|
|
dependencies: [originalTaskId],
|
|
source: {
|
|
sourceType: "api",
|
|
sourceParentTaskId: originalTaskId,
|
|
sourceMetadata: { prNumber: prInfo.number, prUrl: prInfo.url },
|
|
},
|
|
});
|
|
prMonitorLog.log(`Created follow-up task ${task.id} for PR #${prInfo.number}`);
|
|
} catch (err) {
|
|
prMonitorLog.error(`Failed to create follow-up task:`, err);
|
|
}
|
|
}
|
|
|
|
private async upsertReviewItem(
|
|
taskId: string,
|
|
prInfo: PrInfo,
|
|
comment: PrComment,
|
|
status: "queued" | "in-progress" | "addressed" | "failed",
|
|
): Promise<void> {
|
|
const task = await this.store.getTask(taskId);
|
|
const now = new Date().toISOString();
|
|
const current = task.review ?? {
|
|
mode: "pull-request",
|
|
source: "github-pr",
|
|
decision: "pending",
|
|
items: [],
|
|
selectedItemIds: [],
|
|
};
|
|
const itemId = `gh-comment-${comment.id}`;
|
|
const existingIndex = current.items.findIndex((item: { id: string }) => item.id === itemId);
|
|
const nextItem = {
|
|
id: itemId,
|
|
source: "github-pr" as const,
|
|
status,
|
|
summary: comment.body.trim().slice(0, 160) || `Feedback from @${comment.user.login}`,
|
|
body: comment.body,
|
|
reviewer: comment.user.login,
|
|
commentUrl: comment.html_url,
|
|
createdAt: comment.created_at,
|
|
updatedAt: now,
|
|
};
|
|
const nextItems = [...current.items];
|
|
if (existingIndex >= 0) {
|
|
nextItems[existingIndex] = { ...nextItems[existingIndex], ...nextItem };
|
|
} else {
|
|
nextItems.push(nextItem);
|
|
}
|
|
|
|
const currentReviewState = task.reviewState ?? {
|
|
source: "pull-request" as const,
|
|
items: [],
|
|
addressing: [],
|
|
};
|
|
const existingReviewStateIndex = currentReviewState.items.findIndex((item) => item.id === itemId);
|
|
const nextReviewStateItem = {
|
|
id: itemId,
|
|
githubCommentId: comment.id,
|
|
body: comment.body,
|
|
author: { login: comment.user.login },
|
|
createdAt: comment.created_at,
|
|
updatedAt: now,
|
|
htmlUrl: comment.html_url,
|
|
source: "github-pr" as const,
|
|
};
|
|
const nextReviewStateItems = [...currentReviewState.items];
|
|
if (existingReviewStateIndex >= 0) {
|
|
nextReviewStateItems[existingReviewStateIndex] = { ...nextReviewStateItems[existingReviewStateIndex], ...nextReviewStateItem };
|
|
} else {
|
|
nextReviewStateItems.push(nextReviewStateItem);
|
|
}
|
|
|
|
await this.store.updateTask(taskId, {
|
|
review: {
|
|
...current,
|
|
mode: "pull-request",
|
|
source: "github-pr",
|
|
summary: `PR #${prInfo.number} feedback items: ${nextItems.length}`,
|
|
latestRefreshAt: now,
|
|
items: nextItems,
|
|
},
|
|
reviewState: {
|
|
...currentReviewState,
|
|
source: "pull-request",
|
|
summary: currentReviewState.summary,
|
|
items: nextReviewStateItems,
|
|
},
|
|
});
|
|
}
|
|
}
|