# Service Estimation & AI Consultation Guide

This guide explains how to use the automated estimation system to generate professional PDF quotes for clients using AI-driven context analysis.

## 🛠 Basic Usage

The primary entry point is the `ai-estimate` script. It orchestrates a 6-pass AI consultation:
1. **Fact Extraction**: Identifying company data and project scope.
2. **Feature Deep-Dive**: Generating technical justifications for items.
3. **Strategic Content**: Creating the Briefing Analysis and Strategic Vision.
4. **Information Architecture**: Designing a hierarchical sitemap.
5. **Position Synthesis**: Mapping everything to a transparent pricing model.
6. **Industrial Critic**: Final quality gate for tone and accuracy.

### Generating an Estimation from Scratch

#### 1. With a Website URL (Recommended)
Providing a URL allows the system to crawl the existing site to understand the "Company DNA" and services.
```bash
npm run ai-estimate -- "Relaunch der Website mit Fokus auf B2B Leads" --url https://example.com
```

#### 2. From a Text File
If you have a long briefing in a `.txt` file:
```bash
npm run ai-estimate -- @briefing.txt --url https://example.com
```

#### 3. Text-Only (No URL)
If no URL is provided, the system relies entirely on your briefing text.
```bash
npm run ai-estimate -- "Neuentwicklung eines Portals für XYZ"
```

---

## 📄 Output Modes

The system can generate two types of documents:

### 1. Full Quote (Default)
Includes everything: Front Page, Briefing Analysis, Vision, Sitemap, Technical Principles, Detailed Pricing, Roadmap, and Legal Terms (AGB).
```bash
npm run ai-estimate -- "Project Briefing"
```

### 2. Estimation Only
A condensed version excluding legal terms and deep technical principles. Focuses purely on the strategic fit and the price.
```bash
npm run ai-estimate -- "Project Briefing" --estimation
```

---

## 📦 Cache & Cache Management

To save costs and time, all AI responses and crawl results are cached in the `.cache` directory.

### Regenerating with Cached Data
If you run the same command again (identical briefing and URL), the system will use the cached results and won't call the AI APIs again. This is useful if you want to tweak the PDF layout without spending tokens.

### Forcing a Refresh
To ignore the cache and get a fresh AI consultation:
```bash
npm run ai-estimate -- "Project Briefing" --clear-cache
```

### Manual Tweaking (JSON State)
Every run saves a detailed state to `out/estimations/json/[Company]_[Timestamp].json`. 
If you want to manually edit the AI's results (e.g., fix a typo in the sitemap or description), you can edit this JSON file and then regenerate the PDF from it:

```bash
npm run ai-estimate -- --json out/estimations/json/Your_Project.json
```
*(Add `--estimation` if you want the condensed version).*

---

## 💡 Advanced Options

- `--comments "..."`: Add manual notes that the AI should consider (e.g., "Customer prefers a minimalist blue theme").
- `--clear-cache`: Purges all cached data for this project before starting.
- `--url [URL]`: Explicitly sets the crawl target (auto-discovered from briefing if omitted).
