Merged
Conversation
PreCompact JSON出力対応(Step 1)として以下を実装: - PreCompactOutput構造体を追加(Common JSON Fieldsのみ、SessionEndパターン) - PreCompactHookにMatcherフィールドを追加(manual/auto対応) - TestPreCompactOutput_JSONSerializationを追加(round-trip、omitempty検証)
PreCompact JSON出力対応(Step 2)として以下を実装: - validatePreCompactOutput関数を追加(JSON Schema検証、SessionEndパターン) - checkUnsupportedFieldsPreCompact関数を追加(未サポートフィールド警告) - TestValidatePreCompactOutput追加(型チェック、有効/無効ケース)
Step 3の実装完了: - シグネチャ変更: error → (*ActionOutput, error) - SessionEndパターン踏襲(Common JSON Fields、fail-safe設計) - commandアクション: JSON解析、checkUnsupportedFieldsPreCompact呼び出し - outputアクション: メッセージ→SystemMessageマッピング、exit_status警告 - テスト追加: TestExecutePreCompactAction_TypeOutput(3ケース) - テスト追加: TestExecutePreCompactAction_TypeCommand(6ケース) - hooks.go: 一時的な修正(Step 4でexecutePreCompactHooksJSONに置き換え予定)
Step 4の実装完了: - executePreCompactHooksJSON実装(SessionEndパターン踏襲) - matcherチェック追加(manual/auto、SessionStartパターン) - matcher無効値警告(設定ミスの早期検出) - finalOutput初期化(Continue: true、fail-safe設計) - systemMessage改行連結、stopReason/suppressOutput最後勝ち - エラー処理(fail-safe: systemMessageに追加) - RunPreCompactHooks公開ラッパー追加 - runHooksのPreCompactケースをexecutePreCompactHooksJSONに委譲 - dryRunPreCompactHooksにmatcherチェック追加 - TestExecutePreCompactHooksJSON追加(7ケース、matcherフィルタリング含む) - TestExecutePreCompactHooksのnil pointer修正(t.Fatal使用)
Step 5の実装完了: - PreCompactブロック追加(SessionEndパターン踏襲) - RunPreCompactHooks呼び出し - エラー時fallback(continue: true, systemMessage) - fail-safe設計: エラー発生時もJSON出力 - JSON MarshalIndent(2-space indent) - validatePreCompactOutput呼び出し - 常にexit 0(compaction cannot be blocked)
Step 7の実装完了: - CLAUDE.md: PreCompact JSON Outputセクション追加 - SessionEndパターンと同じ構造(Common JSON Fields only) - matcher対応の説明(manual/auto) - Field Merging、Exit Code Behavior、例を記載 - README.md: PreCompactをJSON Output Eventsに移動 - JSON Output Eventsリストに追加(Notification含む) - Legacy Exit Code EventsからPreCompactを削除 - default exit_statusの説明を更新 - PreCompact Migration Note追加(exit_status無視、matcher対応)
matcher値が不正(typo等)の場合、スキップ条件でcontinueされるため 検証警告が実行されないバグを修正。検証警告をスキップ条件の前に移動。 - executePreCompactHooksJSON: 検証警告とマッチャーチェックの順序を入れ替え - dryRunPreCompactHooks: 検証警告を追加(dryrun時も同じ警告を表示)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
PreCompactフックをJSON出力形式に移行し、Claude Code公式仕様に準拠させる。SessionEndパターン(Common JSON Fieldsのみ、hookSpecificOutputなし、ブロック不可)を踏襲。
背景
cchookは当初exit codeベースでフック出力を制御していたが、Claude Code公式仕様でJSON出力形式が導入された。Phase 1(SessionStart)からPhase 9(Notification)まで段階的にJSON出力対応を完了しており、PreCompactは残りのLegacy Exit Code Eventsの一つだった。
公式ドキュメントにPreCompact用のhookSpecificOutputが記載されていないため、SessionEndパターン(Common JSON Fieldsのみ)を採用。
変更内容
types.go: PreCompactOutput構造体を追加(continue, stopReason, suppressOutput, systemMessage)types.go: PreCompactHookにMatcherフィールドを追加(manual/auto対応、SessionStartパターン)executor.go: ExecutePreCompactActionをJSON出力形式に書き換え(*ActionOutput, error返却)hooks.go: executePreCompactHooksJSON実装(matcherチェック、fail-safe設計)hooks.go: RunPreCompactHooks公開ラッパー追加、旧executePreCompactHooks削除hooks.go: dryRunPreCompactHooksにmatcherチェックと検証警告を追加utils.go: validatePreCompactOutput, checkUnsupportedFieldsPreCompact追加main.go: PreCompact JSON出力ハンドリング追加(常にexit 0)CLAUDE.md: PreCompact JSON Outputセクション追加README.md: PreCompactをJSON Output Eventsに移動、Migration Note追加設計方針
関連情報