Reconcile local metadata.json against the authoritative server state in
shared-server/server mode. Repairs two drift cases:
1. Stale dolt_database when another server DB matches the local project_id
2. Stale/missing local project_id when the configured DB has one
Also hardens the server metadata probe:
- Escapes backticks in database names to prevent SQL injection
- Distinguishes expected probe errors (table/DB not found) from unexpected
ones (permission denied, connection failures) so reconciliation does not
act on an incomplete server inventory
Co-authored-by: Bella-Giraffety <thalia.geraghty@fiserv.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
normalizeRemoteURL() converts http:// to git+http://, which breaks Dolt
remotesapi endpoints. Stop normalizing URLs from sync.remote (user
explicitly chose the format) while keeping normalization for auto-detected
git origin URLs. Also add git+http to allowedSchemes in remotecache so
ValidateRemoteURL accepts it.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(init): refuse --force when remote has Dolt history
bd init --force in a repo whose origin has refs/dolt/data silently
skipped the bootstrap-from-remote path and then wired origin as a Dolt
remote anyway. The next write auto-pushed an orphan history, failing
with "no common ancestor". Recovery options were all destructive.
This change:
- Adds --reinit-local (named-intent replacement for --force) and
--discard-remote (explicit cross-boundary authorization).
- Routes --force to --reinit-local with a DeprecationWarning. --force
continues to work for ≥2 releases.
- Refuses bd init --force / --reinit-local when origin has
refs/dolt/data, unless --discard-remote is also passed. Exit code 10
(ExitRemoteDivergenceRefused).
- Adds stable numeric exit codes for init refusals (10/11/12).
- Adds bd init-safety documenting the full flag surface and the
destroy-token format.
- Adds an internal race-safety re-check: if remote state changes
during the TTY confirmation window, abort rather than overwrite.
- Retrofits the existing destroy-token echo at init.go:231 to not
print a copy-pasteable destructive invocation, matching the new
error-text-no-echo ADR invariant.
Adds:
- cmd/bd/init_safety.go — CheckRemoteSafety chokepoint (pure fn).
- cmd/bd/init_safety_test.go — guard matrix (13 cases) + subprocess
regression test with a synthetic refs/dolt/data fixture.
- docs/adr/0002-init-safety-invariants.md — ADR encoding the five
invariants (single-source identity, scope-bound --force, central
chokepoint, error-text-no-echo, race-safety).
- docs/RECOVERY.md — named recovery playbooks per refusal exit code.
- .github/CODEOWNERS — review ownership for init*.go pointing at the
ADR so future flags must extend the guard matrix.
Historical pattern (git log for cmd/bd/init.go): 8+ prior commits
patched individual surfaces of this class without encoding the
invariant. The guard matrix test is the structural hedge — adding a
new flag or data source is a signal to extend the table, not to add
another `&& !someFlag` at the call site.
(bd-q83)
* fix(init): satisfy lint for origin safety helpers (bd-main-nwo)
---------
Co-authored-by: matt wilkie <maphew@gmail.com>
* Fix worktree-aware config.yaml resolution
* fix: honor shared worktree config resolution
* fix(doctor-fix): resolve shared-worktree beads paths
intent(doctor-fix): review-fix-loop found that doctor --fix should keep working when a worktree uses a shared .beads directory with no local path
constraint(doctor-fix): permission fixes must still skip chmod on local symlinked .beads directories when they exist
decision(doctor-fix): centralize resolved workspace lookup in a helper and route fix handlers through it instead of rebuilding path/.beads ad hoc
* test(doctor-fix): cover shared-worktree path resolution
intent(doctor-fix): review-fix-loop needed regressions that prove fix handlers operate on the shared workspace when a worktree has no local .beads
decision(doctor-fix): cover one config-regeneration path and two file-mutation paths so future regressions fail close to the real worktree behavior
learned(doctor-fix): metadata regeneration, stale lock cleanup, and permission repair all exercised separate path assumptions inside the fix package
* test(doctor-fix): strengthen workspace validation coverage
Why:
- shared-worktree fix coverage still left validateBeadsWorkspace edge cases loosely asserted
- fix package had no direct test for resolvedWorkspaceBeadsDir local vs shared precedence
What:
- add focused tests for resolvedWorkspaceBeadsDir local/shared selection
- make validateBeadsWorkspace reject file-backed and file-symlinked .beads explicitly
Refs:
- beads-xc4
* refactor(doctor-fix): share workspace beads dir resolution
Why:
- fix package resolved local and shared .beads paths in multiple steps even though they come from the same workspace root
- permissions handling was correct but harder to follow because local/resolved values were stitched together at the call site
What:
- extract a package-local helper that returns both local and resolved .beads paths from one workspace lookup
- make Permissions reuse that helper and add direct tests for local path behavior
Refs:
- beads-rim
* fix(config): remove shared-worktree import cycle
Why:
- shared-worktree config fallback in internal/config imported internal/beads
- that pulled internal/utils back into internal/utils test setup through storage/dolt and caused PR #37 CI import cycle failures
What:
- keep worktree fallback resolution inside internal/config
- reuse the repo-scoped git-dir fallback for config.yaml discovery without importing internal/beads
Refs:
- beads-3ix
* fix(doctor): resolve database-integrity against shared worktrees
intent(doctor): keep integrity recovery from reading a nonexistent worktree-local .beads during shared-worktree repairs
decision(database-integrity): resolve config and dolt paths from resolvedWorkspaceBeadsDir while keeping bd init --force anchored to the worktree repo root
learned(shared-worktree): the server-mode guard must inspect shared config or it can silently bypass the configured database safety check
* fix(doctor): honor shared worktrees in remote-consistency
intent(doctor): keep remote reconciliation pointed at the active shared workspace state during worktree repairs
decision(remote-consistency): resolve shared-worktree config and dolt paths once before comparing SQL and CLI remotes
constraint(remote-consistency): the fixer still runs from the worktree repo path but cannot derive paths from repoPath/.beads when that directory is absent
* fix(doctor): align shared worktree resolution (beads-u8z)
* test(config): cover shared worktree config precedence (beads-7kw)
intent(config): lock down shared worktree config resolution so future fallback fixes do not silently write or read the wrong file
decision(config-tests): cover both write precedence and Initialize() local override behavior in worktree-specific tests
constraint(shared-worktree): runtime resolution can legitimately target either worktree-local or shared .beads, so the regression coverage must assert both paths explicitly
* Add worktree path coverage for beads dir resolution
* Avoid creating .beads on normal Dolt store opens
* Prefer loaded worktree config when finding project config
* test(worktree): add shared config regression coverage (beads-z65b)
intent(worktree-config): keep shared-worktree sync.remote persistence covered at both the YAML helper and CLI command layers
decision(regression-tests): pair a loaded-state config test with a bd subprocess test because the original regression crossed initialization and command execution
constraint(cmd-bd): use the repo CGO test wrapper for command coverage because raw go test ./cmd/bd requires local ICU setup outside the supported path
* fix(doctor): sweep shared-worktree resolver into remaining checks (beads-3y9p)
intent: keep this PR's worktree bugfix coherent by removing the last redirect-only doctor resolution paths
decision: route standalone doctor checks through ResolveBeadsDirForRepo and add shared-worktree regressions for locks, mq cleanup, hook migrations, and remote consistency
constraint: leave local-only semantics alone and validate with targeted doctor tests instead of broad environment-sensitive full-suite expectations
* test(worktree): strengthen resolver regression coverage (beads-i9x1)
intent(worktree-coverage): raise patch coverage for the shared-worktree resolver PR on branches introduced by this change set
decision(config-tests): cover worktree config helpers directly in internal/config so fallback and loaded-state branches stay deterministic
decision(storage-tests): exercise lazy federation credential-key initialization with one server-backed peer lifecycle instead of broader end-to-end sync flows
constraint(doctor-tests): verify tracked runtime cleanup from the resolved main repo because shared .beads lives outside the worktree root
* fix(bootstrap): persist sync remote in resolved config
intent(bootstrap): fresh worktree bootstrap should finalize the shared workspace config instead of failing on a local .beads stub
decision(config-resolution): add a targeted yaml writer for an explicit beads directory so bootstrap can reuse the resolved workspace path
constraint(worktree-config): bare-parent and shared worktree setups can expose a local .beads directory that must not shadow the canonical config.yaml during finalize
* test(config): cover worktree resolution edge paths (beads-adan)
intent(codecov): PR #3265 needed patch coverage above the Codecov complaint on config/worktree resolution changes
decision(tests): add unit coverage in existing config, doctor/fix, and credentials suites instead of broader e2e coverage
constraint(tests): keep sanitizeDBName available to nocgo typecheck because init.go calls it outside cgo-only files
* test(embedded): allow concurrent dolt status
---------
Co-authored-by: matt wilkie <maphew@gmail.com>
When dolt_mode=server is configured in metadata.json (e.g. for an
externally managed dolt sql-server), bd bootstrap was cloning to the
local .beads/dolt/ directory instead of letting the server handle the
clone. The server never discovered the database, causing bd ready to
return empty results.
Root cause: cloneFromRemote() used isEmbeddedMode() which checks
runtime globals not yet initialized during bootstrap, defaulting to
embedded mode. finalizeSyncedBootstrap() had the same issue, resetting
dolt_mode back to embedded.
Fix:
- cloneFromRemote() now uses doltserver.ResolveServerMode() which reads
metadata.json directly to determine the server lifecycle mode
- In ServerModeExternal, connects to the running server via MySQL and
executes CALL DOLT_CLONE so the server places the database in its
own data directory
- finalizeSyncedBootstrap() uses cfg.IsDoltServerMode() to preserve
the server mode from the loaded config
- Added tests for both server-mode clone routing and mode preservation
Fixes#3343
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fix(bootstrap): write metadata.json and config.yaml after sync clone
executeSyncAction created .beads/ and cloned remote Dolt data but never
wrote metadata.json or config.yaml, leaving the workspace in a broken
state where bd status, bd where, and bd dolt push all failed.
Adds finalizeSyncedBootstrap helper that runs after cloneFromRemote and
mirrors what init does: save cfg as metadata.json, create the config.yaml
template, and persist sync.remote. The helper is idempotent so bootstrap
retries remain safe.
Fixesgastownhall/gascity#561
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
* fix(workspace): align resolved workspace messaging and config lookup
intent(workspace): pure worktrees and external BEADS_DIR setups should work without implying a local .beads directory is required
decision(config): derive config repo roots from FindBeadsDir-backed workspace resolution instead of a local-only .beads walk
constraint(workspace-detection): keep FindBeadsDir ordering and storage behavior unchanged while making bd where the primary diagnostic hint
learned(testing): shared-server env and global .beads ignore rules can distort CGO suites, so regression coverage now normalizes those test paths
* fix(bootstrap): align no-workspace JSON wording
intent(bootstrap): machine-readable no-workspace output should match the resolved-workspace guidance used elsewhere on this branch
decision(bootstrap-json): reuse the shared workspace error helpers through a dedicated payload builder so tests can lock the JSON contract
constraint(review-loop): keep the bootstrap CLI flow unchanged outside the no-workspace JSON branch while adding a focused regression test
* fix(where): allow no-workspace diagnostics without db (beads-9f74-5l1)
intent(where): no-workspace guidance should point to a command that actually runs when workspace resolution fails
decision(startup): treat top-level where as a no-db command so it reaches its own handler before database preflight
constraint(where-tests): subprocess mode can change the exact hint text, so the regression test locks the JSON contract and stable guidance fragments instead
* fix(bootstrap): restore bd where guidance for no-workspace output (beads-9f74-3c3)
intent(bootstrap): no-workspace bootstrap guidance should match the resolved-workspace diagnostics introduced on this branch
decision(no-workspace-hints): reuse the shared hint that mentions bd where instead of the bootstrap-specific fallback text
constraint(bootstrap-tests): cover both the payload helper and subprocess CLI path so wording regressions are caught before release
* fix(workspace): remove no-workspace .beads fallbacks (beads-9f74-gr1)
intent(workspace-resolution): finish the GH#3124 follow-up for runtime paths that still fabricated local .beads state
rejected(no-workspace-fallback): inventing ./ .beads paths outside an active workspace hid shared-worktree resolution and created stray files
decision(setup-recipes): keep built-in bd setup recipes usable without a workspace but require an active workspace for custom recipe state
constraint(worktree-support): completion and backup helpers still need to resolve shared main-repo workspaces from a git worktree
* fix(config): skip no-workspace store init for store-free commands
intent(config): review-fix-loop found no-workspace config commands should reach their own graceful paths instead of failing in PersistentPreRun
decision(config-preflight): detect store-free config subcommands before DB synthesis so config.yaml, git-backed, and diagnostic flows can run without an opened store
constraint(json-contract): keep bd config validate --json machine-readable on stdout once pre-run stops short-circuiting into low-level DB errors
learned(config-preflight): the parent config command not being in noDbCommands leaked store init into show, validate, drift, apply, and yaml-only config helpers
* fix(ci): restore init prefix normalization and formatting
intent(ci): clear the current PR failures instead of leaving the branch blocked behind known red checks
decision(init-prefix): normalize dotted prefixes before persisting issue_prefix so config, metadata.json, and Dolt database naming stay aligned for Julia-style repos
constraint(fmt-check): CI runs gofmt over the whole repo, so the existing spacing drift in internal/jira/tracker_test.go had to be cleaned up on this branch to get a green run
learned(ci): the latest main CI was already red on the same formatting file and the same embedded shard, so rebasing surfaced pre-existing blockers rather than introducing a new shard-only regression
When running `bd bootstrap` from a rig subdirectory (its own git repo)
that doesn't have a local .beads/metadata.json, the config fell back to
DefaultConfig() which always returned "beads" as the database name.
Add findParentConfig() that walks up parent directories to find the
workspace-level metadata.json, so server-mode rigs get their configured
dolt_database name instead of the default.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BootstrapFromGitRemoteWithDB previously had a silent fallback to the default "beads" database when called with an empty database name. This masked misconfigurations where FindBeadsDir resolved to the wrong .beads/ directory (lacking a configured dolt_database).
Changes:
- BootstrapFromGitRemoteWithDB now returns an error for empty or whitespace-only database names instead of silently defaulting. Callers must use cfg.GetDoltDatabase() which applies the proper fallback chain.
- BootstrapFromGitRemote explicitly passes DefaultDoltDatabase.
- Added regression tests for bootstrap plan database naming in both embedded and server modes, verifying configured names propagate through the plan and server probe.
Co-authored-by: Ryan R. Fox <ryan@ryanRfox.com>
When dolt.shared-server is enabled (via config.yaml or env var) but
cfg.DoltMode is not explicitly set to "server" in metadata.json,
detectBootstrapAction() incorrectly used the embedded database path
(embeddeddolt/) instead of the shared-server path (~/.beads/shared-server/dolt/).
This caused bd bootstrap to clone the database to the wrong location,
making it invisible to the shared Dolt server.
Fix: use cfg.IsDoltServerMode() (which checks env vars and metadata.json)
combined with doltserver.IsSharedServerMode() (which also checks config.yaml)
to determine the correct database path.
Fixes#30
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: prefer bootstrap for missing database recovery
Executed-By: beads/crew/emma
* fix: align doctor recovery guidance with bootstrap
Executed-By: beads/crew/emma
* fix: let bootstrap recover missing server databases
Executed-By: beads/crew/emma
* fix: bootstrap missing server databases safely
Executed-By: beads/crew/emma
* fix: fail closed on bootstrap server probe errors
Executed-By: beads/crew/emma
* fix: honor runtime server config in bootstrap
Executed-By: beads/crew/emma
* docs: soften bootstrap-first recovery wording
Executed-By: beads/crew/emma
* fix: report resolved bootstrap server port
Executed-By: beads/crew/emma
* fix: repair test failures from build tag mismatch and mode detection
Three issues causing CI failures on macOS and Ubuntu:
1. detectBootstrapAction used isEmbeddedMode() (global state) to choose
the database path, but tests set cfg.DoltMode without updating the
global serverMode flag. Switch to cfg.GetDoltMode() so the detection
logic respects the config object passed by the caller.
2. TestDetectBootstrapAction_NoneWhenDatabaseExists created a "dolt"
directory but default (embedded) config looks for "embeddeddolt".
Fix the test to create the correct directory.
3. embeddeddolt/slots.go and new_methods_test.go used //go:build
embeddeddolt tag while all other files in the package use cgo,
causing interface satisfaction failures. Also fix undefined
isEmbeddedDolt reference (should be isEmbeddedMode()).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Executed-By: beads/crew/emma
---------
Co-authored-by: mayor <thalia.geraghty@fiserv.com>
Co-authored-by: beads/crew/emma <steve.yegge@gmail.com>
bd bootstrap failed in a fresh second clone even when the origin already
had refs/dolt/data. The command required .beads to pre-exist, exiting
with 'No .beads directory found' before ever probing the remote.
Root cause: bootstrap.go called beads.FindBeadsDir() and exited at
line 48-62 when it returned empty, before detectBootstrapAction() could
run its remote detection logic (lines 132-142).
Fix: When .beads doesn't exist, probe the git remote for refs/dolt/data
before giving up. If remote has Beads data, synthesize the theoretical
.beads path and proceed with the sync plan. Actual .beads directory
creation is deferred to executeSyncAction to preserve --dry-run semantics.
Design decisions per council review:
- No filesystem writes during plan generation (--dry-run safe)
- No config.yaml generation needed (Dolt clone carries config)
- .beads created with 0750 permissions in executeSyncAction only
- Existing bootstrap behavior for all other scenarios unchanged
Tests added:
- Fresh clone with remote data: detects refs/dolt/data, produces sync plan
- Fresh clone without remote data: exits cleanly, no .beads created
- Existing .beads directory: normal flow unaffected
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When running `bd bootstrap` in a fresh clone, probe origin for
refs/dolt/data and automatically clone the existing beads database
instead of creating unrelated state. `bd init` warns if the ref
exists and suggests using `bd bootstrap` instead.
Fixes#2580
Make bootstrap actually run init, restore, and sync operations rather than
just printing manual commands. Adds confirmation prompt, proper error handling,
and tests for action detection logic.
Cherry-picked from PR #2516.
Co-authored-by: Melsov Yernur <MelsovCOZY@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>