fix(init): drop bd dolt push from AGENTS.md Quick Reference without a remote (#7694)
A new AGENTS.md written by bd init rendered its managed section with the HasRemote/NoPush rule, but wrote the template text around it verbatim, so the Quick Reference still listed `bd dolt push` in workspaces with no Dolt remote or declared no-push. Add EmbeddedDefaultWithOpts, sharing one omitsDoltPush predicate with the managed-section renderer, and use it for new AGENTS.md files. Managed-section bytes and hashes are unchanged; an existing AGENTS.md and a custom --agents-template are written as before. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4c473b4580
commit
21dac62a4c
9 changed files with 140 additions and 5 deletions
|
|
@ -863,6 +863,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
older bd registered. The hooks are still migrated to the SessionStart
|
||||
`bd prime --hook-json` hook; the removal lines now go to the installer's own
|
||||
output, which `--quiet` discards, instead of straight to stdout.
|
||||
- **A new `AGENTS.md` from `bd init` lists `bd dolt push` in its Quick
|
||||
Reference only when the workspace has a Dolt remote.** The managed Beads
|
||||
section already left out its push lines when no Dolt remote is configured or
|
||||
the workspace is `no-push`, but the Quick Reference above it still showed
|
||||
`bd dolt push # Push beads data to remote`. It now follows the same rule.
|
||||
`bd init` still leaves an existing `AGENTS.md` alone outside the managed
|
||||
section, and writes an `--agents-template` as given.
|
||||
- **`bd setup claude` no longer rewrites a CLAUDE.md whose beads section is
|
||||
already current.** A rerun (and `bd init`, which runs it) wrote the same
|
||||
bytes back as a new file, resetting its mode to 0644 and its mtime, and
|
||||
|
|
|
|||
|
|
@ -893,6 +893,7 @@ go_test(
|
|||
"info_kv_exclusion_test.go",
|
||||
"info_proxied_integration_test.go",
|
||||
"info_test.go",
|
||||
"init_agent_test.go",
|
||||
"init_cancel_e2e_test.go",
|
||||
"init_commit_test.go",
|
||||
"init_embedded_test.go",
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ func updateAgentFile(filename string, verbose bool, templatePath string, profile
|
|||
}
|
||||
newContent = string(data)
|
||||
} else {
|
||||
newContent = agents.EmbeddedDefault()
|
||||
newContent = agents.EmbeddedDefaultWithOpts(opts)
|
||||
}
|
||||
|
||||
// Replace the beads section with the requested profile.
|
||||
// EmbeddedDefault() ships with profile:full; swap to the requested profile
|
||||
// The embedded template ships with profile:full; swap to the requested profile
|
||||
// (which defaults to minimal). Also handles legacy markers without profile metadata.
|
||||
if strings.Contains(newContent, "BEGIN BEADS INTEGRATION") {
|
||||
if replaced, changed, err := agents.ReplaceSectionWithOpts(newContent, profile, opts); err == nil && changed {
|
||||
|
|
|
|||
79
cmd/bd/init_agent_test.go
Normal file
79
cmd/bd/init_agent_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/steveyegge/beads/internal/templates/agents"
|
||||
)
|
||||
|
||||
// TestUpdateAgentFileQuickReferenceFollowsRemote pins that a new AGENTS.md
|
||||
// written by `bd init` lists `bd dolt push` in its Quick Reference exactly
|
||||
// when its managed section does: only with a Dolt remote configured and the
|
||||
// workspace not declared no-push. A custom --agents-template is the user's
|
||||
// own text and is written as given.
|
||||
func TestUpdateAgentFileQuickReferenceFollowsRemote(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
opts agents.RenderOpts
|
||||
wantPush bool
|
||||
}{
|
||||
{name: "remote", opts: agents.RenderOpts{HasRemote: true}, wantPush: true},
|
||||
{name: "no-remote", opts: agents.RenderOpts{}, wantPush: false},
|
||||
{name: "no-push", opts: agents.RenderOpts{HasRemote: true, NoPush: true}, wantPush: false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "AGENTS.md")
|
||||
if err := updateAgentFile(path, false, "", agents.ProfileMinimal, tc.opts); err != nil {
|
||||
t.Fatalf("updateAgentFile: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", path, err)
|
||||
}
|
||||
content := string(data)
|
||||
begin := strings.Index(content, "<!-- BEGIN BEADS INTEGRATION")
|
||||
if begin < 0 {
|
||||
t.Fatalf("AGENTS.md has no managed section:\n%s", content)
|
||||
}
|
||||
if got := listsDoltPush(content[:begin]); got != tc.wantPush {
|
||||
t.Errorf("Quick Reference lists `bd dolt push` = %v, want %v", got, tc.wantPush)
|
||||
}
|
||||
if got := listsDoltPush(content[begin:]); got != tc.wantPush {
|
||||
t.Errorf("managed section lists `bd dolt push` = %v, want %v", got, tc.wantPush)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("custom-template", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
template := "# Ours\n\n```bash\nbd dolt push # our own reminder\n```\n"
|
||||
templatePath := filepath.Join(dir, "template.md")
|
||||
if err := os.WriteFile(templatePath, []byte(template), 0o644); err != nil {
|
||||
t.Fatalf("write template: %v", err)
|
||||
}
|
||||
path := filepath.Join(dir, "AGENTS.md")
|
||||
if err := updateAgentFile(path, false, templatePath, agents.ProfileMinimal, agents.RenderOpts{}); err != nil {
|
||||
t.Fatalf("updateAgentFile: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", path, err)
|
||||
}
|
||||
if string(data) != template {
|
||||
t.Errorf("custom template was not written as given:\n got: %q\nwant: %q", data, template)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// listsDoltPush reports whether any line of s is a `bd dolt push` command.
|
||||
func listsDoltPush(s string) bool {
|
||||
for _, line := range strings.Split(s, "\n") {
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "bd dolt push") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
@ -41,7 +41,6 @@ bd ready # Find available work
|
|||
bd show <id> # View issue details
|
||||
bd update <id> --claim # Claim work atomically
|
||||
bd close <id> # Complete work
|
||||
bd dolt push # Push beads data to remote
|
||||
```
|
||||
|
||||
## Non-Interactive Shell Commands
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ bd ready # Find available work
|
|||
bd show <id> # View issue details
|
||||
bd update <id> --claim # Claim work atomically
|
||||
bd close <id> # Complete work
|
||||
bd dolt push # Push beads data to remote
|
||||
```
|
||||
|
||||
## Non-Interactive Shell Commands
|
||||
|
|
|
|||
|
|
@ -12,11 +12,27 @@ var defaultTemplate string
|
|||
//go:embed defaults/beads-section.md
|
||||
var beadsSection string
|
||||
|
||||
// quickReferencePushLine is the Quick Reference entry in the AGENTS.md
|
||||
// template that tells agents to push beads data to the Dolt remote.
|
||||
const quickReferencePushLine = "bd dolt push # Push beads data to remote\n"
|
||||
|
||||
// EmbeddedDefault returns the full AGENTS.md template content.
|
||||
func EmbeddedDefault() string {
|
||||
return defaultTemplate
|
||||
}
|
||||
|
||||
// EmbeddedDefaultWithOpts returns the AGENTS.md template with the text outside
|
||||
// its managed section adjusted for opts: under the rule the managed section
|
||||
// follows, the Quick Reference leaves out "bd dolt push" when no Dolt remote is
|
||||
// configured or the workspace is declared no-push. The managed section is
|
||||
// returned as embedded; ReplaceSectionWithOpts renders it for a profile.
|
||||
func EmbeddedDefaultWithOpts(opts RenderOpts) string {
|
||||
if !opts.omitsDoltPush() {
|
||||
return defaultTemplate
|
||||
}
|
||||
return strings.ReplaceAll(defaultTemplate, "\n"+quickReferencePushLine, "\n")
|
||||
}
|
||||
|
||||
// EmbeddedBeadsSection returns the beads integration section with markers.
|
||||
// The returned string is trimmed to match the existing agentsBeadsSection behavior
|
||||
// (no trailing newline after the end marker).
|
||||
|
|
|
|||
|
|
@ -139,3 +139,30 @@ func TestGoEmbedDefaultManagedMarkerIsCurrent(t *testing.T) {
|
|||
t.Errorf("marker hash = %q, want %q", meta.Hash, CurrentHash(ProfileFull))
|
||||
}
|
||||
}
|
||||
|
||||
// TestEmbeddedDefaultWithOptsQuickReferenceFollowsRemote pins that the Quick
|
||||
// Reference bd init writes above the managed section lists `bd dolt push`
|
||||
// under the same rule as the managed section itself: only with a Dolt remote
|
||||
// configured and the workspace not declared no-push. Without it the template
|
||||
// loses exactly that line and nothing else.
|
||||
func TestEmbeddedDefaultWithOptsQuickReferenceFollowsRemote(t *testing.T) {
|
||||
if !strings.Contains(EmbeddedDefault(), "\n"+quickReferencePushLine) {
|
||||
t.Fatalf("test precondition: the template's Quick Reference no longer holds %q", quickReferencePushLine)
|
||||
}
|
||||
for _, opts := range []RenderOpts{
|
||||
{HasRemote: true},
|
||||
{},
|
||||
{HasRemote: true, NoPush: true},
|
||||
{NoPush: true},
|
||||
} {
|
||||
got := EmbeddedDefaultWithOpts(opts)
|
||||
sectionPush := strings.Contains(RenderSectionWithOpts(ProfileMinimal, opts), "bd dolt push")
|
||||
want := EmbeddedDefault()
|
||||
if !sectionPush {
|
||||
want = strings.ReplaceAll(want, "\n"+quickReferencePushLine, "\n")
|
||||
}
|
||||
if got != want {
|
||||
t.Errorf("%+v: Quick Reference lists `bd dolt push` = %v, want %v (as the managed section)", opts, strings.Contains(got, "\n"+quickReferencePushLine), sectionPush)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,13 @@ type RenderOpts struct {
|
|||
NoPush bool
|
||||
}
|
||||
|
||||
// omitsDoltPush reports whether rendered instructions leave out "bd dolt push":
|
||||
// no Dolt remote is configured, or the workspace is declared no-push. The
|
||||
// managed section and the AGENTS.md template around it share this rule.
|
||||
func (o RenderOpts) omitsDoltPush() bool {
|
||||
return !o.HasRemote || o.NoPush
|
||||
}
|
||||
|
||||
// DefaultRenderOpts returns opts that assume a remote is configured,
|
||||
// preserving backward-compatible behavior for callers that don't pass opts.
|
||||
func DefaultRenderOpts() RenderOpts {
|
||||
|
|
@ -214,7 +221,7 @@ func templateBodyWithOpts(profile Profile, opts RenderOpts) string {
|
|||
body = strings.TrimSuffix(body, "\n<!-- END BEADS INTEGRATION -->")
|
||||
}
|
||||
|
||||
if !opts.HasRemote || opts.NoPush {
|
||||
if opts.omitsDoltPush() {
|
||||
body = stripDoltPushReferences(body)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue