Commit Graph

728 Commits

Author SHA1 Message Date
Steve Yegge
402931b081 Clean up database split: remove bd.jsonl and issues.jsonl duplicates
- Removed stale bd.jsonl (old data before compaction)
- Removed stale issues.jsonl (old data before compaction)
- Added config.json to track canonical JSONL filename (beads.jsonl)
- Database now has single source of truth: beads.jsonl (167 issues)
- No code changes needed - FindJSONLPath() glob correctly finds existing beads.jsonl

Amp-Thread-ID: https://ampcode.com/threads/T-f25fe193-4185-40be-b5bc-e5725a3dbf1b
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 18:23:29 -07:00
Steve Yegge
5939018972 Restore bd edit command and close duplicate issues
- Restore bd edit command (lost in 671b966 --no-db refactor)
- Document in AGENTS.md with 'HUMANS ONLY' warning
- Close duplicate issues: bd-129, bd-150, bd-144, bd-173/178/180
- Resolve import collisions: 8 issues remapped to new IDs

Amp-Thread-ID: https://ampcode.com/threads/T-e4780c42-9a6e-4021-8f8e-120b26562c2d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 17:45:11 -07:00
Steve Yegge
128baf1da4 bd sync: 2025-10-27 17:41:17 2025-10-27 17:41:17 -07:00
Steve Yegge
f1e2ffb135 bd sync: 2025-10-27 17:29:14 2025-10-27 17:29:14 -07:00
Steve Yegge
adfe177dba Fix bd-132: Implement daemon auto-import after git pull
- Created internal/importer package with all import logic
- Moved import phases from cmd/bd to internal/importer
- Implemented real importFunc in daemon's checkAndAutoImportIfStale()
- Added single-flight concurrency guard to prevent parallel imports
- Added fast mtime check to avoid unnecessary file reads (99% of requests <0.1ms)
- Fixed import options: RenameOnImport=true instead of SkipPrefixValidation
- Added export trigger after ID remapping to prevent collision loops
- Fixed memory storage interface: added GetDirtyIssueHash, GetExportHash, SetExportHash
- Updated GetDependencyTree signature for reverse parameter

Performance:
- Mtime check: ~0.01ms per request
- Import when needed: ~10-100ms (rare, only after git pull)
- Throughput maintained: 4300+ issues/sec
- No duplicate work with single-flight guard

Fixes critical data corruption bug where daemon served stale data after
git pull, causing fresh JSONL changes to be overwritten.

Amp-Thread-ID: https://ampcode.com/threads/T-71224a2d-b2d7-4173-b21e-449b64f9dd71
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 16:29:12 -07:00
Steve Yegge
49dac2b767 Fix test failures: add missing issue_prefix config and use valid bd- prefixes
- Add SetConfig('issue_prefix', 'bd') to collision tests (bd-166)
- Update test cases to use 'bd-' prefix instead of invalid custom IDs (bd-177)
- Fixes 5 test failures in TestDetectCollisions, TestScoreCollisions, TestRemapCollisions, TestCreateIssues

All tests now pass.

Amp-Thread-ID: https://ampcode.com/threads/T-b2413b0e-2720-45b1-9b3d-acaa7d4cf9b4
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 13:11:45 -07:00
Steve Yegge
228ef67ebf Merge PR #160: Add --reverse flag for discovery tree visualization
Co-authored-by: David Laing <david@davidlaing.com>
2025-10-27 13:08:43 -07:00
Steve Yegge
d2989dd0f3 Merge main into PR #160 - combine reverse mode with substring bugfix
Amp-Thread-ID: https://ampcode.com/threads/T-b2413b0e-2720-45b1-9b3d-acaa7d4cf9b4
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 13:07:12 -07:00
David Laing
8c2679a80e Fix substring bug in dependency tree cycle detection (#159)
* Add .worktrees/ to .gitignore

Prevents git worktree contents from being tracked in the repository.

* Fix substring bug in dependency tree cycle detection

The cycle detection in GetDependencyTree() was using a simple substring
match which incorrectly flagged valid nodes as cycles. For example,
"bd-1" would be blocked because "bd-10" contains "bd-1" as a substring.

This bug affects any beads project where issue IDs contain each other as
substrings (BD-1/BD-10, ISSUE-1/ISSUE-10, etc).

Changed from:
  AND t.path NOT LIKE '%' || i.id || '%'

To delimiter-aware checks that respect the → separator:
  AND t.path != i.id
  AND t.path NOT LIKE i.id || '→%'
  AND t.path NOT LIKE '%→' || i.id || '→%'
  AND t.path NOT LIKE '%→' || i.id

This ensures we only match complete issue IDs, not substrings.

Added TestGetDependencyTree_SubstringBug to demonstrate and prevent
regression of this issue. The test creates a chain from bd-10 to bd-1
and verifies all nodes appear in the dependency tree.

Discovered while testing dependency tree visualization with bd-1/bd-10.
2025-10-27 12:51:41 -07:00
Steve Yegge
68ffb9ed40 Complete bd-175, bd-176, bd-177: Memory tests, corruption docs, prefix validation
- bd-175: Added comprehensive test coverage for internal/storage/memory backend
  - All CRUD operations, dependencies, labels, comments
  - Thread safety with race detection
  - LoadFromIssues and counter sync
  - Fixed batch duplicate detection

- bd-176: Documented corruption vs collision distinction
  - Added FAQ entry explaining logical vs physical corruption
  - Updated TROUBLESHOOTING with clear guidance
  - Clarified when to use collision resolution vs reimport

- bd-177: Added prefix validation in SQLite mode
  - Validates explicit IDs match configured prefix
  - Works in both CreateIssue and CreateIssues
  - Comprehensive tests for single and batch operations
2025-10-27 11:29:08 -07:00
Steve Yegge
f5e1a9811a bd sync: 2025-10-27 11:28:52 2025-10-27 11:28:52 -07:00
Steve Yegge
2d8d2cb8f6 Add follow-up issues for PR #149: test coverage, prefix validation, docs 2025-10-27 10:47:16 -07:00
Steve Yegge
edb85700e6 Merge PR #149: Add --no-db mode for JSONL-only operation
Implements --no-db mode to avoid SQLite corruption in multi-process scenarios.

Changes:
- Add in-memory storage backend (internal/storage/memory/)
- Add JSONL persistence layer (cmd/bd/nodb.go)
- Integrate --no-db flag into command flow
- Support config.yaml for no-db and issue-prefix settings
- Refactor atomic JSONL writes into shared helper

Co-authored-by: rrnewton <rrnewton@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-67d6d80f-27dc-490a-a95d-61ad06d5b06d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 10:45:01 -07:00
David Laing
2035e02a34 docs: add reverse mode documentation with examples
- Add --reverse flag to tree command documentation
- Document normal vs reverse mode differences
- Add comprehensive reverse mode section with use cases
- Update examples to show both directions
2025-10-27 09:25:57 +00:00
David Laing
28b7fed0ec feat: add --reverse flag to bd dep tree command
- Add --reverse boolean flag to depTreeCmd
- Pass reverse parameter to GetDependencyTree
- Update display messages based on mode:
  - Normal: 'Dependency tree' / 'no dependencies'
  - Reverse: 'Dependent tree' / 'no dependents'

Enables discovery tree visualization from goals downward.
2025-10-27 09:25:57 +00:00
David Laing
dd8f51c433 feat: add reverse mode to dependency tree traversal
- Add reverse parameter to GetDependencyTree interface
- Implement reverse SQL traversal (dependents vs dependencies)
- Add comprehensive test for reverse mode (TDD: test-first approach)
- Update existing test calls with reverse=false for backward compatibility

Reverse mode inverts tree direction to show dependents instead of dependencies:
- Normal: JOIN dependencies d ON i.id = d.depends_on_id (traverse UP)
- Reverse: JOIN dependencies d ON i.id = d.issue_id (traverse DOWN)

All storage tests passing. No regressions.
2025-10-27 09:25:57 +00:00
Steve Yegge
969f3ac03b Merge PR #150: Multishow - allow bd show on multiple issues 2025-10-26 23:55:53 -07:00
Claude Code
1ea936d7c3 Sort issues by ID when showing multiple issues
When bd show displays multiple issues, they are now sorted by ID
for consistent and predictable ordering:
- bd show bd-7 bd-5 bd-6 displays them as bd-5, bd-6, bd-7
- Works with explicit IDs, --all-issues, and --priority flags
- Applies to both text and JSON output
- Uses alphabetical sorting which works for typical ID formats

This makes the output easier to read and more predictable,
especially when showing many issues at once.
2025-10-26 23:55:30 -07:00
Claude Code
3b8d13f100 Add --priority flag to bd show command
Adds a new --priority (-p) flag to filter issues by priority:
- bd show --priority 0 shows all P0 issues
- bd show -p 0 -p 1 shows all P0 and P1 issues
- Can be used multiple times to show multiple priority levels
- Combines with --all-issues if both are specified
- Works only in direct mode (--no-daemon required for now)

This makes it easy to focus on high-priority issues without
needing to specify each issue ID individually.

Example: bd show -p 0 -p 1 shows all critical and high-priority
issues in the database.
2025-10-26 23:55:30 -07:00
Claude Code
75541c3ff6 Add --all-issues flag to bd show command
Adds a new --all-issues flag that displays all issues in the database:
- bd show --all-issues shows every issue
- Warns when showing more than 20 issues (performance)
- Works only in direct mode (--no-daemon required for now)
- Provides clear error message in daemon mode
- Help text warns that this may be expensive for large databases

This is useful for getting a complete overview of the database,
but users should be aware it can be slow with many issues.
2025-10-26 23:55:30 -07:00
Claude Code
60b84afa3a Add support for showing multiple issues with bd show
bd show now accepts multiple issue IDs and displays each one:
- bd show bd-1 bd-2 bd-3 shows all three issues
- Issues are separated by a horizontal line for clarity
- Works in both daemon and direct modes
- JSON output returns an array of all requested issues

This feature already worked in the implementation (it looped through
args), but now it's properly documented in the help text.
2025-10-26 23:55:10 -07:00
Steve Yegge
b9dca73cdf Merge PR #151: Allow numeric-only ID for bd show 2025-10-26 23:54:01 -07:00
Ryan Newton + Claude
47d5032622 Allow numeric-only ID for only 2025-10-26 23:51:07 -07:00
Steve Yegge
c4be0896ea Add dist/ to .gitignore for GoReleaser artifacts 2025-10-26 23:49:35 -07:00
Steve Yegge
9eafdf9f0e Remove unused strings import in Windows build 2025-10-26 23:47:14 -07:00
Steve Yegge
d7b5cf75ba Update uv.lock for 0.17.7 2025-10-26 23:45:55 -07:00
Steve Yegge
0e13a4268d Fix Go version in release workflow (1.24 -> 1.23) 2025-10-26 23:38:53 -07:00
Steve Yegge
687376f969 chore: Bump version to 0.17.7
Updated all component versions:
- bd CLI: 0.17.6 → 0.17.7
- Plugin: 0.17.6 → 0.17.7
- MCP server: 0.17.6 → 0.17.7
- Documentation: 0.17.6 → 0.17.7

Generated by scripts/bump-version.sh
2025-10-26 23:30:37 -07:00
Steve Yegge
740a6aea99 Update uv.lock for 0.17.6 2025-10-26 23:30:24 -07:00
Steve Yegge
f07b60b23a Add 0.17.7 release notes 2025-10-26 23:30:09 -07:00
Steve Yegge
1b4f56d675 chore: Bump version to 0.17.6
Updated all component versions:
- bd CLI: 0.17.5 → 0.17.6
- Plugin: 0.17.5 → 0.17.6
- MCP server: 0.17.5 → 0.17.6
- Documentation: 0.17.5 → 0.17.6

Generated by scripts/bump-version.sh
2025-10-26 23:08:15 -07:00
Steve Yegge
571a596641 Fix export test failures with ClearAllExportHashes for test isolation
Amp-Thread-ID: https://ampcode.com/threads/T-5335d274-44e1-4811-b63f-15c52ea3394f
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 23:06:03 -07:00
Steve Yegge
648ecfafe7 Address gosec security warnings (bd-102)
- Enable gosec linter in .golangci.yml
- Tighten file permissions: 0755→0750 for directories, 0644→0600 for configs
- Git hooks remain 0700 (executable, user-only access)
- Add #nosec comments for safe cases with justifications:
  - G204: Safe subprocess launches (git show, bd daemon)
  - G304: File inclusions with controlled paths
  - G201: SQL formatting with controlled column names
  - G115: Integer conversions with controlled values

All gosec warnings resolved (20→0). All tests passing.

Amp-Thread-ID: https://ampcode.com/threads/T-d7166b9e-cbbe-4c7b-9e48-3df36b20f0d0
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 22:48:19 -07:00
Steve Yegge
4ea347e08a Fix all test failures from bd-166 (missing issue_prefix)
Completed bd-167: Fixed all tests that failed with 'database not initialized: issue_prefix config is missing' error.

Changes:
- Created test helper functions in 3 locations:
  * cmd/bd/test_helpers_test.go (already existed)
  * internal/rpc/test_helpers.go (new)
  * internal/storage/sqlite/test_helpers.go (new)

- Updated all affected test files to use newTestStore():
  * cmd/bd: comments, export, git_sync, label, list, reopen, direct_mode
  * internal/rpc: rpc_test, version_test
  * internal/storage/sqlite: sqlite_test, underlying_db_test

- Fixed config test: updated flush-debounce default from 5s to 30s

- Removed unused sqlite imports from test files

All tests now passing 

Also:
- Closed bd-167, bd-170 (cleanup of beads-* duplicates)
- Removed corrupt backup files

Amp-Thread-ID: https://ampcode.com/threads/T-4a8c6002-9384-45b6-81f6-2907d1e4c6c2
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 22:31:24 -07:00
Steve Yegge
09e881022e Fix bd-166: Prevent duplicate issues with wrong prefix
Critical fix for silent data corruption where database created 173
duplicate issues with wrong prefix (beads- instead of bd-).

Root cause: When issue_prefix config was missing, CreateIssue fell
back to deriving prefix from database filename (beads.db → 'beads'),
while auto-import imported bd- issues from git with SkipPrefixValidation.
This created duplicates.

Changes:
1. Removed derivePrefixFromPath() - never derive prefix from filename
2. CreateIssue/CreateIssues now REJECT if issue_prefix config missing
   - Fail-fast with clear error message
3. Auto-import now SETS issue_prefix from first imported issue if missing
   - Handles fresh clone scenario safely
4. Added newTestStore() helper that sets issue_prefix for tests
5. Updated test setup in multiple files to prevent test failures

Follow-ups filed: bd-167, bd-168, bd-169

Closes bd-166

Amp-Thread-ID: https://ampcode.com/threads/T-b2ee0738-b90b-40ef-ae44-f2d93729842c
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 21:55:01 -07:00
Steve Yegge
669c054332 bd sync: 2025-10-26 21:42:08 2025-10-26 21:42:08 -07:00
Steve Yegge
cabe5e8d9b bd sync: 2025-10-26 21:38:55 2025-10-26 21:38:55 -07:00
Steve Yegge
36fc8a19e6 Restore clean issue state after database corruption recovery
- Removed 173 duplicate beads- prefix issues
- Database now contains 165 clean bd- issues
- Fixed database prefix config from beads- to bd-
- All data recovered successfully from .beads/beads.db

Amp-Thread-ID: https://ampcode.com/threads/T-229f87e4-f015-4284-8568-9069cfae4fda
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 21:35:12 -07:00
Steve Yegge
79b7a48a73 Add database fingerprinting and validation (bd-166)
- Add fingerprint.go with robust URL canonicalization
  - Handles git@, ssh://, https://, http://, file://, and local paths
  - Normalizes URLs to produce consistent repo_id across formats
  - Clone ID uses git repo root for stability

- Update init.go to store repo_id and clone_id metadata
  - repo_id: SHA256 hash of canonical git remote URL
  - clone_id: SHA256 hash of hostname + repo root path

- Add daemon validation to prevent database mismatches
  - Validates repo_id on daemon start
  - Fails on legacy databases (requires explicit migration)
  - Clear error messages with actionable solutions

- Add migrate --update-repo-id command
  - Updates repo_id after remote URL changes
  - Confirmation prompt (can bypass with --yes)
  - Supports --dry-run

Prevents accidental database mixing across repos and provides
migration path for remote URL changes or bd upgrades.

Closes bd-166

Amp-Thread-ID: https://ampcode.com/threads/T-a9d9dab1-5808-4f62-93ea-75a16cca978b
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 21:15:57 -07:00
Steve Yegge
f24573a5f8 Enforce canonical database naming (beads.db) - bd-165
- Added CanonicalDatabaseName constant (beads.db) and LegacyDatabaseNames list
- Updated bd init to use canonical name via constant
- Added daemon validation to reject non-canonical database names
- Updated bd migrate to use canonical name constant
- Enhanced FindDatabasePath to warn when using legacy database names
- All database discovery now prefers beads.db with backward compatibility

Closes bd-165
2025-10-26 20:42:18 -07:00
Steve Yegge
a02729ea57 Complete bd-164: Fix timestamp-only export deduplication
- Add export_hashes table to track last exported content state
- Implement GetExportHash/SetExportHash in storage interface
- Update shouldSkipExport to use export_hashes instead of dirty_issues
- Call SetExportHash after successful export
- Clean up dirty_issues table (remove content_hash column)
- Simplify MarkIssueDirty functions (no longer compute hashes)
- Update markIssuesDirtyTx signature (remove store parameter)

Testing:
- Timestamp-only updates are skipped during export ✓
- Real content changes trigger export ✓
- export_hashes table populated correctly ✓

Fixes bd-159, bd-164
2025-10-26 20:35:37 -07:00
Steve Yegge
a898df6915 WIP: bd-164 timestamp-only export deduplication (~80% complete)
Implemented content hash-based deduplication to skip exports when only
timestamps changed. Core logic complete, needs export_hashes table wiring.

Completed:
- Added computeIssueContentHash() excluding timestamps
- Created shouldSkipExport() logic
- Updated export loop to skip timestamp-only changes
- Added hash.go with content hashing
- Extended Storage interface

Remaining:
- Complete export_hashes table migration
- Add SetExportHash/GetExportHash to interface
- Revert content_hash from dirty_issues approach
- Wire up hash persistence in export
- Testing

See bd-164 notes for details.

Amp-Thread-ID: https://ampcode.com/threads/T-d70657d1-4433-4f7e-b10a-3fccf8bf17fb
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 20:29:10 -07:00
Steve Yegge
d05e94d80d bd sync: 2025-10-26 20:27:23 2025-10-26 20:27:23 -07:00
Steve Yegge
6271b521b4 bd-162: Add database integrity checks with oracle review fixes
- Added validatePreExport to prevent data loss
- Added checkDuplicateIDs to detect corruption
- Added checkOrphanedDeps to find orphaned dependencies (both sides)
- Added validatePostImport to ensure imports don't lose data
- CRITICAL FIX: Removed post-pull export that clobbered fresh JSONL
- Conservative checks when JSONL is unreadable
- Efficient COUNT(*) SQL path instead of loading all issues
- Comprehensive test coverage including edge cases
2025-10-26 20:17:48 -07:00
Steve Yegge
3cbd913f31 bd-162: Add database integrity checks with oracle review fixes 2025-10-26 20:17:42 -07:00
Steve Yegge
b893be7d0e Fix bd-161: Implement daemon JSONL import (fix NO-OP stub)
Replace the NO-OP importToJSONLWithStore() stub with full implementation:
- Reads and parses JSONL file line by line using bufio.Scanner
- Uses importIssuesCore() with auto-collision resolution enabled
- Integrates with existing import infrastructure
- Fixes PRIMARY root cause of bd-160 multi-clone sync failure

The daemon now properly imports remote changes pulled from git instead
of ignoring them, allowing databases to converge across clones.

Amp-Thread-ID: https://ampcode.com/threads/T-9b92c2dc-e0e2-4d77-b562-136da8c3f64e
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 20:05:31 -07:00
Steve Yegge
293de96310 removed handoff file 2025-10-26 19:43:21 -07:00
Steve Yegge
4a340902a8 bd sync: 2025-10-26 19:42:46 2025-10-26 19:42:46 -07:00
Steve Yegge
c6494c3916 bd sync: 2025-10-26 19:39:31 2025-10-26 19:39:33 -07:00
Steve Yegge
f3005d3dc8 Export with bd-150/152/153 closed 2025-10-26 19:39:24 -07:00