mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Address greptile review feedback
This commit is contained in:
parent
81b96c6021
commit
b5e177df7e
4 changed files with 208 additions and 14 deletions
|
|
@ -170,6 +170,29 @@ describe("buildAssistantPartsFromTranscript", () => {
|
|||
]);
|
||||
expect(result.notices).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves diff transcript output as a fenced diff block", () => {
|
||||
const result = buildAssistantPartsFromTranscript([
|
||||
{ kind: "assistant", ts: "2026-04-06T12:00:00.000Z", text: "Applied the patch." },
|
||||
{ kind: "diff", ts: "2026-04-06T12:00:01.000Z", changeType: "file_header", text: "ui/src/lib/issue-chat-messages.ts" },
|
||||
{ kind: "diff", ts: "2026-04-06T12:00:02.000Z", changeType: "add", text: "+function formatDiffBlock(lines: string[]) {" },
|
||||
{ kind: "diff", ts: "2026-04-06T12:00:03.000Z", changeType: "add", text: "+ return ````diff`;" },
|
||||
]);
|
||||
|
||||
expect(result.parts).toMatchObject([
|
||||
{ type: "text", text: "Applied the patch." },
|
||||
{
|
||||
type: "text",
|
||||
text: [
|
||||
"```diff",
|
||||
"ui/src/lib/issue-chat-messages.ts",
|
||||
"+function formatDiffBlock(lines: string[]) {",
|
||||
"+ return ````diff`;",
|
||||
"```",
|
||||
].join("\n"),
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildIssueChatMessages", () => {
|
||||
|
|
|
|||
|
|
@ -151,6 +151,10 @@ function mergePartText(
|
|||
: `${previous.text}\n${next.text}`;
|
||||
}
|
||||
|
||||
function formatDiffBlock(lines: string[]) {
|
||||
return `\`\`\`diff\n${lines.join("\n")}\n\`\`\``;
|
||||
}
|
||||
|
||||
function createAssistantMetadata(custom: Record<string, unknown>) {
|
||||
return {
|
||||
unstable_state: null,
|
||||
|
|
@ -297,6 +301,7 @@ function computeSegmentTimings(entries: readonly IssueChatTranscriptEntry[]): Se
|
|||
entry.kind === "thinking" ||
|
||||
entry.kind === "tool_call" ||
|
||||
entry.kind === "tool_result" ||
|
||||
entry.kind === "diff" ||
|
||||
(entry.kind === "result" && ((entry.isError && !!entry.errors?.length) || !!entry.text));
|
||||
const isText = entry.kind === "assistant" && !!entry.text;
|
||||
|
||||
|
|
@ -434,8 +439,29 @@ export function buildAssistantPartsFromTranscript(entries: readonly IssueChatTra
|
|||
const toolParts = new Map<string, ToolCallMessagePart<JsonObject, unknown>>();
|
||||
const toolIndices = new Map<string, number>();
|
||||
const notices: string[] = [];
|
||||
let pendingDiffLines: string[] = [];
|
||||
let pendingDiffParentId: string | undefined;
|
||||
|
||||
const flushPendingDiff = () => {
|
||||
if (pendingDiffLines.length === 0) return;
|
||||
orderedParts.push({
|
||||
type: "text",
|
||||
text: formatDiffBlock(pendingDiffLines),
|
||||
parentId: pendingDiffParentId,
|
||||
});
|
||||
pendingDiffLines = [];
|
||||
pendingDiffParentId = undefined;
|
||||
};
|
||||
|
||||
for (const [index, entry] of entries.entries()) {
|
||||
if (entry.kind === "diff") {
|
||||
pendingDiffParentId ??= `diff-group:${index}`;
|
||||
pendingDiffLines.push(entry.text ?? "");
|
||||
continue;
|
||||
}
|
||||
|
||||
flushPendingDiff();
|
||||
|
||||
if (entry.kind === "assistant" && entry.text) {
|
||||
orderedParts.push({ type: "text", text: entry.text });
|
||||
continue;
|
||||
|
|
@ -510,6 +536,8 @@ export function buildAssistantPartsFromTranscript(entries: readonly IssueChatTra
|
|||
}
|
||||
}
|
||||
|
||||
flushPendingDiff();
|
||||
|
||||
const mergedParts: Array<TextMessagePart | ReasoningMessagePart | ToolCallMessagePart<JsonObject, unknown>> = [];
|
||||
for (const part of orderedParts) {
|
||||
if (part.type === "tool-call") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue