Skip to content

Comments

feat: enhance decision tracking beyond PR #23 with smart truncation#25

Merged
douglaz merged 1 commit intomasterfrom
feat/smart-truncation-and-error-handling
Sep 1, 2025
Merged

feat: enhance decision tracking beyond PR #23 with smart truncation#25
douglaz merged 1 commit intomasterfrom
feat/smart-truncation-and-error-handling

Conversation

@douglaz
Copy link
Owner

@douglaz douglaz commented Sep 1, 2025

Summary

This PR builds upon PR #23's foundation by adding intelligent improvements to decision tracking and tool output handling.

What PR #23 Added

PR #23 introduced tool_name and tool_output fields to DecisionResult, providing basic tool output visibility.

What This PR Adds Beyond PR #23

1. Smart JSON-Aware Truncation

2. Error Handling for Failed Decisions

3. Improved Parameter Serialization

4. Complete Tool Output for All Actions

5. Removed Redundant Memory Storage

Changes

  • Enhanced smart truncation algorithm in src/lib.rs
  • Added error result handling for invalid action formats
  • Improved parameter display using JSON serialization
  • Complete tool output for Remember, Wait, and Explore actions
  • Updated test cases with new DecisionResult fields

Test Plan

  • Unit tests pass with enhanced DecisionResult structure
  • Smart truncation preserves JSON structure
  • Invalid actions get proper error results (no NULL)
  • All action types store meaningful output
  • No redundant memory entries created

Breaking Changes

None - backward compatible enhancements only

- Implement intelligent JSON-aware truncation that preserves structure
- Add error handling for failed decision parsing (prevents NULL results)
- Improve parameter serialization using JSON instead of Debug format
- Include complete tool output for all action types (Remember, Wait, Explore)
- Remove redundant tool_result_* memory entries (outputs only in decisions)
- Add metadata fields (_truncated, _original_size) for truncated outputs
- Recursively handle nested objects in truncation algorithm

These improvements build on PR #23's foundation by adding:
1. Smart truncation vs basic string cutting
2. Error result handling for invalid actions
3. Better parameter display format
4. Complete output tracking for all actions
@douglaz douglaz merged commit 671e128 into master Sep 1, 2025
4 checks passed
@douglaz douglaz deleted the feat/smart-truncation-and-error-handling branch September 1, 2025 16:15
douglaz added a commit that referenced this pull request Sep 1, 2025
- Attempt to parse tool text content as JSON before wrapping
- If content is valid JSON, return it directly to preserve structure
- Only fall back to simplified format for non-JSON content
- Complements PR #25's smart truncation by ensuring structured data flows cleanly

This allows tools to return complex structured data like:
{"files": [...], "stats": {...}, "metadata": {...}}

Instead of flattening everything to:
{"success": true, "content": "...stringified JSON..."}

The combination of this change with PR #25's smart truncation ensures
that structured tool outputs are preserved and intelligently truncated
throughout the entire decision tracking pipeline.
douglaz added a commit that referenced this pull request Sep 1, 2025
* feat: preserve JSON structure in MCP tool results

- Attempt to parse tool text content as JSON before wrapping
- If content is valid JSON, return it directly to preserve structure
- Only fall back to simplified format for non-JSON content
- Complements PR #25's smart truncation by ensuring structured data flows cleanly

This allows tools to return complex structured data like:
{"files": [...], "stats": {...}, "metadata": {...}}

Instead of flattening everything to:
{"success": true, "content": "...stringified JSON..."}

The combination of this change with PR #25's smart truncation ensures
that structured tool outputs are preserved and intelligently truncated
throughout the entire decision tracking pipeline.

* feat: add debug logging for non-JSON tool results

Log a debug message when tool results fall back to simplified format,
showing a preview of the content. This helps developers understand:
- When tools are returning plain text vs structured data
- Why certain results aren't being preserved as JSON
- What the actual content looks like (first 100 chars)
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