Commit graph

12 commits

Author SHA1 Message Date
Julian Knutsen
57ef364501
build(bazel): side-by-side Bazel scaffold + policy tests (#6798)
* build(bazel): add side-by-side Bazel scaffold (module + gazelle)

Add a Bzlmod Bazel build alongside the Go toolchain. `go build` and
`go test` are unchanged; nothing in CI invokes Bazel yet.

- MODULE.bazel: rules_go 0.63.0, gazelle 0.53.0, Go SDK 1.26.7 (matches
  the go.mod toolchain directive), go_deps from go.mod.
- ICU policy (engdocs/ICU-POLICY.md): a go-mysql-server gazelle_override
  selects the pure-Go regex backend and excludes regex_cgo.go, and
  .bazelrc builds with --@rules_go//go/config:tags=gms_pure_go, so no
  target depends on go-icu-regex or links libicu.
- third_party/patches: three module_override patches for dolt deps that
  ship WORKSPACE-era BUILD files, adapted from the gascity project.
- .bazelrc: prcore/ci test configs (inert for now; they match pr-core's
  test selection, not yet its environment isolation) and a generic
  remote-exec config with a bounded remote timeout. Executor endpoints and
  TLS credentials come only from a gitignored .bazelrc.local/user.bazelrc
  or a CI rc outside the workspace.
- .bazelversion pins Bazel 9.2.0; .bazelignore skips separate modules,
  non-Go trees, nested agent worktrees (.claude, .worktrees) and local
  data/output dirs (.beads, .dolt, dist, .runtime, tmp), so a primary
  checkout neither builds nor gazelle-rewrites nested worktree copies.
- Gazelle-generated BUILD.bazel files for every Go package.
- Makefile: `make bazel-sync` (gazelle + bazel mod tidy).
- .gitignore: bazel-* output symlinks and machine-local rc files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): policy tests for the Bazel configuration

Add scripts/bazel_policy_test.go, plain Go tests that run under both
`go test ./scripts` and `bazel test //scripts:scripts_test`:

- MODULE.bazel go_sdk.download version equals the go.mod toolchain.
- ICU policy: .bazelrc sets gms_pure_go for build, the go-mysql-server
  gazelle_override excludes regex_cgo.go, and the root BUILD.bazel
  carries `# gazelle:build_tags gms_pure_go`.
- .bazelversion pins an exact Bazel release.
- .bazelrc.local and user.bazelrc are gitignored (parsed from .gitignore
  and cross-checked with git check-ignore when in a checkout).
- No remote-execution endpoints or credentials in committed bazelrc-like
  files, Markdown docs or .github/**: remote/BES/TLS flags
  (--remote_executor, --remote_cache, --bes_backend, --remote_header,
  --tls_client_certificate, ...) with a literal value, with or without a
  URL scheme, and non-loopback gRPC URLs in rc/.github files. Placeholders,
  $VARIABLES, and loopback are allowed; Markdown gRPC URLs (OTel exporter
  docs) are not flagged. Skipped outside a git checkout, e.g. in the Bazel
  sandbox.

Each check is a pure function also exercised against fixtures that break
the invariant. The files the tests read are declared as data via
//:bazel_policy_files so they resolve from runfiles under Bazel.

scripts/check-build-tags.sh now treats Bazel invocations as governed by
.bazelrc: the shell command segment that invokes Bazel (split on &&, ||,
;, |, $( and backticks) is exempt from the per-line `go` tag check, while
a bare `go` in another segment of the same line is still flagged. When
any scanned file invokes Bazel (or .bazelrc exists) .bazelrc must set
--@rules_go//go/config:tags=gms_pure_go for build.
scripts/check_build_tags_test.go covers both in a temp repository.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(scripts): split bazel lines in pure bash so check-build-tags works with BSD sed

BSD sed (macOS) does not expand \n in s/// replacements, so the segment
split never happened and the Bazel-exemption tests failed on macos-latest.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(scripts): skip check-build-tags tests when bash lacks mapfile

macOS runners use /bin/bash 3.2, which has no mapfile; check-build-tags.sh
has always required bash >= 4, so the new tests are skipped there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 03:41:02 -07:00
Vishnu J
eb1689cb9d
fix(timeparsing): add min minutes unit to compact duration parser (#6609) (#6629)
* fix(timeparsing): add unambiguous "min" minute unit to compact durations

--defer/--due use the compact duration parser, whose smallest unit was
one hour. "+30m" silently parsed as 30 months (rc 0, no warning), so a row
meant to return in half an hour became ready again years later, while
"+30min" was rejected outright.

Add "min" as a new minute spelling alongside h/d/w/m/y. Bare "m" keeps
meaning months, so existing callers are unchanged; redefining or refusing
bare "m" is a semantics change left for maintainer sign-off.

Fixes #6609

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(query): resolve the "min" minutes unit as "N ago" in bd query

The widened compact-duration grammar reached the `bd query` plane through
the evaluator's ungated fallback arm: `isDurationSuffix` classifies a
single rune, so `30min` lexed as TokenIdent, skipped `parseDurationAgo`,
and resolved through `ParseRelativeTime` as 30 minutes in the *future* --
the opposite direction from `created > 30m` (30 months ago) and from the
command's own documented contract at cmd/bd/query.go:66.

Recognize multi-rune duration suffixes in `readNumberOrDuration` so
`30min` lexes as TokenDuration and resolves to 30 minutes ago. Plural,
uppercase, and identifier-continuation spellings (`30mins`, `30MIN`,
`30min-window`) keep their existing identifier classification.

Maintainer review fixups for PR #6629, review iteration 1:
- pin the query-plane semantics with EvaluateAt tests against a fixed now
- make the months assertion in TestParseTimeFlag_MinutesVsMonths
  two-sided, so it can no longer stay green if "m" regressed to years
- mention +30min in the ParseRelativeTime error examples

Maintainer review fixups for PR #6629, review iteration 2 (non-gating):
- bind the query lexer's unit set to the shared timeparsing grammar with
  a cross-package test. ParseCompactDuration is the oracle, so a unit
  added to that grammar but missed in durationWords/isDurationSuffix now
  fails loudly instead of silently resolving as a future offset -- the
  class this fixup previously closed only for "min". Verified by adding
  "sec" to the shared pattern alone: the test discovers and fails it with
  no test edit.
- pin that a duration token on a non-time field (label=1min) is still
  filtered as a literal string, since parseTimeValue is the only consumer
  of ValueType.
- list min/m/y in the bd query duration help, so "m" reads as months
  right next to "min". The generated CLI docs are release-pinned
  (docs/cli-docs.pin v1.2.2, built from the tag rather than the working
  tree), so they are deliberately not regenerated here;
  ./scripts/generate-cli-docs.sh --check reports them fresh.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-09-26 18:51:37 -07:00
Isis Anisoptera
40b7f75c26
fix(query): make slash and mixed-case metadata keys queryable (#4896)
* fix(metadata): allow / in metadata keys

ValidateMetadataKey rejected slashes even though keys are always passed
as bind parameters and JSONMetadataPath quotes non-identifier keys, so
the restriction had no safety purpose. Allow / in the key charset and
quote slash keys in JSON paths (unquoted, / is a path syntax error).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

* fix(query): make slash metadata keys queryable; always quote JSON paths

Code-review follow-ups to the / metadata-key change:

- Allow / in query-language identifiers so keys like jira/sprint are
  reachable from 'metadata.jira/sprint=42' expressions, not just the
  --metadata-field flag.
- JSONMetadataPath now quotes every key unconditionally (valid for plain
  keys too), removing the separator char list that had to stay in sync
  with validMetadataKeyRe.
- Derive the ValidateMetadataKey error message from the regex itself.
- Collapse the five JSONMetadataPath clone tests into one table-driven
  test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

* test(query): enforce that all valid metadata keys are queryable

Sweep every printable ASCII character and assert each key accepted by
storage.ValidateMetadataKey parses as metadata.<key>=<value>, so the
lexer's identifier alphabet and the storage key regex can't drift apart
and silently recreate the unqueryable-key bug class.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

* fix(query): preserve metadata key case; escape JSON path keys

Review follow-ups on this branch:

- The parser lowercased the whole field token, so mixed-case metadata
  keys (valid per ValidateMetadataKey, stored case-sensitively) were
  silently unqueryable via metadata.<key>=<value> — and inconsistent
  with has_metadata_key and the --metadata flag, which preserve case.
  Keep field-name matching case-insensitive but restore the key
  suffix's original case.

- JSONMetadataPath spliced the key into the quoted path unescaped,
  relying on every caller validating first. Escape \ and " locally so
  the function is correct for any input.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jrTawz2CRUiJLCt2UTQ2B

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-24 17:52:22 -07:00
Rome Thorstenson
0121718514
fix(query): lex digit-led identifier-shaped tokens as identifiers (#4403)
The query lexer unconditionally dispatched digit-led tokens to the
number/duration reader, which only accepts digits followed by an optional
single-character duration suffix. Identifier-shaped values like
"1-alpha" or "42d-sla" tripped the reader at the first non-digit /
non-suffix byte:

    $ bd query 'assignee=1-alpha'
    Error: parsing query: expected digit at position 11

Every caller that wanted to filter on such a value had to quote it or
fall back to a client-side filter, which is silly given that the
character set is already accepted in the identifier reader. The query
DSL otherwise treats identifiers and values uniformly (cf. existing
"identifier with hyphen" / "unquoted identifier with colon" coverage),
so it is the digit-led case that is the outlier.

Two changes in readNumberOrDuration:

  - The duration suffix only fires when the suffix character stands
    alone (no further identifier-continuation lookahead). "7d" → still
    a duration; "7day" → falls through to identifier.
  - After reading the digit run, if an unsigned token butts against
    more identifier characters, the lex restarts at the start position
    and re-reads the token as an identifier. Signed forms ("-3-foo")
    still error so arithmetic-shaped input doesn't silently become an
    identifier.

Five lexer cases added covering both directions: digit-led identifiers
parse cleanly, durations still survive when the suffix is terminal.
2026-07-05 11:15:15 -07:00
matt wilkie
f03d4e7fac
feat(issues): add started_at timestamp (GH#2796) (#3206)
* fix: enable auto-export by default with canonical issues.jsonl name (GH#2973)

Users expected JSONL export to refresh automatically but export.auto
defaulted to false, requiring explicit opt-in. Also the default filename
(export.jsonl) didn't match the canonical issues.jsonl used in docs and
git hooks. Change defaults: export.auto=true, export.path=issues.jsonl,
export.git-add=true so viewers (bv) and git workflows see fresh data
without extra configuration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(init): add auto-export prompt and document export.* config (GH#2973)

Interactive bd init now asks whether to enable auto-export (default: yes).
Users can opt out during setup instead of discovering the setting later.

Also documents the export.* config namespace in bd config --help with
all four keys (export.auto, export.path, export.interval, export.git-add)
and adds export examples.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(issues): add started_at timestamp (GH#2796)

Adds a `started_at` field to issues that is auto-populated when an
issue transitions to in_progress status. Preserved across subsequent
status changes.

- Migration 0027 adds started_at column to issues and wisps tables
- ManageStartedAt() in issueops mirrors ManageClosedAt() pattern
- Query filter support: `started>2026-01-01`, `started<...`
- Displayed in `bd show` between Created and Updated
- Exposed in --json output via struct tag

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: gofmt alignment in update.go and types.go

Amp-Thread-ID: https://ampcode.com/threads/T-019d887d-4eb1-7648-96be-8d906797c382
Co-authored-by: Amp <amp@ampcode.com>

* fix(claim): set started_at when claiming via --claim (GH#2796)

ClaimIssueInTx had its own bespoke UPDATE that only wrote assignee, status,
and updated_at. Since `bd update --claim` is the canonical way agents transition
issues to in_progress, started_at was left NULL in the common case. Set it on
first transition, mirroring ManageStartedAt's guard (preserve existing value on
re-claim).

Also document the `started` field in `bd query --help`.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Amp <amp@ampcode.com>
2026-04-14 09:24:08 -07:00
guzzle
4856644766 fix: allow colons in unquoted query identifier values
The query lexer's isIdentChar function did not include ':' as a valid
character, causing expressions like "label=gt:merge-request" to fail
with "unexpected character ':'" errors. This broke bd query for any
label using the namespaced gt: prefix convention.

Add ':' to isIdentChar so that namespaced label values can be used
without quoting. Quoted form ("gt:merge-request") continues to work.

Fixes: mo-qki
2026-03-14 05:02:22 +00:00
beads/refinery
69573b8810 fix: add test coverage for quoted label values with colons (bd-wnr1)
Adds lexer and evaluator tests for label="gt:merge-request" syntax,
verifying the query parser correctly handles colon characters in
quoted string values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 01:46:11 -07:00
Joseph Turian
9457158f2d feat: add has_metadata_key to bd query DSL
Support metadata existence checks in the query DSL:
  bd query "has_metadata_key=team AND status=open"

Completes the list/search/query triangle for metadata existence
filtering. Uses existing IssueFilter.HasMetadataKey field and
SQL-level JSON_EXTRACT IS NOT NULL from PR2.

Implements GH#1406.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 12:43:06 -05:00
Joseph Turian
00e802f60c
feat: make metadata queryable from bd list, bd search, and bd query (#1908)
Add SQL-level metadata filtering using Dolt's JSON_EXTRACT/JSON_UNQUOTE
with parameterized queries. New CLI flags: --metadata-field key=value
(repeatable, AND semantics) and --has-metadata-key key. Add metadata.<key>
support to bd query DSL. Strict key validation prevents JSON path injection.

Remove //go:build cgo tag from metadata_filter_test.go (CGO bifurcation
was removed in c4010c19).
2026-02-22 15:30:07 -08:00
jasper
619f34a441 chore: add explanatory comments to silently ignored errors across codebase
Code health review found 30+ instances of error suppression using blank
identifier without explanation. Added comments to 82 files explaining WHY
each error is safely ignored (best-effort cleanup, advisory operations,
safe defaults, etc.) to improve code maintainability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/polecats/jasper
Rig: beads
Role: polecats
2026-02-14 17:16:43 -08:00
beads/crew/lizzy
2bb827facb style: run gofmt across entire codebase (bd-nmk12)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 19:35:20 -08:00
Patrick Farrell
f3874edee0 feat: add simple query language for complex filtering
Adds a new `bd query` command that enables complex filtering with a simple
query language supporting boolean operators, comparisons, and date-relative
expressions.

Features:
- Field comparisons: status=open, priority>1, updated>7d
- Boolean operators: AND, OR, NOT (case-insensitive)
- Parentheses for grouping: (status=open OR status=blocked) AND priority<2
- Date-relative expressions: 7d, 24h, 2w (interpreted as "X ago")
- Supports all IssueFilter fields: status, priority, type, assignee, label,
  title, description, notes, created, updated, closed, id, spec, pinned,
  ephemeral, template, parent, mol_type

Implementation:
- New internal/query package with lexer, parser, and evaluator
- Simple AND queries converted directly to IssueFilter for SQL efficiency
- Complex OR queries use predicate functions for in-memory filtering
- Comprehensive test coverage (62 tests)

Examples:
  bd query "status=open AND priority>1"
  bd query "(status=open OR status=blocked) AND updated>7d"
  bd query "NOT status=closed AND type=bug"
  bd query "label=urgent OR label=critical"

Closes: bd-o9g

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 15:57:40 +00:00