* fix: replace deprecated --force flag with --reinit-local in init error messages
Four error messages in init.go suggested 'bd init --force --prefix <x>'
when a workspace was already initialized. The --force flag was deprecated
in favor of --reinit-local, but the error messages were never updated.
Fixes#3684
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* test: add regression tests for GH#3684 --reinit-local in error messages
Add TestCheckExistingBeadsData_SuggestsReinitLocal with two subtests
(embedded_dolt, sqlite_db_file) that verify the 'already initialized'
error messages recommend --reinit-local instead of the deprecated --force.
Also strengthen existing guard tests (server_mode_with_dolt_dir_blocks_init,
embedded_mode_with_existing_db_blocks_init, embedded_metadata_ignores_ambient)
with GH#3684 assertions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Add staleness detection so agents and devs automatically get fresh
Linear data without retry infrastructure.
- New staleness library (internal/linear/staleness.go): WriteLastPull,
ReadLastPull, IsPullStale, IsWithinDebounce, GetStalenessInfo
- --pull-if-stale flag on bd linear sync with configurable --threshold
(default 20m) and 5-minute debounce to prevent agent loops
- bd prime auto-pulls when stale and LINEAR_API_KEY is set
- Per-session stderr warning on any bd command when data is stale
- 14 new tests covering all staleness functions
Design validated by three adversarial reviewers (architecture,
performance, agent-native). Morning storm (50 devs) = 1% of rate
limits. Scales to 500 devs safely.
Refs: PLAN.md d16, btl-seo
OAuth-only sync path (no LINEAR_API_KEY required):
- Tracker.Init() now checks for OAuth credentials first
(LINEAR_OAUTH_CLIENT_ID + LINEAR_OAUTH_CLIENT_SECRET), constructs
NewOAuthClient per team when present, and only falls back to API key
when OAuth is absent. Missing both is a clear error naming both options.
Lint fixes:
- oauth.go: add //nolint:gosec on DefaultOAuthTokenURL (G101 false
positive — URL path component, not a credential)
- oauth.go: change defer resp.Body.Close() to
defer func() { _ = resp.Body.Close() }() to satisfy errcheck
- .golangci.yml: add unparam exclusion for getLinearConfig (ctx param
kept for context propagation)
Docs/code precedence alignment:
- getLinearConfig: env vars now take precedence over config.yaml for
yaml-only keys (was reversed). Matches documented precedence:
OAuth > LINEAR_API_KEY > config file.
Tests:
- TestTrackerInitOAuthOnly: validates OAuth client construction without
API key
- TestTrackerInitNoAuthFails: validates error message when no auth
configured
The PR introduced exportIncludeMemories as a new package-level flag but
did not add it to saveAndRestoreGlobals, making test outcomes
order-dependent when export tests toggle it.
Add all six export flag globals (exportOutput, exportAll,
exportIncludeInfra, exportScrub, exportNoMemories,
exportIncludeMemories) to the savedGlobals snapshot so that
saveAndRestoreGlobals atomically covers all export state. Tests that
already call saveAndRestoreGlobals now get full isolation without manual
t.Cleanup per-global.
Addresses maintainer feedback on GH#3660.
- Format types.go (struct field alignment was off by one space)
- parseRetryAfter: use http.ParseTime for HTTP-date form (RFC 1123 /
RFC 850 / ANSI C) instead of time.Parse(time.RFC1123) — the latter
requires an exact timezone abbreviation while http.ParseTime accepts
the canonical GMT form mandated by RFC 9110 §10.2.3
- Add MaxRetryAfterDelay (300s) cap on server-provided Retry-After
delays; log a warning to stderr and clamp when the hint exceeds the cap
- Wire linear.rate_limit_floor / LINEAR_RATE_LIMIT_FLOOR through both
Tracker.Init() and getLinearClient() so the config key is functional
via `bd config set linear.rate_limit_floor <n>` and the env var
- ErrRateLimitExhausted now implements RateLimitExhausted() bool;
engine.go uses an interface check (no import cycle) to abort the
push loop immediately on quota exhaustion instead of cascading the
error across every remaining issue
- Tests: extend TestParseRetryAfter with HTTP-date future/past cases;
add TestExecute_RetryAfterCapApplied to confirm the cap path is taken
Carry forward the useful CLI dependency parsing fix from gastownhall/beads PR #3560 while excluding unrelated governance/template and Dolt subsystem changes.
blocked-by:<id> and depends-on:<id> now store a blocks dependency from the new issue to the target, while explicit blocks:<id> continues to invert direction so the target depends on the new issue.
Also reject unknown create --deps dependency types using the centralized well-known dependency type policy.
Co-authored-by: kev <kglynn@pryoninc.com>
* fix(config): refuse to write secret keys to git-tracked config.yaml
P0 security fix. bd config set for secret keys (api_key, secret, token,
password) now detects git tracking of the target config file and refuses
the write with an actionable error pointing to env var alternatives.
Adds --force-git-tracked escape hatch for tests. Updates stale template
documentation and setup guides to lead with env var approach.
* fix(config): scope secret git safety check to YAML-backed keys
Use real environment variable hints for known secret config keys and avoid blocking database-backed secret-looking keys such as notion.token.
Maintainer follow-up for PR #3652.
* fix(config): silence gosec on env var hint names
The map contains environment variable names, not secret values.
---------
Co-authored-by: matt wilkie <maphew@gmail.com>
Add OAuthTokenManager for machine-to-machine authentication using
Linear's client_credentials grant. This enables CI workers to use a
service identity (actor=application) instead of personal API keys.
Key changes:
- New OAuthTokenManager with lazy acquisition, caching, thread-safe
refresh (5-min buffer before expiry), and Invalidate() for 401 retry
- AuthMode enum (APIKey vs OAuth) on Client with appropriate header
format: API keys use "Authorization: <key>", OAuth uses "Bearer"
- NewOAuthClient() constructor and WithOAuth() option
- 401 auto-retry: invalidate token and re-acquire on first 401
- Auth precedence: LINEAR_OAUTH_CLIENT_ID/SECRET env vars >
LINEAR_API_KEY env var > bd config
- Mark oauth_client_secret as secret key (uses IsSecretKey from PR-1)
- 12 new tests covering acquisition, caching, refresh, invalidation,
error handling, thread safety, and header format
Validated against Linear sandbox: client_credentials grant works with
scope=read,write, actor=application gives bot identity, 30-day TTL.
Refs: gastownhall/beads integration charter, PLAN.md §6 PR-3
Memories (from `bd remember`) may contain sensitive agent context — API
patterns, debugging notes, credential hints. They were included in both
`bd export` and auto-export (pre-commit hook) by default, leaking
private data into git history.
Changes:
- auto-export: pass includeMemories=false to exportToFile
- bd export: flip default to exclude memories; add --include-memories
opt-in flag; --all also includes memories
- --no-memories is preserved (hidden) for backward compat but is now
the default behavior
Adds TestExportExcludesMemoriesByDefault to verify default exclusion
and that --include-memories / --all still include them.
Wisps are private/transient and must not reach git history or external
integrations. Both bd export and auto-export (pre-commit hook) included
wisps because the SearchIssues filter had Ephemeral=nil (match all).
Set filter.Ephemeral=false (persistent-only) in both export.go and
export_auto.go. The --all flag overrides to include everything.
Adds TestExportExcludesWispsByDefault to verify default exclusion and
that --all still includes wisps.
Acquires .beads/.linear-sync.lock at start of bd linear sync to
serialize concurrent invocations. Stale lock detection via PID
check. Clean release on SIGTERM via defer. Prevents duplicate
creates and conflict thrash from overlapping sync runs.
The fallback (non-embedded) path already calls s.Commit() explicitly.
Setting commandDidWrite afterward would cause PersistentPostRun to
run maybeAutoCommit again redundantly.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The "auto-importing N bytes..." message was printed before
ImportJSONLData checked whether the database was empty. When
auto-export had created issues.jsonl (the default), every subsequent
command printed the message to stderr even though the DB already had
issues and the import was a no-op. Tests using CombinedOutput() saw
the message mixed into their expected output, breaking ID parsing
and JSON deserialization.
Move the message inside the `imported > 0` branch so it only prints
when an import actually occurs.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* doctor: detect AGENTS.md / CLAUDE.md user-authored divergence
Adds CheckAgentDocDivergence to bd doctor and bd preflight. The check
flags cases where AGENTS.md and CLAUDE.md exist as independent regular
files whose content outside the BEGIN/END BEADS INTEGRATION markers has
drifted apart — a common drift mode when agents hand-edit one of the
pair without mirroring the change.
Skipped when:
- Either file is missing
- The pair is symlinked or shares an inode (hardlink)
- Normalized user-authored content matches
- Either file contains the opt-out marker
<!-- bd-doctor-divergence: ok --> (for projects that intentionally
keep distinct files for different audiences, like beads itself)
Adds the opt-out marker to AGENTS.md so the upstream beads repo, whose
AGENTS.md and CLAUDE.md serve intentionally different audiences, does
not regress its own preflight.
Closes mybd-31m.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(lint): hyphenate hardlinked to satisfy misspell linter
misspell flags 'hardlinked' as a typo for 'hardline'. Hyphenating to
'hard-linked' is a common alternate spelling and sidesteps the false
positive without changing meaning.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: CI Bot <ci@beads.test>