Commit Graph

581 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
bbfedb060a Refactor: extract duplicated validation and flag logic (bd-g5p7)
- Created internal/validation package for centralized validation logic
- Created cmd/bd/flags.go for shared flag registration
- Updated create and update commands to use shared logic
- Added support for 'P1' style priority to update command
- Added tests for validation logic

Amp-Thread-ID: https://ampcode.com/threads/T-c8d369a3-32f0-42a0-96d1-fd589e89bd6b
Co-authored-by: Amp <amp@ampcode.com>
2025-11-20 19:11:27 -05:00
Steve Yegge
6a25f5eaa6 fix: resolve remaining hyphenated ID issues in memory store and doctor 2025-11-20 19:01:30 -05:00
Zachary Rosen
408244ed73 fix: isHashID matches for hyphenated application names
Fixes `isHashID` checks for hyphenated application names

When a user calls bd init inside an application that has a "-" for
example my-first-application without any options than ids will follow a
pattern of my-first-application-{ID}. When using SplitN on the "-"
separator it would result in the split parts returning as [my,
first-application-{ID}] which is incorrectly pulling out the {ID}
resulting in the `isHashID` returning false when it could be a hash id.

Instead of using SplitN, this changes to find the last index of the
separator resulting in the suffix becoming the actual {ID}.
2025-11-20 19:01:30 -05:00
Steve Yegge
7b865eb541 Remove legacy issues.jsonl and update defaults to beads.jsonl
Amp-Thread-ID: https://ampcode.com/threads/T-ae11b392-24b5-4060-b431-606dd81c1763
Co-authored-by: Amp <amp@ampcode.com>
2025-11-20 19:00:36 -05:00
Steve Yegge
e5428abbb7 Merge branch 'main' into fix-monitor
Amp-Thread-ID: https://ampcode.com/threads/T-7bbd9558-2eb4-483a-bf7b-c61ea9c22092
Co-authored-by: Amp <amp@ampcode.com>
2025-11-20 12:34:30 -05:00
Steve Yegge
d933d98d47 Merge pull request #338 from cpdata/fix-daemon-lifetime
Fixes issue #278: Prevent daemon from exiting when launcher process dies
2025-11-20 09:15:51 -08:00
Steve Yegge
78a893d17d Merge pull request #337 from cpdata/fix-resolve-partial-id
Fix: Restore JSON unmarshaling in ResolveID for fixing failed bd show/update/close operations
2025-11-20 09:15:08 -08:00
Steve Yegge
0041efdf45 Merge pull request #333 from cpdata/cpdata-issue-322
Fix doctor incorrectly diagnosing hash IDs as sequential (#322)
2025-11-20 09:12:15 -08:00
Ryan
fb65163692 fix: address critical resource leaks and error handling issues (#327)
* fix: address critical resource leaks and error handling issues

Fixes 5 critical and high-priority issues identified in codebase analysis:

1. bd-vavh: Fix row iterator resource leak in recursive dependency queries
   - Move defer rows.Close() to execute on all code paths
   - Previously leaked connections on scan errors
   - Location: internal/storage/sqlite/sqlite.go:1121-1145

2. bd-qhws: Configure database connection pool limits for daemon mode
   - Set MaxOpenConns to runtime.NumCPU() + 1 for file-based databases
   - Prevents connection exhaustion under concurrent RPC load
   - Only affects daemon mode (long-running server)
   - Location: internal/storage/sqlite/sqlite.go:108-125

3. bd-jo38: Add WaitGroup tracking to FileWatcher goroutines
   - Track goroutines with sync.WaitGroup for graceful shutdown
   - Wait for goroutines to finish before cleanup in Close()
   - Prevents race condition on debouncer access during shutdown
   - Location: cmd/bd/daemon_watcher.go (Start, startPolling, Close)

4. bd-2d5r: Fix silent error handling in RPC response writing
   - writeResponse now returns errors instead of ignoring them
   - Prevents sending partial JSON and client hangs
   - Closes connection on marshal/write errors
   - Location: internal/rpc/server_lifecycle_conn.go:227-246

5. bd-zqmb: Fix goroutine leak in daemon restart
   - Add 10-second timeout to daemon Wait() goroutine
   - Kill process if it doesn't fork within timeout
   - Prevents goroutine accumulation on restart failures
   - Location: cmd/bd/daemons.go:250-268

All changes follow Go best practices and maintain backward compatibility.

* Add feature request for .beads/README.md generation during init

Created bd-m7ge to automatically generate a promotional/documentation
README in the .beads directory when running 'bd init'. This will help
advertise Beads in open source repositories and provide quick reference
documentation for developers using AI coding agents.

The README will include:
- Brief explanation of Beads (AI-native issue tracking)
- Link to steveyegge/beads repository
- Quick reference of essential commands
- Compelling messaging to encourage adoption
2025-11-20 08:13:06 -08:00
Matt Wilkie
4985a6803c Merge branch 'fix-ci-issue-328' into fix-monitor 2025-11-19 15:15:30 -07:00
Matt Wilkie
e538dbdee2 Merge show-rev-in-dev commit 'c922dc1ec32d5e3a470c22036891e239f4ab1350' into stable-fixes 2025-11-19 09:25:08 -07:00
Matt Wilkie
d72e57854b Merge branch 'pr-338' into stable-fixes 2025-11-19 09:15:35 -07:00
Charles P. Cross
4432af0aa4 fix: improve ResolvePartialID / ResolveID handling for bd show (issue #336)
- Add fast path for exact ID matches in ResolvePartialID
- Properly unmarshal ResolveID RPC responses used by `bd show`

Summary:
--------
Fixes regression introduced after v0.23.1 where `bd show <issue_id>`,
`bd update <issue_id>`, and `bd close <issue_id>` commands failed with
"operation failed: issue not found" errors even when the issue existed
in the database.

Root Cause:
-----------
The daemon's ResolveID RPC handler (handleResolveID in
internal/rpc/server_issues_epics.go) returns a JSON-encoded string
containing the resolved issue ID. For example, when resolving "ao-izl",
the RPC response contains the JSON string: "ao-izl" (with quotes).

After v0.23.1, the show/update/close commands in cmd/bd/show.go were
changed to use string(resp.Data) to extract the resolved ID, which
treats the raw bytes as a string without decoding the JSON. This caused
the resolved ID to literally be "ao-izl" (including the quotes),
which then failed to match the actual issue ID ao-izl (without quotes)
when passed to subsequent Show/Update/Close RPC calls.

In v0.23.1 (commit 77dcf55), the code correctly unmarshaled the JSON:
  var resolvedID string
  if err := json.Unmarshal(resp.Data, &resolvedID); err != nil {
      // handle error
  }

This unmarshal step was removed in later commits, causing the regression.

Fix:
----
Restored the JSON unmarshaling step in three places in cmd/bd/show.go:
1. showCmd - line 37-42
2. updateCmd - line 400-405
3. closeCmd - line 723-728

Each now properly decodes the JSON string response before using the
resolved ID in subsequent RPC calls.

Testing:
--------
- Verified `bd show <issue-id-with-prefix>` works correctly in both daemon and direct modes
- Tested with newly created issues to ensure the fix works for all IDs
- All Go tests pass (go test ./... -short)
- Confirmed behavior matches v0.23.1 working binary

The fix ensures that issue ID resolution works correctly regardless of
whether the ID prefix matches the configured issue_prefix.
2025-11-19 05:54:28 -05:00
Charles P. Cross
68f9bef98c fix: prevent daemon from exiting when launcher process exits (issue #278) 2025-11-19 05:07:16 -05:00
Charles P. Cross
04a1996fd9 fix: Fix daemon export leaving JSONL newer than database (issues #301, #321)
After daemon auto-export, JSONL mtime could be newer than database mtime
due to SQLite WAL mode not updating beads.db until checkpoint. This caused
validatePreExport to incorrectly block subsequent exports with "JSONL is
newer than database" error, leading to daemon shutdown.

Solution: Call TouchDatabaseFile after all export operations to ensure
database mtime >= JSONL mtime. This prevents false positives in validation
2025-11-19 05:06:12 -05:00
Charles P. Cross
8c1f865e23 Fix doctor incorrectly diagnosing hash IDs as sequential (issue #322)
- Enhanced checkIDFormat to sample multiple issues instead of just one
- Added detectHashBasedIDs function with robust multi-heuristic detection:
  * Checks for child_counters table (hash ID schema indicator)
  * Detects letters in IDs (base36 encoding)
  * Identifies leading zeros (common in hash IDs, rare in sequential)
  * Analyzes variable length patterns (adaptive hash IDs)
  * Checks for non-sequential numeric ordering
- Added comprehensive test coverage (16 new test cases)
- Fixes false positives for numeric-only hash IDs like 'pf-0088'

Closes #322
2025-11-18 05:20:11 -05:00
Codex Agent
070107caee Handle formatting errors in onboard renderer 2025-11-17 11:32:37 -07:00
Codex Agent
4e222145ac Fix onboard test deadlock on Windows 2025-11-17 11:26:59 -07:00
Codex Agent
bf9b2c83fb Annotate gosec-safe file accesses 2025-11-17 10:12:46 -07:00
Codex Agent
7b63b5a30b Fix CI regressions and stabilize tests 2025-11-17 10:06:35 -07:00
matt wilkie
12dfa0b555 also report branch in dev version 2025-11-16 18:10:46 -07:00
matt wilkie
6d390f7728 Merge branch 'main' into show-rev-in-dev
# Conflicts:
#	.beads/beads.jsonl
2025-11-16 15:50:09 -07:00
Steve Yegge
b9919fe031 Fix: --parent flag now creates parent-child dependency
When using 'bd create --parent <id>', the system now automatically
creates a parent-child dependency linking the child to the parent.
This fixes epic status reporting which was showing zero children.

Fixes #318 (bd-jijf)

Changes:
- cmd/bd/create.go: Add parent-child dependency after issue creation
- internal/rpc/server_issues_epics.go: Add same fix for daemon mode

Tested:
- Created epic with children, verified epic status shows correct count
- Verified closing all children makes epic eligible for closure
- All tests pass

Amp-Thread-ID: https://ampcode.com/threads/T-f1a1aee1-03bd-4e62-a63c-c1d339f8300b
Co-authored-by: Amp <amp@ampcode.com>
2025-11-15 13:20:02 -08:00
Steve Yegge
6f7e7fa930 Fix lint errors: handle error return values 2025-11-15 12:52:34 -08:00
Ryan
690c73fc31 Performance Improvements (#319)
* feat: add performance testing framework foundation

Implements foundation for comprehensive performance testing and user
diagnostics for beads databases at 10K-20K scale.

Components added:
- Fixture generator (internal/testutil/fixtures/) for realistic test data
  * LargeSQLite/XLargeSQLite: 10K/20K issues with epic hierarchies
  * LargeFromJSONL/XLargeFromJSONL: test JSONL import path
  * Realistic cross-linked dependencies, labels, assignees
  * Reproducible with seeded RNG

- User diagnostics (bd doctor --perf) for field performance data
  * Collects platform info (OS, arch, Go/SQLite versions)
  * Measures key operation timings (ready, list, show, search)
  * Generates CPU profiles for bug reports
  * Clean separation in cmd/bd/doctor/perf.go

Test data characteristics:
- 10% epics, 30% features, 60% tasks
- 4-level hierarchies (Epic → Feature → Task → Subtask)
- 20% cross-epic blocking dependencies
- Realistic status/priority/label distributions

Supports bd-l954 (Performance Testing Framework epic)
Closes bd-6ed8, bd-q59i

* perf: optimize GetReadyWork with compound index (20x speedup)

Add compound index on dependencies(depends_on_id, type, issue_id) to
eliminate performance bottleneck in GetReadyWork recursive CTE query.

Performance improvements (10K issue database):
- GetReadyWork: 752ms → 36.6ms (20.5x faster)
- Target: <50ms ✓ ACHIEVED
- 20K database: ~1500ms → 79.4ms (19x faster)

Benchmark infrastructure enhancements:
- Add dataset caching in /tmp/beads-bench-cache/ to avoid regenerating
  10K-20K issues on every benchmark run (first run: ~2min, subsequent: <5s)
- Add progress logging during fixture generation (shows 10%, 20%... completion)
- Add database size logging (17.5 MB for 10K, 35.1 MB for 20K)
- Document rationale for only benchmarking large datasets (>10K issues)
- Add CPU/trace profiling with --profile flag for performance debugging

Schema changes:
- internal/storage/sqlite/schema.go: Add idx_dependencies_depends_on_type_issue

New files:
- internal/storage/sqlite/bench_helpers_test.go: Reusable benchmark setup with caching
- internal/storage/sqlite/sqlite_bench_test.go: Comprehensive benchmarks for critical operations
- Makefile: Convenient benchmark execution (make bench-quick, make bench)

Related:
- Resolves bd-5qim (optimize GetReadyWork performance)
- Builds on bd-6ed8 (fixture generator), bd-q59i (bd doctor --perf)

* perf: add WASM compilation cache to eliminate cold-start overhead

Configure wazero compilation cache for ncruces/go-sqlite3 to avoid
~220ms JIT compilation on every process start.

Cache configuration:
- Location: ~/.cache/beads/wasm/ (platform-specific via os.UserCacheDir)
- Automatic version management: wazero keys entries by its version
- Fallback: in-memory cache if directory creation fails
- No cleanup needed: old versions are harmless (~5-10MB each)

Performance impact:
- First run: ~220ms (populate cache)
- Subsequent runs: ~20ms (load from cache)
- Savings: ~200ms per cold start

Cache invalidation:
- Automatic when wazero version changes (upgrades use new cache dir)
- Manual cleanup: rm -rf ~/.cache/beads/wasm/ (safe to delete anytime)

This complements daemon mode:
- Daemon mode: eliminates startup cost by keeping process alive
- WASM cache: reduces startup cost for one-off commands or daemon restarts

Changes:
- internal/storage/sqlite/sqlite.go: Add init() with cache setup

* refactor: improve maintainability of performance testing code

Extract common patterns and eliminate duplication across benchmarks, fixture generation, and performance diagnostics. Replace magic numbers with explicit configuration to improve readability and make it easier to tune test parameters.

* docs: clarify profiling behavior and add missing documentation

Add explanatory comments for profiling setup to clarify why --profile
forces direct mode (captures actual database operations instead of RPC
overhead) and document the stopCPUProfile function's role in flushing
profile data to disk. Also fix gosec G104 linter warning by explicitly
ignoring Close() error during cleanup.

* fix: prevent bench-quick from running indefinitely

Added //go:build bench tags and skipped timeout-prone benchmarks to
prevent make bench-quick from running for hours.

Changes:
- Add //go:build bench tag to cycle_bench_test.go and compact_bench_test.go
- Skip Dense graph benchmarks (documented to timeout >120s)
- Fix compact benchmark prefix: bd- → bd (validation expects prefix without trailing dash)

Before: make bench-quick ran for 3.5+ hours (12,699s) before manual interrupt
After: make bench-quick completes in ~25 seconds

The Dense graph benchmarks are known to timeout and represent rare edge
cases that don't need optimization for typical workflows.
2025-11-15 12:46:13 -08:00
Steve Yegge
bd6dca507d Remove orphaned TestFormatDependencyType test
The formatDependencyType function was removed in commit 57b6ea6 when
the dependency display UI was simplified. The test was left behind
and is now failing CI.

This completes the cleanup that was partially done in PR #309.
2025-11-15 11:55:15 -08:00
Peter Loron
92f3af56c5 fix: Improve missing git hook message (#306)
Install hooks with 'bd hooks install' message added to bd doctor output.

Co-authored-by: Peter Loron <ploron@protonmail.com>
2025-11-15 11:53:38 -08:00
Codex Agent
7c96142432 Add commit hash to bd version output (bd-hpt5) 2025-11-13 13:45:52 -07:00
David Laing
57b6ea606b fix: add external_ref support to daemon mode RPC (fixes #303) (#304)
Add external_ref field to CreateArgs and UpdateArgs RPC protocol
structs to enable linking issues to external systems (GitHub, Jira,
Shortcut, etc.) when using daemon mode.

Changes:
- Add ExternalRef field to rpc.CreateArgs and rpc.UpdateArgs
- Update bd create/update commands to pass external_ref via RPC
- Update daemon handlers to process external_ref field
- Add integration tests for create and update operations

The --external-ref flag now works correctly in both daemon and direct modes.

Fixes https://github.com/steveyegge/beads/issues/303

Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Happy <yesreply@happy.engineering>
2025-11-13 12:01:27 -08:00
Steve Yegge
f4a2f87aff Fix #274: Add automatic .beads/.gitignore upgrade (#300)
* Fix #274: Add automatic .beads/.gitignore upgrade

Implements three mechanisms to ensure users get updated gitignore:

1. bd doctor --fix: Manually upgrade gitignore
2. Daemon auto-upgrade: Upgrades on startup if outdated
3. bd init idempotent: Safe to re-run, always updates gitignore

The gitignore template now lives in cmd/bd/doctor/gitignore.go
for consistent updates across all three mechanisms.

Fixes: #274

* Remove test binary

Amp-Thread-ID: https://ampcode.com/threads/T-7042cfcc-ac97-43d7-a40f-3fa1bb4e1c2b
Co-authored-by: Amp <amp@ampcode.com>

* Fix critical issues: remove merge artifact and apply gitignore template

- Remove .beads/beads.left.jsonl (merge artifact that shouldn't be committed)
- Apply new gitignore template to .beads/.gitignore (was missing patterns)

Amp-Thread-ID: https://ampcode.com/threads/T-7042cfcc-ac97-43d7-a40f-3fa1bb4e1c2b
Co-authored-by: Amp <amp@ampcode.com>

* bd sync: 2025-11-12 11:09:30

* Retrigger CI

Amp-Thread-ID: https://ampcode.com/threads/T-8d532264-6d5e-4b68-88e9-e4511851b64a
Co-authored-by: Amp <amp@ampcode.com>

* Fix duplicate DoctorCheck type definition

* Trigger CI after fixing type conflict

Amp-Thread-ID: https://ampcode.com/threads/T-8d532264-6d5e-4b68-88e9-e4511851b64a
Co-authored-by: Amp <amp@ampcode.com>

---------

Co-authored-by: Amp <amp@ampcode.com>
2025-11-12 12:46:27 -08:00
Ryan
f7e80dd80c feat: add context optimization features for AI agents (#297)
* feat: add bd prime and setup commands for AI agent integration

This commit consolidates context optimization features for AI agents:

## New Commands

**bd prime** - AI-optimized workflow context injection
- Outputs ~1-2k tokens of workflow context
- Context-aware: adapts to MCP vs CLI mode
- MCP mode: minimal reminders (~500 tokens)
- CLI mode: full command reference (~1-2k tokens)
- Warns against TodoWrite tool and markdown TODOs
- Designed for SessionStart/PreCompact hooks

**bd setup claude** - Claude Code integration installer
- Installs hooks via JSON configuration (not file scripts)
- Supports --project for project-only installation
- Supports --check to verify installation
- Supports --remove to uninstall hooks
- Idempotent (safe to run multiple times)
- Merges with existing settings

**bd setup cursor** - Cursor IDE integration installer
- Creates .cursor/rules/beads.mdc with workflow rules
- Simplified implementation (just overwrites file)

## bd doctor Enhancements

- New: CheckClaude() verifies Claude Code integration
- Detects plugin, MCP server, and hooks installation
- Provides actionable fix suggestions
- Extracted legacy pattern detection to doctor/legacy.go
- Detects JSONL-only mode and warns about legacy issues.jsonl

## Core Improvements

- FindBeadsDir() utility for cross-platform .beads/ discovery
- Works in JSONL-only mode (no database required)
- Sorted noDbCommands alphabetically (one per line for easy diffs)

## Testing

- Unit tests for setup command hook manipulation
- Tests for idempotency, adding/removing hooks
- All tests passing

## Documentation

- cmd/bd/doctor/claude.md - Documents why beads doesn't use Claude Skills
- commands/prime.md - Slash command for bd prime
- Fixed G304 gosec warnings with nosec comments

## Token Efficiency

The bd prime approach reduces AI context usage dramatically:
- MCP mode: ~500 tokens (vs ~10.5k for full MCP tool scan)
- CLI mode: ~1-2k tokens
- 80-99% reduction in standing context overhead

* fix: resolve linting errors in setup utils and remove obsolete test

- Add error check for tmpFile.Close() in setup/utils.go to fix golangci-lint G104
- Remove TestCheckMultipleJSONLFiles test that referenced deleted checkMultipleJSONLFiles function

Fixes golangci-lint errcheck violations introduced in the bd prime/setup feature.
2025-11-12 10:48:36 -08:00
dezer32
d9904a8830 Fix compact command failing with 'SQLite DB needed' error when daemon is running by removing premature store check and using ensureDirectMode for analyze/apply modes (closes beads-vlo) (#294) 2025-11-12 10:37:54 -08:00
Matteo Landi
9dff345e7a Fix: Update DB mtime after import even with 0 changes (#296)
When bd import finds no changes (0 created, 0 updated), it now updates
the database modification timestamp to signal sync validation passed.

This fixes 'bd sync' refusing to export with 'JSONL is newer than database'
error that occurs after git pull updates JSONL mtime without content changes.

Root cause: Import validated DB/JSONL are in sync but didn't update DB mtime,
causing timestamp-based sync validation to perpetually fail.

Amp-Thread-ID: https://ampcode.com/threads/T-560b9c11-e368-45e6-b1e3-512b6d6010a1

Co-authored-by: Amp <amp@ampcode.com>
2025-11-12 10:37:32 -08:00
Steve Yegge
1deaad124f Fix bd sync Windows upstream detection (#281)
Use git config instead of @{u} symbolic ref for better
compatibility with Git for Windows.

Fixes #281
2025-11-10 10:59:46 -08:00
Steve Yegge
9e9db62954 Fix daemon exiting after 5s on macOS due to PID 1 parent monitoring (GH #278)
Amp-Thread-ID: https://ampcode.com/threads/T-87e6732c-f7bf-4e8d-9ebc-f778ac6f0c40
Co-authored-by: Amp <amp@ampcode.com>
2025-11-10 10:22:03 -08:00
Steve Yegge
4de9f015d6 Support local-only git repos without remote origin (bd-biwp)
- Add hasGitRemote() helper to detect if any remote exists
- Gracefully skip git pull/push when no remote configured
- Daemon now works in local-only mode (RPC, auto-flush, JSONL export)
- Add comprehensive test coverage for local-only workflows
- Fixes GH#279: daemon crash on repos without origin remote

Amp-Thread-ID: https://ampcode.com/threads/T-5dad0ca8-ac77-4ae0-8de6-208b23ea47af
Co-authored-by: Amp <amp@ampcode.com>
2025-11-09 16:16:45 -08:00
Steve Yegge
23fce6ea49 fix: add version marker to post-checkout hook and include in CheckGitHooks
The post-checkout hook was missing the bd-hooks-version marker that the other
hooks have, and it wasn't being checked by CheckGitHooks(). This caused
version mismatch issues during hook status checks.

Changes:
- Added 'bd-hooks-version: 0.23.1' marker to post-checkout hook
- Updated CheckGitHooks() to include post-checkout in the list of hooks to check

This ensures all four git hooks (pre-commit, post-merge, pre-push, post-checkout)
have consistent version tracking.

Fixes bd-kb4g

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 14:58:03 -08:00
Steve Yegge
83472aca3d bd sync: 2025-11-09 14:53:59 2025-11-09 14:53:59 -08:00
Steve Yegge
d482d9ea6e bd sync: 2025-11-09 14:13:48 2025-11-09 14:13:48 -08:00