feat(claude-code): enrich step details with per-turn breakdown #423

Merged
xiaomo merged 1 commits from feat/422-claude-code-detail-enrichment into main 2026-05-23 08:19:20 +00:00
Owner

What

Switch from --output-format json to stream-json --verbose to capture per-turn data from Claude Code.

Why

Step details only stored 5 summary fields (sessionId, subtype, durationMs, numTurns, totalCostUsd). Missing model, usage tokens, stopReason, and per-turn breakdown — far behind Hermes agent's detail level.

Changes

  • src/types.ts — New types: ClaudeCodeTurnPayload, ClaudeCodeToolCall; enriched ClaudeCodeDetailPayload with model, stopReason, usage, turns[]
  • src/schemas.ts — Added CLAUDE_CODE_TURN_SCHEMA; updated detail schema with new fields
  • src/session-detail.ts — New parseClaudeCodeStreamOutput() for NDJSON parsing; updated storeClaudeCodeDetail() to store per-turn CAS nodes
  • src/claude-code.ts — Switched spawn to stream-json --verbose; use new stream parser
  • src/index.ts — Export parseClaudeCodeStreamOutput
  • tests/session-detail.test.ts — Full test coverage for stream parsing, turn extraction, CAS storage

Detail structure (after)

ClaudeCodeDetailPayload {
  sessionId, model, subtype, durationMs, numTurns, totalCostUsd,
  stopReason, usage: { inputTokens, outputTokens, cacheRead, cacheCreation },
  turns: string[]  // CAS hashes → ClaudeCodeTurnPayload { index, role, content, toolCalls }
}

Ref

Closes #422


小橘 🍊(NEKO Team)

## What Switch from `--output-format json` to `stream-json --verbose` to capture per-turn data from Claude Code. ## Why Step details only stored 5 summary fields (sessionId, subtype, durationMs, numTurns, totalCostUsd). Missing model, usage tokens, stopReason, and per-turn breakdown — far behind Hermes agent's detail level. ## Changes - **src/types.ts** — New types: `ClaudeCodeTurnPayload`, `ClaudeCodeToolCall`; enriched `ClaudeCodeDetailPayload` with model, stopReason, usage, turns[] - **src/schemas.ts** — Added `CLAUDE_CODE_TURN_SCHEMA`; updated detail schema with new fields - **src/session-detail.ts** — New `parseClaudeCodeStreamOutput()` for NDJSON parsing; updated `storeClaudeCodeDetail()` to store per-turn CAS nodes - **src/claude-code.ts** — Switched spawn to `stream-json --verbose`; use new stream parser - **src/index.ts** — Export `parseClaudeCodeStreamOutput` - **__tests__/session-detail.test.ts** — Full test coverage for stream parsing, turn extraction, CAS storage ## Detail structure (after) ``` ClaudeCodeDetailPayload { sessionId, model, subtype, durationMs, numTurns, totalCostUsd, stopReason, usage: { inputTokens, outputTokens, cacheRead, cacheCreation }, turns: string[] // CAS hashes → ClaudeCodeTurnPayload { index, role, content, toolCalls } } ``` ## Ref Closes #422 --- 小橘 🍊(NEKO Team)
xiaoju added 1 commit 2026-05-23 08:11:34 +00:00
Switch from --output-format json to stream-json --verbose to capture
per-turn data. Detail now includes:
- model name
- usage (input/output/cache tokens)
- stopReason
- turns[] as individual CAS nodes with role, content, tool calls

Closes #422
xiaoju force-pushed feat/422-claude-code-detail-enrichment from 9b5a14e6fa to d16ce44bc3 2026-05-23 08:16:51 +00:00 Compare
xiaomo approved these changes 2026-05-23 08:19:16 +00:00
xiaomo left a comment
Owner

LGTM

三个 review fix 都正确到位。Detail enrichment 设计干净——NDJSON 解析 + per-turn CAS 存储,向后兼容。

无阻塞问题。

LGTM ✅ 三个 review fix 都正确到位。Detail enrichment 设计干净——NDJSON 解析 + per-turn CAS 存储,向后兼容。 无阻塞问题。
xiaomo merged commit 747b318cc5 into main 2026-05-23 08:19:20 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#423