Skip to content

Conversation

@kiloconnect
Copy link
Contributor

@kiloconnect kiloconnect bot commented Dec 31, 2025

Problem

This PR fixes CLI formatting issues identified in the analysis where unknown message types and JSON content were not being properly handled in both CI mode and interactive terminal mode.

Solution

1. Improved JSON parsing in CI mode (jsonOutput.ts)

  • Added robust JSON parsing with proper error handling
  • Distinguishes between JSON objects/arrays (placed in metadata field) and plain text (placed in content field)
  • Added debug logging for JSON parsing failures
  • Handles edge cases: empty text, malformed JSON, nested structures, null values

2. Enhanced unknown message type handling (interactive mode)

  • ExtensionMessageRow: Now displays message text for unknown types
  • DefaultAskMessage & DefaultSayMessage: Exported and improved to format JSON content nicely
  • Added proper fallback rendering for future/unknown message types

3. Comprehensive test coverage

  • Added jsonOutput.test.ts with 50+ test cases covering:
    • Valid JSON parsing (objects, arrays, nested structures)
    • Malformed JSON handling
    • Empty/undefined/null values
    • Mixed content scenarios
    • Unknown message types
  • Added UnknownMessageType.test.tsx with 30+ test cases covering:
    • Unknown root message types
    • Unknown ask/say subtypes
    • Edge cases with images, partial flags, markdown
    • Error boundary integration

Edge Cases Handled

  • Unknown message types with various content structures
  • JSON content in different message fields (text, content blocks)
  • Mixed content (JSON + regular text)
  • Malformed JSON
  • Empty messages
  • Nested JSON structures
  • Arrays vs objects
  • Null/undefined values
  • Markdown and code fence content

Testing

  • 80+ comprehensive test cases added
  • Tests will run in CI
  • All existing tests should continue to pass

Backward Compatibility

  • All existing message types continue to work as before
  • Only affects handling of unknown/future message types and JSON parsing
  • No breaking changes

Related Issue

Fixes the CLI formatting issue identified in the earlier analysis.

Checklist

  • Test-driven development: Tests written first
  • All edge cases covered in tests
  • Backward compatibility maintained
  • Changeset created
  • Code reviewed via git diff
  • No unintended side effects identified

- Add robust JSON parsing in CI mode with proper error handling
- Distinguish between JSON objects/arrays (metadata) and plain text (content)
- Enhance unknown message type handling in interactive mode
- Add comprehensive test coverage (80+ test cases)
- Handle edge cases: malformed JSON, empty values, nested structures
- Ensure backward compatibility with existing message types
@changeset-bot
Copy link

changeset-bot bot commented Dec 31, 2025

🦋 Changeset detected

Latest commit: 0fbe56f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

// Try to parse JSON content for better display
let displayContent = message.text || `Unknown say type: ${message.say}`

// If text looks like JSON, try to format it nicely
Copy link
Contributor Author

Choose a reason for hiding this comment

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

⚠️ WARNING: Operator precedence issue - missing parentheses

This condition is inconsistent with AskMessageRouter.tsx line 34 which correctly uses parentheses. Due to operator precedence (&& binds tighter than ||), this evaluates as (message.text && message.text.trim().startsWith("{")) || message.text?.trim().startsWith("[") which happens to work but is harder to read and maintain.

Suggested change
// If text looks like JSON, try to format it nicely
if (message.text && (message.text.trim().startsWith("{") || message.text.trim().startsWith("["))) {

@kiloconnect
Copy link
Contributor Author

kiloconnect bot commented Dec 31, 2025

⚠️ 1 Issue Found

Severity Issue Location
WARNING Operator precedence issue - missing parentheses for consistency with AskMessageRouter.tsx cli/src/ui/messages/extension/SayMessageRouter.tsx:39

Recommendation: Address the warning before merge for code consistency.

Review Details (7 files)

Files reviewed:

  • .changeset/cli-formatting-fix.md (new file - changeset)
  • cli/src/ui/messages/extension/AskMessageRouter.tsx (1 issue pattern reference)
  • cli/src/ui/messages/extension/ExtensionMessageRow.tsx (no issues)
  • cli/src/ui/messages/extension/SayMessageRouter.tsx (1 issue)
  • cli/src/ui/messages/extension/__tests__/UnknownMessageType.test.tsx (new test file)
  • cli/src/ui/utils/__tests__/jsonOutput.test.ts (new test file)
  • cli/src/ui/utils/jsonOutput.ts (no issues)

Checked: Security, bugs, code consistency, error handling

Fix these issues in Kilo Cloud

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