Files
magpie/internal/agent/claude_attribution.go
T
yetone e3e774be7a agents: Claude Code's Co-Authored-By commit signature on or off from its settings (9_bishi on X)
Claude Code's row in Agents > Settings gets a "Commit signature" On/Off menu. Off writes
Claude Code's own key attribution.commit = "" in settings.json; On takes out only what
hid it (attribution.commit "" , attribution false, includeCoAuthoredBy false), so the
default comes back. A custom attribution text is the user's own: the row shows "Your own
text", is disabled, and is never written over. attribution.pr is untouched.
Route POST /api/settings/claude-attribution, S2 in the settings parity test.

Run at the rebased head (on 967fefcec), on mote with a private GOCACHE:
- go test ./internal/agent -run Claude, ./internal/cli -run Parity|Settings,
  ./internal/gui -run Budget|Script: ok
- GUI claude-attribution.test.cjs + i18n-keys.test.cjs in chromium and webkit: 6/6 each
  (en and zh, fake API)
- gofmt -l clean; go vet darwin, linux (-tags nogui), windows: ok
- agent-prefs.test.cjs chromium: 5 of 28 red, identical at base 745d209dc and here
  (#6139); not from this change.
Broken by hand: Off writing "x" instead of "" turns TestClaudeAttributionSet red.
Not tried: a real Claude Code making a real commit, the Windows box, the full suite
before the tag (started after it), webkit for agent-prefs.
2026-11-11 18:14:10 +08:00

72 lines
2.3 KiB
Go

package agent
import (
"fmt"
"path/filepath"
"github.com/yetone/magpie/internal/edit"
)
// Claude Code adds a Co-Authored-By trailer to the commits it makes
// (9_bishi on X wanted it off). Its own setting for that is
// attribution.commit in settings.json: unset keeps the trailer, "" hides
// it, other text replaces it; `attribution: false` hides all attribution,
// and the deprecated includeCoAuthoredBy: false does until attribution
// sets commit or pr. The pull request text (attribution.pr) is left alone.
const (
AttributionOn = "on"
AttributionOff = "off"
AttributionCustom = "custom" // the user's own trailer text: magpie never writes over it
)
func attributionPath(home string) string {
return filepath.Join(here(tuneHome(home)).claudeDir(), "settings.json")
}
// ClaudeAttribution reads whether Claude Code adds its commit trailer.
func ClaudeAttribution(home string) string {
p := attributionPath(home)
if raw, ok := edit.GetJSONRaw(p, "attribution"); ok && raw == "false" {
return AttributionOff
}
if v, ok := edit.GetJSON(p, "attribution.commit"); ok {
if v == "" {
return AttributionOff
}
return AttributionCustom
}
if raw, ok := edit.GetJSONRaw(p, "includeCoAuthoredBy"); ok && raw == "false" {
return AttributionOff
}
return AttributionOn
}
// ClaudeAttributionSet turns Claude Code's commit trailer on (Claude Code's
// own default: what hid it is taken out) or off (attribution.commit = "").
// A trailer text the user wrote is left as it is, whatever is asked.
func ClaudeAttributionSet(home string, on bool) error {
p := attributionPath(home)
cur := ClaudeAttribution(home)
if cur == AttributionCustom {
return fmt.Errorf("attribution.commit holds your own text in Claude Code's settings.json: change it there")
}
if on == (cur == AttributionOn) {
return nil
}
if !on {
return edit.SetJSON(p, edit.KV{Path: "attribution.commit", Value: ""})
}
// everything that hides the trailer is taken out: the user clicked On
var del []string
if raw, ok := edit.GetJSONRaw(p, "attribution"); ok && raw == "false" {
del = append(del, "attribution")
}
if v, ok := edit.GetJSON(p, "attribution.commit"); ok && v == "" {
del = append(del, "attribution.commit")
}
if raw, ok := edit.GetJSONRaw(p, "includeCoAuthoredBy"); ok && raw == "false" {
del = append(del, "includeCoAuthoredBy")
}
return edit.DelJSON(p, del...)
}