Skip to content

Commit c9874ed

Browse files
committed
feat: implement Rust foundation crates for polysafe-gitfixer
This implements the core safety layer for the polyglot git backup merger tool. Components implemented: - capability: DirCapability for path traversal prevention, AuditLog for tamper-evident hash-chained logging - fs_ops: FsTransaction with RAII for atomic filesystem operations with automatic rollback on drop - git_ops: Safe wrappers around git2 for repository operations - polysafe_nifs: Stub for future Rustler NIF bindings to Elixir Also includes: - Nickel configuration schemas (config/schema.ncl, config/default.ncl) - Top-level Makefile for polyglot build orchestration - README with architecture diagram All 30 tests pass.
0 parents  commit c9874ed

17 files changed

Lines changed: 2658 additions & 0 deletions

File tree

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
target/
2+
Cargo.lock
3+
.DS_Store
4+
*.log
5+
*.tmp
6+
_build/
7+
deps/
8+
.elixir_ls/
9+
.erlang.cookie
10+
*.beam
11+
*.ez
12+
erl_crash.dump
13+

Makefile

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
.PHONY: all rust haskell idris elixir clean test check fmt
2+
3+
# Default target: build everything
4+
all: rust haskell idris elixir
5+
6+
# Rust components
7+
rust:
8+
cd crates && cargo build --release
9+
10+
rust-debug:
11+
cd crates && cargo build
12+
13+
rust-test:
14+
cd crates && cargo test
15+
16+
rust-check:
17+
cd crates && cargo check
18+
19+
rust-fmt:
20+
cd crates && cargo fmt
21+
22+
rust-clippy:
23+
cd crates && cargo clippy -- -D warnings
24+
25+
# Haskell components
26+
haskell: haskell-diff haskell-tui
27+
28+
haskell-diff:
29+
cd haskell/diff-engine && cabal build
30+
31+
haskell-tui:
32+
cd haskell/tui && cabal build
33+
34+
haskell-test:
35+
cd haskell/diff-engine && cabal test
36+
cd haskell/tui && cabal test
37+
38+
haskell-clean:
39+
cd haskell/diff-engine && cabal clean
40+
cd haskell/tui && cabal clean
41+
42+
# Idris 2 workflow (optional - fallback to Haskell if not available)
43+
idris:
44+
@if command -v idris2 >/dev/null 2>&1; then \
45+
cd idris/workflow && idris2 --build workflow.ipkg; \
46+
else \
47+
echo "Idris 2 not found, skipping workflow build (Haskell fallback will be used)"; \
48+
fi
49+
50+
# Elixir orchestrator (depends on Rust NIFs)
51+
elixir: rust
52+
cd elixir/polysafe_gitfixer && mix deps.get && mix compile
53+
54+
elixir-test:
55+
cd elixir/polysafe_gitfixer && mix test
56+
57+
# Config validation
58+
config-check:
59+
@if command -v nickel >/dev/null 2>&1; then \
60+
nickel typecheck config/schema.ncl; \
61+
else \
62+
echo "Nickel not found, skipping config validation"; \
63+
fi
64+
65+
# Run all tests
66+
test: rust-test haskell-test elixir-test
67+
68+
# Check all (no tests, just compilation/type checking)
69+
check: rust-check config-check
70+
cd haskell/diff-engine && cabal build --only-dependencies
71+
cd haskell/tui && cabal build --only-dependencies
72+
73+
# Format all code
74+
fmt: rust-fmt
75+
@echo "Note: Add Haskell formatters (ormolu/fourmolu) as needed"
76+
77+
# Clean all build artifacts
78+
clean:
79+
cd crates && cargo clean
80+
-cd haskell/diff-engine && cabal clean
81+
-cd haskell/tui && cabal clean
82+
-cd idris/workflow && rm -rf build/
83+
-cd elixir/polysafe_gitfixer && mix clean
84+
85+
# Development: watch and rebuild on changes
86+
watch-rust:
87+
cd crates && cargo watch -x check
88+
89+
# Help
90+
help:
91+
@echo "polysafe-gitfixer build system"
92+
@echo ""
93+
@echo "Targets:"
94+
@echo " all - Build all components"
95+
@echo " rust - Build Rust crates (release)"
96+
@echo " rust-debug - Build Rust crates (debug)"
97+
@echo " haskell - Build Haskell components"
98+
@echo " idris - Build Idris workflow (if available)"
99+
@echo " elixir - Build Elixir orchestrator"
100+
@echo " test - Run all tests"
101+
@echo " check - Type check without building"
102+
@echo " fmt - Format all code"
103+
@echo " clean - Remove build artifacts"
104+
@echo " help - Show this help"

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# polysafe-gitfixer
2+
3+
A polyglot implementation of a git backup merger tool, where each component is written in the language that provides the strongest safety guarantees for that component's concerns.
4+
5+
## Overview
6+
7+
This tool:
8+
1. Scans a directory tree for git repositories
9+
2. Finds backup directories (`*-backup`, `*.backup-*`)
10+
3. Matches backups to their corresponding repos
11+
4. Diffs backup vs repo contents
12+
5. Offers interactive merge/replace/delete options
13+
6. Maintains append-only audit log
14+
7. Handles failures gracefully (supervision)
15+
16+
## Architecture
17+
18+
```
19+
┌─────────────────────────────────────────────────────────────────────────────┐
20+
│ COMPONENT MAP │
21+
├─────────────────────────────────────────────────────────────────────────────┤
22+
│ │
23+
│ ┌─────────────────┐ ┌─────────────────┐ │
24+
│ │ Haskell │ │ Nickel │ │
25+
│ │ TUI/CLI │◄────────│ Config │ │
26+
│ │ (Brick) │ │ (schemas) │ │
27+
│ └────────┬────────┘ └─────────────────┘ │
28+
│ │ │
29+
│ ▼ │
30+
│ ┌─────────────────────────────────────────────────────────────┐ │
31+
│ │ Elixir/OTP │ │
32+
│ │ Orchestration & Supervision │ │
33+
│ └───┬─────────────────┬─────────────────┬─────────────────┬───┘ │
34+
│ │ │ │ │ │
35+
│ ▼ ▼ ▼ ▼ │
36+
│ ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
37+
│ │ Idris │ │ Haskell │ │ Rust │ │ Rust │ │
38+
│ │Workflow │ │ Diff │ │ Git │ │ F/S │ │
39+
│ │ State │ │ Engine │ │ Ops │ │ Ops │ │
40+
│ └─────────┘ └──────────┘ └──────────┘ └──────────┘ │
41+
│ │
42+
│ ┌──────────────────────────────┐ │
43+
│ │ Rust │ │
44+
│ │ Capability & Audit Layer │ │
45+
│ └──────────────────────────────┘ │
46+
└─────────────────────────────────────────────────────────────────────────────┘
47+
```
48+
49+
## Components
50+
51+
| Component | Language | Safety Guarantee |
52+
|-----------|----------|------------------|
53+
| Configuration | Nickel | Schema validation, typed defaults |
54+
| Capability & Audit | Rust | Path traversal prevention, tamper-evident logging |
55+
| Filesystem Ops | Rust | RAII, atomic transactions, rollback on failure |
56+
| Git Operations | Rust | Error handling, effect tracking |
57+
| Diff Engine | Haskell | Totality, streaming for large files |
58+
| Workflow State | Idris 2 | Typestate (can't call operations in wrong order) |
59+
| Orchestration | Elixir/OTP | Fault isolation, supervision trees |
60+
| TUI/CLI | Haskell (Brick) | Elm Architecture, exhaustive event handling |
61+
62+
## Building
63+
64+
### Prerequisites
65+
66+
- Rust (1.75+)
67+
- Haskell (GHC 9.4+, Cabal 3.8+)
68+
- Elixir (1.15+, OTP 26+)
69+
- Nickel (1.4+)
70+
- Idris 2 (0.6+) - optional, Haskell fallback available
71+
72+
### Build All
73+
74+
```bash
75+
make all
76+
```
77+
78+
### Build Individual Components
79+
80+
```bash
81+
# Rust crates
82+
make rust
83+
84+
# Haskell components
85+
make haskell
86+
87+
# Elixir orchestrator
88+
make elixir
89+
```
90+
91+
## Project Structure
92+
93+
```
94+
polysafe-gitfixer/
95+
├── config/ # Nickel configuration schemas
96+
├── crates/ # Rust components
97+
│ ├── capability/ # Path safety & audit logging
98+
│ ├── fs_ops/ # Transactional filesystem operations
99+
│ ├── git_ops/ # Git repository operations
100+
│ └── polysafe_nifs/# Rustler NIFs for Elixir
101+
├── haskell/ # Haskell components
102+
│ ├── diff-engine/ # Tree/file diffing
103+
│ └── tui/ # Terminal UI
104+
├── idris/ # Idris 2 workflow state machine
105+
├── elixir/ # Elixir orchestrator
106+
└── test/ # Integration tests
107+
```
108+
109+
## License
110+
111+
MIT OR Apache-2.0

config/default.ncl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# polysafe-gitfixer Default Configuration
2+
#
3+
# This configuration can be overridden by:
4+
# 1. ~/.config/polysafe-gitfixer/config.ncl (user config)
5+
# 2. .polysafe-gitfixer.ncl (project config)
6+
# 3. Command-line arguments
7+
8+
let schema = import "schema.ncl" in
9+
10+
schema & {
11+
base_dir = "$HOME/workspace",
12+
13+
backup_patterns = [
14+
"*-backup",
15+
"*.backup-*",
16+
"*_backup",
17+
"*.bak",
18+
],
19+
20+
max_scan_depth = 10,
21+
22+
git_remotes = {
23+
preferred_remote = "origin",
24+
gitlab_orgs = [],
25+
},
26+
27+
safety = {
28+
require_confirmation = true,
29+
dry_run = false,
30+
create_backups = true,
31+
},
32+
33+
diff = {
34+
ignore_patterns = [
35+
".git",
36+
"node_modules",
37+
"__pycache__",
38+
".DS_Store",
39+
"*.pyc",
40+
".venv",
41+
"target",
42+
"_build",
43+
"deps",
44+
],
45+
max_file_size = 10485760,
46+
show_binary = false,
47+
},
48+
49+
ui = {
50+
color = true,
51+
verbose = false,
52+
mode = 'Tui,
53+
},
54+
}

0 commit comments

Comments
 (0)