From 773212863cebaf55a7302875914f2f33e337699e Mon Sep 17 00:00:00 2001 From: Alex Alecu Date: Wed, 18 Mar 2026 16:09:37 +0200 Subject: [PATCH] fix(cli): delay paste summary --- .../cli/cmd/tui/component/prompt/index.tsx | 12 ++--- .../opencode/src/kilocode/paste-summary.ts | 13 +++++ .../test/kilocode/paste-summary.test.ts | 48 +++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 packages/opencode/src/kilocode/paste-summary.ts create mode 100644 packages/opencode/test/kilocode/paste-summary.test.ts diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index 22be5ab8ec3..40b985b31a7 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -34,6 +34,7 @@ import { useToast } from "../../ui/toast" import { useKV } from "../../context/kv" import { useTextareaKeybindings } from "../textarea-keybindings" import { DialogSkill } from "../dialog-skill" +import { shouldSummarize as shouldPasteSummary } from "@/kilocode/paste-summary" export type PromptProps = { sessionID?: string @@ -981,15 +982,14 @@ export function Prompt(props: PromptProps) { } catch {} } - const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1 - if ( - (lineCount >= 3 || pastedContent.length > 150) && - !sync.data.config.experimental?.disable_paste_summary - ) { + // kilocode_change start + const summary = shouldPasteSummary(pastedContent) + if (summary.summarize && !sync.data.config.experimental?.disable_paste_summary) { event.preventDefault() - pasteText(pastedContent, `[Pasted ~${lineCount} lines]`) + pasteText(pastedContent, `[Pasted ~${summary.lines} lines]`) return } + // kilocode_change end // Force layout update and render for the pasted content setTimeout(() => { diff --git a/packages/opencode/src/kilocode/paste-summary.ts b/packages/opencode/src/kilocode/paste-summary.ts new file mode 100644 index 00000000000..7e8ec5173f7 --- /dev/null +++ b/packages/opencode/src/kilocode/paste-summary.ts @@ -0,0 +1,13 @@ +// kilocode_change - new file + +export function count(text: string) { + return (text.match(/\n/g)?.length ?? 0) + 1 +} + +export function shouldSummarize(text: string) { + const lines = count(text) + return { + lines, + summarize: lines >= 5 || text.length > 800, + } +} diff --git a/packages/opencode/test/kilocode/paste-summary.test.ts b/packages/opencode/test/kilocode/paste-summary.test.ts new file mode 100644 index 00000000000..8cd0d18ca84 --- /dev/null +++ b/packages/opencode/test/kilocode/paste-summary.test.ts @@ -0,0 +1,48 @@ +import { describe, expect, it } from "bun:test" +import { shouldSummarize } from "../../src/kilocode/paste-summary" + +describe("paste-summary", () => { + it("does not summarize 4 lines", () => { + const text = Array.from({ length: 4 }, (_, i) => `line ${i + 1}`).join("\n") + expect(shouldSummarize(text)).toEqual({ lines: 4, summarize: false }) + }) + + it("summarizes 5 lines", () => { + const text = Array.from({ length: 5 }, (_, i) => `line ${i + 1}`).join("\n") + expect(shouldSummarize(text)).toEqual({ lines: 5, summarize: true }) + }) + + it("does not summarize 800 chars", () => { + const text = "a".repeat(800) + expect(shouldSummarize(text)).toEqual({ lines: 1, summarize: false }) + }) + + it("summarizes 801 chars", () => { + const text = "a".repeat(801) + expect(shouldSummarize(text)).toEqual({ lines: 1, summarize: true }) + }) + + it("summarizes when either threshold triggers independently", () => { + const lines = Array.from({ length: 5 }, () => "a").join("\n") + const chars = "b".repeat(801) + + expect(shouldSummarize(lines)).toEqual({ lines: 5, summarize: true }) + expect(shouldSummarize(chars)).toEqual({ lines: 1, summarize: true }) + }) + + it("keeps 4 lines and 780 chars expanded", () => { + const row = "a".repeat(194) + const text = Array.from({ length: 4 }, () => row).join("\n") + + expect(text.length).toBe(779) + expect(shouldSummarize(text)).toEqual({ lines: 4, summarize: false }) + }) + + it("summarizes 5 lines and 500 chars", () => { + const row = "b".repeat(96) + const text = Array.from({ length: 5 }, () => row).join("\n") + + expect(text.length).toBe(484) + expect(shouldSummarize(text)).toEqual({ lines: 5, summarize: true }) + }) +})