Commit Graph

23 Commits

Author SHA1 Message Date
Jordan Hubbard
c9fa7af04c test: expand compact and ui coverage 2025-12-29 16:01:11 -08:00
Steve Yegge
9480041605 fix: skip interactions.jsonl in FindJSONLInDir (GH#709)
FindJSONLInDir() was returning interactions.jsonl when issues.jsonl
didn't exist. This caused bd sync to write issue data to the wrong
file after fresh init.

Add interactions.jsonl to the skip list alongside deletions.jsonl
and merge artifacts, so the function correctly defaults to issues.jsonl.
2025-12-22 23:37:45 -08:00
Steve Yegge
4f504bdff8 fix(test): resolve target path in symlink test for macOS
On macOS, /var is a symlink to /private/var, so EvalSymlinks returns
the canonical path. The test needs to resolve the expected target path
before comparison.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-20 18:02:41 -08:00
Doug Campos
c7615e4075 fix(setup): preserve symlinks in atomicWriteFile
Add ResolveForWrite helper that resolves symlinks before writing,
so atomic writes go to the symlink target instead of replacing
the symlink itself.
2025-12-20 20:15:55 -05:00
Steve Yegge
52135d0370 feat(types): add template molecules infrastructure for beads-1ra
Add support for template molecules (is_template field and TypeMolecule type):

- Add IsTemplate field to Issue type with JSON support
- Add TypeMolecule constant to IssueType constants
- Add IsTemplate filter to IssueFilter for querying
- Update all SQL queries to include is_template column
- Add migration 024 for is_template column
- Add FindMoleculesJSONLInDir helper for molecules.jsonl path detection

This enables treating certain issues as read-only templates that can be
instantiated to create work items. The template flag allows separating
template molecules from regular work items in queries and exports.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-19 22:03:22 -08:00
Steve Yegge
aed166fe85 fix: improve issue ID prefix extraction for word-like suffixes
Refine ExtractIssuePrefix to better distinguish hash IDs from English
words in multi-part issue IDs. Hash suffixes now require digits or be
exactly 3 chars, preventing "test", "gate", "part" from being treated
as hashes. This fixes prefix extraction for IDs like "vc-baseline-test".

Also updates git hooks to use -q flag and adds AGENTS.md documentation.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 13:19:22 -08:00
Steve Yegge
77aeb50d27 fix(utils): parse multi-hyphen prefixes correctly (GH#405)
The ExtractIssuePrefix function was falling back to first-hyphen
extraction when the suffix didn't look like a hash (e.g., 4+ char
words without digits). This broke prefixes like 'hacker-news' where
an issue ID 'hacker-news-test' would incorrectly extract 'hacker'.

Fix: Always use last-hyphen extraction for alphanumeric suffixes.
Only fall back to first-hyphen for non-alphanumeric suffixes.

Examples:
- 'hacker-news-test' -> 'hacker-news' (was: 'hacker')
- 'me-py-toolkit-abc' -> 'me-py-toolkit' (was: 'me')
- 'vc-baseline-hello' -> 'vc-baseline' (was: 'vc')

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 01:13:15 -08:00
Shaun Cutts
d541ff48e3 fix: accept 3-char all-letter base36 hashes in ExtractIssuePrefix (#446)
isLikelyHash() required at least one digit to distinguish hashes from
English words, but base36 hashes can be all-letters by chance.

This caused ExtractIssuePrefix("xa-adt-bat") to return "xa" instead
of "xa-adt", breaking import for 20 issues in xa-adapt.

Fix: Accept all-letter suffixes for 3-char only, keep digit requirement
for 4+ chars where word collision probability is low enough (~0.2%).

Rationale:
- 3-char: 36³ = 46K hashes, ~1000 common words = ~2% collision
- 4-char: 36⁴ = 1.6M hashes, ~3000 words = ~0.2% collision
- 5+ char: collision rate negligible
2025-12-02 23:00:24 -08:00
Steve Yegge
2320a1c2ef fix: ExtractIssuePrefix now handles 3-char base36 hashes (#425)
- Lower minimum hash length from 4 to 3 characters
- Update hash validation to support base36 (0-9, a-z) instead of just hex
- Require at least one digit to distinguish hashes from English words
- Fixes prefix extraction for hyphenated prefixes with 3-char hashes
  e.g., 'document-intelligence-0sa' now correctly extracts 'document-intelligence'
- Add test cases for 3-char hashes with multi-part prefixes
- Resolves bd sync failures with 'prefix mismatch detected' errors
2025-11-30 20:50:56 -08:00
Steve Yegge
8becf0d9b9 fix: handle multi-hyphen prefixes with hash IDs (#419)
Fixed bug where issue IDs with multiple hyphens in the prefix and hash
suffixes were incorrectly parsed. For example, `web-app-a3f8e9` was
being parsed with prefix `web-` instead of `web-app`.

Root cause: ExtractIssuePrefix() only checked for numeric suffixes.
When it encountered a hash suffix, it fell back to using the first
hyphen instead of the last hyphen.

Changes:
- Added isLikelyHash() helper to detect hexadecimal hash suffixes (4-8 chars)
- Updated ExtractIssuePrefix() to handle both numeric and hash suffixes
- Added comprehensive test cases for various prefix patterns

Test coverage includes:
- web-app-123 (numeric suffix)
- web-app-a3f8e9 (hash suffix)
- my-cool-app-a3f8e9 (three-part prefix with hash)
- super-long-project-name-1a2b (four-part prefix)
- Various hash lengths and case variations

Co-authored-by: dubstylee <dubstylee@users.noreply.github.com>

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 15:05:25 -08:00
Steve Yegge
40b07045c7 refactor: deduplicate FindJSONLInDir function (bd-8a5)
Extract shared JSONL file discovery logic to internal/utils/path.go.
Both autoimport and beads packages now use this shared implementation.

Changes:
- Add utils.FindJSONLInDir with common logic
- Update autoimport.go to use utils.FindJSONLInDir
- Update beads.go to delegate to utils.FindJSONLInDir
- Update server_export_import_auto.go to use utils.FindJSONLInDir
- Move FindJSONLInDir test to utils/path_test.go
- Fix pre-existing duplicate countIssuesInJSONLFile in init.go

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 23:07:53 -08:00
Kris Hansen
9931ac9bd9 fix: support multi-part prefixes in issue ID extraction (#398) 2025-11-26 17:42:14 -08: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
Steve Yegge
934ae04fa0 Fix gh-316: Prefer exact ID matches over prefix matches
The ID disambiguation logic treated 'offlinebrew-3d0' as ambiguous when
child IDs like 'offlinebrew-3d0.1' existed. Now the system:

1. Checks for exact full ID matches first (issue.ID == input)
2. Checks for exact hash matches (handling cross-prefix scenarios)
3. Only falls back to substring matching if no exact match is found

Added test cases verifying:
- 'offlinebrew-3d0' matches exactly, not ambiguously with children
- '3d0' without prefix still resolves to exact match

Amp-Thread-ID: https://ampcode.com/threads/T-5358ea57-e9ea-49e9-aedf-7044ebf8b52a
Co-authored-by: Amp <amp@ampcode.com>
2025-11-15 14:07:38 -08:00
Steve Yegge
83472aca3d bd sync: 2025-11-09 14:53:59 2025-11-09 14:53:59 -08:00
Steve Yegge
b4cb636d92 Switch from hex to Base36 encoding for issue IDs (GH #213)
This change improves information density by using Base36 (0-9, a-z) instead
of hex (0-9, a-f) for hash-based issue IDs. Key benefits:

- Shorter IDs: Can now use 3-char IDs (was 4-char minimum)
- Better scaling: 3 chars good for ~160 issues, 4 chars for ~980 issues
- Case-insensitive: Maintains excellent CLI usability
- Backward compatible: Old hex IDs continue to work

Changes:
- Implemented Base36 encoding with proper truncation (keep LSB)
- Updated adaptive length thresholds (3-8 chars instead of 4-8)
- Fixed collision probability math to match encoding (was calculating
  for base36 but encoding in hex - now both use base36)
- Fixed ID parser bug (use prefixWithHyphen for substring matching)
- Updated all tests and test data patterns

Fixes #213

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 12:02:15 -08:00
Steve Yegge
22756509cc Refactor: Extract path canonicalization into utils.CanonicalizePath()
Extracts duplicated path canonicalization logic (filepath.Abs + EvalSymlinks)
into a reusable helper function utils.CanonicalizePath() in internal/utils/path.go.

Changes:
- Add internal/utils/path.go with CanonicalizePath() function
- Add comprehensive tests in internal/utils/path_test.go
- Replace inline canonicalization in beads.go:131-140
- Replace inline canonicalization in cmd/bd/main.go:446-454
- Replace inline canonicalization in cmd/bd/nodb.go:25-33

The new helper maintains identical behavior:
1. Converts path to absolute form via filepath.Abs
2. Resolves symlinks via filepath.EvalSymlinks
3. Falls back gracefully on errors (returns absPath if EvalSymlinks fails,
   returns original path if Abs fails)

Fixes bd-efe8

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 19:11:08 -08:00
Steve Yegge
2b086951c4 fix: Address all errcheck and misspell linter errors 2025-11-01 23:56:03 -07:00
Midworld Kim
21ab565819 Fix hyphenated issue prefix detection (#199)
- update prefix/number parsing to use the last hyphen across utils and nodb paths
- add regression tests covering multi-hyphen prefixes in both packages
2025-11-01 19:57:37 -07:00
Steve Yegge
cd8cf997c9 Add comprehensive tests for internal/utils ID parsing functions
- Added tests for ExtractIssuePrefix (100% coverage)
- Added tests for ExtractIssueNumber (100% coverage)
- Enhanced ResolvePartialID tests with edge cases
- Added ResolvePartialIDs error handling tests
- Improved internal/utils coverage from 42% to 88%
- Overall project coverage increased from 45.6% to 45.8%

Amp-Thread-ID: https://ampcode.com/threads/T-1a44c987-7e49-431d-8e0b-467157d079eb
Co-authored-by: Amp <amp@ampcode.com>
2025-10-31 17:52:36 -07:00
Steve Yegge
11c26d5af8 Add substring ID matching for all bd commands
- Enhanced ResolvePartialID to handle:
  - Bare hashes: 07b8c8 → bd-07b8c8
  - Prefix without hyphen: bd07b8c8 → bd-07b8c8
  - Full IDs: bd-07b8c8 (unchanged)
  - Substring matching: 07b → finds bd-07b8c8

- Added RPC support:
  - New OpResolveID operation
  - handleResolveID server handler
  - ResolveID client method

- Updated all commands to resolve IDs:
  - show, update, close, reopen
  - dep (add, remove, tree)
  - label (add, remove, list)

- Works in both daemon and direct modes

Fixes bd-0591c3
2025-10-30 19:20:50 -07:00
Steve Yegge
2eb4c883ab Implement prefix-optional ID parsing (bd-170)
- Add internal/utils/id_parser.go with ParseIssueID and ResolvePartialID
- Update all CLI commands to accept IDs without prefix (e.g., '170' or 'bd-170')
- Add comprehensive tests for ID parsing functionality
- Works in direct mode; RPC handlers to be updated in bd-177

Commands updated:
- show, update, edit, close (show.go)
- reopen (reopen.go)
- dep add/remove/tree (dep.go)
- label add/remove/list (label.go)
- comments (comments.go)

Amp-Thread-ID: https://ampcode.com/threads/T-1f6a301b-b53f-440f-bd79-e453234ac1c9
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 15:41:46 -07:00
Ryan Newton + Claude
e3df9cfa97 Add rename-prefix --repair flag and consolidate issue ID parsing
Enhances rename-prefix command with --repair flag to consolidate databases
with multiple prefixes. Creates shared issue ID utilities to eliminate code
duplication across import and rename operations.

Key changes:
- Add --repair flag to detect and consolidate multiple issue prefixes
- Create internal/utils/issue_id.go with ExtractIssuePrefix() and ExtractIssueNumber()
- Update all duplicate prefix extraction code to use shared utilities
- Add comprehensive tests for repair functionality

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

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2025-10-27 18:31:01 +00:00