Skip to content

QNTX-Core, rs based ax#331

Open
teranos wants to merge 31 commits intomainfrom
claude/rust-wasm-qntx-core-KGzhN
Open

QNTX-Core, rs based ax#331
teranos wants to merge 31 commits intomainfrom
claude/rust-wasm-qntx-core-KGzhN

Conversation

@teranos
Copy link
Copy Markdown
Owner

@teranos teranos commented Jan 24, 2026

Part of the Larger vision to have a stable rust based QNTX-core.
Part of the vision to convert the entirety of ATS into rust.

  • Implements ax parser in rust

  • Add 17 new tests:

    • Edge cases: empty query, whitespace, empty vocabulary
    • Unicode: CJK, accented chars, emoji, mixed scripts, case folding
    • Boundary: single char, very long queries, regex chars, hyphens
    • Deduplication verification

Continues from: #189
SQLite backend: #333

claude and others added 25 commits January 5, 2026 23:36
- Fix string allocation: use trim().to_lowercase() to avoid intermediate
- Use idiomatic if-let for substring position instead of contains+unwrap
- Handle null bytes in FFI gracefully instead of panicking
- Add 17 new tests:
  - Edge cases: empty query, whitespace, empty vocabulary
  - Unicode: CJK, accented chars, emoji, mixed scripts, case folding
  - Boundary: single char, very long queries, regex chars, hyphens
  - Deduplication verification
Performance improvements:
- SIMD-accelerated substring search via memchr crate
- Parallel matching via rayon for vocabularies > 1000 items
- Configurable parallel_threshold in EngineConfig

New features:
- Phonetic matching via Double Metaphone algorithm (rphonetic)
- Catches misspellings like "Djikstra" → "Dijkstra", "smyth" → "smith"
- Configurable enable_phonetic flag (ASCII-only due to library limitation)

New dependencies:
- memchr 2.7 (SIMD substring search)
- rayon 1.10 (parallel iteration)
- rphonetic 3.0 (phonetic encoding)

Test coverage:
- 7 new tests for phonetic, parallel, and SIMD functionality
- Total: 33 tests (up from 26)
Phase 1 of AX parser migration from Go to Rust:
- Zero-copy tokenization with lifetime annotations
- Compile-time perfect hashing (phf) for O(1) keyword lookup
- Case-insensitive keyword recognition
- Support for quoted strings, temporal expressions, dates
- Unicode identifier support
- 26 unit tests with full coverage
- AST types: AxQuery, TemporalClause, DurationExpr, DurationUnit
- State-machine parser with 7 states (Start, Subjects, Predicates, etc.)
- Full grammar support: subjects, is/are, of/from, by/via, temporal, so/therefore
- Temporal expressions: since, until, on, between X and Y, over
- Duration parsing: 5y, 3m, 2w, 10d with alternative forms
- Error types with position tracking
- 36 new parser tests (62 total)
- All clippy warnings resolved
Rust FFI layer:
- C-compatible structs for query results
- Temporal clause types (Since, Until, On, Between, Over)
- Duration parsing with unit support
- Memory management functions (parser_result_free)
- 7 FFI unit tests

C header (include/ax_parser.h):
- Type definitions for FFI structs
- Function declarations for Go integration

Go CGO wrapper (axparser package):
- Parse() function returning structured ParseResult
- Helper methods (HasSubjects, HasTemporal, IsEmpty, etc)
- 8 integration tests
- Benchmarks: ~1.1μs simple, ~2.9μs full queries

Total: 69 Rust tests, 8 Go tests, all passing
- Add ParseAxQuery() function for string-based parsing
- CGO build uses Rust parser via axparser package
- nocgo build falls back to existing Go parser
- Shared tokenizeQuery() for quote-aware tokenization
- parseTemporalToFilter() converts Rust temporal to AxFilter

Performance with Rust parser (CGO):
- Simple query: ~1.3μs
- Full query: ~5.6μs

All tests passing with both CGO and nocgo builds.
The Rust parser CGO code was being compiled in CI even though the Rust
library wasn't built there, causing linker errors.

Changes:
- Add `//go:build cgo && rustparser` to CGO files so they only compile
  when explicitly requested with `-tags rustparser`
- Update nocgo fallback to `!cgo || !rustparser` so it's used by default
- Format Rust code with cargo fmt
Resolve conflicts in fuzzy-ax:
- Keep SIMD (memchr), parallel (rayon), and phonetic (rphonetic) from PR
- Keep serde_json from main for attribute search functionality
- Regenerate Cargo.lock with all dependencies

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
The parser is a CGO library like fuzzy-ax and vidstream,
built separately for Go integration via FFI.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Universal Rust core that runs identically in browser (WASM) and server (native):

## Parser (from PR #189's qntx-parser)
- Zero-copy AX query lexer and parser
- Full AST: subjects, predicates, contexts, actors, temporal, actions
- Temporal expressions: since, until, on, between, over (duration)

## Fuzzy Matching (from fuzzy-ax, feature-gated)
- Multi-strategy: exact, prefix, word-boundary, substring, jaro-winkler, levenshtein
- Native features: SIMD (memchr), parallel (rayon), phonetic (rphonetic)
- WASM: Sequential pure-Rust fallbacks

## Classification
- Actor credibility hierarchy: Human > LLM > System > External
- Conflict types: Evolution, Verification, Coexistence, Supersession, Review

## Features
- `native` - All optimizations (SIMD + parallel + phonetic)
- `wasm` - WASM-compatible build

Tested: 36 unit tests pass, compiles for both native and wasm32-unknown-unknown

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
WASM bindings exposing qntx-core to JavaScript/TypeScript via wasm-bindgen.

## API

```typescript
import init, { QntxEngine, parseQuery, getActorCredibility } from 'qntx-wasm';

await init();
const engine = new QntxEngine();

// Parse queries
const query = engine.parseQuery("ALICE is author_of of GitHub");
// { subjects: ["ALICE"], predicates: ["author_of"], contexts: ["GitHub"], ... }

// Fuzzy search
engine.rebuildIndex(["is_author_of", "is_maintainer_of"], ["GitHub"]);
const matches = engine.searchPredicates("author", 10, 0.6);

// Actor credibility
const cred = getActorCredibility("human:alice@verified");
// { level: "human", score: 1.0, isHuman: true }
```

## Makefile targets

- `make wasm` - Build npm package (bundler target)
- `make wasm-release` - Build optimized production package
- `make wasm-web` - Build for direct browser import
- `make wasm-test` - Run WASM tests in headless browser
- `make wasm-check` - Verify WASM compilation

## Build requirements

- wasm-pack: `cargo install wasm-pack`
- wasm32 target: `rustup target add wasm32-unknown-unknown`

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Enables WASM development workflow in nix develop:
- wasm-pack for building npm packages
- wasm-bindgen-cli for bindgen operations
- Auto-installs wasm32-unknown-unknown target if missing

Usage:
  nix develop
  make wasm        # Build WASM package
  make wasm-test   # Run WASM tests

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Document that the current heuristic (underscores, is_/has_ prefixes) is
basic and could be enhanced with NLP, camelCase support, and semantic
pattern detection.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Port the core attestation data types from Go (ats/types/attestation.go):
- Attestation: the fundamental unit of verifiable claims
- AttestationBuilder: ergonomic builder pattern for creating attestations
- AxFilter, AxResult, AxSummary: query types
- Conflict: for representing conflicting attestations

This is the foundation for client-side storage across browser, Tauri,
and mobile platforms.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
This consolidates the fuzzy matching implementation:
- fuzzy-ax now depends on qntx-core instead of having its own engine
- Removed duplicate engine.rs (~1000 lines)
- Added ThreadSafeFuzzyEngine wrapper for CGO thread safety
- CGO API unchanged - Go code needs no modifications

The Rust fuzzy matching logic now lives in one place (qntx-core) and is
shared between WASM (browser), CGO (Go server), and native Rust consumers.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Now that qntx-core is the single source of truth for fuzzy matching,
remove the Go fallback implementations:

- ats/ax/fuzzy.go (Go FuzzyMatcher - 211 lines)
- ats/ax/fuzzy_test.go (tests for Go implementation)
- ats/ax/matcher_nocgo.go (stub when CGO disabled)
- ats/ax/fuzzy-ax/fuzzyax/fuzzy_stub.go (stub when Rust disabled)
- server/syscap/fuzzy_go.go (fallback version reporting)

Updated matcher.go to panic if Rust is not available, making it clear
that qntx-core is required. This ensures one implementation across all
deployment targets.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Implements AttestationStore and QueryStore traits that abstract over
different storage backends, enabling the same storage interface across:
- Native platforms (Tauri desktop, server) via SQLite
- Browser WASM via IndexedDB
- Testing via in-memory HashMap

Includes:
- AttestationStore trait: put, get, delete, update, ids, clear
- QueryStore trait: query, predicates, contexts, subjects, actors, stats
- MemoryStore: in-memory implementation for testing
- StoreError: storage-specific error types
- TODOs for SQLite, IndexedDB, and CGO wrapper backends

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Allows Go compilation without CGO/Rust for CI type checking.
All functions return ErrRustRequired - qntx-core is required at runtime.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
qntx-core is now required - no stubs, no fallbacks, no pure Go testing.

Changes:
- Add rsgo.yml: Hybrid Rust + Go pipeline that builds Rust first,
  then tests Go with qntx-core always available
- Deprecate go.yml: Pure Go tests disabled (used stubs)
- Update rs.yml: fuzzy-ax moved to rsgo.yml, keeps qntx-python only
- Remove fuzzy_stub.go: No longer needed

The seam is now visible: rsgo.yml is the single source of truth for
testing the Go server stack with its Rust dependencies.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
@teranos teranos mentioned this pull request Jan 24, 2026
@teranos teranos changed the title Improve fuzzy-ax Rust code quality and test coverage QNTX-Core, rs based ax Jan 24, 2026
Documents the architectural direction:
- Rust as the deep core language
- Proto as type source of truth (phase out typegen)
- Consolidate qntx + qntx-core into qntxrs
- Go server consumes Rust via CGO and proto types

Current state documented, future work captured for later.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Remove:
- Unused `Conflict` import (conflict detection is TODO)
- Unused `HashMap` import
- Unused `AttestationFilter` struct (not yet used)

Fixes CI failure with -Dwarnings.

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
Key changes:
- Rename concept from "QNTXrs" to "Q: The Execution Kernel"
- Add boundary definition: Inside Q (invariant) vs Outside Q (replaceable)
- Q owns behavior, proto owns contract surface
- Go reframed as distribution host consuming Q through stable boundaries
- Aspired crate consolidation: qntx + qntx-core → q

https://claude.ai/code/session_016XDKv7ojw3JLwYohjcrfiD
@teranos teranos force-pushed the claude/rust-wasm-qntx-core-KGzhN branch from fbeef39 to 44df3b5 Compare March 19, 2026 22:47
@teranos teranos force-pushed the claude/rust-wasm-qntx-core-KGzhN branch from 44df3b5 to 702511a Compare March 19, 2026 22:56
@teranos teranos force-pushed the main branch 2 times, most recently from 69e0dcb to 9cffef6 Compare April 7, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants