Cambria is a version control system implemented in Go that aims to achieve feature parity with Fossil SCM's core version control and data model capabilities.
Project Status: Phase 2 Complete ✓
The project has completed foundational infrastructure (Phase 0), core version control operations (Phase 1), working directory state tracking (Phase 1.5), and command-line interface (Phase 2). The VCS is now functional and ready for advanced features.
Current Phase Summary
✅ Phase 0 (Foundation) - Complete
- Go module initialized, SQLite schema, core library packages
✅ Phase 1 (Version Control Operations) - Complete
- Repository management, checkin/checkout, add/commit, diff operations
✅ Phase 1.5 (VFILE Working Directory Tracking) - Complete
- SQLite-based working directory state tracking
- Efficient change detection via vfile table
- Integration with all VCS operations
✅ Phase 2 (CLI & User Interface) - Complete
- Command-line interface using urfave/cli v3
- Core commands: init, add, commit, checkout, status, diff, open, close
- Repository discovery via _cambria metadata file
- Version resolution (UUIDs, prefixes, tags)
- Automatic initial commit handling
🔄 Phase 3 (Advanced Features) - Next
- Branch and merge operations
- Timeline/log visualization
- Network operations (clone, push, pull)
- File removal and renaming
See AGENTS.md for detailed implementation status.
What's Been Accomplished
Phase 0: Foundation ✅
- ✅ Go module initialized (go 1.25.5)
- ✅ SQLite schema implemented and tested
- ✅
pkg/hashpackage (SHA-256 hashing, 91.7% coverage) - ✅
pkg/storepackage (SQLite data access, 80.7% coverage) - ✅
pkg/artifactpackage (manifest parsing/generation, 93.3% coverage) - ✅ All tests pass, no race conditions detected
- ✅ Code passes
go vet, all exported functions documented
Phase 1: Version Control Operations ✅
- ✅ Repository initialization and management (
pkg/vcs/repo.go) - ✅ Working directory state tracking (
pkg/vcs/workdir.go) - ✅ File addition operations (
pkg/vcs/add.go) - ✅ Commit/checkin operations (
pkg/vcs/checkin.go) - ✅ Checkout operations with path security (
pkg/vcs/checkout.go) - ✅ Diff operations (files, manifests, working directory) (
pkg/vcs/diff.go) - ✅ Comprehensive VCS integration tests
- ✅ Path traversal security protection
- ✅ All deprecated APIs replaced with modern equivalents
Phase 1.5: VFILE Working Directory Tracking ✅
- ✅
vfileandvmergetables defined in schema (pkg/store/schema.go) - ✅ Core vfile functions implemented (
pkg/vcs/vfile.go):LoadVFileFromManifest()- Populate vfile from manifest during checkoutCheckVFileSignatures()- Detect file changes by comparing hashesWriteVFileToDisk()- Write files from vfile to disk- Helper functions for vfile entry management
- ✅ VCS integration complete:
Checkout()- Populates vfile table and sets current checkoutAdd()- Inserts/updates vfile entries for added filesScan()- Queries vfile table for efficient status detectionCommit()- Reads changed files from vfile, updates baseline
- ✅ Comprehensive testing:
- 8 unit tests for vfile core functions
- 3 integration tests for complete workflows
- All 31 VCS tests passing
- ✅ Path security validation and transactional safety
Documentation: See doc_cambria/CAMBRIA_VFILE_IMPL.md for detailed implementation documentation.
Phase 2: CLI & User Interface ✅
- ✅ CLI framework using urfave/cli v3
- ✅ Implemented commands (
cmd/cambria/):init- Initialize a new repositoryadd- Add files to version controlcommit/ci- Commit changes (handles initial and subsequent commits)checkout/co- Checkout specific versionsstatus- Show working directory statusdiff- Show differences between versions or working directoryopen- Open repository into working directoryclose- Close working directory
- ✅ Core utilities (
cmd/cambria/common.go):- Repository discovery via
_cambriametadata file - Version resolution (full UUIDs, prefixes ≥6 chars, tags/labels)
- Error formatting and handling
- Repository discovery via
- ✅ Features:
- Automatic initial commit handling (uses Checkin + Checkout)
- Repository metadata file creation
- Path security validation
- User-friendly status output with file counts
- Support for global flags (--repository, --verbose)
- ✅ End-to-end workflow tested and functional
Documentation: See doc_cambria/CAMBRIA_CLI_PLAN.md for detailed CLI specifications.
Project Structure
cambria/
├── go.mod # Go module definition
├── go.sum # Dependency checksums
├── README.md # Project documentation (this file)
├── AGENTS.md # Implementation guide for AI agents
│
├── pkg/
│ ├── hash/ # Content hashing utilities (SHA-256)
│ │ ├── hash.go # Hash computation and verification
│ │ └── hash_test.go # 91.7% coverage
│ │
│ ├── store/ # SQLite data access layer
│ │ ├── db.go # Database connection management
│ │ ├── dbtx.go # Transactional interface
│ │ ├── schema.go # Schema creation (includes vfile/vmerge)
│ │ ├── blob.go # Blob storage operations
│ │ ├── manifest.go # Manifest storage operations
│ │ ├── mlink.go # Manifest-file linkage
│ │ ├── plink.go # Parent-child linkage
│ │ ├── label.go # Tag/branch labels
│ │ └── *_test.go # 80.7% coverage total
│ │
│ ├── artifact/ # Artifact parsing and generation
│ │ ├── manifest.go # Manifest format parsing/serialization
│ │ └── manifest_test.go # 93.3% coverage
│ │
│ └── vcs/ # High-level version control operations
│ ├── repo.go # Repository initialization and management
│ ├── checkin.go # Commit/checkin operations (uses vfile)
│ ├── checkout.go # Checkout operations (populates vfile)
│ ├── add.go # File addition (updates vfile)
│ ├── diff.go # Diff computation
│ ├── workdir.go # Working directory state (uses vfile)
│ ├── vfile.go # VFILE system implementation
│ ├── vfile_test.go # VFILE unit tests (8 tests)
│ ├── vfile_integration_test.go # VFILE integration tests (3 tests)
│ ├── checkout_test.go # Checkout tests
│ └── main_test.go # VCS integration tests
│
├── internal/ # Private packages
│ └── testutil/ # Test utilities and helpers
│ └── testutil.go
│
├── cmd/ # Command-line application
│ └── cambria/ # CLI (Phase 2 complete)
│ ├── main.go # CLI entry point
│ ├── common.go # Shared utilities (repo discovery, version resolution)
│ ├── init.go # init command
│ ├── add.go # add command
│ ├── commit.go # commit/ci command
│ ├── checkout.go # checkout/co command
│ ├── status.go # status command
│ ├── diff.go # diff command
│ ├── open.go # open command
│ └── close.go # close command
│
├── testdata/ # Test fixtures and golden files
│ ├── manifests/
│ └── repos/
│
└── doc_cambria/ # Design documentation
├── CAMBRIA_PHASE_0.md # Phase 0 specification
├── CAMBRIA_PHASE_1.md # Phase 1 specification
├── CAMBRIA_VFILE_IMPL.md # Phase 1.5 implementation (VFILE system)
├── CAMBRIA_CLI_PLAN.md # Phase 2 specification (next)
├── CAMBRIA_DATA_MODEL_DESIGN.md
├── FOSSIL_VERSION_CONTROL.md
└── FOSSIL_VERSION_CONTROL_TEST.md
Module Information
- Module Name:
cambria(local module) - Go Version: 1.25.5
- Dependencies:
github.com/mattn/go-sqlite3v1.14.32 - SQLite driver (requires CGo)github.com/sergi/go-diffv1.4.0 - Diff computation library
Building and Testing
Prerequisites
- Go 1.25.5 or later
- CGo enabled (required for SQLite)
- Build tools (gcc/clang)
Environment Setup
# Ensure CGo is enabled
export CGO_ENABLED=1
# Verify Go installation
go version # Should show: go version go1.25.5 linux/amd64
Build
# Build all packages
go build ./...
# Build CLI
go build -o cambria ./cmd/cambria
# Install to $GOPATH/bin
go install ./cmd/cambria
Static Build (musl)
You can produce a fully static cambria binary using musl and cgo (required for github.com/mattn/go-sqlite3). Ensure musl-tools is installed.
Quick commands:
export CGO_ENABLED=1
export CC=musl-gcc
go build -v -tags 'sqlite_omit_load_extension' -ldflags '-linkmode external -extldflags "-static"' ./cmd/cambria
# Verify static linking
file ./cambria
ldd ./cambria || true
Makefile targets:
make static # builds ./cambria as a static binary
make verify # prints file type and ldd output
make clean # removes ./cambria
VS Code tasks:
- "Build cambria (static musl)": runs the static build command.
- "Verify cambria binary": runs
fileandldd.
Tasks are defined in .vscode/tasks.json.
Test
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with race detector (CRITICAL before committing)
go test -race ./...
# Run specific package tests
go test ./pkg/vcs
go test ./pkg/vcs -v # Verbose output
Code Quality
# Format code
go fmt ./...
# Static analysis
go vet ./...
# View test coverage
go test -cover ./...
Package Overview
pkg/hash
Content-addressable hashing utilities using SHA-256.
Key Functions:
ComputeSHA256(data []byte) string- Compute hex-encoded SHA-256ComputeFileSHA256(path string) (string, error)- Hash file contentsVerify(data []byte, expectedHash string) bool- Verify hash matches
pkg/store
SQLite data access layer for all repository data.
Key Operations:
- Database lifecycle (open, close, schema setup)
- Blob CRUD (create, read, find by UUID)
- Manifest CRUD
- Mlink operations (add, list, query)
- Plink operations (add, query ancestry)
- Label operations (add, list, query)
- Transaction management (DBTX interface)
Database Schema:
blob- Immutable artifact storagemanifest- Manifest identificationmlink- Manifest-file linkageplink- Parent-child DAGlabel- Branch and tag labelsconfig- Repository metadatavfile- Working directory file state tracking (Phase 1.5)vmerge- Merge state tracking (Phase 1.5, for future use)
pkg/artifact
Parse and generate manifest artifacts in canonical text format.
Key Functions:
ParseManifest(content []byte) (*Manifest, error)- Parse manifest textGenerateManifest(m *Manifest) ([]byte, error)- Generate canonical textCanonicalize(m *Manifest) []byte- Ensure canonical formComputeUUID(m *Manifest) (string, error)- Compute manifest hash
Manifest Format:
F <path> <file-uuid> # File entry
P <parent-uuid> [<parent2>] # Parent manifest(s)
C <comment> # Commit message
T <label> # Tag/branch label
pkg/vcs
High-level version control operations and repository management.
Key Operations:
InitRepository(path)- Create new repositoryOpenRepository(path)- Open existing repositoryrepo.Checkin(files, parents, opts)- Create manifest/commitrepo.Checkout(root, manifestUUID, opts)- Checkout files to directoryrepo.Commit(workDir, opts)- Commit working directory changesrepo.Add(workDir, paths...)- Add files to version controlrepo.DiffFiles(uuid1, uuid2, opts)- Diff between file versionsrepo.DiffManifests(uuid1, uuid2, opts)- Diff between manifestsrepo.DiffWorkDir(workDir, uuid, opts)- Diff working directoryNewWorkDir(root, repo)- Create working directory trackerworkDir.Scan()- Scan for file changes (uses vfile)workDir.HashFile(path)- Hash file contentworkDir.SetBaseline(uuid)- Set checkout baseline
VFILE System (Phase 1.5):
LoadVFileFromManifest(tx, vid)- Populate vfile from manifestCheckVFileSignatures(tx, vid, workDir, opts)- Detect file changesWriteVFileToDisk(tx, vid, workDir, opts)- Write files to diskGetVFileEntry(tx, vid, pathname)- Get single vfile entryGetCurrentCheckout(tx)- Get current checked-out manifestSetCurrentCheckout(tx, vid, uuid)- Set current checkout
Security Features:
- Path traversal protection (rejects "..", absolute paths)
- Safe file operations with validation
- Transactional integrity via SQLite
internal/testutil
Test utilities and helpers for writing tests.
Key Functions:
NewTempDB(t *testing.T)- Create temporary SQLite databaseNewInMemoryDB(t *testing.T)- Create in-memory databaseCreateTestFile(t, dir, name, content)- Create test file- Database assertion helpers
Test Coverage Summary
| Package | Coverage | Tests | Notes |
|---|---|---|---|
| pkg/hash | 91.7% | 8 tests | SHA-256 hashing |
| pkg/store | 80.7% | 68 tests | SQLite operations |
| pkg/artifact | 93.3% | 13 tests | Manifest parsing |
| pkg/vcs | ~80% | 31 tests | VCS operations + VFILE |
| Total | 80%+ | 120+ tests | All passing ✅ |
VFILE Tests (Phase 1.5):
- 8 unit tests for vfile core functions
- 3 integration tests for complete workflows
- No race conditions detected
Design Philosophy
- Minimal and Correct: Start with the simplest correct implementation
- SQLite-Backed: Use SQLite as the single source of truth for all versioned data
- Content-Addressable: All artifacts identified by cryptographic hash (SHA-256)
- Immutable Artifacts: Once written, artifacts never change
- Transactional Integrity: All multi-step operations use SQLite transactions
- Go Idioms: Embrace Go's simplicity, composition, and standard library
- Standard Testing: Use only Go's standard library
testingpackage - Security First: Path validation, no directory traversal, safe file operations
Usage
Quick Start
# Build the CLI
go build -o cambria ./cmd/cambria
# Initialize a new repository
cambria init myproject.db
# Create a working directory and make initial commit
mkdir work && cd work
echo "Hello World" > test.txt
cambria -R ../myproject.db commit -m "Initial commit"
# Add and commit more files
echo "New content" > newfile.txt
cambria add newfile.txt
cambria commit -m "Add newfile"
# Check status
cambria status
# View differences (Note: diff for working directory has known issue)
# cambria diff --from <uuid> --to <uuid>
# Checkout different versions
cambria checkout --force <uuid-prefix>
Workflow
- Initialize:
cambria init repo.dbcreates a new repository - First Commit:
cambria -R repo.db commit -m "Initial"creates initial commit and sets up working directory with_cambriametadata file - Subsequent Operations: Commands automatically find repository via
_cambriafile - Add Files:
cambria add <files>stages files for commit - Commit:
cambria commit -m "message"creates new manifest - Status:
cambria statusshows working directory state - Checkout:
cambria checkout <version>switches to different version
Known Issues
- diff command:
cambria diff(without arguments) currently fails when diffing working directory with modified files. This is a VCS library issue whereDiffWorkDirtries to fetch working directory content from the database instead of reading from disk. - checkout: Requires
--forceflag when switching versions with existing files (intentional for safety).
Next Steps: Phase 3 (Advanced Features)
Phase 3 will implement advanced version control features:
Planned Features
- Timeline/Log - Show commit history with
cambria timelineorcambria log - Branch Management - Create and switch branches with
cambria branch - Tag Management - Advanced tagging beyond commit-time labels
- Merge Operations - Merge branches with conflict resolution
- File Operations -
rm,mvcommands for tracked files - Network Operations -
clone,push,pull,syncfor remote repositories - Configuration - Support for
.cambria/configfiles - Ignore Patterns - Enhanced
.cambriaignoresupport - Web UI - Optional web interface like Fossil's
uicommand
Documentation
Project Documentation
- README.md - This file, project overview and status
- AGENTS.md - Implementation guide for AI agents working on this project
Phase Documentation
- doc_cambria/CAMBRIA_PHASE_0.md - Phase 0 specification (Foundation)
- doc_cambria/CAMBRIA_PHASE_1.md - Phase 1 specification (VCS Operations)
- doc_cambria/CAMBRIA_VFILE_IMPL.md - Phase 1.5 implementation (VFILE System) ✨ NEW
- doc_cambria/CAMBRIA_CLI_PLAN.md - Phase 2 specification (CLI) - NEXT
Design Documentation
- doc_cambria/CAMBRIA_DATA_MODEL_DESIGN.md - Minimal data model specification
- doc_cambria/FOSSIL_VERSION_CONTROL.md - Fossil C module mapping
- doc_cambria/FOSSIL_VERSION_CONTROL_TEST.md - Test suite organization
Reference
Future Reference
- CLI library documentation: https://cli.urfave.org/v3/examples/full-api-example/
- Fossil CLI reference: https://fossil-scm.org/home/doc/2010-01-01/www/reference.wiki
- Fossil source code: https://fossil-scm.org/home/dir
License
[To be determined]
Contributing
Phases 0, 1, 1.5, and 2 are complete. The VCS is now functional with a working CLI. Work on Phase 3 (Advanced Features) can now begin.
See AGENTS.md for detailed implementation guidance and current project status.
Current Status: ✅ Phase 2 Complete - Command-Line Interface Next Milestone: 🔄 Phase 3 - Advanced Features (branches, merge, timeline, network) All Tests: ✅ 120+ tests passing, no race conditions Test Coverage: ✅ 80%+ across all packages CLI Status: ✅ Functional with core commands (init, add, commit, checkout, status, diff)