Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,46 @@ The workspace endpoints are locked until the project sandbox (YOLO) or full acce

---

### Step 5 — fast uploads (no token)
### Step 5 — ask what this machine can do (`/api/skills`, `/api/tools`)

Before starting a reverse-engineering or forensics job, ask the bridge instead of guessing:

```bash
curl -H "Authorization: Bearer <TOKEN>" https://<TUNNEL_URL>/api/skills?state=ready
curl -H "Authorization: Bearer <TOKEN>" https://<TUNNEL_URL>/api/tools
```

```json
{
"skills": [
{"id": "binary-triage", "state": "ready", "missing": [],
"tools": ["objdump", "strings"], "summary": "What a file is before you run it"}
],
"summary": {"total": 12, "by_state": {"ready": 3, "partial": 2, "blocked": 7}}
}
```

`state` is `ready`, `partial` or `blocked`, computed from what is actually installed. `GET
/api/skills/<id>` returns the body **and** that verdict: follow a `ready` skill, start a `partial`
one only up to the point where its `missing` tools are needed, and do not start a `blocked` one —
say what is missing instead. `GET /api/tools/plan?id=<tool>` says whether a one-press download
exists; if it does, tell the user to press it (or run
`python3 -m nerveforge.toolkit --install <tool>`), and do not try to install anything yourself.

### Step 6 — use an MCP server, if one is configured

`GET /api/mcp` lists sessions and `GET /api/mcp/presets` names what blocks each bridge. Call a tool
with:

```json
{"id": "ghidra-mcp", "tool": "decompile_function", "arguments": {"address": "0x401000"}}
```

A tool whose name suggests a change (`rename_`, `patch_`, `run_*`, …) is refused with `409`
`"changes state"`; resend with `"allow_mutating": true` **only after the user has approved it in
the panel**. Ask for `allow_mutating` on a read is a bug, not a shortcut.

### Step 7 — fast uploads (no token)

When you only need to create a new text file in the workspace root:

Expand Down Expand Up @@ -164,7 +203,15 @@ print(f"Exit code: {exit_code}\nOutput:\n{output}")

---

## 4. Built-in self-documentation
## 4. When the bridge is an MCP server

An operator can also run `python3 -m nerveforge.toolkit --serve` so that *this* bridge is an MCP
server for another agent. It offers `list_skills`, `read_skill`, `list_tools`, `workspace_list`,
`workspace_read`, `workspace_write`, `run_command` and `mcp_servers`. Write and run are absent
unless it was started with `--allow-write`, and `run_command` additionally needs armed full access
— a `403` there means "ask the user to enable it", not "retry".

## 5. Built-in self-documentation

* `GET /api/docs` or `GET /llms.txt` — open Markdown manual for agents.
* `GET /api/agent-prompt` — structured JSON with the system prompt and the endpoint map.
Expand Down
19 changes: 11 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

**English** · [Русский](docs/ru/CHANGELOG.md)

## Unreleased
## 8.2.0

8.2.0 collects everything that had accumulated under `Unreleased`: the public
drop box that streams five-gigabyte uploads, the panel rewritten from scratch,
the token bootstrap fix, the cloudflared installer, and skills + MCP. It also
retires the transitional headings those entries lived under, so the history
reads as five releases rather than three releases and a pile of "earlier"
sections. `VERSION` and every artifact behind it now say 8.2.0.

### Skills, MCP clients and MCP servers

The agent could already drive the bridge; it had no idea what the machine it was
running on could *do*. Three things close that gap, and they are deliberately
separate: a **skill** is knowledge plus the tools it needs, an **MCP client**
talks to somebody else's tool server, and an **MCP server** exposes this bridge
to somebody else's client. `VERSION` stays 8.1.0; this rides in `Unreleased`.
to somebody else's client.

A skill is a Markdown file under `toolkit/skills/` with a declared list of
tools. `GET /api/skills` reports each one as `ready`, `partial` or `blocked`
Expand All @@ -20,7 +27,7 @@ without it says so instead of failing halfway through a procedure. Twelve
skills ship: binary triage, function recovery, native debugging, malware
static analysis, YARA authoring, dependency audit, protocol reversing, Android
APK, firmware/IoT, disk forensics, memory forensics, dynamic tracing. On a bare
container three are ready, two are one download away, and seven are blocked —
container three are ready, one is one button away, and eight are blocked —
which is the honest answer, not a bug.

The tool catalogue is 24 entries across RE, debugging, mobile, forensics and
Expand Down Expand Up @@ -50,7 +57,7 @@ The panel gets two tabs: **Skills** (what is ready, what each one needs, an
install button where one exists) and **MCP** (presets with their blockers,
connected servers and their tools, a call box that asks before a mutation).

Tests went from 1432 to 1657 and the new package is at 99% branch coverage.
Tests went from 1432 to 1660 and the new package is at 99% branch coverage.
Six of those tests found real defects rather than covering them: `send()` let a
`ValueError` from a closed pipe escape as a 500; `arguments: []` was silently
accepted because `or {}` turns an empty list into a dict; a `jadx-1.0.tar.gz`
Expand Down Expand Up @@ -241,8 +248,6 @@ runner refuses to start without `bubblewrap`. That is now a test, not a comment.
**907 tests** (was 301), coverage measured with `coverage.py` over `src/`, and
`pylint --enable=duplicate-code` reports no blocks over six lines.

## Unreleased (earlier)

### Added: 5 GiB public uploads, streamed instead of buffered

- **The public drop box stopped being a JSON endpoint in disguise.** It accepted
Expand Down Expand Up @@ -277,8 +282,6 @@ hourly budget. Content is not filtered — only the extension is checked, and an
archive is not unpacked on upload. That is the cost of a large drop box without
a token; the route is still removable.

## Unreleased (earlier)

### Fixed: `unauthorized` on a fresh browser, and a rewritten Windows installer

- **The panel can obtain its own token again.** The token comes from the
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mocks do not verify Windows process behaviour.
| State | `service/state.py` | the only mutable object, everything under one `RLock` |
| Infrastructure | `core/` | `AuditLog`, `JobStore`, `Limits`, `RateLimiter`, `safe_path`, `process` |
| Providers | `tunnel/`, `config/` | external processes and files; each stops itself |
| Toolbox | `toolkit/` | skills, tool detection, one-asset installer, MCP client and server; no HTTP, no globals |
| Composition root | `bridge.py` | port, token, servers, startup; no more than ~300 lines |

### No module-level mutable state
Expand All @@ -42,6 +43,17 @@ Reasons:

Allowed: constants, `Enum`, registries, loggers, `typing` aliases.

### The toolbox respects the machine

`toolkit/` carries the same rule as the rest of the code, applied to things that live outside the
process: a `GET` never downloads, spawns or connects; an install writes exactly one verified file
into the data dir; a stdio MCP server starts on an explicit connect and is killed on disconnect.
Every MCP call is audited, and a mutation-shaped tool name needs `allow_mutating` — the gate lives
in `mcpservice`, never in the panel, so a UI bug cannot bypass it. If you add a tool to
`tools.py`, give it the release asset it would actually use, or leave it out of the download path
entirely; an entry that promises a download the project does not publish is worse than none.
See `docs/TOOLKIT.md` and `docs/ADR/0006-toolkit-safety.md`.

### Import without side effects

`import nerveforge.bridge` must not create directories or read the token. Side effects belong to an
Expand Down
76 changes: 69 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NerveForge 8.1.0 ⚡ Arena.ai ↔ PC & Android Bridge
# NerveForge 8.2.0 ⚡ Arena.ai ↔ PC & Android Bridge

![NerveForge — Build boldly. Ship cleverly.](assets/nerveforge-lockup.png)

Expand Down Expand Up @@ -33,6 +33,11 @@ edit files, build projects and run arbitrary toolchains.
- **Three platforms in one:** native support for **Linux**, **Windows 10/11** and **Android (Termux)**.
- **Direct Arena.ai integration:** the agent connects over a secure HTTPS tunnel and can write
code, build, read logs and fix errors autonomously.
- **Skills and a tool catalogue:** twelve reverse-engineering and forensics skills, each tied to
the tools it needs, plus 24 catalogued tools with a one-press installer. The panel lists what is
`ready`, what a single download would fix and what is blocked on this machine.
- **MCP in both directions:** twelve presets (IDA, Ghidra, radare2, jadx, Frida, Volatility, …) as a
client, and this bridge itself as an MCP server for another agent.
- **Self-documenting:** `/api/docs`, `/llms.txt` and `/api/agent-prompt` let a fresh agent learn
the protocol without any manual briefing.
- **Async engine:** worker pool (`ThreadPoolExecutor`), `TCP_NODELAY` sockets, buffered I/O.
Expand All @@ -46,7 +51,9 @@ edit files, build projects and run arbitrary toolchains.
adjustable at runtime via `GET/POST /api/limits`.
- **Full access:** unlocked with the passphrase `yesiknow`; no artificial throttling and no
lock against parallel runs.
- **Zero dependencies:** pure Python 3.10+ standard library, no third-party `pip` packages.
- **Zero runtime dependencies:** pure Python 3.10+ standard library, no third-party `pip` packages.
Tools the toolbox can install (radare2, jadx, …) are separate programs in the data directory; the
Python packages it can detect (capstone, LIEF, Volatility) are never imported by the bridge.

---

Expand Down Expand Up @@ -111,11 +118,56 @@ Downloads are on request only; nothing is fetched at startup. If the digest does
not match, or the connection drops, the partial file is deleted and nothing is
installed.

### Skills, tools and MCP (optional)

Above the terminal the panel now has a toolbox. It is the same idea three times: tell the agent
what this machine can do, and let it ask for what is missing.

**Skills** (`Skills` tab, `GET /api/skills`). A skill is a written procedure — binary triage,
function recovery, native debugging, malware static analysis, YARA authoring, dependency audit,
protocol reversing, Android APK, firmware/IoT, disk forensics, memory forensics, dynamic tracing —
with an explicit list of the tools it needs. Each one reports `ready`, `partial` or `blocked`
from what is actually installed, so an agent reading `read_skill` never starts a procedure it
cannot finish. On a clean container three are ready, one is one button away and eight are
blocked; that is the honest answer, not a bug.

**Tools** (`GET /api/tools`). 24 entries across reverse engineering, debugging, mobile, forensics
and networking, each with the GitHub release asset a download would use. The **install** button
and the CLI follow the same rule as cloudflared: release asset only, SHA-256 from the same API
response, into `<data dir>/tools/` with mode `0700`, no `PATH` and no root. Ghidra, IDA, Binary
Ninja and the Sleuth Kit publish no standalone Linux binary, so they say "use a package manager"
instead of offering a button that would fail.

```bash
python3 -m nerveforge.toolkit --list-skills # what is ready here
python3 -m nerveforge.toolkit --list-tools # what is installed, what is missing
python3 -m nerveforge.toolkit --install jadx # download, verify, unpack, chmod
```

**MCP** (`MCP` tab, `GET /api/mcp`). As a client, a preset names the bridge *and* what blocks it:
`ida-pro-mcp` and `ghidra-mcp` want a server you already run, `ghidra-headless-mcp` wants
`uvx`, `radare2-mcp` shells out to `npx`. HTTP presets connect to a running server; stdio presets
start a child process only when you press connect, never at startup. Every call lands in
`<data dir>/mcp-audit.jsonl` with secret-looking arguments redacted, and a tool whose name says it
changes something (`rename_`, `patch_`, `run_*`, …) is refused with `409` until the panel asks you
and resends it with `allow_mutating`.

As a server, the same code exposes this bridge to somebody else's agent:

```bash
python3 -m nerveforge.toolkit --serve # read-only tools
python3 -m nerveforge.toolkit --serve --allow-write # adds workspace_write and run_command
```

It speaks MCP `2025-06-18` over stdio and offers eight tools — `list_skills`, `read_skill`,
`list_tools`, `workspace_list`, `workspace_read`, `workspace_write`, `run_command`,
`mcp_servers`. Write and run are annotated as mutating and need the second flag.

### Step 2 — read the connection details

```
================================================================
NERVEFORGE 8.1.0 READY
NERVEFORGE 8.2.0 READY
Public address: https://sample-subdomain-1234.trycloudflare.com
Local panel: http://127.0.0.1:8766/
Token: <YOUR_TOKEN>
Expand Down Expand Up @@ -173,6 +225,14 @@ Every protected call needs `Authorization: Bearer <token>`.
| `POST /api/workspace/write` | bearer | `{"path": "file.txt", "content": "..."}` (previous version is backed up) |
| `POST /api/public/scripts` | public | Create a new `.cs` file (legacy) in the workspace root |
| `POST /api/public/assets` | public | Create a text file with an allowlisted extension |
| `GET /api/skills`, `GET /api/skills/<id>` | bearer | Skill catalogue with `ready`/`partial`/`blocked` and the body of one skill |
| `GET /api/tools` | bearer | Tool catalogue: what is installed, what is missing, what can be downloaded |
| `POST /api/tools/install` | bearer | `{"id": "jadx"}` — download, verify the SHA-256, unpack into the data dir; `201` |
| `GET /api/mcp/presets` | bearer | Twelve MCP bridges and what blocks each one |
| `POST /api/mcp/connect`, `/call`, `/disconnect` | bearer | Drive an MCP server; mutations need `allow_mutating` |
| `GET /api/mcp/server/tools` | bearer | This bridge as an MCP server: eight tools, write and run annotated |

The reference lists all 61 routes; [docs/API.md](docs/API.md) is generated from the table, so it cannot drift.

Full allowlist: `GET /api/quick` → `capabilities.public_upload.extensions`; add your own with
`NERVEFORGE_PUBLIC_UPLOAD_EXTRA`. Details: [docs/PUBLIC_UPLOAD.md](docs/PUBLIC_UPLOAD.md).
Expand All @@ -181,11 +241,11 @@ Full allowlist: `GET /api/quick` → `capabilities.public_upload.extensions`; ad

## 🧪 Tests and code quality

The repository ships **1657 automated unit tests** (Linux, Windows, Android/Termux, API, security,
The repository ships **1660 automated unit tests** (Linux, Windows, Android/Termux, API, security,
tunnels). CI runs them on Linux and Windows:

```bash
python3 -m unittest discover -s tests -v # 1657 tests
python3 -m unittest discover -s tests -v # 1660 tests
python3 -m compileall -q src tests run.py # Python bytecode
find static -name '*.js' -print0 | xargs -0 -n1 node --check # JavaScript syntax # JS syntax
bash -n setup.sh && bash -n setup_termux.sh # shell installers
Expand All @@ -205,7 +265,8 @@ Bump the version with `python3 scripts/bump_version.py X.Y.Z`.
| [docs/API.md](docs/API.md) | Endpoint reference (generated from the code) |
| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Layers, state owners, tunnels, sandbox |
| [docs/PANEL.md](docs/PANEL.md) | Panel modules, data flow, design tokens, adding a screen |
| [docs/ADR/](docs/ADR/README.md) | Decisions that are expensive to reverse (0001–0005) |
| [docs/TOOLKIT.md](docs/TOOLKIT.md) | Skills, the tool catalogue, the installer and MCP |
| [docs/ADR/](docs/ADR/README.md) | Decisions that are expensive to reverse (0001–0006) |
| [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | Checks, test layout, change checklist |
| [docs/PUBLIC_UPLOAD.md](docs/PUBLIC_UPLOAD.md) | Public upload: allowlist and quotas |
| [SECURITY.md](SECURITY.md) | Trust boundaries and what must not be weakened |
Expand All @@ -227,6 +288,7 @@ nerveforge/
│ ├── PANEL.md # Panel architecture (ES modules)
│ ├── DEVELOPMENT.md # Development process and checks
│ ├── PUBLIC_UPLOAD.md # Anonymous upload (extension allowlist)
│ ├── TOOLKIT.md # Skills, tool catalogue, installer and MCP
│ ├── REFACTORING_PLAN.md # Refactoring plan and status
│ ├── ADR/ # Architecture decision records
│ └── ru/ # Russian translation of every document
Expand All @@ -246,7 +308,7 @@ nerveforge/
│ ├── uzhas_manager.py # Shell runner with timeout and tree cancellation
│ └── workspace_manager.py # File operations, bwrap sandbox, public uploads
├── static/ # Web panel assets (HTML, CSS, JS)
├── tests/ # Unit tests (1657 tests)
├── tests/ # Unit tests (1660 tests)
├── pyproject.toml # PEP 517/518 build metadata
├── run.py # Run in place
├── setup.sh / setup_windows.ps1 / setup_termux.sh
Expand Down
38 changes: 37 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Security policy — NerveForge 8.1.0
# Security policy — NerveForge 8.2.0

**English** · [Русский](docs/ru/SECURITY.md)

Expand Down Expand Up @@ -86,6 +86,42 @@ file as untrusted input.
- Importing the module no longer creates files or tokens: the token is issued by an explicit
`bootstrap()` at server start, and a server without an initialised token answers `401` (fail closed).

## The toolbox: downloads, subprocesses and MCP

Three new ways for the process to reach outside itself, and what each one refuses to do.

**Downloads (`POST /api/tools/install`).** The installer writes one file into `<data
dir>/tools/` with mode `0700`, verified by the SHA-256 that came in the same GitHub API response
that named the release. No `PATH` edit, no system install, no root, no automatic download at
startup. An asset without a digest is refused, because a download that cannot be verified is a
download that should not happen. This is the same rule as cloudflared.

**Subprocesses (MCP over stdio).** An HTTP preset connects to a server the operator already runs;
a stdio preset starts a child only when somebody presses connect, and it is killed with
`terminate_process_tree` on disconnect. Nothing is spawned at startup and nothing is respawned in
the background, so "the panel opened" never means "a process started".

**Talking to other servers (MCP client).** Every `tools/call` lands in
`<data dir>/mcp-audit.jsonl` (`0600`) with `token`/`key`/`secret`/`password`/`authorization`/`cookie`
arguments replaced by `***`. Results are capped at 64 KiB. A tool whose name suggests a mutation
(`rename`, `patch`, `set_`, `write`, `create`, `delete`, `remove`, `run`, `exec`, …) is refused with
`409` until the request carries `allow_mutating`, and the panel only sends that after a
confirmation dialog — the gate is in the service, not in the UI.

Two risks are worth naming rather than hiding:

- **A connected MCP server is code running with your privileges.** A Ghidra or IDA plugin that
exposes `run_script` runs whatever you send it. Connect only to servers you installed, and read
the tool list before calling anything.
- **The mutation gate is name-based.** MCP has no required "this changes state" flag, so a tool
called `get_and_set_x` is gated and one called `apply` may not be. When it matters, prefer a
read-only server or a disposable copy of the database.

**The server half.** `python3 -m nerveforge.toolkit --serve` exposes this bridge over stdio. It is
read-only unless started with `--allow-write`, `run_command` additionally needs armed full access,
and both are annotated as mutating. The two flags are separate on purpose: an agent that can write
to your workspace should have been asked for it twice.

## Recommendations

- Use a dedicated PC or VM, without valuable data and outside any corporate network.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.1.0
8.2.0
Loading
Loading