* feat: move git operations to Rust via git2 crate (#524) Eliminates ~70 execSync/execFileSync git CLI calls across 15 TypeScript files by implementing native libgit2 operations in Rust and routing all consumers through the native-git-bridge. Rust (native/crates/engine/src/git.rs): - Added 28 new NAPI functions covering both read and write operations - Read: git_is_repo, git_has_staged_changes, git_diff_stat, git_diff_name_status, git_diff_numstat, git_diff_content, git_log_oneline, git_worktree_list, git_branch_list, git_branch_list_merged, git_ls_files, git_for_each_ref, git_conflict_files, git_batch_info - Write: git_init, git_add_all, git_add_paths, git_reset_paths, git_commit, git_checkout_branch, git_checkout_theirs, git_merge_squash, git_merge_abort, git_rebase_abort, git_reset_hard, git_branch_delete, git_branch_force_reset, git_rm_cached, git_rm_force, git_worktree_add, git_worktree_remove, git_worktree_prune, git_revert_commit, git_revert_abort, git_update_ref TypeScript (native-git-bridge.ts): - Added 35 bridge functions with native-first + execSync fallback - New types: GitDiffStat, GitNameStatus, GitNumstat, GitLogEntry, GitWorktreeEntry, GitBatchInfo, GitMergeResult Consumer migrations (15 files): - worktree-manager.ts: removed local runGit/getMainBranch, all ops native - auto-worktree.ts: merge, checkout, conflict resolution all native - git-service.ts: smart staging, commits, snapshots all native - auto.ts, guided-flow.ts: repo init/bootstrap native - auto-supervisor.ts: working tree detection native - git-self-heal.ts: merge/rebase abort, reset all native - doctor.ts: health checks, branch listing, worktree cleanup native - commands.ts: branch/snapshot cleanup native - session-forensics.ts: diff stat queries native - auto-recovery.ts: merge state reconciliation native - gitignore.ts, undo.ts, worktree-command.ts: remaining ops native Kept as execSync (by design): - git push (credential handling too complex for libgit2) - native-git-bridge.ts fallbacks (graceful degradation) - runPreMergeCheck (runs arbitrary user commands) Closes #524 * fix: restore getMainBranch export from worktree-manager The agent migration removed getMainBranch from worktree-manager.ts but worktree-command.ts still imports it. Re-add as a thin wrapper around nativeDetectMainBranch. * fix: address PR #572 review feedback — security, correctness, error handling CRITICAL: - Path traversal protection via validate_path_within_repo() for git_rm_force and git_checkout_theirs - git_branch_delete defaults to safe delete (force=false) HIGH: - Replace silent .ok() with proper error propagation in git_commit, git_merge_abort, git_rebase_abort, git_rm_force, git_checkout_theirs - nativeDiffStat fallback parses numeric stats from git output - nativeBatchInfo fallback counts staged/unstaged from porcelain status MEDIUM: - Wire up dead force param in removeWorktree() - Read MERGE_MSG/SQUASH_MSG when commit message empty - nativeLsFiles uses gitFileExec without fragile quote wrapping - Fix operator precedence in git_ls_files |
||
|---|---|---|
| .. | ||
| .cargo | ||
| crates | ||
| npm | ||
| scripts | ||
| .gitignore | ||
| .npmignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
GSD Native Engine
Rust N-API addon providing high-performance native modules for GSD.
Architecture
JS (packages/native) -> N-API -> Rust crates
├── engine/ (N-API bindings, cdylib)
└── grep/ (ripgrep internals, pure Rust lib)
Inspired by Oh My Pi's pi-natives, adapted for GSD's Node.js runtime.
Prerequisites
- Rust (stable, 1.70+): https://rustup.rs
- Node.js (20.6+)
Build
# Release build (optimized)
npm run build:native
# Debug build (fast compile, no optimizations)
npm run build:native:dev
The build script compiles the Rust code and copies the .node shared library to native/addon/.
Test
# Rust unit tests
cd native && cargo test
# Node.js integration tests
npm run test:native
Modules
grep
Ripgrep-backed regex search using the grep-regex, grep-searcher, and grep-matcher crates.
Functions:
search(content, options)— Search in-memory Buffer/Uint8Array contentgrep(options)— Search files on disk with glob filtering and .gitignore support
TypeScript usage:
import { grep, searchContent } from "@gsd/native";
// Search files
const result = grep({
pattern: "TODO",
path: "./src",
glob: "*.ts",
ignoreCase: true,
maxCount: 100,
});
// Search content
const contentResult = searchContent(Buffer.from(fileContent), {
pattern: "function\\s+\\w+",
contextBefore: 2,
contextAfter: 2,
});
Adding New Modules
- Create a new crate in
native/crates/(pure Rust library) - Add N-API bindings in
native/crates/engine/src/ - Add TypeScript wrapper in
packages/native/src/ - Add the crate to
engine/Cargo.tomldependencies