Files
CLIProxyAPI/internal/translator/common/codex_commentary.go
Luis Pater cc4b9949e7 feat(claude): add opt-in visible Codex commentary with preserved replay
- Add `client.claude.show-codex-commentary` config and propagate the request-scoped display policy through HTTP and WebSocket Codex executors.
- Mirror public Codex `commentary` messages into visible Claude text blocks alongside the `cpa:commentary:v1` thinking marker in streaming and non-streaming responses without altering genuine reasoning or token accounting.
- Deduplicate only the exact adjacent mirrored commentary text block during Claude-to-Codex request replay when enabled.

Closes: #7129
2026-10-31 10:04:12 +08:00

28 lines
739 B
Go

package common
import (
"context"
"os"
)
type codexCommentaryKey struct{}
// WithVisibleCodexCommentary snapshots the display policy for one request.
func WithVisibleCodexCommentary(ctx context.Context, enabled bool) context.Context {
if ctx == nil {
ctx = context.Background()
}
return context.WithValue(ctx, codexCommentaryKey{}, enabled)
}
// VisibleCodexCommentary reports the per-request display policy. The environment
// fallback supports SDK-only users and existing deployments of the opt-in mode.
func VisibleCodexCommentary(ctx context.Context) bool {
if ctx != nil {
if enabled, ok := ctx.Value(codexCommentaryKey{}).(bool); ok {
return enabled
}
}
return os.Getenv("CPA_VISIBLE_CODEX_COMMENTARY") == "1"
}