Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ The project is pre-1.0.

## [Unreleased]

## [0.4.0] - 2026-12-04

### Breaking

- Exhaustive `GameDataQuery` struct literals must include the new `position` and `record_scope` fields (or use `..Default::default()`). See [the search guide](docs/search.md). Existing header-only defaults are preserved.

### Added

- **Canonical "Position" search.** `GameDataQuery::position` takes a `PositionQuery`: "Look for", "Or" and "Exclude" boards of men (a piece, or a colour-specific joker), horizontal and vertical mirrors, bounded inclusive `First..=Last` move windows, consecutive-position `Length`, `MoveNumbering` (`Fen` or `Relative`), and optional branch-local `include_variations`. `GameDataQuery::record_scope` (`RecordScope::Games`, `Analysis`, or `GamesAndAnalysis`) controls playable record eligibility. The fragment compiles to bitboards and is evaluated in the same single replay pass as mate, stalemate and check, stopping early once settled. "Sacrifice" is refused as unsupported. `cbvault search` gains `--look-for`, `--or`, `--exclude`, `--mirror`, `--first-move`, `--length`, `--last-move`, `--move-numbering`, `--include-variations`, and `--records`; `parse_fragment` reads the same board text (`Kg1 Rf1 Pf2g2h2 bh7`). Also fixes White null-move move-number tracking in position replay and updates GigaChess to 0.3.1, which corrects the upstream fullmove counter.

### Validation and contributors

- Position search originates from [Tulio Vianna's PR #11](https://github.com/itshak/cbvault/pull/11), integrated with maintainer improvements in PR #12.
- Canonical semantics and independent validation are documented in [ADR-009](openspec/adr/009-canonical-chess-search-semantics.md) and [search validation](docs/search-validation.md). Both native formats have public synthetic regression coverage; the private Mega acceptance uses independently collected ChessBase references and exact discrepancy fingerprints.

## [0.3.0] - 2026-11-30

### Breaking
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]

[workspace.package]
version = "0.3.0"
version = "0.4.0"
edition = "2024"
license = "MIT"
rust-version = "1.88"
Expand All @@ -17,9 +17,9 @@ readme = "README.md"

[workspace.dependencies]
gigachess = "0.3.1"
cbvault-format = { version = "0.3.0", path = "crates/cbvault-format" }
cbvault-chess = { version = "0.3.0", path = "crates/cbvault-chess" }
cbvault = { version = "0.3.0", path = "crates/cbvault" }
cbvault-format = { version = "0.4.0", path = "crates/cbvault-format" }
cbvault-chess = { version = "0.4.0", path = "crates/cbvault-chess" }
cbvault = { version = "0.4.0", path = "crates/cbvault" }
# Path-only on purpose. `cbvault-fixtures` is `publish = false`, so it will never
# exist on crates.io — and a dev-dependency that carries a version requirement
# makes cargo resolve it from the registry when preparing a package for upload,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Unlike a workflow that requires importing an entire collection into a new databa
Requires **Rust 1.88+**.

```bash
cargo add cbvault@0.3.0
cargo install cbvault-cli --version 0.3.0
cargo add cbvault@0.4.0
cargo install cbvault-cli --version 0.4.0
```

Open a database with Rust. Pass either a classic `.cbh` file, a modern `.2cbh` file, or an unambiguous database base path:
Expand Down
45 changes: 45 additions & 0 deletions docs/search-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,48 @@ CBVAULT_TEST_DB_2CBH="/path/to/Database.2cbh" \
--cli target/release/cbvault \
--report /path/to/gate-b-report.json
```

## Revalidation with GigaChess 0.3.1

The upstream White null-move counter correction was published in Rust GigaChess
0.3.1 and adopted in CBVault commit `beff433`. The search counter remains
branch-local so FEN-relative and record-relative numbering do not depend on a
particular replay entry point.

Fresh validation of this dependency upgrade:

- All 20 synthetic position-search integration tests passed in mapped and
positioned I/O on aiserver (40 executions). All 15 Python acceptance-tool
unit tests and strict OpenSpec validation passed.
- Functional GitHub CI passed all six jobs on `beff433`:
[run 47240221280](https://github.com/itshak/cbvault/actions/runs/47240221280).
- Licensed Mega 2026 Gate A: 22/22 checks over 1,213 stratified records.
Gate B: 66/66 exact discrepancy-accountability checks, with the same
independently collected reference lists and no unaccounted memberships.
- Full database verification: 11,743,083 records, 933,185,514 total plies,
including 3,084 null moves; zero failures.

Three alternating timed repetitions per executable on the same licensed
snapshot, four workers, positioned I/O. Exact ordered result memberships
agreed in every comparison:

| Query | GigaChess 0.3.0 median | GigaChess 0.3.1 median |
|---|---:|---:|
| Pe2, Last=1 | 0.490084 s | 0.466586 s |
| Bh7, default window | 9.777245 s | 9.765316 s |
| Kg1, First=10, Last=10, relative | 2.550084 s | 2.561676 s |

These are internal search times, not wall-clock times; the three workloads
show no meaningful measured regression. This is an upstream dependency
comparison, not a new exhaustive benchmark of every supported search option.

The supplemental server-side public-corpus audit reached verified fixture
fingerprints after the targeted Rust tests but exceeded its 300-second
execution budget; it is not recorded as a pass. Hosted native-corpus checks subsequently passed on `671014d`:
[native smoke and extreme](https://github.com/itshak/cbvault/actions/runs/47241618143)
(96/96 position benchmark configurations, 46/46 independent fragment checks
and 24/24 full 25,000-game exact-key configurations);
[functional CI](https://github.com/itshak/cbvault/actions/runs/47241618350)
passed all six jobs. PR #12 merged into main at `eb3e8a3` with the
contributor commits preserved. No private source data or
membership fingerprints are published.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
- [x] 5.11 Verify public cross-generation ordered fragment memberships, independent PGN matcher (44 case/format checks), full 25,000-game exact-key oracle (24 configurations) and public audit tooling.
- [x] 5.12 Run synthetic external-ID, divergent-export, and Gate B exact-discrepancy-identity negative controls in CI (`test-query-private-acceptance.py` 9/9 PASS, `test-position-audit.py` PASS).

- [ ] 5.13 Revalidate final integration against published GigaChess 0.3.1 (public CI, private Gate A/B, database verification, paired measurements).
- [x] 5.13 Revalidate against published GigaChess 0.3.1: 8/8 hosted jobs, 40/40 server position tests, private Gate A 22/22, Gate B 66/66, whole-database verification zero failures, exact-membership paired upgrade measurements. PR #12 merged at eb3e8a3.
53 changes: 53 additions & 0 deletions openspec/specs/cbvault/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,56 @@ a FEN, or a sequence of SAN or UCI moves) and `book verify`, each with a stable
- **WHEN** `cbvault book verify` is run on a book with damaged pages, undecodable keys, invalid positions, key mismatches, illegal moves, unknown move bytes, or missing children when `--children` is requested
- **THEN** the command exits with a non-zero exit status
- **AND** the counts of damaged pages, unknown moves, or missing children are reported

### Requirement: Canonical ChessBase-style "Position" search

The library SHALL answer ChessBase-style partial-position searches combined
with the "Game data" fields over a classic (`.cbh`) or 2CBH (`.2cbh`)
database: a "Look for", an "Or" and an "Exclude" board of men on squares
(piece of a colour or colour-specific joker); horizontal and vertical mirrors;
a bounded inclusive move window `First..=Last`; consecutive-position
persistence `Length`; configurable move numbering (`MoveNumbering::Fen` or
`MoveNumbering::Relative`); configurable playable record eligibility
(`RecordScope::Games`, `RecordScope::Analysis`, or
`RecordScope::GamesAndAnalysis`); and optional variation traversal
(`include_variations`). The results SHALL be independent of physical format,
search indexes, I/O mode, and worker thread count, and SHALL match an
independent canonical oracle.

#### Scenario: Boards and jokers
- **WHEN** the "Look for" board holds men, the "Or" board alternatives and the "Exclude" board men
- **THEN** a position holds the fragment when every "Look for" man stands on its square, at least one "Or" man (if any) stands on its square, and no "Exclude" man does
- **AND** a joker matches any man of its colour, and squares left empty are unconstrained.

#### Scenario: Mirrors
- **WHEN** "Horizontal" is set
- **THEN** the fragment reflected across the horizontal axis (ranks 1↔8), with the colours swapped, also matches
- **AND** with "Vertical" set, the fragment reflected across the vertical axis (files a↔h) also matches.

#### Scenario: Bounded First, Length and Last
- **WHEN** First, Length and Last are given
- **THEN** only positions whose assigned move number lies in the bounded inclusive interval `First..=Last` are counted (including initial and final positions when their move number lies in `First..=Last`)
- **AND** `Last` is never silently expanded to `First + 1`, nor is an extra White move beyond `Last` searched
- **AND** the fragment must hold in `Length` consecutive counted positions within `First..=Last` (a persistence run cannot begin before `First` or extend past `Last`)
- **AND** `MoveNumbering::Fen` (default) labels positions from the initial board's FEN fullmove number while `MoveNumbering::Relative` labels the start position and first move as move 1, advancing the next move number only after Black moves (including null moves). A reached board is labelled with the move just played, not the next move in its FEN; e.g. both boards after 1.e4 and 1...e5 belong to move 1.

#### Scenario: Record eligibility
- **WHEN** `record_scope` is `Games` (default), `Analysis`, or `GamesAndAnalysis`
- **THEN** only live records of the selected playable kind(s) are searched
- **AND** deleted records and guiding texts are excluded from position searches
- **AND** missing metadata on analysis records does not silently satisfy header filters that require it.

#### Scenario: Mainline and variations
- **WHEN** `include_variations` is `false` (default)
- **THEN** a fragment standing only in a variation does not match
- **AND** when `include_variations` is `true`, variations are evaluated with branch-local move numbering and persistence state so persistence never spans unrelated branches, and matching game IDs are deduplicated and ordered.

#### Scenario: Unanswerable pages are refused
- **WHEN** "Sacrifice" is set
- **THEN** the query is refused with `QueryError::Unsupported`
- **AND** empty boards, two men on one "Look for" square, First after Last, or combining `text_records` with a non-default `record_scope` are refused with `QueryError::Invalid`.

#### Scenario: The replay stops early
- **WHEN** the answer is known before the end of the line
- **THEN** the replay of that game stops, unless a matching fragment still needs the final main-line position checked
- **AND** a validated initial board is evaluated before decoding the first move; a corrupt unneeded suffix does not invalidate a settled answer.
Loading