Skip to content

Conversation

@PeterDaveHello
Copy link
Contributor

Summary

  • Add explicit schema versioning and unified event types for CLI JSON output
  • Improve automation integration stability with --json/--json-io modes

Schema v1.0.0 Features

Output Messages

All JSON output messages now include:

  • schemaVersion: Version identifier ("1.0.0") for automation compatibility
  • messageId: Unique identifier for message tracking (format: cli-{ts}-{hash} or ext-{ts}-{hash})
  • event: Unified event type for semantic categorization
    • system.* - System events (welcome, error, ready, empty)
    • user.* - User events (message, approval)
    • assistant.* - Assistant events (message, reasoning, completion)
    • tool.* - Tool events (request, output)
    • api.* - API events (request_started, request_completed, request_failed)
    • task.* - Task events (resumed, completed, checkpoint)
    • context.* - Context events (condensed, truncated)
  • status: Message completion status (partial | complete)

Input Messages

Supports both versioned (v1.0.0) and legacy formats:

Versioned format:

{"schemaVersion": "1.0.0", "type": "user_input", "content": "hello"}
{"schemaVersion": "1.0.0", "type": "approval"}
{"schemaVersion": "1.0.0", "type": "rejection", "content": "reason"}
{"schemaVersion": "1.0.0", "type": "abort"}
{"schemaVersion": "1.0.0", "type": "response", "response": "retry_clicked"}

Legacy format (still supported):

{"type": "askResponse", "text": "hello"}
{"type": "respondToApproval", "approved": true}
{"type": "cancelTask"}

Implementation

New Files

  • packages/core-schemas/src/messages/events.ts - Event types and mapping functions
  • packages/core-schemas/src/messages/output.ts - Output message schemas
  • packages/core-schemas/src/messages/input.ts - Input message schemas (discriminated union)
  • cli/src/ui/utils/eventMapper.ts - CLI event mapping utilities
  • cli/src/ui/utils/messageId.ts - Message ID generation (streaming-stable)

Key Design Decisions

  1. Backward Compatibility

    • Output: .passthrough() preserves all original fields
    • Input: Dual handler for versioned + legacy formats
    • Legacy messages log deprecation warning but work normally
  2. Event Mapping Correctness

    • user_feedbackuser.message (not assistant)
    • command_output ask → tool.request (not output)
    • command_output say → tool.output
  3. Streaming Stability

    • messageId uses stable properties (type, ask/say, timestamp)
    • Does NOT use text content (which changes during streaming)
    • Same messageId for partial/complete updates
  4. Special Response Types

    • retry_clicked - Payment/model error retry
    • objectResponse - Multi-file diff selection
    • Handled via discriminated union with required response field

Test Coverage

  • ✅ 2025+ tests pass
  • ✅ Event mapper tests (170 lines) - All event mappings
  • ✅ Message ID tests (129 lines) - Streaming stability
  • ✅ JSON output tests (updated) - v1.0.0 fields validation
  • ✅ Stdin handler tests (256 lines) - Versioned + legacy formats, images, response types

Test Plan

  • Type check passes
  • All CLI tests pass (2025 tests)
  • Build succeeds
  • Backward compatibility verified (legacy format works)
  • Event mappings tested (user_feedback, command_output)
  • Special responses tested (retry_clicked, objectResponse)

@changeset-bot
Copy link

changeset-bot bot commented Jan 17, 2026

🦋 Changeset detected

Latest commit: 2507cfa

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

This PR includes changesets to release 3 packages
Name Type
@kilocode/cli Minor
@kilocode/core-schemas Minor
kilo-code 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

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41f5b1fb09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@PeterDaveHello
Copy link
Contributor Author

cc #5107 #5173 for CI issue.

Add explicit schema versioning and unified event types for CLI JSON output,
improving automation integration stability.

Output schema v1.0.0 adds:
- schemaVersion: Version identifier for automation compatibility
- messageId: Unique identifier for message tracking
- event: Unified event type (system.*, user.*, assistant.*, tool.*, api.*, task.*, context.*)
- status: Message completion status (partial/complete)

Input schema supports both versioned (v1.0.0) and legacy formats for backward compatibility:
- user_input, approval, rejection, abort, response message types
- Legacy format continues to work without changes

New files:
- packages/core-schemas/src/messages/events.ts - Event types and mapping functions
- packages/core-schemas/src/messages/output.ts - Output message schemas
- packages/core-schemas/src/messages/input.ts - Input message schemas
- cli/src/ui/utils/eventMapper.ts - CLI event mapping utilities
- cli/src/ui/utils/messageId.ts - Message ID generation
@PeterDaveHello PeterDaveHello force-pushed the feat/cli-json-schema-contract branch from 41f5b1f to 2507cfa Compare January 17, 2026 23:08
@PeterDaveHello
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2507cfa73f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +107 to +111
export function mapAskToEvent(ask: string): OutputEvent {
switch (ask) {
case "followup":
return "user.approval"
case "tool":

Choose a reason for hiding this comment

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

P2 Badge Map followup asks to user.message

The new mapping returns user.approval for followup asks, but followups are clarifying questions that expect free‑form user text, not a yes/no decision. For example, AskFollowupQuestionTool calls task.ask("followup") and consumes the returned text to produce the tool result, so an automation client that uses event to decide response type will likely send an approval instead of a message, yielding an empty follow‑up answer. This misclassification can break follow‑up flows; mapping followup to user.message aligns with how the response is used.

Useful? React with 👍 / 👎.

@marius-kilocode marius-kilocode added the CLI Kilo Code CLI label Jan 18, 2026
@marius-kilocode
Copy link
Collaborator

marius-kilocode commented Jan 18, 2026

Thanks @PeterDaveHello, however I tend to the opinion that we don't want to introduce versioning for the --json API at this point. We planned to use it mostly internally.

@marius-kilocode
Copy link
Collaborator

Closing for now, maybe we reiterate later on this.

@PeterDaveHello
Copy link
Contributor Author

Sure, no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI Kilo Code CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants