Skip to content

feat(cli): add programmatic JS/TS SDK and Rust library API - #149

Merged
avidianity merged 1 commit into
mainfrom
feat/146-programmatic-api
Nov 22, 2026
Merged

avidianity merged 1 commit into
mainfrom
feat/146-programmatic-api

Conversation

@avidianity

Copy link
Copy Markdown
Owner

Summary

Expose programmatic APIs for both JavaScript/TypeScript (dual ESM + CJS + .d.ts inside npm/codeint) and Rust (crates/cli/src/lib.rs), with structured outcomes for Budget/Regression failures (exit 1) and typed CodeintError on operational errors (exit 2), plus documentation in docs/programmatic.md.

Closes #146
Closes #147
Closes #148

Tier

Tier 2 from the tier check: new Rust library surface in crates/cli/src/lib.rs, new dual ESM/CJS/TypeScript exports in npm/codeint, automated Rust and Node.js tests, and documentation in docs/programmatic.md.

Task

Spec #146 (Tickets #147 & #148):

  • Expose check, diff, trend, init, CheckOptions, DiffOptions, TrendOptions, CheckOutcome, DiffOutcome, and CodeintError from crates/cli/src/lib.rs with crates/cli/src/main.rs delegating to run_cli()
  • Add Rust library integration test in crates/cli/tests/sdk.rs
  • Extract resolveBinary() into npm/codeint/lib/binary.cjs shared by bin/codeint.js and lib/index.cjs
  • Ship dual ESM (lib/index.mjs), CommonJS (lib/index.cjs), and TypeScript types (lib/index.d.ts) via npm/codeint/package.json exports
  • Add automated Node.js test npm/codeint/test/sdk.test.mjs verifying ESM, CJS, check, diff, trend, init, exit 1 vs exit 2
  • Add docs/programmatic.md and link it from README.md and docs/reference.md

Fail-first test

  • Test: crates/cli/tests/sdk.rs::rust_sdk_supports_init_check_diff_trend_and_budget_failures and npm/codeint/test/sdk.test.mjs
  • Before the change: neither codeint-cli nor npm/codeint exported a programmatic API
  • After the change: both Rust SDK tests and Node.js ESM/CJS SDK tests pass.

Checks

Check Result
cargo test --locked --package codeint-cli --test sdk --test reference passed
CODEINT_BIN=./target/debug/codeint node --test npm/codeint/test/sdk.test.mjs passed
cargo clippy --workspace --all-targets --locked -- -D warnings passed
cargo xtask merged-result passed
./target/release/codeint diff origin/main passed
lefthook pre-commit hooks passed

Safety proof

  • Safety fact: the JS/TS SDK adds zero runtime dependencies and delegates directly to the already-verified bundled native binary; the Rust library preserves #![forbid(unsafe_code)].
  • Proof: crates/cli/tests/sdk.rs and npm/codeint/test/sdk.test.mjs ran real init, check, diff, trend, exit 1, and exit 2 flows against temporary Git repositories.
  • interrogate: none run below Tier 3.

Runtime evidence

Verified both the Rust library (crates/cli/tests/sdk.rs) and Node.js ESM/CJS SDK (npm/codeint/test/sdk.test.mjs) end-to-end against real Git repositories.

Gaps

  • Deferred coverage: crates.io publication of Rust crates remains publish = false until explicitly requested
  • Pre-existing failures: none
  • Environmental failures: none

Comment thread crates/cli/src/lib.rs
}
}

fn run() -> Result<Outcome, CliError> {
@github-actions github-actions Bot added the tier-3 Tier 3 from the tier check label Nov 22, 2026
@avidianity
avidianity merged commit e8512f0 into main Nov 22, 2026
9 checks passed
@avidianity
avidianity deleted the feat/146-programmatic-api branch November 22, 2026 09:25
@avidianity avidianity mentioned this pull request Nov 22, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tier-3 Tier 3 from the tier check

Projects

None yet

2 participants