Skip to main content
Glama
README.md
<div align="center">

# ZhiDian (指点) v1.2

**Local-First Spatial Desktop AI Workbench · 7 Strict-CSP Studios · Offline Qwen3.5 4B/9B · Cross-Platform Headless MCP**

**English** | **[中文文档 (README.zh-CN.md)](README.zh-CN.md)**

[![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
[![Node >= 22.13](https://img.shields.io/badge/Node-%3E%3D22.13-339933.svg)](package.json)
[![Strict CSP](https://img.shields.io/badge/CSP-style--src%20'self'%20Zero%20innerHTML-0ea5e9.svg)](#architecture--safety-invariants)
[![Opaque E2E](https://img.shields.io/badge/Opaque%20E2E-194%20Tests-10b981.svg)](docs/benchmarks.md)

</div>

---

**ZhiDian** turns your cursor into an offline, local-first AI workbench. Press **`F8`** on Windows to frame files or any window region — including **100%-occluded background layers via full stacked-window `overlappingLayers` & `.layer-switch`** — and issue **zero-switch natural-language desktop actions** (auto-routed via `parseDesktopActionIntent()` or locked with the purple **`AI Command Control`** toggle, with live HWND UIA capture, automatic focus release, idle-mode high-risk confirmation, and a live global **`Esc` + `24 px` physical mouse kill-switch**), or launch **7 deterministic strict-CSP studios** (interactive PPTX with native OOXML charts, reversible live-formula XLSX analytics & `@1/@2` dual-window cross-check, ONNX + RGBA image editing, contract redline diff, 4-mode rollback file organization, opt-in 8-second auto-archiver memory hub disabled by default in Settings, and guarded Computer Use).

Not on Windows or don't want to download a multi-GB model first? All 7 studio engines are **100% Electron-free pure Node.js**, so you can launch the **15-second local browser playground (`npm run demo`)**, run the **cross-platform headless MCP server** (`Claude Code` / `Cursor` / `Hermes Agent`), or install the **pure-Python Hermes plugin** on macOS, Linux, or Windows right now.

---

## v1.2 launch videos (1080p)

Download the five launch videos, four GGUF LoRA adapters, and SHA-256 checksum manifest from [GitHub Release v1.2](https://github.com/misakamikotoghr-5205/ZhiDian-Open/releases/tag/v1.2).

| Video | Duration | Contents |
| --- | --- | --- |
| [English animated film](https://github.com/misakamikotoghr-5205/ZhiDian-Open/releases/download/v1.2/zhidian-v1-launch-trailer-en.mp4) · [Chinese edition](https://github.com/misakamikotoghr-5205/ZhiDian-Open/releases/download/v1.2/zhidian-v1-launch-trailer-zh.mp4) | 75.0 s each | Five acts introduce the F8 cursor, the seven offline studios, and the local model. |
| [Windows 11 desktop recording](https://github.com/misakamikotoghr-5205/ZhiDian-Open/releases/download/v1.2/zhidian-v1-real-desktop-demo.mp4) | 110.8 s | Qwen3.5-4B running locally, the browser playground, and the headless MCP server. |
| [Horizontal English clip](https://github.com/misakamikotoghr-5205/ZhiDian-Open/releases/download/v1.2/zhidian-v1-x-hook-15s.mp4) · [Vertical Chinese clip](https://github.com/misakamikotoghr-5205/ZhiDian-Open/releases/download/v1.2/zhidian-v1-xhs-vertical-15s.mp4) | 15.0 s each | Short editions for landscape (16:9) and portrait (9:16) playback. |
| [Seven-act studio walkthrough](promo/zhidian-v06-operation-demo.mp4) | 130.1 s | A recording in the source repository shows the studios exporting PPTX, XLSX, PNG, and redline reports. |

| Interactive PPT Studio + Real OOXML Native Chart Viewer | `@1` Excel × `@2` Word Dual-Cursor Mismatch Audit |
| :---: | :---: |
| ![PPT Studio & Live OOXML Chart Viewer](docs/assets/en-ppt-studio.png) | ![Dual-Window @1/@2 Cross-Check & AI Secondary Cursor](docs/assets/en-sheet-crosscheck.png) |
| **Occluded Layer #2 Computer Use + Kill-Switch + Save-as-Skill** | **ONNX + RGBA Composable Image Studio Split Slider** |
| ![Occluded Layer Computer Use & Save as Skill](docs/assets/en-cu-killswitch.png) | ![AI Image Studio RGBA Split Slider](docs/assets/en-image-studio.png) |

<details>
<summary>More 1080p captures (Contract Redline Diff Studio & Smart Organizer / Auto-Archiver Memory Hub)</summary>

| Contract Redline Diff Studio (`#diffstudio`) | 4-Mode Smart Organizer & 8s Auto-Archiver Memory Hub |
| :---: | :---: |
| ![Contract Redline Diff Studio](docs/assets/en-redline-diff.png) | ![Smart Organizer & Auto-Archiver Memory Hub](docs/assets/en-organizer-archive.png) |

</details>

---

## 3-Path Quickstart

### Path 1: 15-Second Zero-Install Browser Playground (macOS / Linux / Windows · Zero GPU)

Experience all **7 real, unmodified strict-CSP studios** locally on `127.0.0.1` with bundled sample fixtures (`.docx`, `.xlsx`, `.pdf`, `.png`, contracts) — no Electron binary download and no GPU required:

```bash
git clone https://github.com/misakamikotoghr-5205/ZhiDian-Open.git
cd ZhiDian-Open
npm ci --ignore-scripts
npm run demo
# Opens local loopback playground at http://127.0.0.1:47610
```

### Path 2: Cross-Platform Headless MCP Server & Hermes Agent Plugin (macOS / Linux / Windows)

Use ZhiDian's deterministic office/document engines directly from **Claude Code**, **Cursor**, **Claude Desktop**, or **Hermes Agent** — completely offline, workspace-sandboxed, and read-only/dry-run by default:

```bash
# Run standalone headless MCP server (workspace-confined, no Electron required)
node bin/zhidian-mcp.mjs --standalone --workspace ./my-docs

# Optional: opt in to write transforms (otherwise strictly read-only / dry-run)
node bin/zhidian-mcp.mjs --standalone --workspace ./my-docs --allow-write
```

- **Standalone Headless MCP Tools (6 deterministic tools)**: `zhidian_diff_compare`, `zhidian_sheet_analyze`, `zhidian_ppt_blueprint`, `zhidian_image_inspect`, `zhidian_organize_plan`, `zhidian_list_skills`.
- **Live Desktop MCP Tools (8 spatial tools when Windows ZhiDian Desktop is running)**: `list_referents`, `get_referent`, `point_at`, `get_app_context`, `propose_app_actions`, `list_skills`, `identify_screen_layer`, `list_active_files`.
- **Claude Code quick-add**:
  ```bash
  claude mcp add zhidian -- node /abs/path/to/ZhiDian-Open/bin/zhidian-mcp.mjs --standalone --workspace /abs/path/to/workspace
  ```
- **Hermes Agent Plugin (Pure Python 3.11+ stdlib, zero external deps)**: See [`misakamikotoghr-5205/hermes-zhidian-workbench`](https://github.com/misakamikotoghr-5205/hermes-zhidian-workbench) (guarded by `agent.file_safety` + workspace containment, zero `/tmp` literals, optional secret-scoped desktop bridge).

### Path 3: Full Windows 11 Offline Desktop App

Requires **Node.js `>= 22.13.0`**:

```bash
git clone https://github.com/misakamikotoghr-5205/ZhiDian-Open.git
cd ZhiDian-Open
npm ci
npm test
npm start
```

Build a self-contained offline bundle with pinned SHA-256 verification (`llama.cpp b12110` + default `Qwen3.5-4B` + automatic LoRA adapter fetch/verification; pass `--allow-missing-adapters` in slim pre-release environments):

```bash
# Optional China mirror: ZHIDIAN_BUILD_SOURCE=hfmirror (or modelscope)
npm run bundle
node build/bundle-local.mjs --verify-only
npm run package
```

---

## Architecture & Safety Invariants

ZhiDian strictly decouples **LLM intent/planning** from **deterministic execution**. The model never writes raw Office XML or bypasses safety gates.

```mermaid
flowchart LR
  subgraph Capture["Spatial Capture & OS Layer (Windows Native)"]
    F8["F8 Frame / Clipboard / @1 @2 Pins"]
    ZOrder["Multi-Scale Template Match\n+ Win32 EnumWindows & DWMWA_CLOAKED"]
    Shell["Shell COM File Handles\n& Active Document Watcher"]
    F8 --> ZOrder
    F8 --> Shell
  end

  subgraph Brain["Local Offline Inference (llama.cpp b12110)"]
    Models["Qwen3.5 4B / 9B + GGUF LoRAs\n(or local Pruned+Fused IQ3_XS)"]
    MCP["MCP Server\n8 Live Spatial Tools (127.0.0.1)\n+ 6 Standalone Headless Studio Tools"]
  end

  subgraph Studios["7 Strict-CSP Electron-Free Studios (Pure Node)"]
    S1["1. PPT Blueprint & OOXML Charts"]
    S2["2. Sheet Analytics & Live Formulas"]
    S3["3. ONNX + 4-Stage RGBA Image"]
    S4["4. Contract Redline Diff"]
    S5["5. Guarded Computer Use & Skills"]
    S6["6. 4-Mode Organizer + Rollback"]
    S7["7. Opt-in 8s Auto-Archiver Hub"]
  end

  subgraph Safety["Hardened Safety Boundaries"]
    Kill["Step-Confirm Default · High-Risk Pause\nEsc & 24px Physical Mouse Kill-Switch"]
    CSP["Strict CSP style-src 'self'\nZero innerHTML · Zero eval"]
    Sandbox["Workspace realpath Sandbox\nNo .. / Symlink / UNC / Device Paths"]
  end

  Capture --> Brain
  Brain --> Studios
  Studios --> Safety
  MCP --> Studios
```

### The 7 Built-in Interactive Studios

| # | Studio | Core Engine (`src/`) | What It Does Deterministically |
| --- | --- | --- | --- |
| 1 | **Interactive PPT Blueprint (`#pptstudio`)** | `ppt-blueprint.js`, `pptx-blueprint.js`, `pptx-inspect.js` | Frame mixed `.docx`/`.xlsx`/`.pdf`/`.png` files → live blueprint across 8 designer themes → multi-turn NL edits + self-audit repair → native editable `.pptx` with OOXML charts & pure-Node `inspectPptx()` preview. |
| 2 | **Formula Sheet & `@1/@2` Audit (`#sheetstudio`)** | `table-analytics.js`, `sheet-studio.js`, `sheet.js` | Financial KPI & outlier profiling, pure-SVG bar/line/donut charts, reversible filter Undo/Reset (`c:sheetstudio:undo`) + explicit `>60`-row preview truncation notice, allowlisted live Excel formulas (`<f>SUM`/`AVERAGE`), and dual-pin `@1` Excel × `@2` Word cross-checking with secondary `#aicursor` highlighting. |
| 3 | **Composable AI Image Studio (`#imgstudio`)** | `image-pipeline.js`, `image-studio.js`, `image-models/runner.js` | Optional local ONNX (`RMBG-1.4` cutout, `RealESRGAN_x4plus` 4× tiled upscale, `LaMa` masked inpaint) + 4-stage RGBA compositing, keyboard-accessible split-slider before/after preview, true toggleable `Brighten`/`Sharpen` presets, and 1-click insert into PPT Studio. |
| 4 | **Contract Redline Diff (`#diffstudio`)** | `doc-diff.js`, `diff-service.js` | Bounded-LCS clause/token diffing, legal/financial risk triage (penalties, amounts, deadlines), interactive prompt handling, XSS-hardened redline HTML/Markdown/PDF export, and 1-click review deck generation. |
| 5 | **Hybrid Computer Use & Skill Authoring (`#cuplan`)** | `screen-match.js`, `computer-use.js`, `cu-runtime.js`, `windows-layers.js` | Returns full stacked-window `overlappingLayers` (incl. 100%-occluded Layer #2) with `#layercard .layer-switch` (`c:layer:select`), zero-switch NL routing (`parseDesktopActionIntent`) + purple `AI Command Control` toggle + continuous `#cuplan` replanning, live target `HWND` UIA fetching + automatic focus release, transparent payload preview (`st.text`/`st.keys`) + per-step Run & Skip (`c:cu:updateWorkflowStep` risk re-check), HiDPI `#aicursor`, idle-mode `paused_high_risk` confirmation, refcounted live global `Esc` + `24 px` physical mouse kill-switch, and unique-slug `SKILL.md` authoring. |
| 6 | **4-Mode Smart File Organizer (`#orgcard`)** | `file-classifier.js`, `organize.js` | Classifies framed files via fast rules + optional local LLM fallback across 4 modes (`category` / `project` / `date` / `custom`), previews collision-safe moves with 2-phase atomic apply and one-click undo. |
| 7 | **Opt-In 8-Second Auto-Archiver Memory Hub (`#archivememory`)** | `active-files.js`, `auto-archiver.js` | **Disabled by default (`DEFAULTS.archive.enabled = false`, explicit opt-in in Settings)**; watches active Office/WPS/PDF/editor documents read-only, and when enabled triggers a non-intrusive 8-second countdown (auto-extended when changing category) after document close & lock release, indexes text excerpts, and supports one-click rollback or weekly report PPT generation. |

---

## Quantization Cliff & Model Benchmarks (Honest Synthetic Gate Data)

Full methodology, SHA-256 manifests, and per-run JSON logs are in **[`docs/benchmarks.md`](docs/benchmarks.md)** and [`train/v06-colab/results/`](train/v06-colab/results/).

### Structural Pruning (32→28 Layers, 248K→131K Vocab) + `imatrix` Quantization Cliff (`N = 64` Synthetic Gate)

Every candidate was booted on live `llama-server b12110` (CUDA L4) and gated on `N = 64` held-out synthetic tasks (`40` File-Ops + `24` Computer-Use; pass thresholds: Valid JSON ≥ 95%, File-Ops ≥ 90%, CU ≥ 85%):

| Tier & Quant | Model + `Q8_0 mmproj` | vs Unpruned Q4_K_M + 2 LoRAs | Valid JSON | File-Ops (40) | Computer-Use (24) | Overall (64) | Avg Latency | Gate |
| --- | --- | --- | ---: | ---: | ---: | ---: | ---: | --- |
| **4B** `IQ2_S` | 1.65 GB (`1.29 + 0.37`) | -52.8% | 93.75% | 85.00% | **54.17%** | 73.44% | 488.7 ms | **FAIL** |
| **4B** `IQ2_M` | 1.73 GB (`1.37 + 0.37`) | -50.6% | 100.00% | 100.00% | **75.00%** | 90.62% | 499.9 ms | **FAIL** |
| **4B `IQ3_XS`** | **2.00 GB** (`1.63 + 0.37`) | **-42.9%** (0 external LoRA) | **100.00%** | **100.00%** | **100.00%** | **100.00%** | **522.4 ms** | **PASS** |
| **9B** `IQ2_M` | 3.38 GB (`2.76 + 0.62`) | -49.7% | 100.00% | 92.50% | **83.33%** | 89.06% | 697.5 ms | **FAIL** |
| **9B `IQ3_XS`** | **3.89 GB** (`3.26 + 0.62`) | **-42.1%** (0 external LoRA) | **100.00%** | **100.00%** | **95.83%** | **98.44%** | **748.6 ms** | **PASS** |
| **9B** `IQ3_M` | 4.04 GB (`3.41 + 0.62`) | -39.9% | 100.00% | 100.00% | 100.00% | 100.00% | 769.7 ms | PASS |

### Published Standalone GGUF LoRA Adapters (`N = 80` Synthetic Gate)

Mounted directly on upstream `unsloth/Qwen3.5-4B-GGUF` and `unsloth/Qwen3.5-9B-GGUF` (Model Cards: [`docs/model-cards/huggingface-README.md`](docs/model-cards/huggingface-README.md) · [`docs/model-cards/modelscope-README.md`](docs/model-cards/modelscope-README.md)):

| Adapter | Base Model | Size | Base Exact | LoRA Exact | Delta | Valid JSON |
| --- | --- | ---: | ---: | ---: | ---: | ---: |
| `zhidian-v06-computer-use-lora.gguf` | `Qwen/Qwen3.5-4B` | 40.5 MiB | 46.25% | **100.00%** | **+53.75 pp** | 100.0% |
| `zhidian-v06-file-ops-lora.gguf` | `Qwen/Qwen3.5-4B` | 40.5 MiB | 93.75% | **98.75%** | +5.00 pp | 100.0% |
| `zhidian-v06-9b-computer-use-lora.gguf` | `Qwen/Qwen3.5-9B` | 55.5 MiB | 46.25% | **100.00%** | **+53.75 pp** | 100.0% |
| `zhidian-v06-9b-file-ops-lora.gguf` | `Qwen/Qwen3.5-9B` | 55.5 MiB | 100.00% | **100.00%** | +0.00 pp | 100.0% |

---

## Honest Failure Boundaries & Limitations

- **Synthetic regression gates ≠ real-world desktop benchmarks**: The `N = 64` and `N = 80` numbers verify structured JSON schema fidelity after pruning/quantization/LoRA training. They are **not** OSWorld or ScreenSpot scores, and complex unseen third-party UIs still require human confirmation (hence Step-Confirm default and the `24 px` kill-switch).
- **Fused weights are reproducible local builds, not pre-hosted GGUFs**: Public Hubs & Release `v1.2` ship the **4 verified GGUF LoRA adapters** (`40.5 MiB` × 2 + `55.5 MiB` × 2 = `192.1 MiB` total) compatible with upstream public Qwen3.5 GGUFs. The `2.00 GB` / `3.89 GB` `IQ3_XS` fused single-file models are marked `localOnly: true` and built via [`train/v06-colab/`](train/v06-colab/README.md).
- **Platform split**: Screen-layer occlusion (`EnumWindows` + `DWMWA_CLOAKED`), Shell COM desktop icon binding, and UIA/SendInput Computer Use are **Windows-native**. macOS and Linux users get the 15-second `npm run demo` studio playground, cross-platform headless MCP server, and pure-Python Hermes Agent plugin.
- **CPU latency**: The `522 ms` / `748 ms` latencies above were measured on an NVIDIA L4 GPU; pure-CPU laptops run slower depending on core count and RAM bandwidth.

---

## Verification & Testing

- Run `npm test` to execute the Node.js unit and security regression tests.
- **Dual-Track 4-Tier Opaque-Box E2E Harness**: **148 desktop app tests** (`122` baseline + `26` v1.0 / Anti-Human-UX hardening; `5/5` `--self-check` anti-cheat + strict-CSP Chromium gates) + **46 platform-deliverable tests** = **194 combined opaque-box E2E tests** (`10/10` self-check gates).

```bash
# 1. Node.js unit and security regression tests
npm test

# 2. 4-tier Opaque-Box E2E harness (148 desktop tests, 5-gate anti-cheat + strict-CSP Chromium check)
python3 -B test/e2e/opaque/run_all.py --self-check
python3 -B test/e2e/opaque/run_all.py --list
```

## License & Project Docs

- Source code & ZhiDian LoRA adapters: **[Apache-2.0](LICENSE)** · Attribution & third-party notices: **[`NOTICE`](NOTICE)**
- Upstream Qwen3.5 model attribution: [`models/LICENSE-Qwen.txt`](models/LICENSE-Qwen.txt)
- Release notes & installers: [`docs/releases/v1.2.md`](docs/releases/v1.2.md) · [`docs/releases/desktop-installers.md`](docs/releases/desktop-installers.md) · [`CHANGELOG.md`](CHANGELOG.md)
- Contributing & Security: [`CONTRIBUTING.md`](CONTRIBUTING.md) · [`SECURITY.md`](SECURITY.md)