Commit Graph

20 Commits

Author SHA1 Message Date
Steve Yegge
584c266684 Reorganize project structure: move Go files to internal/beads, docs to docs/
Amp-Thread-ID: https://ampcode.com/threads/T-7a71671d-dd5c-4c7c-b557-fa427fceb04f
Co-authored-by: Amp <amp@ampcode.com>
2025-11-05 21:04:00 -08:00
Steve Yegge
14bdc6fe68 Add bd migrate --to-separate-branch command
Implements bd-caa9: migration tool for existing users to enable
separate branch workflow.

Features:
- bd migrate --to-separate-branch <branch> sets sync.branch config
- Validates branch names (no whitespace/empty)
- Dry-run support with --dry-run flag
- Idempotent (safe to run multiple times)
- JSON output support
- Clear next steps for users

Closes bd-caa9, bd-a101

Amp-Thread-ID: https://ampcode.com/threads/T-93c3427d-12a1-4d9a-8690-1d0cfe22188f
Co-authored-by: Amp <amp@ampcode.com>
2025-11-04 12:39:38 -08:00
Steve Yegge
859fbd4976 fix: resolve CI test failures on Linux and Windows
- Fix TestMigrateCommand: Use correct sqlite3 driver name and file URI format
- Fix TestDaemonAutoImportAfterGitPull: Add Windows-specific delay for filesystem timestamp precision
- Fix TestSyncBranchPull_Success: Add Windows-specific delay for file I/O settling

Amp-Thread-ID: https://ampcode.com/threads/T-5abd1f2f-9607-4111-af9d-19df64362ac7
Co-authored-by: Amp <amp@ampcode.com>
2025-11-04 10:02:08 -08:00
Steve Yegge
9ce1d6c7a5 WIP: WASM port - switch to ncruces/go-sqlite3, add WASM stubs
- Switched from modernc.org/sqlite to ncruces/go-sqlite3 for WASM support
- Added WASM-specific stubs for daemon process management
- Created wasm/ directory with build.sh and Node.js runner
- WASM build succeeds (32MB bd.wasm)
- Node.js can load and execute the WASM module
- Next: Need to bridge Go file I/O to Node.js fs module

Related: bd-44d0, bd-8534, bd-c7eb
2025-11-02 22:17:08 -08:00
Steve Yegge
8997fbbbc7 Merge branch 'main' of github.com:steveyegge/beads 2025-11-02 14:31:24 -08:00
Steve Yegge
0215e73780 Fix config system: rename config.json → metadata.json, fix config.yaml loading
- Renamed config.json to metadata.json to clarify purpose (database metadata)
- Fixed config.yaml/config.json conflict by making Viper explicitly load only config.yaml
- Added automatic migration from config.json to metadata.json on first read
- Fixed jsonOutput variable shadowing across 22 command files
- Updated bd init to create both metadata.json and config.yaml template
- Fixed 5 failing JSON output tests
- All tests passing

Resolves config file confusion and makes config.yaml work correctly.
Closes #178 (global flags), addresses config issues from #193

Amp-Thread-ID: https://ampcode.com/threads/T-e6ac8192-e18f-4ed7-83bc-4a5986718bb7
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 14:31:22 -08:00
Steve Yegge
1abe4e75ad Add migration inspection tools for AI agents (bd-627d Phase 2)
Implemented:
- bd migrate --inspect --json: Shows migration plan, db state, warnings
- bd info --schema --json: Returns schema details for agents
- Migration invariants: Validates migrations post-execution
- Added ListMigrations() for introspection

Phase 1 (invariants) and Phase 2 (inspection) complete.
Next: Wire up MCP tools in beads-mcp server.

Amp-Thread-ID: https://ampcode.com/threads/T-c4674660-d640-405f-a929-b664e8699a48
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 14:03:14 -08:00
Steve Yegge
0cfe741553 Fix config version update in migrate command
- Save updated config with current version (fixes GH #193)
- Update version field when loading existing config
- Database version now stays in sync with binary version

Amp-Thread-ID: https://ampcode.com/threads/T-dfacc972-f6c8-4bb3-8997-faa079b5d070
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 12:55:53 -08:00
Steve Yegge
01160082fa Fix bd migrate to detect and set issue_prefix config
- Fixes GH #201
- bd migrate now detects prefix from existing issues
- Sets issue_prefix config before schema version update
- Prevents 'no issue found' errors after migration
- Prevents incorrect prefix in hash ID migrations

When migrating pre-0.17.5 databases, the issue_prefix config
(required since bd-166) was not being set. This caused commands
like 'bd show' to fail with 'no issue found' errors.

The fix queries for existing issues after migration and extracts
the prefix using utils.ExtractIssuePrefix(), then sets the config
before continuing with version updates.

Amp-Thread-ID: https://ampcode.com/threads/T-ba0c6c5c-8812-4ecf-8576-c0870fdbefff
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 10:55:07 -08:00
Steve Yegge
9f9b8bbdc2 Fix Windows test failures: path handling and bd binary references
- Fix TestFindDatabasePathEnvVar to expect canonicalized absolute paths
- Add getBDCommand() helper for platform-specific bd executable paths
- Update beads_hash_multiclone_test.go to use platform-specific bd paths
- Fix cleanupWALFiles linting error (removed unused error return)
2025-11-02 09:49:39 -08:00
Steve Yegge
defc90deeb fix: bd migrate respects config.json database name and fixes I/O errors
Fixes #204

Multiple critical bugs in bd migrate:

1. **Respects config.json database name**: migrate now loads config.json
   and uses the configured database name instead of hardcoding beads.db.
   Users with custom database names (e.g., beady.db) will no longer
   have their databases renamed.

2. **Fixes disk I/O error (522)**: Clean up orphaned WAL files before
   reopening database to update schema version. This prevents SQLite
   error 522 (disk I/O error) when WAL files exist from previous
   database sessions.

3. **Creates backup before migration**: First migration now creates
   a timestamped backup (*.backup-pre-migrate-*.db) before renaming
   database, consistent with hash-id migration behavior.

4. **Cleans up orphaned WAL files**: Removes .db-wal and .db-shm
   files after migrating old database to prevent stale files.

Changes:
- Load config.json in migrate command to get target database name
- Use cfg.Database instead of hardcoded beads.CanonicalDatabaseName
- Add loadOrCreateConfig() helper function
- Add cleanupWALFiles() to remove orphaned WAL/SHM files
- Create backup before first migration
- Clean up WAL files before version update and after migration
- Add TestMigrateRespectsConfigJSON test

All migration tests passing.

Amp-Thread-ID: https://ampcode.com/threads/T-e5b9ddd0-621b-418b-bc52-ba9462975c39
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 08:46:20 -08:00
Steve Yegge
2b086951c4 fix: Address all errcheck and misspell linter errors 2025-11-01 23:56:03 -07:00
Steve Yegge
acb731a4ec bd sync: 2025-10-31 22:39:53 2025-10-31 22:39:53 -07:00
Steve Yegge
e3afecca37 Remove sequential ID code path (bd-aa744b)
- Removed nextSequentialID() and getIDMode() functions
- Removed issue_counters table from schema
- Made SyncAllCounters() a no-op for backward compatibility
- Simplified ID generation to hash-only (adaptive length)
- Removed id_mode config setting
- Removed sequential ID tests and migration code
- Updated CONFIG.md and AGENTS.md to remove sequential ID references

Follow-up bd-2a70 will remove obsolete test files and renumber command.
2025-10-30 21:51:39 -07:00
Steve Yegge
cd7bdb301d Generate 6-char hash IDs with progressive 7/8-char fallback on collision (bd-7c87cf24)
- Changed generateHashID to start with 6 chars (3 bytes), expand to 7/8 on collision
- Updated both CreateIssue and CreateIssues (batch) to use progressive length fallback
- Updated tests to accept 9-11 char IDs (bd- + 6-8 hex chars)
- All new issues now generate with shorter, more readable IDs
- Existing 8-char IDs preserved (no migration needed)

Amp-Thread-ID: https://ampcode.com/threads/T-8a6058af-9f42-4bff-be02-8c8bce41eeb5
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 18:16:24 -07:00
Steve Yegge
1fbfe58ba7 Make hash IDs opt-in via id_mode config (bd-5404)
- Add id_mode config (sequential|hash), defaults to sequential
- Update CreateIssue/CreateIssues to check id_mode and generate appropriate IDs
- Implement lazy counter initialization from existing issues
- Update migrate --to-hash-ids to set id_mode=hash after migration
- Fix hash ID tests to set id_mode=hash
- Fix renumber test to use explicit IDs
- All 183 test packages pass

This makes hash IDs backward-compatible opt-in rather than forced default.
2025-10-30 16:50:38 -07:00
Steve Yegge
0858bdb7ed Implement hash ID migration tool (bd-173)
- Add migrate-hash-ids command for converting sequential to hash-based IDs
- Integrate into bd migrate --to-hash-ids for transparent user experience
- Generate hash IDs for top-level issues, hierarchical IDs for children
- Update all references: dependencies, comments, text mentions
- Auto-backup database before migration
- Comprehensive tests covering migration scenarios
- Update AGENTS.md with migration documentation

Amp-Thread-ID: https://ampcode.com/threads/T-492f81db-5b0e-437a-b54d-ae4525dd7827
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 16:28:13 -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
7591a3bf81 Add bd migrate command for database upgrades (bd-164)
- Implement bd migrate command with detection, version checking, and cleanup
- Update daemon to suggest bd migrate for version mismatches
- Enhance CLI version warnings to recommend bd migrate
- Add comprehensive tests for migration scenarios
- Document migration workflow in QUICKSTART.md and AGENTS.md

Completes bd-164 and epic bd-159

Amp-Thread-ID: https://ampcode.com/threads/T-34ea4682-8c48-44c2-8421-dc40f867773b
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 19:20:59 -07:00