# PrismCAD

**Zero-trust AI for AutoCAD** — natural-language CAD commands with mandatory approval, cryptographic execution, and local-only processing.

[![.NET](https://img.shields.io/badge/.NET-8.0-512BD4?logo=dotnet&logoColor=white)](https://dotnet.microsoft.com/)
[![AutoCAD](https://img.shields.io/badge/AutoCAD-2025%20%7C%202026-red)](https://www.autodesk.com/products/autocad)
[![Tests](https://img.shields.io/badge/tests-92%20C%23%20%2B%2066%20Python-brightgreen)](docs/IMPLEMENTATION-STATUS.md)
[![Platform](https://img.shields.io/badge/platform-Windows%20x64-blue)](deploy/PRIVACY.md)

> Describe what you want in plain English. PrismCAD plans the operation, shows a preview, and only changes your drawing after you approve.

**Author:** [Amin Parva](https://github.com/insightitsGit) · **Support:** [insightits.info@gmail.com](mailto:insightits.info@gmail.com)

*This project is a gift to my beloved sister, Jila.*

---

## Table of contents

- [What is PrismCAD?](#what-is-prismcad)
- [Key features](#key-features)
- [Supported platforms](#supported-platforms)
- [Quick start](#quick-start)
- [AutoCAD commands](#autocad-commands)
- [Example prompts](#example-prompts)
- [How it works](#how-it-works)
- [Project RAG and agent panel](#project-rag-and-agent-panel)
- [Configuration](#configuration)
- [Installation and deployment](#installation-and-deployment)
- [Security model](#security-model)
- [Architecture](#architecture)
- [Development](#development)
- [Testing and QA](#testing-and-qa)
- [Documentation](#documentation)
- [FAQ](#faq)
- [Marketplace and privacy](#marketplace-and-privacy)

---

## What is PrismCAD?

PrismCAD is an **AutoCAD plugin** that connects **natural-language prompts** to **deterministic CAD execution**. It targets drafters, engineers, and BIM teams who want AI-assisted workflow without giving an LLM direct write access to their drawings.

Unlike tools that run arbitrary AutoCAD commands from a model output, PrismCAD uses a **zero-trust pipeline**:

1. **Plan** — a local Python sidecar maps your prompt to signed, versioned operations.
2. **Approve** — a WPF dialog shows the execution plan and geometry preview.
3. **Execute** — the C# kernel runs only after Ed25519 authorization bound to your live drawing context.

All default processing stays **on your machine** (`127.0.0.1`). No cloud account or API key is required for rule-based commands.

**Keywords:** AutoCAD AI plugin · natural language CAD · AutoCAD automation · AutoCAD 2025 · AutoCAD 2026 · CAD approval workflow · local LLM sidecar · zero-trust execution · block attribute automation · project-scoped RAG

---

## Key features

| Feature | Description |
| --- | --- |
| **Natural-language commands** | Move, rotate, copy, delete, and update block attributes via plain English |
| **Mandatory approval** | Every plan requires explicit user confirmation before any drawing change |
| **Zero-trust execution** | Ed25519-signed authorization tied to live `ContextFingerprint` (drawing identity, units, selection) |
| **Local sidecar** | Bundled Python runtime — no separate Python install for end users |
| **Dual RAG** | Global command RAG (VectorPrism) + per-drawing project RAG (ProjectPrism) |
| **Project agent panel** | Cursor-like chat per drawing with persisted session history |
| **Block attribute updates** | Bulk material-code changes (e.g. all toilets) via project entity resolution |
| **Hybrid search** | Structural index + debounced semantic embeddings for entity lookup |
| **Retry and rollback** | Up to 5 planning/execution attempts; step-level rollback on failure |
| **Optional BYOK LLM** | OpenAI key via simple settings UI — disabled by default |

---

## Supported platforms

| Requirement | Details |
| --- | --- |
| **OS** | Windows 10/11 x64 |
| **AutoCAD** | **2025 and 2026** (series `R25.0`–`R25.2`, .NET 8) |
| **Not supported** | AutoCAD 2027+ in this bundle (separate scaffold exists for future .NET 10) |
| **Python (dev only)** | 3.10+ for local sidecar development |
| **.NET (dev only)** | .NET 8 SDK + AutoCAD .NET SDK for building the live adapter |

---

## Quick start

### End users (installed bundle)

1. Build or download the bundle (see [Installation](#installation-and-deployment)).
2. Run the installer (no Administrator required for per-user install).
3. Open **AutoCAD 2025 or 2026**.
4. Run **`PRISMCADLICENSE`** — paste the free beta key from [insightits.com/prismcad/beta](https://www.insightits.com/prismcad/beta) (the agreement includes daily agent-log upload when the log changes).
5. Run **`PRISMCADHEALTH`** — confirm license and sidecar are healthy.
6. Select entities, run **`PRISMCAD`**, enter a prompt, review the plan, and approve.

### Developers (from source)

```powershell
git clone https://github.com/insightitsGit/prismCad.git
cd prismCad
dotnet build PrismCAD.sln -c Release
dotnet test PrismCAD.sln
pip install -r sidecar/requirements.txt
python -m pytest sidecar/tests -q
```

---

## AutoCAD commands

| Command | Description |
| --- | --- |
| `PRISMCAD` | Prompt → plan → approve → execute |
| `PRISMCADPALETTE` | Dockable natural-language command palette |
| `PRISMCADAGENT` | Per-project agent chat panel (session history + index status) |
| `PRISMCADLICENSE` | Activate the free beta license from insightits.com |
| `PRISMCADSETTINGS` | AI settings — paste OpenAI API key without editing JSON |
| `PRISMCADHEALTH` | Check license status and local orchestration sidecar health |

Ribbon: **Plug-Ins → PrismCAD** (Run, Sidecar Health, Project Agent, AI Settings, Beta License).

---

## Example prompts

Select entities first for selection-scoped commands. For bulk project-scoped prompts (e.g. all toilets), leave selection empty and describe the target entities.

```
move selection north 10
rotate selection 90
copy east 5mm
delete selection
set material code to WC-01 on selection
set material code WC-02 for all toilets
delete all lines on layer walls
```

See the full prompt reference: [docs/PROMPT-GUIDE.md](docs/PROMPT-GUIDE.md)

---

## How it works

```mermaid
flowchart LR
    A[User prompt] --> B[Python sidecar]
    B --> C[VectorPrism RAG]
    B --> D[ProjectPrism RAG]
    C --> E[PrismManifest]
    D --> E
    E --> F[Approval dialog]
    F --> G[Ed25519 sign]
    G --> H[AutoCAD kernel execute]
```

1. **Sidecar planning** — PrismGuard verifies pinned artifacts; **PlanningCycle** runs five stages; **ChorusGraph** routes the prompt; VectorPrism + operation contract subgraph retrieve command mappings.
2. **Project context** — per-drawing SQLite index resolves handles for bulk prompts (“all toilets”, “lines on layer WALLS”).
3. **Approval** — UI renders `ExecutionPlan` with geometry preview; user must approve.
4. **Authorization** — C# signs `ExecutionAuthorization` with a DPAPI-protected Ed25519 key.
5. **Execution** — kernel revalidates live fingerprint, runs in a transaction, commits or rolls back.

---

## Project RAG and agent panel

PrismCAD maintains **two separate retrieval systems**:

| RAG | Scope | Purpose |
| --- | --- | --- |
| **VectorPrism** | Global product catalog | Maps language → signed operations |
| **ProjectPrism** | Current drawing only | Maps language → entity handles |

**Storage (per drawing):**

```
%LOCALAPPDATA%\PrismCAD\projects\{project_id}\
  index.db              # SQLite entity index + embeddings
  agent_session.json    # Per-project chat history
```

The **`PRISMCADAGENT`** panel shows chat history, project ID, entity count, index version, and embedding version. Embeddings refresh on a **500 ms debounce** after drawing edits.

Details: [docs/PROJECT-RAG-ARCHITECTURE.md](docs/PROJECT-RAG-ARCHITECTURE.md)

---

## Configuration

### Easy setup (recommended)

In AutoCAD, run **`PRISMCADSETTINGS`** or click **AI Settings** on the palette.

- **No API key** — rule-based routing handles common commands
- **Optional OpenAI key** — better handling of long or vague prompts
- Settings saved to `%LOCALAPPDATA%\PrismCAD\prismcad.settings.json`

Environment variable (advanced): `PRISMCAD_LLM_API_KEY`

### Advanced settings

Copy [deploy/prismcad.settings.json](deploy/prismcad.settings.json) to `%LOCALAPPDATA%\PrismCAD\prismcad.settings.json`.

| Setting | Default | Purpose |
| --- | --- | --- |
| `orchestration.transportMode` | `LocalNamedPipe` | IPC mode |
| `orchestration.port` | `55000` | Loopback gRPC port |
| `sidecar.autoStart` | `true` | Auto-start Python sidecar |
| `security.signingKeyPath` | `%LOCALAPPDATA%\PrismCAD\signing.key.dpapi` | Ed25519 signing key |

---

## Installation and deployment

### Build the marketplace bundle

```powershell
powershell -ExecutionPolicy Bypass -File deploy\Build-PrismCadBundle.ps1
```

Output: `artifacts\PrismCAD.bundle\`

### Install (per-user, no Administrator)

```powershell
powershell -ExecutionPolicy Bypass -File artifacts\PrismCAD.bundle\Install-PrismCad.ps1 -PerUser
```

Restart AutoCAD. The bundle autoloads via `PackageContents.xml`.

### Build an MSI for end users

```powershell
powershell -ExecutionPolicy Bypass -File installer\Build-PrismCadMsi.ps1 -Configuration Release
```

Output: `artifacts\installer\PrismCAD-Release.msi`. See [installer/README.md](installer/README.md).

### Marketplace submission

- Checklist: [deploy/MARKETPLACE-SUBMISSION.md](deploy/MARKETPLACE-SUBMISSION.md)
- Compliance: [deploy/APP-STORE-COMPLIANCE.md](deploy/APP-STORE-COMPLIANCE.md)
- Privacy policy: [deploy/PRIVACY.md](deploy/PRIVACY.md)

---

## Security model

1. Python sidecar proposes an **unsigned** `PrismManifest`.
2. UI renders **ExecutionPlan** (canonical projection for hashing).
3. User approves → `ApprovalHash = SHA-256(ExecutionPlan DTO)`.
4. C# signs **ExecutionAuthorization** (DPAPI-protected Ed25519 key).
5. Kernel **revalidates live ContextFingerprint** before commit.

LLM output never bypasses the approval gate or signing step. See [docs/LLM-DETERMINISTIC-BOUNDARY.md](docs/LLM-DETERMINISTIC-BOUNDARY.md).

---

## Architecture

| Component | Role |
| --- | --- |
| **PrismCAD.Core** | Protocol contracts, canonical hashing, execution kernel, project index |
| **PrismCAD.Security** | Ed25519 signing (DPAPI-protected keys) |
| **PrismCAD.Orchestration** | gRPC client for Python sidecar |
| **PrismCAD.UI** | WPF approval dialog, palette, agent panel, settings |
| **PrismCAD.AutoCADNet8** | AutoCAD 2025/2026 plugin (.NET 8 Managed API) |
| **sidecar/** | Python orchestration (PlanningCycle → PrismGuard → ChorusGraph → VectorPrism → Manifest) |

Full specification: [docs/DESIGN.md](docs/DESIGN.md) (v5.5.1)

AutoCAD .NET patterns in RAG corpus: [docs/AUTOCAD-NET-API-REFERENCE.md](docs/AUTOCAD-NET-API-REFERENCE.md)

---

## Development

### Build

```powershell
dotnet build PrismCAD.sln -c Release
```

### Regenerate Python gRPC stubs (after proto changes)

```powershell
python sidecar/generate_protos.py
powershell -ExecutionPolicy Bypass -File deploy\Generate-PinnedManifest.ps1 `
  -SidecarDirectory sidecar `
  -BundleRoot . `
  -OutputPath sidecar\pinned_manifests\artifacts.sha256.json
```

### Run sidecar manually

```powershell
python -m sidecar.main --host 127.0.0.1 --port 55000
```

---

## Testing and QA

### Unit and integration tests

```powershell
dotnet test
cd sidecar; python -m pytest tests -q
```

**Current coverage:** 92 C# tests + 66 Python tests.

### Full automated QA (recommended before release)

```powershell
powershell -ExecutionPolicy Bypass -File deploy\Invoke-PrismCadVerification.ps1
```

Runs C# tests, Python tests, bundle build, and marketplace bundle verification.

### AutoCAD smoke preflight

```powershell
powershell -ExecutionPolicy Bypass -File deploy\Invoke-PrismCadAutoCadSmokeTest.ps1 `
  -BundleRoot artifacts\PrismCAD.bundle
```

Detects AutoCAD installation, validates bundle layout, and prints a live smoke-test checklist.

---

## Documentation

| Document | Description |
| --- | --- |
| [docs/DESIGN.md](docs/DESIGN.md) | Full protocol specification (v5.5.1) |
| [docs/PROMPT-GUIDE.md](docs/PROMPT-GUIDE.md) | Supported natural-language commands |
| [docs/WEBSITE-USER-GUIDE.md](docs/WEBSITE-USER-GUIDE.md) | Customer-facing installation, commands, examples, and troubleshooting copy |
| [docs/PRISMCAD-FULL-USER-GUIDE.md](docs/PRISMCAD-FULL-USER-GUIDE.md) | Full installation and end-user handbook |
| [docs/PROMPT-KB.md](docs/PROMPT-KB.md) | Prompt knowledge base and routing pipeline |
| [docs/PART-A-ROUTING.md](docs/PART-A-ROUTING.md) | Part A canonical routing (5-tier taxonomy, PrismRAG, contract subgraph) |
| [docs/AGENTIC-DESIGN.md](docs/AGENTIC-DESIGN.md) | Agent nodes, ChorusGraph routing graph, data flow |
| [docs/PROJECT-RAG-ARCHITECTURE.md](docs/PROJECT-RAG-ARCHITECTURE.md) | Per-drawing project RAG design |
| [docs/LLM-DETERMINISTIC-BOUNDARY.md](docs/LLM-DETERMINISTIC-BOUNDARY.md) | LLM vs deterministic trust zone |
| [docs/IMPLEMENTATION-STATUS.md](docs/IMPLEMENTATION-STATUS.md) | Feature completion tracking |
| [docs/AUTOCAD-NET-API-REFERENCE.md](docs/AUTOCAD-NET-API-REFERENCE.md) | Curated AutoCAD .NET API reference |
| [deploy/README-INSTALL.txt](deploy/README-INSTALL.txt) | End-user install notes |

---

## FAQ

### Does PrismCAD send my drawings to the cloud?

No. Default operation is fully local. An optional OpenAI API key sends **prompt text and retrieved snippets** to OpenAI only if you configure it. See [deploy/PRIVACY.md](deploy/PRIVACY.md).

### Do I need an API key?

No. Rule-based routing and RAG handle move, rotate, copy, delete, and many compound prompts without an LLM.

### Which AutoCAD versions are supported?

AutoCAD **2025 and 2026** on Windows x64. The bundle declares compatibility with series `R25.0` through `R25.2`.

### Can the AI modify my drawing without asking?

No. Every change requires explicit approval in the dialog. Unsigned manifests cannot execute.

### How do I update material codes on many blocks?

Use a project-scoped prompt such as `set material code WC-02 for all toilets`. PrismCAD resolves matching block references from the per-drawing index and injects handles into the signed operation.

### How do I get support?

Email [insightits.info@gmail.com](mailto:insightits.info@gmail.com) with your AutoCAD version, Windows version, and the output of **`PRISMCADHEALTH`**.

---

## Marketplace and privacy

PrismCAD is packaged for **Autodesk App Store** submission with:

- Autoloader bundle (`PackageContents.xml`)
- Bundled Python runtime and pinned sidecar integrity manifest (PrismGuard)
- Privacy policy and compliance documentation

Publisher: **Amin Parva** · Support: **insightits.info@gmail.com**

---

<p align="center">
  <strong>PrismCAD</strong> — plan with AI, approve with confidence, execute with proof.
</p>
