Skip to content

Commit 088feea

Browse files
committed
feat: output_format: text でcommand出力をテキストとして扱う機能を追加
PreToolUse, PostToolUse, SessionStart, SessionEnd で output_format: text を設定すると、commandの非JSON出力を正常扱いする。 - PreToolUse: テキスト出力を permissionDecisionReason に格納、allow扱い - PostToolUse: テキスト出力を additionalContext に格納、allow扱い - SessionStart: テキスト出力を additionalContext に格納 - SessionEnd: テキスト出力を systemMessage に格納 非ゼロ終了コード時は既存のfail-safe挙動を維持。 未設定時は既存のJSON出力期待挙動を維持(後方互換性あり)。
1 parent f80cc11 commit 088feea

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

executor.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,15 @@ func (e *ActionExecutor) ExecuteSessionStartAction(action Action, input *Session
698698
}, nil
699699
}
700700

701+
// output_format: text - treat command output as plain text (no JSON parsing)
702+
if action.OutputFormat != nil && *action.OutputFormat == "text" {
703+
return &ActionOutput{
704+
Continue: true,
705+
HookEventName: "SessionStart",
706+
AdditionalContext: strings.TrimSpace(stdout),
707+
}, nil
708+
}
709+
701710
// Parse JSON output
702711
var cmdOutput SessionStartOutput
703712
if err := json.Unmarshal([]byte(stdout), &cmdOutput); err != nil {
@@ -966,6 +975,14 @@ func (e *ActionExecutor) ExecuteSessionEndAction(action Action, input *SessionEn
966975
}, nil
967976
}
968977

978+
// output_format: text - treat command output as plain text (no JSON parsing)
979+
if action.OutputFormat != nil && *action.OutputFormat == "text" {
980+
return &ActionOutput{
981+
Continue: true,
982+
SystemMessage: strings.TrimSpace(stdout),
983+
}, nil
984+
}
985+
969986
// Parse JSON output (SessionEndOutput has Common JSON Fields only)
970987
var cmdOutput SessionEndOutput
971988
if err := json.Unmarshal([]byte(stdout), &cmdOutput); err != nil {

executor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,7 @@ func TestExecuteSessionStartAction_OutputFormatText(t *testing.T) {
28752875
stderr: "command error",
28762876
exitCode: 1,
28772877
wantContinue: false,
2878-
wantHookEventName: "SessionStart",
2878+
wantHookEventName: "", // non-zero exit uses existing behavior (HookEventName not set)
28792879
},
28802880
}
28812881

executor_tool_permission.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ func (e *ActionExecutor) ExecutePreToolUseAction(action Action, input *PreToolUs
3737
return nil, nil
3838
}
3939

40+
// output_format: text - treat command output as plain text (no JSON parsing)
41+
if action.OutputFormat != nil && *action.OutputFormat == "text" {
42+
return &ActionOutput{
43+
Continue: true,
44+
PermissionDecision: "allow",
45+
PermissionDecisionReason: strings.TrimSpace(stdout),
46+
HookEventName: "PreToolUse",
47+
}, nil
48+
}
49+
4050
// Parse JSON output
4151
var cmdOutput PreToolUseOutput
4252
if err := json.Unmarshal([]byte(stdout), &cmdOutput); err != nil {
@@ -244,6 +254,16 @@ func (e *ActionExecutor) ExecutePostToolUseAction(action Action, input *PostTool
244254
}, nil
245255
}
246256

257+
// output_format: text - treat command output as plain text (no JSON parsing)
258+
if action.OutputFormat != nil && *action.OutputFormat == "text" {
259+
return &ActionOutput{
260+
Continue: true,
261+
Decision: "", // Allow tool result
262+
AdditionalContext: strings.TrimSpace(stdout),
263+
HookEventName: "PostToolUse",
264+
}, nil
265+
}
266+
247267
// Parse JSON output (PostToolUseOutput with hookSpecificOutput)
248268
var cmdOutput PostToolUseOutput
249269
if err := json.Unmarshal([]byte(stdout), &cmdOutput); err != nil {

0 commit comments

Comments
 (0)