iTranslated by AI
Bit: A Git-compatible AI sandbox
I have long wanted a base for extending git myself. So, I implemented it.
Warning: This is an experimental implementation. Do not use it in a production environment. In the worst case, it may damage the binary for history management.
The command name is bit. It is a bold name, but since it is a git implementation written in Moonbit and I wanted to use it seamlessly as it is one letter off from git...
You can install it with this.
curl -fsSL https://raw.githubusercontent.com/mizchi/bit/main/install.sh | bash
# ~/.local/bin/bit
Almost git-compatible
It passes 97.6% of the git test suite git/t.
- success: 24,278 / total: 24,858
- failed: 0
- broken: 178 (intentionally ignored)
Unsupported features
- --object-hash=sha256: GitHub itself does not support it yet
-
Interactive features:
bit add -p,bit rebase -i— Terminal UI abstraction is not designed yet -
GPG signing:
commit -S,tag -s— Not implemented - Windows, MINGW: Please use WSL
- git@ protocol push via native Git protocol (HTTP push is supported)
git add -p is a feature I use often, so I want to support it soon, but since I am implementing it with WASM/WASI in mind, I am unsure how to create interactive standard input/output, so it is on the back burner.
Extension: Subdirectory Clone
This is a feature to clone only a specific subdirectory and push bidirectionally as it is. This was almost the entire reason I implemented it.
While git has a sparse-checkout feature to checkout only specific directories, it couldn't resolve an arbitrary subdirectory as the root.
So, I implemented this.
# Example: Extract only src/x/fs from mizchi/bit
$ bit clone mizchi/bit:src/x/fs
$ cd fs
$ ls
fs.mbt types.mbt ...
This works bidirectionally. That is, if you edit it in fs and run bit push, the changes are reflected in the original repository.
cd fs
echo "// new code" >> fs.mbt
bit add .
bit commit -m "update"
bit push origin main # Pushes to the original mizchi/bit
When viewed from git, it is recognized as an embedded repository just like a submodule, ensuring that it cannot cause inconsistencies when operated from the parent repository.
Extension: bit hq
It natively possesses the features of ghq. The path is slightly different, though.
$ bit hq get mizchi/bit
$ cd ~/bhq/mizchi/bit
# For non-GitHub: ~/bhq/gitlab.com/user/repo
(HQ stands for Headquarters, right?)
Internal Implementation
Speaking of full-scratch rewrites of Git, there is gitoxide, but this time I rewrote everything in MoonBit. The reason is simply that I wanted to write it.
I also rewrote zlib from scratch.
The CLI part depends on the filesystem, but almost all IO is abstracted, making it run even on WASM/WASI. You can also create an in-memory git sandbox.
The reason I wanted this is that, combined with the next bit/x/fs, I wanted a sandbox that an AI could freely destroy.
Experimental Feature: bit/x/fs
A virtual filesystem that uses Git objects directly as the filesystem backend.
let fs = Fs::from_commit(fs, ".git", commit_id)
let content = fs.read_file(fs, "src/main.mbt") // Lazy loading of blobs
Like Nix, you can restore any state using the hash value. Within this FS, no matter what operations you perform, you can roll back to any point in time.
Also, since it is designed to run on WASM/WASI, I am currently implementing a coding agent that uses this as an AI sandbox.
Inside this FS, blob resolution can be delayed. In other words, you can use it to load only the necessary parts of a large repository.
Experimental Feature: bit/x/kv
A KV store designed to share Git objects between specific P2P nodes. It is inspired by blockchains.
let db = Kv::init(fs, fs, git_dir, node_id)
db.set(fs, fs, "users/alice/profile", value, ts)
db.sync_with_peer(fs, fs, peer_url) // Synchronize via Gossip protocol
The intended use is to have multiple AI agents parallelize tasks based on a specific git state and synchronize git object blobs between those agents at high speed.
Prototyping: bit/x/collab
I am creating a native collaboration feature that does not depend on GitHub/GitLab. bit itself has a mechanism to accept PRs and a system to process them.
let collab = Collab::init(fs, fs, git_dir)
let pr = collab.create_pr(fs, fs, "Fix bug", "...",
source_branch, target_branch, author, ts)
I am planning to use git notes for storing messages, and I am thinking about whether I can represent PRs with notes on a Merge.
I am assuming a situation where it is deployed as a server along with AI agents, and a cluster of AIs throws PRs at each other via P2P. It's the same kind of image as the vcs + sandbox of openclaw + moltworker that was talked about recently.
Git is originally a decentralized distributed FS, but GitHub doesn't really take advantage of that. So, I'm trying to build a mechanism to utilize it.
Ideation: AI Merge
(Though you can do this even now if you want to) A feature that allows an AI to resolve conflicts. Validation is performed together with CI.
Since there are many areas where 3-way merge is slightly out of reach, I am thinking it would be nice to be able to perform automatic AI Merge in a local development environment.
Performance
Since MoonBit does not currently support multi-threading, the decoding of large amounts of text is slightly slow.
Specifically, bit clone is about 1.8 times slower than git clone. Other operations are sometimes faster and sometimes slower, varying quite a bit.
Conclusion
AI has brought about a great era where we can build what we want, even if we previously lacked the manpower to do so.
While there are concerns about reliability, I plan to nurture it while dogfooding it.
Discussion
aiエージェント前提のバージョン管理を考える上で参考になるかつ、便利ですね!
moonbitは自作言語ですか?