This commit is contained in:
2026-03-25 19:13:57 +00:00
parent 49fa4d623e
commit 958c332bf1
2 changed files with 21 additions and 22 deletions

View File

@@ -359,7 +359,7 @@ type BookmarkRef = {
type ReviewTarget = type ReviewTarget =
| { type: "workingCopy" } | { type: "workingCopy" }
| { type: "baseBookmark"; bookmark: string; remote?: string } | { type: "baseBookmark"; bookmark: string; remote?: string }
| { type: "change"; sha: string; title?: string } | { type: "change"; changeId: string; title?: string }
| { type: "pullRequest"; prNumber: number; baseBookmark: string; baseRemote?: string; title: string } | { type: "pullRequest"; prNumber: number; baseBookmark: string; baseRemote?: string; title: string }
| { type: "folder"; paths: string[] }; | { type: "folder"; paths: string[] };
@@ -377,9 +377,9 @@ const BASE_BOOKMARK_PROMPT_FALLBACK =
"Review the code changes against the base bookmark '{bookmark}'. Start by finding the merge-base revision between the working copy and {bookmark}, then run `jj diff --from <merge-base> --to @` to see what changes would land on the {bookmark} bookmark. Provide prioritized, actionable findings."; "Review the code changes against the base bookmark '{bookmark}'. Start by finding the merge-base revision between the working copy and {bookmark}, then run `jj diff --from <merge-base> --to @` to see what changes would land on the {bookmark} bookmark. Provide prioritized, actionable findings.";
const CHANGE_PROMPT_WITH_TITLE = const CHANGE_PROMPT_WITH_TITLE =
'Review the code changes introduced by change {sha} ("{title}"). Provide prioritized, actionable findings.'; 'Review the code changes introduced by change {changeId} ("{title}"). Provide prioritized, actionable findings.';
const CHANGE_PROMPT = "Review the code changes introduced by change {sha}. Provide prioritized, actionable findings."; const CHANGE_PROMPT = "Review the code changes introduced by change {changeId}. Provide prioritized, actionable findings.";
const PULL_REQUEST_PROMPT = const PULL_REQUEST_PROMPT =
'Review pull request #{prNumber} ("{title}") against the base bookmark \'{baseBookmark}\'. The merge-base revision for this comparison is {mergeBaseSha}. Run `jj diff --from {mergeBaseSha} --to @` to inspect the changes that would be merged. Provide prioritized, actionable findings.'; 'Review pull request #{prNumber} ("{title}") against the base bookmark \'{baseBookmark}\'. The merge-base revision for this comparison is {mergeBaseSha}. Run `jj diff --from {mergeBaseSha} --to @` to inspect the changes that would be merged. Provide prioritized, actionable findings.';
@@ -748,22 +748,22 @@ async function getMergeBase(
/** /**
* Get list of recent changes * Get list of recent changes
*/ */
async function getRecentChanges(pi: ExtensionAPI, limit: number = 10): Promise<Array<{ sha: string; title: string }>> { async function getRecentChanges(pi: ExtensionAPI, limit: number = 10): Promise<Array<{ changeId: string; title: string }>> {
const { stdout, code } = await pi.exec("jj", [ const { stdout, code } = await pi.exec("jj", [
"log", "log",
"-n", "-n",
`${limit}`, `${limit}`,
"--no-graph", "--no-graph",
"-T", "-T",
'commit_id ++ "\\t" ++ description.first_line() ++ "\\n"', 'change_id.shortest(8) ++ "\\t" ++ description.first_line() ++ "\\n"',
]); ]);
if (code !== 0) return []; if (code !== 0) return [];
return parseNonEmptyLines(stdout) return parseNonEmptyLines(stdout)
.filter((line) => line.trim()) .filter((line) => line.trim())
.map((line) => { .map((line) => {
const [sha, ...rest] = line.trim().split("\t"); const [changeId, ...rest] = line.trim().split("\t");
return { sha, title: rest.join(" ") }; return { changeId, title: rest.join(" ") };
}); });
} }
@@ -979,9 +979,9 @@ async function buildReviewPrompt(
case "change": case "change":
if (target.title) { if (target.title) {
return CHANGE_PROMPT_WITH_TITLE.replace("{sha}", target.sha).replace("{title}", target.title); return CHANGE_PROMPT_WITH_TITLE.replace("{changeId}", target.changeId).replace("{title}", target.title);
} }
return CHANGE_PROMPT.replace("{sha}", target.sha); return CHANGE_PROMPT.replace("{changeId}", target.changeId);
case "pullRequest": { case "pullRequest": {
const baseBookmarkLabel = bookmarkRefToLabel({ name: target.baseBookmark, remote: target.baseRemote }); const baseBookmarkLabel = bookmarkRefToLabel({ name: target.baseBookmark, remote: target.baseRemote });
@@ -1014,8 +1014,7 @@ function getUserFacingHint(target: ReviewTarget): string {
case "baseBookmark": case "baseBookmark":
return `changes against '${bookmarkRefToLabel({ name: target.bookmark, remote: target.remote })}'`; return `changes against '${bookmarkRefToLabel({ name: target.bookmark, remote: target.remote })}'`;
case "change": { case "change": {
const shortSha = target.sha.slice(0, 7); return target.title ? `change ${target.changeId}: ${target.title}` : `change ${target.changeId}`;
return target.title ? `change ${shortSha}: ${target.title}` : `change ${shortSha}`;
} }
case "pullRequest": { case "pullRequest": {
@@ -1441,12 +1440,12 @@ export default function reviewExtension(pi: ExtensionAPI) {
} }
const items: SelectItem[] = changes.map((change) => ({ const items: SelectItem[] = changes.map((change) => ({
value: change.sha, value: change.changeId,
label: `${change.sha.slice(0, 7)} ${change.title}`, label: `${change.changeId} ${change.title}`,
description: "", description: "",
})); }));
const result = await ctx.ui.custom<{ sha: string; title: string } | null>((tui, theme, keybindings, done) => { const result = await ctx.ui.custom<{ changeId: string; title: string } | null>((tui, theme, keybindings, done) => {
const container = new Container(); const container = new Container();
container.addChild(new DynamicBorder((str) => theme.fg("accent", str))); container.addChild(new DynamicBorder((str) => theme.fg("accent", str)));
container.addChild(new Text(theme.fg("accent", theme.bold("Select change to review")))); container.addChild(new Text(theme.fg("accent", theme.bold("Select change to review"))));
@@ -1480,7 +1479,7 @@ export default function reviewExtension(pi: ExtensionAPI) {
}); });
selectList.onSelect = (item) => { selectList.onSelect = (item) => {
const change = changes.find((c) => c.sha === item.value); const change = changes.find((c) => c.changeId === item.value);
if (change) { if (change) {
done(change); done(change);
} else { } else {
@@ -1532,7 +1531,7 @@ export default function reviewExtension(pi: ExtensionAPI) {
}); });
if (!result) return null; if (!result) return null;
return { type: "change", sha: result.sha, title: result.title }; return { type: "change", changeId: result.changeId, title: result.title };
} }
@@ -1822,10 +1821,10 @@ export default function reviewExtension(pi: ExtensionAPI) {
} }
case "change": { case "change": {
const sha = parts[1]; const changeId = parts[1];
if (!sha) return { target: null, extraInstruction }; if (!changeId) return { target: null, extraInstruction };
const title = parts.slice(2).join(" ") || undefined; const title = parts.slice(2).join(" ") || undefined;
return { target: { type: "change", sha, title }, extraInstruction }; return { target: { type: "change", changeId, title }, extraInstruction };
} }

View File

@@ -1,15 +1,15 @@
{inputs, ...}: final: prev: let {inputs, ...}: final: prev: let
version = "0.22.1"; version = "0.24.0";
srcs = { srcs = {
x86_64-linux = x86_64-linux =
prev.fetchurl { prev.fetchurl {
url = "https://github.com/trycog/cog-cli/releases/download/v${version}/cog-linux-x86_64.tar.gz"; url = "https://github.com/trycog/cog-cli/releases/download/v${version}/cog-linux-x86_64.tar.gz";
hash = "sha256-ET+sNXisUrHShR1gxqdumegXycXcxGzJcQOdTr5005w="; hash = "sha256-9Ka7rPIlWtLVxRg9yNQCNz16AE4j0zGf2TW7xBXrksM=";
}; };
aarch64-darwin = aarch64-darwin =
prev.fetchurl { prev.fetchurl {
url = "https://github.com/trycog/cog-cli/releases/download/v${version}/cog-darwin-arm64.tar.gz"; url = "https://github.com/trycog/cog-cli/releases/download/v${version}/cog-darwin-arm64.tar.gz";
hash = "sha256-jcN+DtOqr3or5C71jp7AIAz0wh73FYybCC4FRBykKO4="; hash = "sha256-YNONHRmPGDhJeF+7rcWmrjqktYpi4b6bLl+M7IEFDtU=";
}; };
}; };
in { in {