Skip to content

feat: TUI polish (truncation, expanded/collapsed, in-flight paths, render cache)#7

Merged
code-yeongyu merged 16 commits into
mainfrom
feat/tui-polish
May 10, 2026
Merged

feat: TUI polish (truncation, expanded/collapsed, in-flight paths, render cache)#7
code-yeongyu merged 16 commits into
mainfrom
feat/tui-polish

Conversation

@code-yeongyu
Copy link
Copy Markdown
Owner

@code-yeongyu code-yeongyu commented May 10, 2026

Summary

Atomic TDD commits implementing 7 TUI improvements:

  1. truncatePreview helper with head/tail strategy + PATCH_PREVIEW_MAX_* constants
  2. displayPath cwd-relative formatting
  3. formatPatchPreview collapsed (header-only) vs expanded (with diff) modes — backward compat preserved via optional defaults
  4. formatInFlightCallText for in-flight renderCall labels (path extraction + count)
  5. argsComplete fallback to "Patching" placeholder during streaming
  6. per-toolCallId render state cache + clearApplyPatchRenderState
  7. Pi renderDiff integration with safe try/catch fallback to themed manual rendering

Backward compatibility

  • All previously-existing function signatures preserved via optional parameters with defaults
  • Tool wire format unchanged (name, description, parameters schema, freeform Lark grammar)
  • Existing 18 tests pass without modification

Tests

  • Existing 18 tests pass unchanged
  • New test/render.test.ts (13 tests) covering: truncatePreview, displayPath, formatPatchPreview collapsed/expanded, formatInFlightCallText, render state cache, renderResult collapsed/multi-file/truncation, renderCall argsComplete/paths
  • Total: 31 passing

Verification

  • npm run check: clean
  • npm test: 31/31 green

Commits (atomic TDD)

(list will be auto-shown in PR)

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/index.ts">

<violation number="1" location="src/index.ts:101">
P2: Render-state caching is unbounded and retains full patch strings per tool call, which can cause memory growth during long sessions.</violation>

<violation number="2" location="src/index.ts:331">
P2: `truncatePreview` can duplicate lines for short-but-very-long diffs because head/tail slices overlap. This produces confusing previews and inaccurate truncation output.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/index.ts Outdated
Comment on lines +331 to +332
const head = lines.slice(0, PATCH_PREVIEW_HEAD_LINES);
const tail = lines.slice(-PATCH_PREVIEW_TAIL_LINES);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: truncatePreview can duplicate lines for short-but-very-long diffs because head/tail slices overlap. This produces confusing previews and inaccurate truncation output.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/index.ts, line 331:

<comment>`truncatePreview` can duplicate lines for short-but-very-long diffs because head/tail slices overlap. This produces confusing previews and inaccurate truncation output.</comment>

<file context>
@@ -275,16 +309,48 @@ function formatPatchOperation(operation: ApplyPatchOperation): string {
+	}
+
+	const lines = text.split("\n");
+	const head = lines.slice(0, PATCH_PREVIEW_HEAD_LINES);
+	const tail = lines.slice(-PATCH_PREVIEW_TAIL_LINES);
+	let preview = [...head, "…", ...tail].join("\n");
</file context>
Suggested change
const head = lines.slice(0, PATCH_PREVIEW_HEAD_LINES);
const tail = lines.slice(-PATCH_PREVIEW_TAIL_LINES);
const headCount = Math.min(PATCH_PREVIEW_HEAD_LINES, Math.ceil(lines.length / 2));
const tailStart = Math.max(headCount, lines.length - PATCH_PREVIEW_TAIL_LINES);
const head = lines.slice(0, headCount);
const tail = lines.slice(tailStart);

Comment thread src/index.ts
export const PATCH_PREVIEW_MAX_CHARS = 4000;
const PATCH_PREVIEW_HEAD_LINES = 8;
const PATCH_PREVIEW_TAIL_LINES = 8;
const applyPatchRenderStates = new Map<string, ApplyPatchRenderState>();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Render-state caching is unbounded and retains full patch strings per tool call, which can cause memory growth during long sessions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/index.ts, line 101:

<comment>Render-state caching is unbounded and retains full patch strings per tool call, which can cause memory growth during long sessions.</comment>

<file context>
@@ -86,6 +94,11 @@ type ApplyPatchTheme = {
+export const PATCH_PREVIEW_MAX_CHARS = 4000;
+const PATCH_PREVIEW_HEAD_LINES = 8;
+const PATCH_PREVIEW_TAIL_LINES = 8;
+const applyPatchRenderStates = new Map<string, ApplyPatchRenderState>();
 
 function normalizeApplyPatchArguments(args: unknown): ApplyPatchParams {
</file context>

@code-yeongyu code-yeongyu force-pushed the feat/tui-polish branch 2 times, most recently from 8c71148 to 3333dc0 Compare May 10, 2026 05:46
@code-yeongyu code-yeongyu merged commit ff11344 into main May 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant