Repository navigation
feat: native Rust implementation of the Lore CLI (parity port) - #71
Ian-stetsenko wants to merge 12 commits into
Conversation
…ler parser, test doubles Lays the foundation for the Rust implementation of the Lore CLI under rust/: domain types, config schema, query/output shapes, the trait ports that mirror the TypeScript interfaces, protocol constants and error/exit-code mapping, clap definitions for every command, the TrailerParser, and shared test doubles (MockGitClient, MockPrompt, fixtures). Service, formatter and command modules are placeholders filled in by the following commits. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s for the Rust port Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Port JsonFormatter and TextFormatter from the TypeScript implementation with case-for-case test ports. Key order, nesting and literal strings match the TS output exactly; the text formatter reproduces chalk level-1 ANSI sequences (including dim.strikethrough nesting and per-line re-styling of multi-line text) without a colour crate. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…lter, squash merger Port slice A of the Rust parity work: - PathResolver (parse_target / to_git_log_args / to_git_blame_args, BlameArgs uses Option<u32> instead of the TS -1 end-of-file sentinel) - RandomLoreIdGenerator implementing the LoreIdGenerator port via rand - SupersessionResolver (direct + transitive chains, cycle-safe) - SearchFilter (all lore search filters plus has/text helpers) - SquashMerger with SquashOptions; empty input returns LoreError - Case-for-case ports of the vitest suites for CustomTrailerCollection and TrailerParser; new unit tests for SearchFilter (no TS test file exists) - TrailerParser: use slice::contains for the custom-key check (clippy) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…reIdReader, TomlConfigLoader Parity-first port of the query/validation/staleness/config services with their vitest suites ported case-for-case. Also fixes a pre-existing manual_contains clippy lint in trailer_parser.rs that blocked -D warnings. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…input readers and collectors Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Wires all sixteen commands (context, constraints, rejected, directives, tested/coverage, why, search, log, stale, trace, commit, validate, squash, doctor, hooks, init) with clap, ports the command unit tests, and adds an end-to-end suite that drives the built binary against throwaway git repositories (34 scenarios: exit codes, text and JSON output, hooks, amend). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
TommyC81
left a comment
There was a problem hiding this comment.
Requesting changes on exactly one point; everything else here is exemplary.
What I verified (with file evidence):
- Layering holds: no
commands/formattersimports underservices/;main.rsis the sole composition root (concretes wired atmain.rs:81-111, error-to-exit mapping at:55-70,271-295). - Exit codes 1/2/3 message-identical to
src/util/errors.ts(rust/src/util/errors.rs:69-73). - JSON output key order preserved (
serde_jsonpreserve_order,Cargo.toml:29); log/trace key sequences identical to the TS formatters (json_formatter.rs:126-164,219-245). - Config defaults, merge precedence, and aliases identical; hook script line-for-line identical (
hook_script_generator.rs:20-108); amend preserves the Lore-id the same way (commit.rs:67-87). - Test claims exact: 629 unit / 34 e2e / 9 integration; the e2e suite asserts exit codes and JSON shape with a hermetic git environment and zero hardcoded temp paths.
- Zero
unsafe, zero#[allow], no productionunwrap, a small dependency tree, andrust.ymlruns fmt + clippy-D warnings+ tests on all three OSes + MSRV. Genuinely nice work.
The blocker: the JSON commit-input path ports the silent-drop bug, and its tests enshrine it.
rust/src/services/readers/json_input_reader.rs mirrors the 0.6.0 TS reader: unknown top-level keys are never inspected; non-string intent becomes "" (json_input_reader.rs:26-28); non-string body becomes None (:29-31); non-object trailers is dropped (:33-35); and the tests assert that leniency (should_default_intent_to_empty_string_when_not_a_string, json_input_reader/tests.rs:85; trailers_that_are_not_an_object_are_ignored, :222). In the TS CLI this is a live bug: a flat schema ({"intent": "...", "Constraint": [...]}) commits with exit 0 and every trailer dropped, and lore validate passes the barren atom.
Strict top-level validation is ready as #72 (commit a648bce, Lore-id cd854cfb): reject unknown top-level keys (naming them and the allowed schema), wrong-typed intent/body/trailers, non-object payloads, and invalid JSON, all as exit-1 errors. If this PR ships the lenient behavior, the two CLIs diverge the moment #72 merges. Recommend porting the strict validation instead - landing #72 first gives the Rust side an exact spec to port against, tests included.
Nits (none blocking):
- The description says nothing outside
rust/plus one workflow file changes; the PR also adds.gitattributesand editsREADME.md(native-build paragraph) andCLAUDE.md(Rust section). All fine by me - just amend the description. - Two micro-divergences worth a line on the
rust/README.mddeltas list: Rust drops non-string elements in config arrays (config_loader.rs:283-295) where TS keeps them (config-loader.ts:168-169); hook chmod is#[cfg(unix)](hook_installer.rs:56-62) versus unconditional in TS (a no-op difference on Windows either way). - One e2e test asserting JSON key order (not just shape) would pin the
preserve_orderguarantee the parity claim rests on.
The documented deltas (update-check opt-outs without a network check, usage errors exit 1, eager formatter, epoch fallback for unparseable dates, id-index caching successful builds only, Unicode length counting) all read as reasonable and are properly documented.
With the blocker addressed (or sequenced behind #72): happy to approve.
|
One heads-up since my review above: main has two more changes in flight that touch the port's parity surface. #74 is the one to watch - it changes Lore-id lookup semantics to HEAD-reachable-first (with an --all fallback on miss), so without the same two-pass logic the port would re-introduce the #57 side-branch shadowing in Rust. #73 is smaller: it adds Happy to re-review once you push. |
Summary
A native Rust implementation of the whole Lore CLI under
rust/, as a parity port of the TypeScript sources: same 16 commands and flags, same text and JSON output (key names and order), same exit codes, same.lore/config.tomlschema and merge rules, same commit-msg hook script.This PR is additive. The npm package,
src/,tests/and the existing CI are untouched, so open PRs and the 0.6.0 release path are unaffected. The plan for retiring the TypeScript sources is inrust/README.md.Why
Startup. The commit-msg hook runs
lore validateon every commit and agents calllorein loops. Measured on this machine (20 runs each, same harness):dist/main.js)target/release/lore)lore --versionlore log --json(this repo)Most of the remaining Rust time is process spawning on Windows plus the
gitcalls themselves.Distribution. A 3.4 MB static binary with no runtime dependency; hooks stop breaking on missing or mismatched Node.
Headroom. In-process git (gitoxide) and a persistent atom index become possible later. Deliberately not in this PR: the port shells out to
gitexactly likeGitClientdoes today so behaviour stays byte-comparable.What is in the box
The layering rules from
CLAUDE.mdhold (commands -> services -> interfaces/types; nothing inservices/importscommands/orformatters/). Module names map 1:1 onto the TypeScript files so behaviour can be diffed side by side.Tests
tests/unit/**/*.test.tscase ported case-for-case, plus Rust-only edge cases)tests/integration/git-client.integration.test.ts+ more)cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo +1.85 checkare clean. All suites pass on Windows (this machine); CI covers Linux and macOS.Deliberate behaviour differences
All documented in code comments and in
rust/README.md:--no-update-notifier,LORE_NO_UPDATE_CHECK,NO_UPDATE_NOTIFIER,CI, JSON,[cli] update_check) is honoured, but no network check runs until there is a release channel for binaries (the Node package checked npm).--help/--versionexit 0 and--versionprints the bare version.getFormatter()factory.Invalid Date.Follow-ups (not in this PR)
npm install -g lore-protocolkeeps working.src/and moverust/to the repository root once a release has been exercised by the hook and by agents.