Commit graph

101 commits

Author SHA1 Message Date
matt wilkie
cf88aa760d test: fix regression workflow gate 2026-04-24 10:55:11 -07:00
Kevin Glynn
0d4b979354
feat: JSON schema contract, bd ping, structured errors, import enhancements (#3368)
* feat: add schema_version to all --json output (beads-5uh)

All bd commands that emit --json output now include a schema_version
field so consumers (Jawnt MCP, BeadsX, gt mail, sync scripts) can
detect format changes without silently breaking.

- Object output: schema_version injected as top-level field
- Array output: wrapped as {"schema_version": 1, "items": [...]}
- Error output: schema_version added to stderr JSON

Central implementation in outputJSON() via wrapWithSchemaVersion()
means all 272 call sites get the field automatically.

Includes:
- Unit tests for wrapping logic (object, struct, slice, nil, roundtrip)
- Updated protocol contract tests for new envelope format
- New schema_version presence test across list/ready/show
- docs/JSON_SCHEMA.md documenting the field contract per command

* feat: add ready/blocked JSON contract tests (beads-clt)

bd ready --json and bd blocked --json already return full issue objects
with dependency counts and blocked_by fields. Add protocol contract
tests to pin this behavior:

- TestJSONContract_ReadyOutputHasFullObjects: verifies dependency_count,
  dependent_count fields on ready items
- TestJSONContract_BlockedOutputHasBlockedBy: verifies blocked_by and
  blocked_by_count fields on blocked items

Update docs/JSON_SCHEMA.md with blocked output contract.

* feat: add bd ping lightweight health-check command (beads-8cc)

New minimal command that confirms bd can reach its database:
1. Resolves the .beads workspace
2. Opens the store (embedded or server)
3. Runs a trivial query (SearchIssues with Limit=1)
4. Reports timing breakdown

Supports --json for structured output with resolve_ms, store_ms,
query_ms, and total_ms fields. Exit 0 on success, 1 on failure.

Registered as read-only command (no auto-push, no file writes).
Includes protocol contract test for JSON output.

* feat: structured JSON errors on stderr when --json active (beads-06n)

All fatal error functions (FatalError, FatalErrorWithHint,
FatalErrorRespectJSON, FatalErrorWithHintRespectJSON) now emit
structured JSON with schema_version when --json is active:

  {"schema_version": 1, "error": "message", "hint": "optional"}

Centralized via jsonStderrError() and jsonStdoutError() helpers.
Replaces ad-hoc json.MarshalIndent calls scattered across error
functions with a consistent, schema-versioned format.

Includes unit tests and updated protocol contract test verifying
schema_version presence in error JSON output.

* feat: enhance bd import with stdin, --dedup, --json (beads-c6i)

Enhance the existing bd import command for bulk JSONL ingest:

- Stdin support: bd import - reads JSONL from stdin for piped workflows
- --dedup flag: skips lines whose title matches an existing open issue
  (case-insensitive) to prevent duplicate creation
- --json flag: structured output with created/skipped counts and IDs

Refactored import to use runImportFromReader() for unified file/stdin
handling. Added filterDuplicatesByTitle() for dedup logic. Updated
docs/JSON_SCHEMA.md with import output contract.

Backward compatible: existing bd import [file] and --dry-run work
exactly as before.

* fix: update tests for schema_version envelope in JSON output

Three test files expected raw JSON arrays or map[string]string, which
broke when schema_version (a number) was added to the output envelope:

- ado_test.go: parse envelope with items array instead of raw []json.RawMessage
- bootstrap_embedded_test.go: use map[string]interface{} for mixed types
- where_embedded_test.go: same map[string]interface{} fix

* fix: drop array envelope wrapping to fix 200+ test failures

The schema_version envelope was wrapping arrays as
{"schema_version": N, "items": [...]} which broke every integration
test that parses --json array output. Objects (show, create, ping)
still get schema_version injected. Arrays (list, ready, blocked)
now pass through unchanged for backwards compatibility.

Also fixes: gofmt on import.go, doc-flags reference to bd import,
uses importIssuesCore result to satisfy unparam lint.

* fix: update remaining tests for schema_version number field

config_embedded_test.go, kv_embedded_test.go, config_nodb_embedded_test.go,
and show_test.go all parsed JSON output into map[string]string but
schema_version is a number. Parse to map[string]interface{} and
skip/assert schema_version appropriately.

---------

Co-authored-by: kev <kglynn@pryoninc.com>
2026-04-20 21:09:48 -07:00
coffeegoddd☕️✨
fa87dd2bdd feat: add global beads_global database for shared-server mode
Adds a project-agnostic beads_global database to shared-server mode so
clients can track issues globally across all projects on the server.

- Add EnsureGlobalDatabase() to create the DB during shared server init
- Add --global persistent flag to switch CLI commands to the global DB
- Add global_dolt_database field to metadata.json for connection info
- Seed global DB with issue_prefix="global" and sentinel project ID
- Export/import default to global-issues.jsonl with --global flag
- --global errors when not in shared-server mode (additive, no breakage)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 09:18:43 -07:00
Okano, Osamu
ef6c6e3e48
Follow up remaining runtime .beads fallbacks after GH#3124 (#3183)
* 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
2026-04-10 21:23:14 -07:00
beads/crew/emma
a22af2db56 feat: include memories in export/import round-trip
bd export now includes persistent memories (from bd remember) as JSONL
lines with {"_type":"memory","key":"...","value":"..."}. bd import
detects these records and restores them via SetConfig, making
bd export | bd import a lossless round-trip for both issues and memories.

New flags:
- bd export --no-memories: exclude memories from export

Backward compatible: JSONL without _type fields imports as before.

Co-Authored-By: Patrick Farrell <pfarrell@whamcloud.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 14:52:14 -07:00
beads/crew/emma
c36b4edb74 fix: gofmt import.go and update stale embedded dolt from_jsonl test
The from_jsonl test expected CreateIssuesWithFullOptions to not be
implemented, but it was implemented in create_issue.go. Update the
test to expect success.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 11:58:50 -07:00
Patrick Farrell
04799bc229 feat: add bd import command for incremental JSONL import
The git-tracked .beads/issues.jsonl is the portable format for moving
beads between machines via git. With the Dolt backend, bootstrap only
imports on fresh clones — there was no way to pick up new issues added
to the JSONL by another machine after git pull.

bd import reads the JSONL and upserts into the existing database:
- New issues are created
- Existing issues are updated
- Tombstones are filtered
- Labels, dependencies, comments are deduplicated

Defaults to .beads/issues.jsonl if no file argument given.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 17:32:39 -07:00
gastown/crew/george
1e1568fafa refactor(jsonl): remove JSONL plumbing — Dolt-native only (gt-vemg9q Phase 1)
Delete 21 files and gut JSONL code paths from 13 more, removing ~6,400
lines of JSONL import/export/sync/integrity infrastructure that is
superseded by Dolt git remotes for sync and portability.

Deleted: import.go, export.go, sync_helpers.go, integrity.go, hook.go,
events_export.go, stubs.go, doctor checks (jsonl_integrity, sync_divergence),
and all associated tests. Removed .beads-hooks/ legacy hook templates.

Gutted: hooks.go (now chain-only), sync.go (Dolt push only), repo.go
(Dolt push), restore.go (stubbed for dolt_history_), delete.go, init.go,
rename_prefix.go, doctor.go, doctor_fix.go (removed JSONL registrations).

Phase 2 TODOs remain for: bootstrap clone, restore via dolt_history_,
doctor recovery, create/rename flush, git-portable mode removal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: gastown/crew/george
Rig: gastown
Role: crew
2026-02-21 17:49:37 -08:00
beads/crew/wickham
4102096666 refactor: standardize error handling with FatalError wrappers (bd-qioh)
Convert ~250 instances of direct fmt.Fprintf(os.Stderr)+os.Exit(1)
to FatalError/FatalErrorWithHint/FatalErrorRespectJSON across 54 files.

Complex multi-line messages, warnings, loop-internal errors, and
JSON-branching patterns intentionally preserved where the helpers
do not fit cleanly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 16:27:09 -08:00
G. Hussain Chinoy
1d4ff862de
feat(import): add --skip-prefix-validation flag for legacy data migration
- Fixes #1949
- Allows importing issues whose IDs do not match the current issue_prefix
- Automatically enabled when --rename-on-import is used
- Added E2E test to verify prefix validation bypass
2026-02-21 14:51:58 -08:00
beads/crew/emma
ff7244b619 feat: remove JSONL sync-branch pipeline, replace with Dolt-in-Git
Remove 10,955 lines of dead code from the JSONL sync-branch pipeline,
now replaced by native Dolt push/pull via git remotes.

Deleted:
- internal/syncbranch/ (5,720 lines: worktree management, integrity checks)
- cmd/bd/deletion_tracking.go (3-way JSONL merge)
- cmd/bd/snapshot_manager.go (JSONL snapshot tracking)
- cmd/bd/doctor/sync_branch_jsonl.go (JSONL validation)
- cmd/bd/doctor/fix/sync_branch.go (sync branch repair)
- All associated test files

Preserved:
- bd export / bd import (manual tools)
- isGitRepo(), gitHasUpstream() (still have callers)
- Doctor check stubs (return StatusOK N/A)

Added:
- BootstrapFromGitRemote() for Dolt-in-Git bootstrap
- Dolt push in bd sync via store.Push()
- sync.git-remote config key
- HasRemote() on DoltStore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-18 20:13:55 -08:00
quartz
131abeffe5 Remove dead 3-way merge code and update stale comments
Remove the attemptAutoMerge stub in import.go that always returned an error,
and the entire code path that called it. When conflict markers are detected,
immediately show manual resolution guidance instead of misleading users.

Update 7 stale comments in syncbranch/worktree.go that still referenced the
removed 3-way merge engine.

Closes: bd-ihfav

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/polecats/quartz
Rig: beads
Role: polecats
2026-02-16 19:31:12 -08:00
beads/crew/emma
ff0b469154 chore: Clean up stale daemon references in code comments and doctor messages
Update comments and user-facing messages across 17 production files to
reflect the current Dolt-native architecture (no daemon):

- Gitignore template: reorganized, daemon/SQLite entries moved to legacy section
- Doctor fix messages: removed references to non-existent bd daemon commands
- Doctor federation: updated fix suggestions to use gt dolt start / server mode
- Doctor integrity: removed "daemon won't start" messaging
- Code comments: replaced daemon mode references with current architecture terms
- Lock handling: marked daemon.lock as legacy cleanup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-16 19:25:17 -08:00
beads/crew/emma
5ffd625b40 refactor: Phase 8 CLI & config cleanup - remove SQLite/daemon remnants (dolt-1s40.8)
Remove all vestiges of the SQLite backend, daemon system, and JSONL auto-sync
from CLI flags, config keys, doctor checks, init flows, and the bd backend command.

Key changes:
- Delete bd backend command and tests (backend selection obsolete)
- Remove --backend, --skip-merge-driver flags from bd init
- Remove --lock-timeout flag from main; use fixed 30s default
- Remove deprecated config keys: no-daemon, no-auto-flush, no-auto-import,
  auto-start-daemon, lock-timeout, daemon.* keys
- Remove auto-sync daemon setup wizard (Step 4) from bd init --team
- Clean up doctor checks: remove SQLite mtime divergence check, SQLite-only
  migrations, obsolete boolean config validation
- Replace all "bd init --backend dolt" references with "bd init"
- Simplify storage/dolt/open.go to always create Dolt store
- Change configfile.GetBackend() default from SQLite to Dolt
- Fix pre-existing build errors: AsVersioned removal, duplicate imports,
  missing compact/dirty stubs, signature mismatches, undefined functions

Also adds bridge/stub files for functions removed in prior phases:
- sync_bridge.go: exportToJSONL, importFromJSONL, doSyncFromMain, etc.
- import_shared.go: ImportOptions, ImportResult, importIssuesCore
- stubs.go: findJSONLPath, clearAutoFlushState, readFromGitRef
- dolt/compact.go, dolt/dirty_issues.go: no-op method stubs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-15 15:43:11 -08:00
beads/crew/emma
8e10fd09d3 refactor: remove JSONL sync layer (Phase 5)
Remove autoflush, autoimport, dirty tracking, export hashes, and JSONL
sync machinery. Dolt handles persistence natively, eliminating the need
for SQLite-to-JSONL synchronization. -11,458 lines removed across 69 files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-15 10:37:22 -08:00
beads/crew/emma
7eed8b8a1e refactor: remove tombstone/soft-delete system (Phase 4)
Remove the tombstone soft-delete mechanism across the codebase. Dolt handles
delete propagation natively, making tombstones obsolete.

Key changes:
- Remove StatusTombstone constant and all status checks
- Remove DeletedAt/DeletedBy/DeleteReason/OriginalType fields from Issue struct
- Remove resurrection mechanism (JSONL parent recovery), replace with existence checks
- Simplify schema CHECK constraint (2 clauses instead of 3)
- Remove compact_tombstone.go, resurrection.go, migrate_tombstones.go
- Remove tombstone-specific tests (resurrection, expired tombstones, migration)
- Update doctor/fix validation to skip tombstone-specific checks
- Preserve migration files for backward compatibility with existing databases
- 104 files changed, 6117 deletions, 422 insertions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-14 21:22:24 -08:00
beads/crew/emma
5102512917 refactor: remove 3-way merge engine (Phase 3)
Delete internal/merge/ (3,958 LOC), cmd/bd/merge.go, cmd/bd/resolve_conflicts.go
and all related tests. Stub callers: deletion_tracking returns no-op,
git/worktree uses local-wins, syncbranch/worktree uses remote-wins.
Make mergeDriverInstalled/installMergeDriver no-ops. Update 11 test files.

Dolt handles sync natively, eliminating the need for JSONL-level 3-way merge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-14 20:31:29 -08:00
lydia
4be0f382b7 refactor: strip dirty tracking from Storage interface (woho.4)
Phase 2 of Dolt transition: remove JSONL dirty tracking methods from
the Storage interface and all implementations.

Removed from Storage interface:
- GetDirtyIssues, GetDirtyIssueHash, ClearDirtyIssuesByID
- GetExportHash, SetExportHash, ClearAllExportHashes
- GetJSONLFileHash, SetJSONLFileHash

Removed from CompactableStorage interface:
- MarkIssueDirty

Deleted implementation files:
- internal/storage/dolt/dirty.go
- internal/storage/sqlite/dirty.go
- internal/storage/sqlite/dirty_test.go
- internal/storage/sqlite/hash.go

Cleaned up all callers in cmd/bd/, internal/compact/, internal/importer/,
internal/rpc/, and internal/storage/ packages. Removed or stubbed dead
code paths (incremental export thresholds, JSONL integrity validation).

Note: Internal SQLite markDirty() helpers that INSERT INTO dirty_issues
remain as harmless side effects - follow-up cleanup tracked separately.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 12:21:14 -08:00
lizzy
dbb93728b0 feat: delete JSONL sync layer and internal/importer (woho.3 Phase 2)
Delete the JSONL sync layer files (autoflush.go, autoimport.go, export.go,
import.go, jsonl_deprecated.go) and the internal/importer/ package as part
of the Dolt transition Phase 2.

Preserved actively-used functions in new focused files:
- config_local.go: YAML config parsing (isNoDbModeConfigured, etc.)
- jsonl_path.go: JSONL path resolution and utilities
- jsonl_bootstrap.go: Git-based auto-import on empty database
- import_engine.go: Core import engine inlined from internal/importer/

Removed all FlushManager references, markDirtyAndScheduleFlush calls,
autoImportIfNewer calls, and deleted tests for removed functionality.

38 files changed, -9,753 lines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 12:14:34 -08:00
elinor
b136996b90 refactor: delete daemon/RPC layer and internal/rpc/ package (-19,663 lines)
Phase 2 of Dolt transition (woho.2): Remove the entire daemon/RPC layer
now that all commands use direct storage access.

- Delete internal/rpc/ directory (40 files, ~11K lines)
- Delete daemon_deprecated.go stub layer
- Delete compact_rpc.go (daemon-only compact via RPC)
- Delete daemon-specific test files (delete_rpc_test.go, direct_mode_test.go,
  dual_mode_test.go, list_watch_test.go)
- Clean up remaining daemon references in ~25 source files:
  - Remove daemon RPC branches from update, create, template, markdown,
    gate_discover, mol_stale, mol_current, import, query, version, prime
  - Remove rpc.Client parameter from show_thread functions
  - Simplify info.go to always show "direct" mode
  - Simplify sync_import.go to always use inline import
  - Remove daemon status checks from staleness, migrate_dolt, rename_prefix
  - Remove unused fallbackToDirectMode function
  - Remove stale daemon comments from sync.go
- Add daemon_compat.go with --no-daemon flag (backward compat for hooks)
  and utility functions (boolToFlag, truncateString, formatUptime, progressBar)
- Fix test files: remove daemonClient cleanup blocks, update findRepliesTo/
  findReplies call signatures, remove RPC test functions
- go vet ./... passes clean

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 12:10:24 -08:00
Steve Yegge
2c4581719e
Merge pull request #1577 from turian/fix/nix-and-windows-ci
fix(ci): unbreak all CI — Nix, Windows, lint 🎉
2026-02-07 20:11:00 -08:00
beads/crew/lizzy
2bb827facb style: run gofmt across entire codebase (bd-nmk12)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 19:35:20 -08:00
Joseph Turian
307cd1b1b5 fix(ci): update vendorHash, fix pre-existing lint failures
- Update default.nix vendorHash after go.mod version change
- Suppress gosec G204 false positive in countLinesInGitHEAD (relPath
  is from filepath.Rel, not user input)
- Remove dead clearSyncBranchGitignore function (never called, always
  returned nil)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 21:23:14 -05:00
beads/crew/lydia
531f7a9f7d fix(security): path traversal in export handler and command injection in import
Adds workspace containment validation for JSONLPath in the RPC export
handler, preventing arbitrary file writes via path traversal. Removes
the shell-based runGitCommand function and refactors all callers to
use exec.Command with individual arguments, eliminating command injection
via shell metacharacters in file paths.

Fixes: dolt-test-31d, dolt-test-7fa

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 08:37:12 -08:00
beads/crew/darcy
fc27840354 feat(import): process JSONL deletion markers (bd-9qywp)
Add support for processing deletion markers during JSONL import.
When importing, detect compact deletion markers like:
{"id": "gt-123", "_deleted": true, "_deleted_at": "..."}

And call store.DeleteIssue() for those IDs, enabling proper
bidirectional sync with deletion support.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 11:15:57 -08:00
Dustin Brown
132f9d2f6f
feat(dolt): auto-commit write commands and set explicit commit authors (#1267)
* /{cmd,docs,internal}: autocommit writes in dolt backend

Executed-By: beads/crew/emma
Rig: beads
Role: crew

* /{cmd,internal}: fix commit author

Executed-By: beads/crew/emma
Rig: beads
Role: crew

* /cmd/bd: fix race condition

Executed-By: beads/crew/emma
Rig: beads
Role: crew

---------

Co-authored-by: Test <test@example.com>
2026-01-25 17:02:12 -08:00
Steve Yegge
ab61b0956b
feat(dolt): auto-commit write commands and set explicit commit authors (#1270)
Adds Dolt auto-commit functionality for write commands and sets explicit commit authors.

Includes fix for race condition in commandDidWrite (converted to atomic.Bool).

Original PR: #1267 by @coffeegoddd
Co-authored-by: Dustin Brown <dustin@dolthub.com>
2026-01-22 20:52:20 -08:00
matt wilkie
1f8a6bf84e
fix(autoimport): auto-correct deleted status to tombstone for JSONL compatibility (#1231)
* fix(autoimport): auto-correct deleted status to tombstone for JSONL compatibility (GH#1223)

This fix addresses the 'Stuck in sync diversion loop' issue where v0.48.0
encountered validation errors during JSONL import. The issue occurs when
JSONL files from older versions have issues with status='deleted' but the
current code expects status='tombstone' for deleted issues.

Changes:
- Add migration logic in parseJSONL to auto-correct 'deleted' status to 'tombstone'
- Ensure tombstones always have deleted_at timestamp set
- Add debug logging for both migration operations
- Prevents users from being stuck in sync divergence when upgrading

Fixes GH#1223: Stuck in sync diversion loop

* fix(autoimport): comprehensively fix corrupted deleted_at on non-tombstone issues (GH#1223)

The initial fix for GH#1223 only caught issues with status='deleted', but the real
data in the wild had issues with status='closed' (or other statuses) but also
had deleted_at set, which violates the validation rule.

Changes:
- Add broader migration logic: any non-tombstone issue with deleted_at should become tombstone
- Apply fix in all three JSONL parsing locations:
  - internal/autoimport/autoimport.go (parseJSONL for auto-import)
  - cmd/bd/import.go (import command)
  - cmd/bd/daemon_sync.go (daemon sync helper)
- Add comprehensive test case for corrupted closed issues with deleted_at
- Fixes the 'non-tombstone issues cannot have deleted_at timestamp' validation error
  during fresh bd init or import

Fixes GH#1223: Stuck in sync diversion loop

* Add merge driver comment to .gitattributes

* fix: properly clean up .gitattributes during bd admin reset

Fixes GH#1223 - Stuck in sync diversion loop

The removeGitattributesEntry() function was not properly cleaning up
beads-related entries from .gitattributes. It only removed lines
containing "merge=beads" but left behind:
- The comment line "# Use bd merge for beads JSONL files"
- Empty lines following removed entries

This caused .gitattributes to remain in a modified state after
bd admin reset --force, triggering sync divergence warning loop.

The fix now:
- Skips lines containing "merge=beads" (existing behavior)
- Skips beads-related comment lines
- Skips empty lines that follow removed beads entries
- Properly cleans up file so it's either empty (and gets deleted)
  or contains only non-beads content

---------

Co-authored-by: Amp <amp@example.com>
2026-01-21 21:50:38 -08:00
Test
b849f598d7 /{cmd,docs,internal}: support import export for dolt backends 2026-01-21 13:13:24 -08:00
Peter Chanthamynavong
e110632afc
fix(context): complete RepoContext migration for remaining sync files (#1114)
Follow-up to #1102 - migrates remaining git command locations to use
RepoContext API for correct repo resolution when BEADS_DIR is set.

Files migrated:
- sync_branch.go: getCurrentBranch, showSyncStatus, mergeSyncBranch
- sync_check.go: checkForcedPush
- sync_import.go: doSyncFromMain
- autoimport.go: readFromGitRef, checkGitForIssues
- status.go: getGitActivity
- import.go: attemptAutoMerge (gitRoot lookup)
- reinit_test.go: add ResetCaches for test isolation

Pattern used throughout:
- Try RepoContext first: rc.GitCmd() runs in beads repo
- Fallback to CWD for tests or repos without beads
- Graceful degradation maintains backwards compatibility
2026-01-15 19:23:07 -08:00
emma
1c1dabcfdd fix(duplicates): prefer issues with children/deps when choosing merge target (GH#1022)
The duplicate merge target selection now considers structural relationships:
1. Dependent count (children, blocked-by) - highest priority
2. Text reference count - secondary
3. Lexicographically smallest ID - tiebreaker

This fixes the bug where `bd duplicates --auto-merge` would suggest closing
an epic with 17 children instead of the empty shell duplicate.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:45:25 -08:00
emma
62e4eaf7c1 fix(sync): make snapshot protection timestamp-aware (GH#865)
The --protect-left-snapshot mechanism was protecting ALL local issues
by ID alone, ignoring timestamps. This caused newer remote changes to
be incorrectly skipped during cross-worktree sync.

Changes:
- Add BuildIDToTimestampMap() to SnapshotManager for timestamp-aware
  snapshot reading
- Change ProtectLocalExportIDs from map[string]bool to map[string]time.Time
- Add shouldProtectFromUpdate() helper that compares timestamps
- Only protect if local snapshot is newer than incoming; allow update
  if incoming is newer

This fixes data loss scenarios where:
1. Main worktree closes issue at 11:31
2. Test worktree syncs and incorrectly skips the update
3. Test worktree then pushes stale open state, overwriting mains changes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 13:27:36 -08:00
Steve Yegge
f46cc2e798 chore: remove issue ID references from comments and changelogs
Strip (bd-xxx), (gt-xxx) suffixes from code comments and changelog
entries. The descriptions remain meaningful without the ephemeral
issue IDs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 10:05:16 -08:00
Steve Yegge
9e7ccb3e03 fix: update jsonl_file_hash on import to prevent hash mismatch warnings (bd-0vtq)
The import command was only updating jsonl_content_hash, not jsonl_file_hash.
After sync imports JSONL but skips re-export (because DB matches JSONL),
the jsonl_file_hash remained stale, causing validateJSONLIntegrity() to
emit spurious "JSONL file hash mismatch" warnings on subsequent operations.

Now import also calls SetJSONLFileHash with the same hash value, keeping
both hashes in sync and eliminating the false warnings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:22:18 -08:00
Steve Yegge
92e6f4c079 refactor: remove legacy autoflush code paths (bd-xsl9)
Remove dual code paths in the autoflush system. FlushManager is now the
only code path for auto-flush operations.

Changes:
- Remove legacy globals: isDirty, needsFullExport, flushTimer
- Remove flushToJSONL() wrapper function (was backward-compat shim)
- Simplify markDirtyAndScheduleFlush/FullExport to just call FlushManager
- Update tests to use FlushManager or flushToJSONLWithState directly

FlushManager handles all flush state internally in its run() goroutine,
eliminating the need for global state. Sandbox mode and tests that do
not need flushing get a no-op when FlushManager is nil.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 01:56:19 -08:00
Steve Yegge
e67712dcd4 refactor(cmd): migrate sort.Slice to slices.SortFunc (bd-u2sc.2)
Modernize sorting code to use Go 1.21+ slices package:
- Replace sort.Slice with slices.SortFunc across 16 files
- Use cmp.Compare for orderable types (strings, ints)
- Use time.Time.Compare for time comparisons
- Use cmp.Or for multi-field sorting
- Use slices.SortStableFunc where stability matters

Benefits: cleaner 3-way comparison, slightly better performance,
modern idiomatic Go.

Part of GH#692 refactoring epic.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 15:39:55 -08:00
Ryan Snodgrass
acfdcebc0f
fix: misc improvements and dependency updates
- Update nix vendorHash after fatih/color removal
- Bump version to 0.30.7
- Add GroupID to remaining commands for proper cobra grouping
- Apply semantic color rendering to list and stale commands
- Update pre-commit hook template
2025-12-20 17:09:50 -08:00
Steve Yegge
6c060461cb feat(jsonl): add omitempty to reduce JSONL bloat (beads-399)
Add omitempty JSON tags to Issue struct fields (Description, Status,
Priority, IssueType) and SetDefaults method to apply proper defaults
when importing JSONL with omitted fields.

This reduces JSONL file size for minimal issues like notifications
by not exporting empty/default values.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 23:18:11 -08:00
Steve Yegge
f270d90f12 fix: Resolve 3 P1 bugs and add --body-file flag to bd create
- bd-06px: Add --no-git-history flag to import command for sync subprocess compatibility
- bd-0zp7: Add missing hook calls (EventMessage in mail reply, EventClose in mail ack)
- bd-hy9p: Implement --body-file and --description-file flags for reading descriptions from files

Also closed stale issues that were already fixed:
- bd-0d5p: macOS test timeout (already fixed with SysProcAttr)
- bd-7yg: Merge driver placeholders (already using correct %A %O %A %B)
- bd-4ri: Test deadlock (test passes in 0.04s now)
- bd-b3og: TestImportBugIntegration (test no longer exists)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 17:29:33 -08:00
Steve Yegge
9f76cfda01 refactor: remove all deletions.jsonl code (bd-fom)
Complete removal of the legacy deletions.jsonl manifest system.
Tombstones are now the sole deletion mechanism.

Removed:
- internal/deletions/ - entire package
- cmd/bd/deleted.go - deleted command
- cmd/bd/doctor/fix/deletions.go - HydrateDeletionsManifest
- Tests for all removed functionality

Cleaned:
- cmd/bd/sync.go - removed sanitize, auto-compact
- cmd/bd/delete.go - removed dual-writes
- cmd/bd/doctor.go - removed checkDeletionsManifest
- internal/importer/importer.go - removed deletions checks
- internal/syncbranch/worktree.go - removed deletions merge
- cmd/bd/integrity.go - updated validation (warn-only on decrease)

Files removed: 12
Lines removed: ~7500

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 14:20:49 -08:00
Rod Davenport
6985ea94e5
fix(sync): protect local issues from git-history-backfill during sync (#485)
Fix sync bug where newly created issues were incorrectly tombstoned during bd sync.

The root cause was git-history-backfill finding issues in local commits on the sync branch, then tombstoning them when they weren't in the merged JSONL. The fix protects issues from the left snapshot (local export) from git-history-backfill.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-12-12 13:28:48 -08:00
Darin
e0734e230f
fix: NixOS symlink compatibility for mtime and permission checks (#459)
* fix: use os.Lstat for symlink-safe mtime and permission checks

On NixOS and other systems using symlinks heavily (e.g., home-manager),
os.Stat follows symlinks and returns the target's metadata. This causes:

1. False staleness detection when JSONL is symlinked - mtime of target
   changes unpredictably when symlinks are recreated
2. os.Chmod failing or changing wrong file's permissions when target
   is in read-only location (e.g., /nix/store)
3. os.Chtimes modifying target's times instead of the symlink itself

Changes:
- autoimport.go: Use Lstat for JSONL mtime in CheckStaleness()
- import.go: Use Lstat in TouchDatabaseFile() for JSONL mtime
- export.go: Skip chmod for symlinked files
- multirepo.go: Use Lstat for JSONL mtime cache
- multirepo_export.go: Use Lstat for mtime, skip chmod for symlinks
- doctor/fix/permissions.go: Skip permission fixes for symlinked paths

These changes are safe cross-platform:
- On systems without symlinks, Lstat behaves identically to Stat
- Symlink permission bits are ignored on Unix anyway
- The extra Lstat syscall overhead is negligible

Fixes symlink-related data loss on NixOS. See GitHub issue #379.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* test: add symlink behavior tests for NixOS compatibility

Add tests that verify symlink handling behavior:
- TestCheckStaleness_SymlinkedJSONL: verifies mtime detection uses
  symlink's own mtime (os.Lstat), not target's mtime (os.Stat)
- TestPermissions_SkipsSymlinkedBeadsDir: verifies chmod is skipped
  for symlinked .beads directories
- TestPermissions_SkipsSymlinkedDatabase: verifies chmod is skipped
  for symlinked database files while still fixing .beads dir perms

Also adds devShell to flake.nix for local development with go, gopls,
golangci-lint, and sqlite tools.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-05 13:22:09 -08:00
Steve Yegge
28a661a320 feat: add --readonly flag for worker sandboxes (gt-ymo)
Add a --readonly flag that blocks all write operations, allowing workers
to read beads state without modifying it. Workers can use:
- bd show, bd list, bd ready (read operations)

Workers cannot use:
- bd create, bd update, bd close, bd sync, etc. (write operations)

The flag can be set via:
- --readonly flag on command line
- BD_READONLY=true environment variable
- readonly: true in config file

This enables swarm workers to see their assigned work from a static
snapshot of the beads database without accidentally modifying it.

Commands protected by readonly mode:
- create, update, close, delete, edit
- sync, import, reopen
- comment add, dep add/remove, label add/remove
- repair-deps, compact, migrate, migrate-hash-ids, migrate-issues
- rename-prefix, validate --fix-all, duplicates --auto-merge
- epic close-eligible, jira sync

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 23:44:22 -08:00
Steve Yegge
f7dea354d8 fix(import): add warning when issues are skipped due to deletions manifest
When importing JSONL that contains issues in the deletions manifest,
import now:
- Filters out deleted issues before import
- Prints per-issue warning with deletion details (date, actor)
- Shows count of skipped issues in summary
- Suggests --ignore-deletions flag to force import

The new --ignore-deletions flag allows importing issues that are in the
deletions manifest, useful for recovering accidentally deleted issues.

Fixes bd-4zy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 21:23:04 -08:00
Steve Yegge
eb4b81d209 fix: prevent bd sync corruption from stale daemon SQLite connection
Root cause: When beads.db is deleted and recreated while daemon is running,
daemon's SQLite connection becomes stale (points to old deleted file via
file descriptor), causing export to return incomplete/corrupt data.

Fix:
- sync command now forces direct mode by closing daemonClient at start
- importFromJSONL subprocess uses --no-daemon to avoid daemon connection issues
- Added documentation to import.go explaining the daemon behavior

Also:
- Skip TestZFCSkipsExportAfterImport (broken test - subprocess spawning
  doesn't work in test environment, needs refactoring
- Update hook templates to version 0.26.2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)
2025-11-29 20:54:28 -08:00
Steve Yegge
f59f8c20d0 refactor: rename last_import_hash to jsonl_content_hash (bd-39o)
The metadata key 'last_import_hash' was misleading because it's updated on
both import AND export. Renamed to 'jsonl_content_hash' which more accurately
describes its purpose - tracking the content hash of the JSONL file.

Added migration support: read operations try new key first, then fall back
to old key for backwards compatibility with existing databases.

Files modified:
- cmd/bd/integrity.go: Update key name with migration support
- cmd/bd/import.go: Update key name
- cmd/bd/sync.go: Update key name
- cmd/bd/autoflush.go: Update key name with migration support
- cmd/bd/daemon_sync.go: Update key name
- cmd/bd/daemon_event_loop.go: Update key name with migration support
- internal/autoimport/autoimport.go: Update key name with migration support
- Updated all related tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 23:14:12 -08:00
Steve Yegge
8b8a662acb Fix fresh clone UX with friendly error messages (bd-dmb)
When opening a database that exists but is missing issue_prefix config
(typical in fresh clone scenarios), show a helpful error message instead
of cryptic migration invariant errors.

The new message:
- Explains the database needs initialization
- Detects if a JSONL file exists and shows the issue count
- Suggests the exact command to run: bd import -i <path>
- Falls back to suggesting bd init --prefix if no JSONL exists

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 22:40:57 -08:00
Steve Yegge
cdc156428c fix(staleness): use RFC3339Nano precision for last_import_time (#399)
The staleness check compares last_import_time against JSONL file mtime.
File mtime has nanosecond precision, but last_import_time was stored with
only second precision (RFC3339). This caused a race condition where the
stored time could be slightly earlier than the file mtime, triggering
false "Database out of sync" errors - particularly in git worktrees.

Changed all 6 locations that set last_import_time to use RFC3339Nano.
The CheckStaleness parser already handles both formats, so this is
backward compatible.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 00:11:01 -08:00
Steve Yegge
5506486dc5 feat(import,sync): add --no-git-history flag to prevent spurious deletions
Fixes bd-0b2: The git history backfill mechanism was causing data loss
during JSONL filename migrations (beads.jsonl → issues.jsonl). When issues
existed in the old filename's git history, the backfill incorrectly treated
them as "deleted" and purged them from the database.

Changes:
- Add NoGitHistory field to importer.Options and ImportOptions structs
- Modify purgeDeletedIssues() to skip git history check when flag is set
- Add --no-git-history flag to bd import command
- Add --no-git-history flag to bd sync command
- Update purge_test.go to pass Options argument

Usage:
  bd import -i .beads/issues.jsonl --no-git-history
  bd sync --no-git-history

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 23:10:43 -08:00
Steve Yegge
6294ef0cc6 fix(init,import): preserve metadata.json and improve prefix detection
- bd init now preserves existing metadata.json settings instead of
  overwriting with defaults (bd-zai)
- bd init detects existing JSONL filename (beads.jsonl vs issues.jsonl)
  when creating new metadata.json
- bd import now correctly reports prefix source ("issues" vs "directory")
- bd import avoids using ".beads" as prefix when run from inside .beads/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 22:57:17 -08:00