blog.dopana

Back

Code Storage là hạ tầng Git được quản lý dành cho AI agents, được xây dựng bởi Pierre Computer Company. Nó cho phép tạo repository, viết commit, merge branch và lấy Git remote URLs thông qua SDK, HTTP API hoặc Git qua HTTPS.

Vấn đề#

Khi xây dựng các hệ thống AI-powered, đặc biệt là AI agents, các giải pháp lưu trữ truyền thống gặp nhiều hạn chế:

  • Giải pháp S3/R2 makeshift: Chậm và dễ hỏng, không được thiết kế cho workloads collaboratively
  • API lưu trữ truyền thống: Không được xây dựng cho công việc có tính cộng tác
  • Phức tạp của Git primitives: Teams phải nhân bản Git primitives qua Postgres và các datastore khác, trong khi cố gắng quản lý snapshots phân kỳ trong S3
  • Hiệu suất kém: Các giải pháp hiện tại không thể xử lý hàng triệu repository mới mỗi ngày
  • Rate limits và authentication phức tạp: Các API công khai có giới hạn rate và flows authentication phức tạp

Đối với AI agents, Git cung cấp state xác định, có thể tái tạo, với snapshots content-addressed có thể pin trong prompts, evals và rollbacks, cũng như các chiến lược multi-player quen thuộc (như branching) cho human-agent collaboration.

Giải pháp#

Code Storage là hệ thống lưu trữ phân tán có khả năng mở rộng cao, được xây dựng trên Git để lưu trữ và cộng tác trên repos, với API ergonomics được tối ưu hóa cho machines.

Kiến trúc cốt lõi#

Code Storage sử dụng giao thức commit ba-phase của Git và kiến trúc dựa trên quorum kiểu “spoke” để đảm bảo độ bền và tính nhất quán của tất cả reads và writes ở quy mô lớn.

graph TD
    A[AI Agent/Application] --> B[Code Storage SDK]
    B --> C[HTTP API]
    C --> D[Quorum-based Storage Layer]
    D --> E[Git Repository Storage]
    D --> F[Git LFS Storage]
    D --> G[Metadata Storage]
    
    H[JWT Authentication] --> C
    I[Ref Policies] --> C
    J[Commit Signing] --> C
    
    K[Webhooks] --> L[Build Systems]
    K --> M[Bots]
    K --> N[AI Agents]
    
    C --> K

Tính năng chính#

Git Operations#

  • Clone, fetch, push và pull qua HTTPS với remotes được JWT-authenticated
  • Không cần rate limits, authentication flows phức tạp, hoặc các hạn chế khác

Git LFS#

  • Track large files trên cùng remote, không cần server LFS riêng biệt

Git Notes#

  • Attach metadata đến commits và giữ note streams isolated theo ref

Ref Policies#

  • Giới hạn refs mà JWT có thể update và reject force pushes

Commit Signing#

  • Register keys và yêu cầu signed commits trên refs được chọn

Import Namespace#

  • Bulk push large repositories, Code Storage chuyển đến cold storage

Ephemeral Namespace#

  • Tạo isolated refs cho previews và experiments, sau đó promote chúng

Repository Forks#

  • Copy repository cho template, snapshot, hoặc work isolated

GitHub Sync#

  • Mirror GitHub repository tới và từ Code Storage

Generic Sync#

  • Mirror GitLab, Bitbucket, hoặc các HTTPS Git repository khác

Webhooks#

  • Nhận push và sync events, được verify với HMAC signatures

Workflows cho AI Agents#

Code Storage cung cấp các workflows chuyên biệt cho agents:

Connect a Sandbox#

Clone vào Modal, E2B, Daytona và các sandbox khác với authenticated URLs.

sequenceDiagram
    participant Agent as AI Agent
    participant CodeStorage as Code Storage
    participant Sandbox as Modal/E2B/Daytona
    
    Agent->>CodeStorage: Request authenticated URL
    CodeStorage-->>Agent: JWT-authenticated Git URL
    Agent->>Sandbox: Clone with authenticated URL
    Sandbox->>CodeStorage: Git clone via HTTPS
    CodeStorage-->>Sandbox: Repository data
    Sandbox-->>Agent: Clone complete

Store Session State#

Lưu session state của agent như ephemeral commits, với các branch bình thường không thay đổi.

Resume Sandbox Work#

Khôi phục session state cuối cùng trong sandbox mới.

Run Parallel Attempts#

Bắt đầu nhiều attempts từ một commit và promote kết quả tốt nhất.

graph TD
    A[Base Commit] --> B[Attempt 1]
    A --> C[Attempt 2]
    A --> D[Attempt 3]
    
    B --> E{Result Quality?}
    C --> F{Result Quality?}
    D --> G{Result Quality?}
    
    E -->|Best| H[Promote to Main]
    F -->|Best| H
    G -->|Best| H
    
    H --> I[Final Result]

Show Live Diffs#

Render một agent branch như live diff mà refresh trên mỗi state mới.

Bắt đầu nhanh#

Installation#

# TypeScript
pnpm i @pierre/storage

# Python (sử dụng uv - recommended)
uv add pierre-storage

# Hoặc sử dụng pip
pip install pierre-storage

# Go
go get github.com/pierrecomputer/sdk/packages/code-storage-go@latest
bash

Khởi tạo client#

TypeScript#

import { GitStorage } from '@pierre/storage';

const storage = new GitStorage({
  name: 'your-org',
  key: process.env.PIERRE_PRIVATE_KEY!,
});
typescript

Python#

from pierre_storage import GitStorage

storage = GitStorage({
    "name": "your-org",
    "key": os.environ["PIERRE_PRIVATE_KEY"],
})
python

Go#

client, err := storage.NewClient(storage.Options{
	Name: "your-org",
	Key:  os.Getenv("PIERRE_PRIVATE_KEY"),
})
go

Tạo repository và commit đầu tiên#

TypeScript#

const repo = await storage.createRepo({ id: 'new-workspace' });

const result = await repo
  .createCommit({
    targetBranch: 'main',
    commitMessage: 'Get started with Code Storage',
    author: { name: 'Pierre', email: 'pierre@pierre.co' },
  })
  .addFileFromString('README.md', '# Getting started\n')
  .addFileFromString('main.ts', 'console.log("Hello from Code Storage");')
  .send();

console.log(result.commitSha);
typescript

Python#

repo = await storage.create_repo(id="new-workspace")

result = await (
    repo.create_commit(
        target_branch="main",
        commit_message="Get started with Code Storage",
        author={"name": "Pierre", "email": "pierre@pierre.co"},
    )
    .add_file_from_string("README.md", "# Getting started\n")
    .add_file_from_string("main.py", "print('Hello from Code Storage')")
    .send()
)

print(result["commit_sha"])
python

Go#

ctx := context.Background()
repo, err := client.CreateRepo(ctx, storage.CreateRepoOptions{ID: "new-workspace"})

builder, err := repo.CreateCommit(storage.CommitOptions{
	TargetBranch:  "main",
	CommitMessage: "Get started with Code Storage",
	Author:        storage.CommitSignature{Name: "Pierre", Email: "pierre@pierre.co"},
})

result, err := builder.
	AddFileFromString("README.md", "# Getting started\n", nil).
	AddFileFromString("main.go", "package main\n\nfunc main() {}\n", nil).
	Send(ctx)

fmt.Println(result.CommitSHA)
go

Authentication & Security#

Code Storage sử dụng JSON Web Tokens (JWT) cho authentication. Mỗi request Code Storage sử dụng JWT mà organization của bạn signs. Bạn kiểm soát repository access, scopes, expiration và ref policy trong mỗi JWT, nên mỗi client, agent hoặc task nhận được chính xác access cần thiết.

flowchart TD
    A[Organization] --> B[Sign JWT]
    B --> C[JWT with Scopes]
    C --> D[Ref Policies]
    C --> E[Expiration]
    C --> F[Repository Access]
    
    D --> G[Limit Ref Updates]
    E --> H[Token Expiry]
    F --> I[Repository Permissions]
    
    G --> J[Agent Request]
    H --> J
    I --> J
    
    J --> K[Code Storage API]
    K --> L[Validate JWT]
    L --> M[Apply Policies]
    M --> N[Execute Operation]

Hiệu suất và Quy mô#

Code Storage được thiết kế để xử lý workloads ở quy mô lớn:

  • Millions of repos per day: Có thể xử lý hàng triệu repository mới mỗi ngày
  • 60x faster: Read/write operations nhanh hơn ~60x so với các giải pháp S3/R2 tương tự
  • 99.99% uptime: Độ sẵn sàng cao cho hạ tầng repository quan trọng
  • 90,000+ operations at peak: Có thể duy trì hơn 90,000 operations tại thời điểm cao điểm

Case Study: Lovable#

Lovable, một platform phát triển phần mềm AI-powered, đã chọn Code Storage để xử lý 8M+ repos mới mỗi tuần với yêu cầu về tốc độ, quy mô và độ tin cậy chưa từng có.

Kết quả đạt được#

  • 99.99% uptime cho hạ tầng repository quan trọng
  • 90,000+ operations tại thời điểm cao điểm
  • 230% improvement trong p50 fetch latency
  • 160% improvement trong push latency

“Pierre đã trở thành hạ tầng nền tảng cho cách chúng ta vận hành generation phần mềm AI-native ở quy mô. Team của họ hiểu sâu sắc về hiện thực vận hành của workloads phát triển driven-by-agent.”

— Will Rudenmalm, Member of Technical Staff, Lovable

Best Practices#

  1. Sử dụng ephemeral branches cho experiments và previews
  2. Implement ref policies để giới hạn force pushes và bảo vệ branches quan trọng
  3. Leverage webhooks để integrate với build systems và bots
  4. Sử dụng session state workflow cho agent state management
  5. Implement parallel attempts cho exploration và optimization

Lưu ý quan trọng#

[!NOTE] Code Storage không cung cấp pull requests, issues hoặc code review. Nó tập trung vào hạ tầng Git và storage, không phải collaboration features của GitHub.

Tài liệu tham khảo#