Skip to content
FarhatFINPublic

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

⚒ OpenForge

Open-source AI coding assistant. An autonomous agent that reads your project, plans changes, edits code, runs commands and verifies the result — right inside your codebase. Desktop app (Electron + React) and CLI. MIT-licensed.

you>  add a multiply() function to src/math.ts and verify with a script

Plan:
  1. Read src/math.ts
  2. Add multiply() next to add() and subtract()
  3. Verify by running a quick node script

→ read_file {"path":"src/math.ts"}
→ edit_file {"path":"src/math.ts", ...}
→ run_terminal {"command":"node -e \"...\""}
✔ Done in 5 iterations.

Features

  • AI agent with tool calling — the model works through 14 built-in tools: read_file, write_file, edit_file, multi_edit, search_code, run_terminal, git_diff, git_status, git_log, create_plan, plus list_files, find_symbol, impact_of and revert_changes. The loop is: analyze → plan → edit → verify → report.
  • Stop button that really stops — cancel a run from the app or with Ctrl+C in the CLI: the in-flight model request is aborted and the running command's whole process tree is killed, then the transcript is closed cleanly so you can continue afterwards.
  • Resumable sessions — openforge run "…" --continue replays the previous session's transcript, so a follow-up task starts with everything the agent already learned. --session <id> targets a specific one.
  • Cost budget — openforge run "…" --budget 2 (or maxCostUsd in the config / Settings) stops the run cleanly once the estimated spend reaches the cap.
  • Checkpoints & undo — every write is snapshotted first. The agent can roll back its own mistakes with revert_changes, you can undo from the CLI (openforge undo, --all, --path src/math.ts, undo list) or from the Usage panel in the desktop app.
  • Atomic multi-file-safe edits — multi_edit applies a batch of replacements to one file all-or-nothing, so a half-applied refactor can no longer leave a file broken.
  • MCP support — connect any Model Context Protocol server (GitHub, Postgres, a browser driver, your own) and its tools appear to the agent as mcp__<server>__<tool>. A server that fails to start costs its tools, never the run.
  • Streaming — answers arrive token by token from Anthropic and OpenAI instead of appearing in one lump when the model finishes.
  • Subagents — the task tool delegates open-ended investigation to a nested agent with its own context, so twenty file reads collapse into one paragraph in the main conversation.
  • Live task list — todo_write keeps a visible checklist during multi-step work, in the CLI (/todos) and the desktop app.
  • Custom commands — drop review.md into .openforge/commands/ and type /review in chat.
  • Project instructions — drop an OPENFORGE.md (or AGENTS.md, .openforge/instructions.md, .github/copilot-instructions.md) in the repository and the agent follows your conventions, test command and no-go areas on every task. They are treated as guidance, never as authority: repository content can never widen what the agent is allowed to do.
  • Impact analysis & symbol search — impact_of shows which modules import the file you are about to change; find_symbol jumps straight to a function, class or type definition instead of grepping blindly.
  • Dry-run mode — openforge run "..." --dry-run lets the agent read, reason and produce a plan while every write and every command is blocked at the security layer.
  • Token & cost accounting — usage is recorded per model and openforge stats (or the Usage panel) shows tokens and an estimated cost in USD.
  • Resilient agent loop — transient provider failures (429/5xx/timeouts) are retried with exponential backoff, and the conversation is automatically compacted when it approaches the context limit.
  • .openforgeignore — gitignore-style rules (plus your .gitignore) keep generated folders out of the index and out of the model's context.
  • Codebase awareness — the whole project is indexed (symbols, imports, dependency graph) and a compact project map is injected into the model's context. Code search works over the index.
  • Multi-provider — OpenAI, Anthropic, Google Gemini, and local models via Ollama. Bring your own API key; keys are stored locally in ~/.openforge/config.json and sent only to the provider you choose.
  • Modern UI — file explorer, AI chat with live agent events and a working Stop button, diff viewer, guarded terminal, agent audit log, usage & checkpoints panel (with one-click undo), settings.
  • Security by default — file access is jailed to the project root, secret files (.env, keys, certs) are blocked, dangerous commands (rm -rf, sudo, force-push, curl|sh, …) always require explicit confirmation, and every action is written to an audit log.
  • Local storage — sessions, messages and the audit log are stored in SQLite (built-in node:sqlite, zero native dependencies; JSON fallback where unavailable).
  • Zero runtime dependencies — the core engine uses only the Node.js standard library.

Quick start

Requirements: Node.js ≥ 20 (≥ 24 recommended), git.

npm install

# Run the test suite (offline, no API key needed)
npm test

# CLI — works immediately:
export OPENAI_API_KEY=sk-...        # or ANTHROPIC_API_KEY / GEMINI_API_KEY / Ollama
npm run cli -- run "explain what this project does" 
npm run cli -- chat                  # interactive session
npm run cli -- index                 # show the project index
npm run cli -- config                # show effective config (keys masked)
npm run cli -- audit                 # every guarded action taken in this project
npm run cli -- stats                 # tokens used and estimated cost
npm run cli -- undo                  # roll back the agent's last file change
npm run cli -- run "refactor X" --dry-run       # plan only, nothing is written
npm run cli -- run "now add tests" --continue   # resume the previous session
npm run cli -- run "big refactor" --budget 2    # stop at ~$2 of estimated spend

# Desktop app (dev mode: Vite + Electron)
npm run dev

# Desktop app (production build)
npm start

Useful CLI flags: --project <dir>, --provider openai|anthropic|gemini|ollama, --model <name>, --yes (auto-approve safe commands; dangerous ones still ask), --dry-run, --continue / -c, --budget <usd>, --session <id>, and for undo: --steps <n>, --path <file>, --all.

Press Ctrl+C during a run to stop the agent: the model request is aborted, the running command's process tree is killed, and the session is saved so you can pick it up again with --continue. A run that failed or was stopped exits with code 1, so scripts can tell success from failure.

Ignoring files

Create .openforgeignore in the project root (same syntax as .gitignore) to keep folders out of the index:

build/
*.generated.ts
!src/keep.generated.ts
**/snapshots

Comments, negation (!), directory rules, anchored rules, *, ** and ? are supported, with git semantics: **/snapshots matches a whole path segment, so mysnapshots/ is not excluded by accident.

Connecting MCP servers

Add them to the global config ~/.openforge/config.json (a project config cannot introduce one — that would let any cloned repository run code on your machine):

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "..." }
    },
    "postgres": { "command": "mcp-server-postgres", "enabled": false }
  }
}

Their tools show up as mcp__github__create_issue and so on. Everything an MCP server returns is treated as untrusted input: the system prompt tells the agent to use it as information only and to refuse instructions embedded in it.

Custom commands

.openforge/commands/review.md   ->  /review
~/.openforge/commands/pr.md     ->  /pr        (global; project wins on conflict)
---
description: Review the current diff
---
Review the changes in $ARGUMENTS. Focus on correctness and error handling.

$ARGUMENTS is everything after the command; $1, $2, … are the individual words. Type /help in openforge chat to list what is available.

Teaching the agent your conventions

Create OPENFORGE.md in the project root (or AGENTS.md, .openforge/instructions.md, .github/copilot-instructions.md — the first one found wins) and it is injected into every task:

- TypeScript, tabs, no new runtime dependencies.
- Run `npm run verify` before finishing a task.
- Never touch `src/legacy/**` — it is generated.

This repository ships its own OPENFORGE.md as an example.

Using local models (Ollama)

ollama pull qwen2.5-coder:7b
npm run cli -- --provider ollama --model qwen2.5-coder:7b chat

Configuration

~/.openforge/config.json (global) and <project>/.openforge.json (per-project override):

{
	"provider": "anthropic",
	"model": "claude-3-5-sonnet-latest",
	"apiKeys": { "anthropic": "sk-ant-..." },
	"maxIterations": 25,
	"maxCostUsd": 0,
	"autoApprove": false
}

maxCostUsd is a per-task spending cap in USD (0 = no cap); the run stops cleanly as soon as the estimated cost reaches it. For safety, a project file (.openforge.json, i.e. content that ships with a cloned repository) can never set autoApprove, apiKeys, smtp or oauth — those come from your global config only.

Environment variables OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, OLLAMA_BASE_URL take precedence.

Accounts, guest mode & sign-in

OpenForge works fully offline as a guest (local Ollama models only). Sign in to unlock all providers (OpenAI, Anthropic, Gemini, Ollama):

  • Google (Gmail), Microsoft (Outlook), Apple ID — OAuth 2.0 + PKCE in your system browser (bring your own OAuth client id, see docs/PROVIDERS.md).
  • Email + one-time code — passwordless sign-in for any mailbox.
  • Email + password + confirmation code — classic sign-in with 2FA.

Accounts are stored locally in ~/.openforge/auth.json (scrypt-hashed passwords, hashed single-use codes). Codes are emailed via your SMTP settings, or shown in-app in clearly-labelled dev mode when SMTP is not configured. Sign out any time from Settings; openforge login / whoami / logout in the CLI.

Cross-platform

OS Shell used by the agent & terminal panel Desktop build
macOS bash (or $OPENFORGE_SHELL, e.g. zsh) npm run package:mac — dmg + zip (arm64/x64)
Linux bash (or $OPENFORGE_SHELL) npm run package:linux — AppImage, deb, tar.gz
Windows PowerShell (powershell.exe, or pwsh via OPENFORGE_SHELL=pwsh) npm run package:win — NSIS installer + portable

Command screening is platform-aware: the POSIX rules (rm -rf, sudo, curl | sh, force-push, …) are complemented by PowerShell/cmd rules (Remove-Item -Recurse, rd /s, Set-ExecutionPolicy, reg delete, iwr … | iex, vssadmin delete, …), so the default Windows shell is screened as strictly as bash. On POSIX a timed-out or cancelled command is killed as a whole process group, so background grandchildren cannot survive it.

The CLI (npm run cli …) runs on all three platforms in any terminal, including Windows PowerShell. Desktop packages are produced by electron-builder; build on the target OS (or configure cross-compilation) after npm install.

UI personalization

Settings → Appearance: dark / light theme, 7 accent colors, and compact / comfortable density. Preferences persist in ~/.openforge/config.json and apply instantly.

Project structure

openforge/
├── src/
│   ├── core/                  # UI-agnostic engine (zero runtime deps)
│   │   ├── agent/             #   agent loop + system prompt
│   │   ├── providers/         #   OpenAI / Anthropic / Gemini / Ollama / Mock
│   │   ├── tools/             #   tool schemas + guarded executor
│   │   ├── indexer/           #   project index, symbols, deps, code search, ignore rules
│   │   ├── checkpoints/       #   pre-write snapshots + undo
│   │   ├── usage/             #   token accounting and cost estimation
│   │   ├── security/          #   path jail, command screening, approvals
│   │   ├── storage/           #   SQLite (node:sqlite) with JSON fallback
│   │   ├── git/               #   git status/diff/log wrapper
│   │   ├── config.ts          #   layered configuration
│   │   ├── engine.ts          #   composition root (used by CLI & Electron)
│   │   └── types.ts           #   shared types
│   ├── cli/                   # headless CLI (run/chat/index/audit/config)
│   ├── main/                  # Electron main process + preload (IPC bridge)
│   └── renderer/              # React UI (chat, files, diff, terminal, …)
├── tests/                     # node:test suite (offline, uses MockProvider)
└── docs/                      # architecture & security docs

See docs/ARCHITECTURE.md for the full design and docs/SECURITY.md for the threat model.

How the agent works

  1. The engine indexes the project and builds a system prompt containing the project map and working rules.
  2. Your task is sent to the configured model together with the tool schemas.
  3. The model responds either with tool calls (executed by the guarded ToolExecutor, results fed back) or with a final summary.
  4. Every message is persisted to SQLite; every file access and command is recorded in the audit log; dangerous actions require your explicit approval.

Testing

npm test        # runs tests/*.test.ts with the built-in node:test runner
npm run typecheck

The suite covers the security guard, tools, indexer, storage, provider factory, and a full end-to-end agent cycle with a scripted mock provider — no network or API keys required.

Contributing

See CONTRIBUTING.md. Issues and PRs are welcome.

License

MIT

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages