Skip to content

Add --json-standard option for opencode/claude output formats#21

Merged
konard merged 6 commits intomainfrom
issue-20-8704d00e8b4e
Dec 9, 2025
Merged

Add --json-standard option for opencode/claude output formats#21
konard merged 6 commits intomainfrom
issue-20-8704d00e8b4e

Conversation

@konard
Copy link
Copy Markdown
Contributor

@konard konard commented Dec 8, 2025

Summary

  • Add new --json-standard CLI option with opencode (default) and claude choices
  • Implement JSON format adapters in src/json-standard/index.ts
  • Add comprehensive unit tests for both formats (17 tests)
  • Update README.md and EXAMPLES.md with documentation
  • Bump version to 0.0.9

JSON Output Standards

The agent now supports two JSON output format standards:

OpenCode Standard (default)

  • Format: Pretty-printed JSON (human-readable with indentation)
  • Event Types: step_start, step_finish, text, tool_use, error
  • Timestamps: Unix milliseconds (number)
  • Session ID: sessionID (camelCase)

Claude Standard (experimental)

  • Format: NDJSON (Newline-Delimited JSON - compact, one JSON per line)
  • Event Types: init, message, tool_use, tool_result, result
  • Timestamps: ISO 8601 strings
  • Session ID: session_id (snake_case)

Usage

# Default OpenCode format (unchanged behavior)
echo "hi" | agent

# Explicit OpenCode format
echo "hi" | agent --json-standard opencode

# Claude CLI compatible format (experimental)
echo "hi" | agent --json-standard claude

Test Plan

  • Unit tests for JSON standard module (tests/json-standard-unit.test.js)
  • Integration tests for OpenCode format (tests/json-standard-opencode.test.js)
  • Integration tests for Claude format (tests/json-standard-claude.test.js)
  • Verify --help shows new option correctly
  • Verify default behavior unchanged (opencode format)

Fixes #20

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #20
@konard konard self-assigned this Dec 8, 2025
- Add new --json-standard CLI option with 'opencode' (default) and 'claude' choices
- Implement JSON format adapters in src/json-standard/index.ts
- OpenCode format: pretty-printed JSON with step_start/step_finish/text/tool_use events
- Claude format: NDJSON with init/message/tool_use/tool_result/result events
- Add comprehensive unit tests for both formats (17 tests)
- Update README.md and EXAMPLES.md with documentation
- Bump version to 0.0.9

The Claude format is experimental and provides compatibility with Anthropic's
Claude CLI stream-json output format for use with Claude-based tools.

Fixes #20

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add --json-standard option Add --json-standard option for opencode/claude output formats Dec 9, 2025
@konard konard marked this pull request as ready for review December 9, 2025 00:01
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.162898 USD
  • Calculated by Anthropic: $3.042879 USD
  • Difference: $-1.120019 (-26.90%)
    📎 Log file uploaded as GitHub Gist (613KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit them.

Uncommitted files:

M bun.lock

Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $3.368518 USD
  • Calculated by Anthropic: $2.023933 USD
  • Difference: $-1.344585 (-39.92%)
    📎 Log file uploaded as GitHub Gist (1492KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard marked this pull request as draft December 9, 2025 00:19
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-09T00:19:38.879Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Resolved merge conflicts in src/index.js by combining changes from both branches:
- Keep hasError flag tracking from main branch (issue #22 fix)
- Keep eventHandler.output() for JSON standard formatting from our branch

The resolution ensures both error tracking and proper JSON output formatting work together.

Changes:
- Set hasError = true when session.error events occur
- Set hasError = true in catch blocks for error handling
- Use eventHandler.output() for all error output (respects --json-standard flag)
- Include new experiment scripts from main branch

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 9, 2025 00:27
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.103300 USD
  • Calculated by Anthropic: $0.649535 USD
  • Difference: $-0.453764 (-41.13%)
    📎 Log file uploaded as GitHub Gist (327KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard marked this pull request as draft December 9, 2025 00:30
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-09T00:30:42.637Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Resolved merge conflicts between:
- PR #21 (issue-20): --json-standard option for opencode/claude formats
- main branch: MCP command support and test infrastructure

Changes:
- Integrated both imports (json-standard and McpCommand)
- Updated runAgentMode to validate and pass jsonStandard parameter
- Modified runServerMode and runDirectMode to accept jsonStandard
- Maintained event handler functionality for both output formats
- Preserved command execution check from main branch refactoring

All JSON standard tests passing:
- json-standard-unit.test.js: 17 pass
- json-standard-opencode.test.js: 9 pass
- json-standard-claude.test.js: 11 pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

✅ Merge Conflict Resolved

Successfully merged main branch into issue-20 branch and resolved all conflicts.

Changes Made

Merge Resolution:

  • Integrated both imports: json-standard module and McpCommand
  • Updated runAgentMode to validate and pass jsonStandard parameter
  • Modified runServerMode and runDirectMode to accept jsonStandard parameter
  • Maintained event handler functionality for both output formats (opencode and claude)
  • Preserved command execution check from main branch refactoring

Test Results:
All JSON standard tests passing locally:

  • json-standard-unit.test.js: 17 pass
  • json-standard-opencode.test.js: 9 pass
  • json-standard-claude.test.js: 11 pass

PR Status:

  • ✅ All conflicts resolved
  • ✅ All JSON standard features working
  • ✅ Mergeable with main
  • ✅ Ready for review

The --json-standard option now works correctly alongside the new MCP command structure from main.

@konard konard marked this pull request as ready for review December 9, 2025 00:38
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $2.856975 USD
  • Calculated by Anthropic: $1.477713 USD
  • Difference: $-1.379262 (-48.28%)
    📎 Log file uploaded as GitHub Gist (731KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 2dbd9ff into main Dec 9, 2025
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.

Add --json-standard option

1 participant