Skip to content

karagozemin/0G-Forge

Repository files navigation

0G Forge

0G Forge Logo

0G Forge is a terminal-native agent framework and CLI for building, previewing, and deploying AI-generated apps on the 0G stack β€” powered by 0G Compute for inference, 0G Storage for persistent memory, and 0G Chain for on-chain registration.

0G Forge serves as a ZeroClaw-style framework alternative: where OpenClaw provides autonomous agent execution loops, 0G Forge provides the code-generation and deployment substrate β€” a framework primitive that agent builders can use to autonomously scaffold, modify, and ship on-chain AI apps using 0G Compute + Storage

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Developer / Agent                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚  og CLI commands
                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  0G Forge CLI (og)                   β”‚
β”‚  og init β”‚ og create β”‚ og edit β”‚ og preview          β”‚
β”‚  og deploy vercel β”‚ og sync push/pull                β”‚
β”‚  og login β”‚ og model list/use                        β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                 β”‚                   β”‚
       β–Ό                 β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  0G Compute  β”‚ β”‚  0G Storage  β”‚  β”‚    0G Chain      β”‚
β”‚  Network     β”‚ β”‚  (Indexer +  β”‚  β”‚  FrameworkReg.  β”‚
β”‚  (inference) β”‚ β”‚   KV Layer)  β”‚  β”‚  (EVM contract) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                 β”‚                   β”‚
       β–Ό                 β–Ό                   β–Ό
 Plan + Diff       Sync metadata        On-chain
 generation        across machines      framework entry
packages/
  forge-agent/       # Agent runtime β€” AgentLoop, ToolRegistry, MemoryLayer (NEW)
  core/              # .og manifest + history schema
  compute-client/    # 0G Compute auth + model client
  storage/           # SyncProvider interface + local-file provider
  storage-0g/        # 0G Storage SyncProvider (Indexer + contract)
apps/
  cli/               # og CLI β€” all commands wired here
contracts/
  FrameworkRegistry  # Solidity β€” deployed on 0G Chain mainnet
examples/
  goal-agent/        # Autonomous agent built on forge-agent runtime
    src/agent.mjs        # basic agent (mock mode)
    src/agent-0g.mjs     # 0G-native agent using forge-agent framework

forge-agent Runtime (packages/forge-agent/)

The core framework primitive β€” a ZeroClaw-style agent runtime built natively on 0G.

import { AgentLoop, ToolRegistry, MemoryLayer, createLocalMemoryBackend } from "@og/forge-agent";
import { createOgCreateTool, createOgEditTool, createOgSyncTool } from "@og/forge-agent";

const registry = new ToolRegistry()
  .register(createOgCreateTool({ cliEntry, tsxBin, projectDir, apply: true }))
  .register(createOgEditTool({ cliEntry, tsxBin, projectDir, apply: true }))
  .register(createOgSyncTool({ cliEntry, tsxBin, projectDir }));

const memory = new MemoryLayer(createLocalMemoryBackend("./state.json"), "my-agent");

const loop = new AgentLoop({
  registry,
  memory,
  maxRetries: 2,
  onStepEnd(reflection) {
    console.log(`${reflection.decision}: ${reflection.goal}`);
  }
});

loop
  .addGoal("Create a landing page with hero section", "og:create")
  .addGoal("Improve accessibility and contrast", "og:edit")
  .addGoal("Add feature list below hero", "og:edit");

const result = await loop.run();
// { goalsCompleted: 3, goalsSkipped: 0, reflections: [...] }

Three extensible primitives:

  • AgentLoop β€” goal execution engine with reflection (continue / retry / skip / abort)
  • ToolRegistry β€” register any tool; built-ins wrap og create, og edit, og sync
  • MemoryLayer β€” read/write/append agent state; backend-agnostic (local file or 0G Storage)

Install

npm install -g @kaptan_web3/og-cli
og --version
og --help

Before you start

Not every command needs setup. What each step requires:

Command What you need
og init, og preview Nothing β€” works fully offline
og create / og edit An inference endpoint + token (see below)
og sync push/pull (0G mode) A 0G mainnet wallet with a small balance (storage fee + gas, well under 0.1 0G per sync)
og deploy vercel Vercel CLI installed and logged in (npm i -g vercel && vercel login)

Getting an inference endpoint + token

og talks to any OpenAI-compatible chat-completions API. Use whichever you have access to:

  • 0G Compute proxy β€” if you have a token from a 0G Compute provider, use it directly (this is the recommended path; example endpoint shown in Quick start below).
  • Any OpenAI-compatible provider β€” endpoints exposing /chat/completions or /v1/chat/completions work with og login --endpoint <url> --token <key>.

After login, run og model list β€” it discovers the model ids your provider actually accepts, even if the endpoint has no /models catalog. If your project's default model is rejected, og create/og edit automatically retries with a provider-accepted model.

Getting a 0G wallet for sync (optional)

og sync works without any wallet (local-file mode). To sync through real 0G Storage + 0G Chain:

  1. Use any EVM wallet; export its private key as OG_PRIVATE_KEY (with or without the 0x prefix).
  2. Fund it with a small amount of 0G on 0G Mainnet (chain id 16661, RPC https://evmrpc.0g.ai).
  3. Set OG_STORAGE_ENABLED=1. That's all β€” RPC endpoints and the registry contract default to mainnet values.

Quick start

1) Login with 0G Compute credentials

og login \
  --token "$OG_COMPUTE_TOKEN" \
  --endpoint "https://compute-network-4.integratenetwork.work/v1/proxy"

Any OpenAI-compatible 0G Compute proxy endpoint works. After login, og model list discovers the models your provider actually accepts. If your project's default model is not supported by the provider, og create/og edit automatically retries with a provider-accepted model.

2) Init a project

og init --template react-vite --dir ./my-app --yes
cd ./my-app && pnpm install

3) Generate from a prompt

og create --prompt "Add a hero section with gradient background" --dry-run
og create --prompt "Add a hero section with gradient background" --yes

4) Edit β†’ preview β†’ deploy

og edit --prompt "Improve CTA contrast and add mobile nav" --yes
og preview
og deploy vercel --yes

5) Sync metadata to 0G Storage

Only a funded 0G mainnet wallet key is required β€” RPC endpoints and the registry contract default to 0G mainnet values:

export OG_STORAGE_ENABLED=1
export OG_PRIVATE_KEY=<your_key>

og sync push   # uploads payload to 0G Storage, stores hash on 0G Chain
og sync pull   # reads hash from chain, downloads from 0G Storage

Without OG_STORAGE_ENABLED=1, sync falls back to a local-file provider (no network, no wallet needed).

0G Protocol Integration

Component Usage
0G Compute Network AI inference for og create / og edit β€” OpenAI-compatible /v1/chat/completions
0G Storage (Indexer) og sync push/pull stores project metadata as files on 0G Storage network
0G Chain (EVM) FrameworkRegistry contract stores latest sync hash per project + framework registration

Goal Agent β€” Autonomous example

The goal agent (examples/goal-agent/) is a working autonomous agent built on top of the og framework. It demonstrates how developers can use og as an agent substrate.

# Basic (mock mode)
node examples/goal-agent/src/agent.mjs --apply

# 0G-native (uses 0G Storage memory + 0G Chain registration + reflection loop)
OG_STORAGE_ENABLED=1 \
OG_PRIVATE_KEY=<key> \
node examples/goal-agent/src/agent-0g.mjs --apply --max-steps 3

What the 0G-native agent does:

  • Reads goal list
  • Runs og create / og edit for each goal
  • Reflection loop: evaluates each step result before continuing (retry / skip / continue)
  • Writes memory to 0G Storage after each step
  • Registers itself on 0G Chain via FrameworkRegistry

Contract Deployment (0G Chain)

cd contracts
npm install
cp .env.example .env  # fill in OG_PRIVATE_KEY
npm run deploy:mainnet

The deploy script also registers "0G Forge" on-chain automatically.

Deployed contract (0G Mainnet): 0x47955e005433A548287358c4DFd6679A0e8F5d50

Environment variables

# 0G Compute (required for real generation)
OG_COMPUTE_TOKEN=          # your compute API token
OG_COMPUTE_ENDPOINT=       # OpenAI-compatible proxy endpoint (set during `og login`)

# 0G Storage sync (optional, enables decentralized sync)
OG_STORAGE_ENABLED=1
OG_PRIVATE_KEY=            # wallet key for signing storage + chain txs (required)
OG_STORAGE_INDEXER_RPC=    # default: https://indexer-storage-turbo.0g.ai (mainnet)
OG_EVM_RPC=                # default: https://evmrpc.0g.ai (mainnet)
OG_REGISTRY_CONTRACT=      # default: 0x47955e005433A548287358c4DFd6679A0e8F5d50 (mainnet)

# Generation tuning (optional)
OG_GENERATION_TIMEOUT_MS=          # default: 120000
OG_GENERATION_MAX_FILE_CHARS=      # default: 6000  (per-file prompt context budget)
OG_GENERATION_MAX_CONTEXT_CHARS=   # default: 32000 (total prompt context budget)

# Developer mock mode (local testing only)
OG_ENABLE_MOCK_MODE=1      # enables mock://local endpoint

Run from source

git clone <repo-url>
cd 0G
pnpm install
pnpm build
pnpm --filter @kaptan_web3/og-cli run dev --help

Validation

pnpm lint
pnpm typecheck
pnpm build

Repository map

apps/cli/              # CLI β€” all og commands
packages/core/         # .og state (manifest, history)
packages/compute-client/ # 0G Compute auth + model client
packages/storage/      # SyncProvider interface + local-file provider
packages/storage-0g/   # 0G Storage SyncProvider (NEW)
contracts/             # FrameworkRegistry.sol β€” 0G Chain (NEW)
examples/goal-agent/   # Autonomous agent example
  src/agent.mjs        # basic version (mock)
  src/agent-0g.mjs     # 0G-native version with reflection (NEW)
scripts/demo-flow.sh   # reproducible demo runner

Supported templates

react-vite Β· nextjs-app Β· static-landing

Commands

og login / logout / whoami
og model list / model use <modelId>
og init
og create / og edit
og preview
og deploy vercel
og sync push / og sync pull
og doctor

About

0G Forge is a terminal-native companion for the 0G app workflow: prompt-driven project changes, local preview, Vercel deploy, and lightweight sync metadata.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages