Commit Graph

1987 Commits

Author SHA1 Message Date
Steve Yegge
c547733366 bd sync: 2025-11-20 20:59:31 2025-11-20 20:59:31 -05:00
Steve Yegge
27c0c331ac Fix #349: Improve compact error messages, remove bogus merge suggestion, add daemon/maintenance docs
- bd-1h8: Add --no-daemon hint to compact error messages
- bd-8ql: Replace non-existent merge command with actionable guidance
- bd-ayw: Add 'When to use daemon mode' decision tree to daemon.md
- bd-keb: Add database maintenance section to QUICKSTART.md

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:58:57 -05:00
Steve Yegge
f20aec672d Add warning that MCP Agent Mail is not configured
Added prominent warning at the top of the Agent Mail section in AGENTS.md
to prevent AI agents from attempting to use mcp-agent-mail tools when the
server is not set up.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:55:42 -05:00
Steve Yegge
7109c47c37 Track issues bd-1h8, bd-8ql, bd-ayw, bd-keb for GitHub #349 2025-11-20 20:52:04 -05:00
Steve Yegge
7b6370f3fa Delete 497 closed beads (resurrection bug cleanup)
Removed all closed beads that were resurrected by the auto-import bug
documented in bd-khnb. Database now at 46 beads (all open/active).

The resurrection happened when:
- Earlier git operation restored old JSONL with 538 issues
- bd migrate --update-repo-id triggered daemon startup
- Auto-import saw "newer" JSONL (recent mtime from git)
- Imported old data over cleaned database
- 490 previously deleted issues resurrected

This cleanup removes those resurrected closed issues.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:50:39 -05:00
Steve Yegge
b2c50bc88a Add bd-khnb: Critical bug in auto-import resurrects deleted issues
Filed bug report for critical data loss issue where bd migrate --update-repo-id
(and other operations) can trigger auto-import that resurrects deleted issues.

Root cause: Auto-import uses mtime-based staleness detection, which fails when
git operations restore old JSONL files with recent mtimes.

Impact: User deletions can be silently undone after git checkout/merge/pull.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:50:39 -05:00
Steve Yegge
9088988edd Improve staleness check error handling and optimization (bd-n4td, bd-o4qy, bd-c4rq)
This commit implements three related improvements to database staleness checking:

**bd-n4td (P2): Add warning when staleness check errors**
- Added stderr warnings when CheckStaleness fails in ensureDatabaseFresh
- Users now see "Warning: could not check database staleness: <error>"
- Provides visibility into staleness check failures while allowing operations to proceed

**bd-o4qy (P2): Improve CheckStaleness error handling**
- Updated CheckStaleness to distinguish between expected and abnormal conditions:
  * Returns (false, nil) for expected "no data yet" scenarios (missing metadata, missing JSONL)
  * Returns (false, err) for abnormal errors (glob failures, permission errors)
- Updated RPC server (2 locations) to log staleness errors but allow requests to proceed
- Prevents blocking operations due to transient staleness check issues
- Added comprehensive function documentation

**bd-c4rq (P3): Refactor staleness check to avoid function call overhead**
- Moved daemon check from inside ensureDatabaseFresh to all 8 call sites
- Avoids unnecessary function call when running in daemon mode
- Updated: list.go, info.go, status.go, show.go, stale.go, duplicates.go, ready.go, validate.go
- Extracted staleness functions to new staleness.go for better organization

**Code review fixes:**
- Removed dead code in CheckStaleness (unreachable jsonlPath == "" check)
- Removed unused ensureDatabaseFreshQuiet function

**Files changed:**
- New: cmd/bd/staleness.go (extracted staleness checking functions)
- Modified: 8 command files (added daemon check before staleness calls)
- Modified: internal/autoimport/autoimport.go (improved error handling)
- Modified: internal/rpc/server_export_import_auto.go (handle errors gracefully)
2025-11-20 20:45:39 -05:00
Steve Yegge
2f6bcccdb6 Merge: Keep AGENTS.md with critical git push emphasis
Resolved conflict in AGENTS.md by keeping our version which emphasizes
that git push is CRITICAL for landing the plane.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:44:56 -05:00
Steve Yegge
f0d3d7345c Fix 'landing the plane' instructions - emphasize git push is CRITICAL
The previous instructions mentioned sync carefully but didn't emphasize that
git push is absolutely required for the plane to actually land. Multiple agents
have failed to push, leaving work uncommitted on the runway.

Changes:
- Added explicit 'git push' step with CRITICAL emphasis
- Added verification step to check 'up to date with origin/main'
- Updated example workflow to show push as mandatory step
- Added clear statement: 'The plane has NOT landed until git push completes'

The metaphor is obvious - if you don't push, the plane is still on the ground!

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:44:26 -05:00
Steve Yegge
94e60b1b72 bd sync: 2025-11-20 20:40:20 2025-11-20 20:40:20 -05:00
Steve Yegge
72084d960a Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 20:40:13 -05:00
Steve Yegge
2156ed593c Update land the plane instructions to use 'bd cleanup' command
- Changed 'bd clean' to 'bd cleanup' (correct command name)
- Added cleanup step to remove backup files and temporary artifacts
- Ensures clean repository state at end of agent sessions
2025-11-20 20:40:11 -05:00
Steve Yegge
fb1d12fe36 bd cleanup: Remove 493 closed issues
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:39:29 -05:00
Steve Yegge
d5239eeef9 Refactor: Extract duplicated validation logic to internal/validation
Extracted repeated priority and ID validation patterns from CLI commands
into reusable functions in internal/validation/bead.go.

Changes:
- Added ValidatePriority(): Combines parsing and error handling
- Added ValidateIDFormat(): Validates ID format and extracts prefix
- Added ValidatePrefix(): Validates prefix matching with database config
- Updated create.go and show.go to use new validation functions
- Simplified force flag logic to always call ValidatePrefix()
- Added comprehensive tests for all validation functions
- Added TODO comment for daemon mode validation enhancement

Results:
- Reduced code duplication by ~20 lines
- Centralized validation logic for easier maintenance
- Consistent error messages across all commands
- All tests passing

Fixes bd-g5p7

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:39:23 -05:00
Steve Yegge
b2ee77fe69 bd sync: 2025-11-20 20:38:15 2025-11-20 20:38:15 -05:00
Steve Yegge
d6bc798ab9 bd sync: 2025-11-20 20:35:20 2025-11-20 20:35:20 -05:00
Steve Yegge
a1e507520c Fix bd-ca0b: bd sync now auto-resolves conflicts instead of failing
Previously, bd sync would fail with "Pre-export validation failed:
refusing to export: JSONL is newer than database" when JSONL was
modified (e.g., after git pull).

Now bd sync intelligently handles this by:
- Detecting when JSONL is newer than the database
- Automatically importing before exporting
- Continuing with the normal sync flow

This makes the workflow much smoother - users can just run 'bd sync'
and it figures out what needs to be done.

Changes:
- Added isJSONLNewer() helper to check file timestamps
- Modified sync command to auto-import when JSONL is newer
- Extracted timestamp check logic for reusability

Resolves: bd-ca0b
🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:33:52 -05:00
Steve Yegge
bba764987a bd sync: 2025-11-20 20:33:30 2025-11-20 20:33:30 -05:00
Steve Yegge
e9aaf7799b bd sync: 2025-11-20 20:32:52 2025-11-20 20:32:52 -05:00
Steve Yegge
06d655ae83 Delete 490 closed issues to streamline database
Ran bd cleanup --force to remove all closed issues, keeping only 48 open issues.
This significantly reduces the database size and makes it easier to work with.

Deleted:
- 490 closed issues
- 221 dependency links
- 54 labels
- 755 events

Orphaned issues (will need parent repair):
- bd-tne, bd-tru, bd-ktng, bd-c362, bd-98c4e1fa.1, bd-7e7ddffa.1, bd-o78

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:31:59 -05:00
Steve Yegge
968d9e2ea1 Optimize bd list: replace N+1 label queries with bulk fetch
Problem:
In direct mode, bd list was making a separate GetLabels() call for
each issue when displaying labels. With 538 issues, this resulted in
538 separate database queries.

While investigating the reported 5+ second slowness, discovered this
N+1 query issue that would impact performance with many issues.

Solution:
1. Added GetLabelsForIssues(issueIDs []string) to Storage interface
2. Implemented bulk fetch in SQLite (already existed, now exposed)
3. Implemented bulk fetch in MemoryStorage
4. Updated list.go to fetch all labels in single query

Changes:
- internal/storage/storage.go: Add GetLabelsForIssues to interface
- internal/storage/memory/memory.go: Implement GetLabelsForIssues
- cmd/bd/list.go: Use bulk fetching in all output modes

Impact:
Eliminates N queries for labels, replacing with 1 bulk query.
This optimization applies to direct mode only (daemon mode already
uses bulk operations via RPC).

Note: The reported 5s slowness was actually caused by daemon auto-start
timeout. Use --no-daemon flag or run 'bd migrate --update-repo-id' to
resolve the legacy database issue causing daemon startup failures.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:27:09 -05:00
Steve Yegge
0916abf8fe Add debug logging to bd merge for troubleshooting
- Log all arguments received by merge driver
- Check file existence for each path
- Help diagnose 'open 7: no such file or directory' errors
2025-11-20 20:24:36 -05:00
Steve Yegge
13be84d99f Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 20:23:28 -05:00
Steve Yegge
3520321591 bd sync: 2025-11-20 20:22:39 2025-11-20 20:22:40 -05:00
Steve Yegge
62e39d0ec1 Delete 490 closed beads to streamline database
Removed all closed beads (490 total, 497 including cascade deletions):
- Completed feature implementations
- Fixed bugs and resolved issues
- Test issues from development
- Deprecated/removed features
- Refactoring tasks

Database reduced from 538 to 48 beads (46 open, 2 other states)

All deleted beads preserved in git history for reference.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:22:07 -05:00
Steve Yegge
e8355c26f0 Add 'bd clean' command to remove temporary merge artifacts
This command cleans up temporary files created during git merges by reading
patterns directly from .beads/.gitignore (Merge artifacts section).

Files removed:
- 3-way merge snapshots (beads.base.jsonl, beads.left.jsonl, beads.right.jsonl)
- Merge metadata (*.meta.json)
- Git merge driver temp files (*.json[0-9], *.jsonl[0-9])

Files preserved:
- beads.jsonl (source of truth)
- beads.db (SQLite database)
- metadata.json, config.yaml
- All daemon files

Usage:
  bd clean           # Clean up temporary files
  bd clean --dry-run # Preview what would be deleted

Implementation:
- Reads patterns from .beads/.gitignore instead of hardcoding them
- No --force flag needed - just runs by default
- Only cleans truly temporary merge artifacts, never the database

Also:
- Restored beads.jsonl to 538 issues from commit 6cd3a32
- Set issue-prefix to "bd" in config.yaml

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 20:21:37 -05:00
Steve Yegge
6cd3a32329 Restore beads.jsonl to 538 issues from d99222d 2025-11-20 19:59:19 -05:00
Steve Yegge
8d52f1deb5 removed zombie backup 2025-11-20 19:51:04 -05:00
Steve Yegge
d99222d895 Restore stable state: revert to beads.jsonl with 538 issues
- Revert migration to issues.jsonl (was causing data corruption)
- Backup issues.jsonl for reference
- Database and beads.jsonl now in sync (538 issues)
- Clean slate for stable operations
2025-11-20 19:48:26 -05:00
Steve Yegge
d1d06e75ff Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 19:38:14 -05:00
Steve Yegge
764886b3e7 bd sync: 2025-11-20 19:38:13 2025-11-20 19:38:13 -05:00
Steve Yegge
e447acce9e Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 19:37:01 -05:00
Steve Yegge
f01326832f Enhance bd doctor with bd prime migration recommendations (bd-0fvq)
Add comprehensive detection and migration guidance for old beads integration
patterns. This helps users adopt the more efficient bd prime approach.

Changes:
- Enhanced CheckLegacyBeadsSlashCommands with detailed migration steps
  and token efficiency benefits (99% reduction: ~10.5k → ~50 tokens)
- Added CheckAgentDocumentation to detect missing AGENTS.md/CLAUDE.md
  and suggest bd onboard or bd setup claude
- Enhanced CheckClaude to recommend bd prime hooks for MCP-only setups
  with clear token efficiency messaging
- Added comprehensive tests for all new checks

bd doctor now detects:
1. Old slash command patterns (/beads:*) and recommends bd prime hooks
2. Missing agent documentation and suggests creating it
3. MCP-only setups without hooks and shows token savings potential
4. Provides clear migration paths and benefits for all scenarios

Token efficiency messaging:
- MCP mode: ~50 tokens vs ~10.5k for full scan (99% reduction)
- CLI mode: ~1-2k tokens with automatic context recovery
- Hooks auto-refresh context on SessionStart and PreCompact

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:36:48 -05:00
Steve Yegge
34c311aba6 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-20 19:33:14 -05:00
Steve Yegge
7806937b0a Add bd doctor --fix flag to automatically repair issues (bd-ykd9)
Implements automatic fix capability for bd doctor with user confirmation
and security hardening.

Features:
- Organizes fix implementations under doctor/fix/ directory structure
- Shows all fixable issues and prompts for confirmation (Y/n) before applying
- Provides clear output about what was fixed and any errors encountered
- Re-runs diagnostics after fixes to show updated state
- Each fix is idempotent and safe to run multiple times

Automatic fixes implemented:
- Git hooks (runs bd hooks install)
- Daemon health issues (runs bd daemons killall)
- DB-JSONL sync problems (runs bd sync --import-only)
- File permissions (fixes .beads/ and database permissions)
- Database version mismatches (runs bd migrate)
- Schema compatibility issues (runs bd migrate)
- Gitignore updates (writes canonical template)

Security improvements:
- Prevents command injection by using os.Executable() instead of PATH lookup
- Prevents path traversal attacks with workspace validation
- Fixes race conditions by using cmd.Dir instead of os.Chdir()
- Corrects file permission logic (proper bit masking)
- Validates all operations run in beads workspaces only

Files changed:
- cmd/bd/doctor.go: Enhanced applyFixes() with confirmation and better UX
- cmd/bd/doctor/gitignore.go: Fixed permissions (0600 → 0644)
- cmd/bd/doctor/fix/common.go: Security helpers (getBdBinary, validateBeadsWorkspace)
- cmd/bd/doctor/fix/hooks.go: Git hooks fix
- cmd/bd/doctor/fix/daemon.go: Daemon health fix
- cmd/bd/doctor/fix/sync.go: DB-JSONL sync fix
- cmd/bd/doctor/fix/permissions.go: File permissions fix
- cmd/bd/doctor/fix/migrate.go: Database migration fixes

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:33:12 -05:00
Steve Yegge
1458519536 Merge remote-tracking branch 'origin/main'
Resolved JSONL conflicts using bd merge tool.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:31:16 -05:00
Steve Yegge
8b0a8faa76 Merge remote-tracking branch 'origin/main'
Resolved JSONL conflicts using bd merge tool.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:31:00 -05:00
Steve Yegge
4f481c88b1 Close bd-5qim (GetReadyWork optimization completed in 690c73f) 2025-11-20 19:30:27 -05:00
Steve Yegge
25e0ff6335 bd sync: 2025-11-20 19:29:56 2025-11-20 19:29:56 -05:00
Steve Yegge
8952254ed8 Update bd JSONL
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:29:44 -05:00
Steve Yegge
614ba8ab20 Add cache invalidation for blocked_issues_cache
Ensures cache stays synchronized with dependency and status changes
by calling invalidateBlockedCache() at all mutation points (bd-5qim).

Cache invalidation points:
- AddDependency: when type is 'blocks' or 'parent-child'
- RemoveDependency: when removed dep was 'blocks' or 'parent-child'
- UpdateIssue: when status field changes
- CloseIssue: always (closed issues don't block)

The invalidation strategy is full cache rebuild on any change,
which is fast enough (<1ms for 10K issues) and keeps the logic simple.

Only 'blocks' and 'parent-child' dependency types affect blocking,
so 'relates-to' and other types skip invalidation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:29:30 -05:00
Steve Yegge
ed23f8f4fe Optimize GetReadyWork to use blocked_issues_cache
Replaces expensive recursive CTE query with simple cache lookup,
achieving 96% performance improvement on 10K databases (bd-5qim).

Performance results:
- Before: ~752ms (recursive CTE on every call)
- After: ~29ms (cache lookup + filters)
- Target: <50ms ✓

The query now uses a simple NOT EXISTS check against the
blocked_issues_cache table instead of computing the full
blocked issue tree on every call.

Cache is maintained by invalidateBlockedCache() called on
dependency and status changes (added in next commit).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:29:30 -05:00
Steve Yegge
62c1f42d9f Add blocked_issues_cache table for GetReadyWork optimization
Introduces a materialized cache table to store blocked issue IDs,
replacing the expensive recursive CTE computation that was causing
~752ms query times on 10K databases (bd-5qim).

The cache is maintained via invalidation on dependency and status
changes, reducing GetReadyWork from O(n²) recursive traversal to
O(1) cache lookup.

Technical details:
- New blocked_issues_cache table with single issue_id column
- ON DELETE CASCADE ensures automatic cleanup
- Migration populates cache using existing recursive CTE logic
- rebuildBlockedCache() fully rebuilds cache on invalidation
- execer interface allows both *sql.DB and *sql.Tx usage

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:29:30 -05:00
Steve Yegge
9e57cb69d8 Improve type safety and fix minor issues in beads-mcp
Type Safety Improvements:
- Change dict → dict[str, Any] throughout codebase for explicit typing
- Add PEP 561 py.typed marker file to export type information
- Add types-requests to dev dependencies
- Improve signal handler typing (FrameType | None)
- Improve decorator typing (Callable[..., Awaitable[T]])
- Add quickstart() abstract method to BdClientBase for interface completeness

Bug Fixes:
- Fix variable shadowing: beads_dir → local_beads_dir in bd_client.py
- Improve error handling in mail.py:_call_agent_mail() to prevent undefined error
- Make working_dir required (not Optional) in BdDaemonClient
- Remove unnecessary 'or' defaults for required Pydantic fields

Validation:
- mypy passes with no errors
- All unit tests passing
- Daemon quickstart returns helpful static text (RPC doesn't support this command)
2025-11-20 19:27:56 -05:00
Steve Yegge
e1c8853748 feat: Add .beads/README.md generation during bd init (bd-m7ge)
Automatically creates a promotional README.md in the .beads directory
when bd init is run. The README explains what Beads is, provides
essential commands, highlights key benefits for AI-assisted workflows,
and encourages developers to try Beads in their own projects.

Changes:
- Added createReadme() function to generate compelling README content
- Integrated README creation in both regular and --no-db init modes
- README creation is idempotent (skips if already exists)
- Non-fatal warnings if README creation fails

The README is designed to get open source contributors excited about
using Beads for their AI-assisted development workflows.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:24:26 -05:00
Steve Yegge
109b9d275a Close bd-g9eu (TestRoutingIntegration investigation)
Issue was already fixed in commit 8e05847. Build error was due to
accidentally deleted sqlite.go, now restored.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:24:16 -05:00
Steve Yegge
88210fe039 Clean up spurious and duplicate issues
Deleted 94 spurious test and duplicate issues:
- 39 simple test placeholders (Issue 1/2, Test issue 0/1/2, Batch/Rapid tests)
- 29 additional test issues with empty descriptions
- 3 test epic issues
- 23 duplicate issues (kept oldest instance of each)

Also cleaned up:
- 10 dependency links
- 17 labels
- 127 events

Reduced issue count from 540 to 446 issues.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:22:47 -05:00
Steve Yegge
0470105fee Merge branch 'main' of https://github.com/steveyegge/beads
# Conflicts:
#	.beads/issues.jsonl
2025-11-20 19:19:28 -05:00
Steve Yegge
3b2cac4d8f Centralize error handling patterns in storage layer (bd-bwk2)
Created internal/storage/sqlite/errors.go with:
- Sentinel errors: ErrNotFound, ErrInvalidID, ErrConflict, ErrCycle
- wrapDBError helpers that auto-convert sql.ErrNoRows to ErrNotFound
- Type-safe error checking with errors.Is() compatibility

Updated error handling across storage layer:
- dirty.go: Added context to error returns, converted sql.ErrNoRows checks
- util.go: Updated withTx to use wrapDBError
- batch_ops.go: Added context wrapping to batch operations
- dependencies.go: Wrapped errors from markIssuesDirtyTx calls
- ids.go: Added error wrapping for ID validation

Also restored sqlite.go that was accidentally deleted in previous commit.

All tests pass. Provides consistent error wrapping with operation context
for better debugging.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 19:17:57 -05:00
Steve Yegge
bc2c3517f9 bd sync: 2025-11-20 19:13:10 2025-11-20 19:13:10 -05:00