feat(KB-617): add diff viewer tab to task detail modal
- Add modifiedFiles and baseCommitSha tracking during task execution - Create GET /tasks/:id/diff API endpoint for file list and patches - Build TaskChangesTab component with expandable file diffs - Integrate Changes tab into TaskDetailModal for in-progress, in-review, and done tasks - Add database columns and types for diff tracking - Update executor to capture modified files during agent sessions
This commit is contained in:
@@ -51,20 +51,29 @@ function validateUuid(id: string): boolean {
|
||||
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id);
|
||||
}
|
||||
|
||||
function validateMissionId(id: string): boolean {
|
||||
return /^M-\d+$/.test(id);
|
||||
function validateMissionId(id: string | string[]): boolean {
|
||||
const str = Array.isArray(id) ? id[0] : id;
|
||||
return /^M-\d+$/.test(str);
|
||||
}
|
||||
|
||||
function validateMilestoneId(id: string): boolean {
|
||||
return /^MS-\d+$/.test(id);
|
||||
function validateMilestoneId(id: string | string[]): boolean {
|
||||
const str = Array.isArray(id) ? id[0] : id;
|
||||
return /^MS-\d+$/.test(str);
|
||||
}
|
||||
|
||||
function validateSliceId(id: string): boolean {
|
||||
return /^SL-\d+$/.test(id);
|
||||
function validateSliceId(id: string | string[]): boolean {
|
||||
const str = Array.isArray(id) ? id[0] : id;
|
||||
return /^SL-\d+$/.test(str);
|
||||
}
|
||||
|
||||
function validateFeatureId(id: string): boolean {
|
||||
return /^F-\d+$/.test(id);
|
||||
function validateFeatureId(id: string | string[]): boolean {
|
||||
const str = Array.isArray(id) ? id[0] : id;
|
||||
return /^F-\d+$/.test(str);
|
||||
}
|
||||
|
||||
/** Helper to extract string from Express param (handles string | string[]) */
|
||||
function paramString(value: string | string[]): string {
|
||||
return Array.isArray(value) ? value[0] : value;
|
||||
}
|
||||
|
||||
function validateTitle(title: unknown): string {
|
||||
|
||||
@@ -1841,6 +1841,82 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/tasks/:id/diff
|
||||
* Get detailed diff information for files modified during task execution.
|
||||
* Returns: { files: string[]; diffs: Record<string, { stat: string; patch: string }> }
|
||||
*/
|
||||
router.get("/tasks/:id/diff", async (req, res) => {
|
||||
try {
|
||||
const task = await store.getTask(req.params.id);
|
||||
|
||||
// Only tasks with worktrees can have diffs
|
||||
if (!task.worktree || !existsSync(task.worktree)) {
|
||||
res.json({ files: [], diffs: {} });
|
||||
return;
|
||||
}
|
||||
|
||||
// Use stored modifiedFiles if available, otherwise compute on-the-fly
|
||||
let files = task.modifiedFiles;
|
||||
|
||||
if (!files || files.length === 0) {
|
||||
// Fallback: compute files using git diff
|
||||
try {
|
||||
const baseRef = task.baseCommitSha ?? "HEAD~1";
|
||||
const output = execSync(`git diff --name-only ${baseRef}..HEAD`, {
|
||||
cwd: task.worktree,
|
||||
encoding: "utf-8",
|
||||
timeout: 5000,
|
||||
}).trim();
|
||||
files = output ? output.split("\n").filter(Boolean) : [];
|
||||
} catch {
|
||||
files = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (files.length === 0) {
|
||||
res.json({ files: [], diffs: {} });
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute diffs for each file
|
||||
const diffs: Record<string, { stat: string; patch: string }> = {};
|
||||
const baseRef = task.baseCommitSha ?? "HEAD~1";
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
// Get stat for this file
|
||||
const stat = execSync(`git diff --stat ${baseRef}..HEAD -- "${file}"`, {
|
||||
cwd: task.worktree,
|
||||
encoding: "utf-8",
|
||||
timeout: 5000,
|
||||
}).trim();
|
||||
|
||||
// Get patch for this file
|
||||
const patch = execSync(`git diff ${baseRef}..HEAD -- "${file}"`, {
|
||||
cwd: task.worktree,
|
||||
encoding: "utf-8",
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
diffs[file] = { stat, patch };
|
||||
} catch (err: any) {
|
||||
// Log error but continue with other files
|
||||
console.warn(`Failed to get diff for ${file}:`, err.message);
|
||||
diffs[file] = { stat: "", patch: "" };
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ files, diffs });
|
||||
} catch (err: any) {
|
||||
if (err.code === "ENOENT") {
|
||||
res.status(404).json({ error: `Task ${req.params.id} not found` });
|
||||
} else {
|
||||
res.status(500).json({ error: err.message || "Internal server error" });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/tasks/:id/workflow-results
|
||||
* Get workflow step execution results for a task.
|
||||
|
||||
Reference in New Issue
Block a user