WebGraft
README.md
<p align="right"><strong>English</strong> · <a href="./README.zh-CN.md">简体中文</a></p>
# WebGraft (`webgraft`)
[](./LICENSE)
[](#quick-start)
[](#verified-benchmarks--real-world-blind-tests)
[](#quick-start)
[-38bdf8.svg)](#quick-start)
> **Turn the fragmented internal portals & legacy ERPs you have access to into an invisible, permission-scoped Personal Capability Graph inside your AI Agent — 100×–350× faster pure-HTTP execution, fail-closed human confirmation, and zero new dashboards.**
**WebGraft** lives silently inside **Claude Code, Cursor, Antigravity, DSH, or OpenClaw** via an ultra-lean **6-tool MCP bridge (`~590` tokens)**. It compiles authorized web apps from **live JS bundles (`oxc-parser` AST) + optional repo/OpenAPI + inherited user session**, maps your **exact role & permission boundary**, evaluates **whether a task can be completed (and what you can do next if blocked)**, enforces **fail-closed native OS human confirmation + Post-Write Read-Back verification**, and **auto-heals in milliseconds via Bundle-Diff** when portals silently upgrade.
---
## Why WebGraft?
| Approach | Examples | What Breaks in Real Enterprise Use |
|---|---|---|
| **Browser / DOM Agents** | Browser Use, Stagehand, Playwright MCP | Boot & drive full Chromium DOM every step (**5–20s**, 600MB RAM, burns VLM/LLM tokens, fragile selectors) |
| **Static HAR Converters** | AnythingMCP, `har-mcp` | Only capture the 3 endpoints you clicked; shatter on CSRF rotation, auth expiry, or app upgrades |
| **Site-Owner Protocols** | WebMCP | Require legacy ERP / internal SaaS teams to rewrite their frontend (99% never will) |
| **WebGraft** | **`npx webgraft`** | **Compiles JS Bundle AST + Inherited RBAC → Permission-Scoped Personal Capability Graph + Pure HTTP (<2ms local / <150ms remote) + Fail-Closed Confirmation + Bundle-Diff Self-Heal** |
---
## Core Capabilities
1. **Permission-Scoped Personal Capability Graph & Task Feasibility Advisor**
- Automatically captures your logged-in identity, role, and permissions (`/session`, `/me`, `/login`, custom auth headers `Cookie` / `Bearer` / `X-Token` / `X-Access-Token`) and prunes `403` boundaries on the fly.
- Keeps the capability graph **internal** so users never have to memorize admin menus — instead, for every natural-language request, WebGraft tells the Agent:
- **Can it be completed?** (`CAN_COMPLETE_NOW`, `AUTO_RESOLVE_THEN_ACT`, `NEEDS_CONFIRMATION`) with logical execution steps & auto-resolution of missing entity IDs;
- **If blocked by permissions (`BLOCKED_PERMISSION`)**, blocks **before** popping any dialog, points to a safe read-only `prepAction` to pull facts, and gives concrete **"what you can do next"** unblock options (e.g., ready-to-send handover summary for an `admin` colleague).
2. **3-Layer Quality Gates & Fail-Closed Unforgeable Human Confirmation**
- **Gate 1 (Pre-Flight)**: Deterministic `<0.1ms` schema, required-param, enum, and type check before touching the network.
- **Gate 2 (Fail-Closed Human Confirmation on `run_write`)**:
- Pops a clean, jargon-free **native desktop confirmation modal** (macOS / Windows — default button is always `Cancel`, 55s timeout auto-denies) that the AI cannot forge or bypass even if the Agent host auto-approves MCP calls.
- Automatically fails closed to **SHA-256 parameter-bound single-use cryptographic tickets** (`--strict-tickets`) in headless / SSH / CI / chat-bot environments.
- **Gate 3 (Post-Write Read-Back Verification)**: Automatically locates the exact parent `GET` detail endpoint (ignoring `/logs` or `/invoice` sub-resources), verifies the persisted write, and computes field-level `before → after` receipts.
3. **Pure Business Outcome Delivery (Zero Scripts, Zero Plumbing)**
- Ships with an Agent skill (`skills/webgraft/SKILL.md`) that keeps the assistant focused on **what was accomplished, verified before → after effect, and where to view it** — never dumping `.mjs` scripts, HTTP paths, or raw JSON.
4. **Bundle-Diff Self-Healing**
- When an ERP silently ships breaking `v1 → v2` endpoint moves or parameter renames (`/api/v1/orders` → `/api/v2/orders`, `keyword` → `searchTerm`), WebGraft catches `404`/`400`, re-fetches live chunks, diffs the AST capability graph, remaps renamed parameters, persists the updated IR, and retries in **~6–10ms** with 0 UI clicks.
---
## Verified Benchmarks & Real-World Blind Tests
### 1. Enterprise ERP Benchmark (`npm run bench` & `npm run demo:chat`)
Same 3-step authenticated ERP workflow (REST list + POST search + GraphQL query) with `HttpOnly` Cookie + rotating CSRF + dual-role RBAC (`operator` vs `admin`):
| Metric | Measured Result |
|---|---|
| One-time compile + Chrome CDP session capture | **1,090 ms** (10 capabilities across 3 chunks, incl. unclicked hidden APIs) |
| Headless Chrome DOM workflow *(excl. LLM wait)* | **585.6 ms avg** |
| **WebGraft Pure-HTTP MCP (0 Chrome, \$0 LLM)** | **1.68 ms avg (348.5× faster)** |
| **Breaking Portal Upgrade (`v1 → v2`: URL moved + `keyword → searchTerm`)** | **Self-healed in 5.8 ms** via Bundle-Diff AST (0 UI clicks) |
| Global Multi-App MCP Schema Footprint | **6 tools (~590 tokens total)** — stays constant even across 10 portals & 500 endpoints |
### 2. Cold Blind Tests on Live Production Web Apps (`npm run blind-test`, zero source code)
| Live Production Target | Bundler / Stack | Real APIs Discovered | False Positives | Elapsed |
|---|---|---|---|---|
| `preview.pro.ant.design` | Webpack 5 + Umi + React | **25 APIs** (36 chunks, 38 vendor skipped) | **0** | 7.8s |
| `panjiachen.github.io/vue-element-admin` | Webpack 4 + Vue CLI (inline map) | **14 APIs** (76 lazy chunks auto-discovered) | **0** | 5.8s |
| `www.vben.pro` | Vite 6 + Rolldown + Vue 3 | **41 CRUD APIs** (100 concurrent chunks) | **0** | 2.2s |
| `app.cal.com/auth/login` | Next.js App Router | **6 APIs** (static `.md`/`/_head` filtered) | **0** | 3.1s |
---
## Architecture
```mermaid
flowchart LR
S1["1. Live JS Bundles<br/>(Webpack 4/5, Vite, Next.js)"] --> IR
S2["2. Optional Source Repo / OpenAPI<br/>(TS, TSX, Vue SFC, Swagger)"] --> IR
S3["3. Inherited Human Auth & Role<br/>(CDP Headed SSO / --attach 9222)"] --> IR
IR["Role-Scoped Personal Capability Graph<br/>~/.webgraft/apps/ (Zero Secrets in IR)"] --> MCP["Ultra-Thin 6-Tool MCP<br/>(~590 tokens) + Agent Skill"]
IR --> CLI["Standalone CLI"]
MCP --> PLAN["Task Feasibility &<br/>Unblock Advisor"]
PLAN --> GATE["3-Layer Quality Gate<br/>Pre-Flight · Fail-Closed Modal · Read-Back"]
GATE --> EXEC["Pure-HTTP Runtime (<150ms)<br/>+ Outcome Receipt + Audit Log"]
EXEC -- "404 / Schema Drift" --> HEAL["Bundle-Diff Self-Heal<br/>Re-parse chunks & patch IR (~6ms)"]
HEAL --> EXEC
```
---
## Quick Start
Requires **Node.js >= 22** (uses native `fetch` & `WebSocket` CDP; single dependency `oxc-parser`).
### 1. Connect inside Claude Code / Cursor / DSH / OpenClaw (Zero New UI)
```bash
# Add WebGraft MCP server once
claude mcp add webgraft -- npx -y webgraft mcp
# Optional: generate project-level Agent Skill (.agents/skills/webgraft-bridge/SKILL.md) + MCP snippet
npx webgraft init
```
Then just talk naturally in your AI Agent:
- `"Connect to our internal ERP at https://erp.company.internal"` *(pops an auto-closing Chrome login window only if auth is required)*
- `"Approve Initech's pending order"` *(auto-locates the order → pops fail-closed confirmation card → verifies persisted state → delivers clean before/after outcome)*
- `"Refund order ORD-1002"` *(if your role lacks permission, blocks with 0 popups, pulls order facts, and drafts a ready-to-send handover message for an admin)*
### 2. Standalone CLI (Great for Enterprise Intranet / Existing Chrome SSO)
```bash
# Option A: Compile + open Chrome to log in via corporate SSO/MFA/QR + verify READ endpoints
npx webgraft connect https://erp.company.internal --name my-erp --headed --verify
# Option B: Attach to your already logged-in Chrome (started with --remote-debugging-port=9222)
npx webgraft connect https://erp.company.internal --name my-erp --attach 9222 --verify
# Inspect compiled capabilities & playbooks (stored under ~/.webgraft/apps/<name>/)
npx webgraft apps
npx webgraft ask "list pending orders" --execute
# Run the local interactive demo without touching any real system
npm run demo:chat
```
---
## Security & Honest Execution Boundaries
- **Local-First & Strict Secret Isolation**: Session cookies, Bearer tokens, custom auth headers, and CSRF tokens live strictly in `~/.webgraft/apps/<appId>/session.json` (`0600`) and are **never** written into `capabilities.json` or Git.
- **Inherited Human RBAC + 403 Self-Pruning**: Executes strictly under the employee's real authenticated session — zero privilege escalation (handles both standard HTTP `401/403` and enterprise HTTP `200` JSON error envelopes).
- **Hard Read/Write Tool Separation & Fail-Closed Confirmation**: `run_read` physically refuses any `WRITE` or `DANGEROUS_WRITE` capability (`READ_ONLY_TOOL_VIOLATION`). `run_write` enforces fail-closed native OS confirmation by default, falling back to single-use SHA-256 parameter-bound tickets (`--strict-tickets`) in headless environments.
- **3-Tier Execution Honesty**:
- **Tier 1 (`pure-http`)**: Direct Node `fetch()` — zero Chrome, millisecond execution.
- **Tier 2 (`page-fetch`)**: In-page `fetch()` via CDP (`--mode page-fetch`) for `SameSite`/proxy quirks — still zero DOM clicks.
- **Tier 3 (Frontend-signed / encrypted payloads)**: Honestly surfaced rather than silently pretending to succeed.
## License
[MIT](./LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues