Skip to content

feat: add tool output truncation to prevent token overflow#625

Merged
FL4TLiN3 merged 3 commits intomainfrom
feat/tool-output-truncation
Feb 25, 2026
Merged

feat: add tool output truncation to prevent token overflow#625
FL4TLiN3 merged 3 commits intomainfrom
feat/tool-output-truncation

Conversation

@FL4TLiN3
Copy link
Contributor

Summary

  • Add truncateText() utility in @perstack/core with 30K char limit, middle-truncation (80/20 head/tail split)
  • Truncate outputs in base skill tools: exec, readTextFile, writeTextFile, editTextFile
  • Add runtime catch-all truncation for MCP tool TextPart results in resolving-tool-result.ts
  • Prevents context window overflow from large tool outputs (e.g. git log --all --numstat producing 220K tokens)

Test plan

  • Unit tests for truncateText() — edge cases, 80/20 split, custom limits
  • Unit tests for each base skill tool — verify truncation of large outputs
  • Unit test for runtime catch-all — verify TextPart truncation
  • bun run typecheck passes
  • bun run test passes
  • bun run build passes
  • E2E tests

🤖 Generated with Claude Code

FL4TLiN3 and others added 2 commits February 25, 2026 06:05
Base skill tools (exec, readTextFile, writeTextFile, editTextFile) now
truncate outputs to 30K chars with middle-truncation (80/20 head/tail).
Runtime catch-all truncates MCP tool TextPart results. Prevents context
window overflow from large tool outputs like `git log --all --numstat`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@FL4TLiN3 FL4TLiN3 enabled auto-merge (squash) February 25, 2026 06:29
@FL4TLiN3 FL4TLiN3 disabled auto-merge February 25, 2026 06:40
@FL4TLiN3 FL4TLiN3 enabled auto-merge (squash) February 25, 2026 06:52
@FL4TLiN3 FL4TLiN3 merged commit c240a17 into main Feb 25, 2026
11 checks passed
@FL4TLiN3 FL4TLiN3 mentioned this pull request Feb 25, 2026
@FL4TLiN3 FL4TLiN3 deleted the feat/tool-output-truncation branch February 25, 2026 13:37
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