-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(cli): add JSON schema contract (v1.0.0) for --json/--json-io modes #5174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): add JSON schema contract (v1.0.0) for --json/--json-io modes #5174
Conversation
🦋 Changeset detectedLatest commit: 2507cfa The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
There was a problem hiding this 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".
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
41f5b1f to
2507cfa
Compare
|
@codex review |
There was a problem hiding this 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".
| export function mapAskToEvent(ask: string): OutputEvent { | ||
| switch (ask) { | ||
| case "followup": | ||
| return "user.approval" | ||
| case "tool": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
|
Thanks @PeterDaveHello, however I tend to the opinion that we don't want to introduce versioning for the |
|
Closing for now, maybe we reiterate later on this. |
|
Sure, no problem. |
Summary
Schema v1.0.0 Features
Output Messages
All JSON output messages now include:
"1.0.0") for automation compatibilitycli-{ts}-{hash}orext-{ts}-{hash})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)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 functionspackages/core-schemas/src/messages/output.ts- Output message schemaspackages/core-schemas/src/messages/input.ts- Input message schemas (discriminated union)cli/src/ui/utils/eventMapper.ts- CLI event mapping utilitiescli/src/ui/utils/messageId.ts- Message ID generation (streaming-stable)Key Design Decisions
Backward Compatibility
.passthrough()preserves all original fieldsEvent Mapping Correctness
user_feedback→user.message(not assistant)command_outputask →tool.request(not output)command_outputsay →tool.outputStreaming Stability
messageIduses stable properties (type, ask/say, timestamp)Special Response Types
retry_clicked- Payment/model error retryobjectResponse- Multi-file diff selectionresponsefieldTest Coverage
Test Plan