# ERNE Google Drive Project Context Ingest

Use this reference when the user asks to import ERNE project folders from Google Drive into the local JARVIS project knowledge vault for later protocol creation, meeting preparation, risk review, or legal/contractual context lookup.

## Trigger

User mentions Drive paths such as:

- `ERNE/Projekte/<project>`
- `ERNE/ERNE_Wissen`
- project context packages containing Werkvertrag, Protokolle, Terminpläne, QS/PQM/Risiken/Chancen, Adresslisten

## Target local structure

Project-specific context should live under:

```text
~/jarvis_memory/work/projects/<project_slug>/documents/
├── README.md              # human-readable document directory
├── document_index.csv     # machine-readable inventory
├── source_files/          # symlinks or copied originals from the local Drive download cache
└── extracted_text/        # text extracted from PDF/DOCX/XLSX/PPTX for search/RAG-style lookup
```

General ERNE knowledge should live under:

```text
~/jarvis_memory/work/erne_wissen/documents/
├── README.md
├── document_index.csv
├── source_files/
└── extracted_text/
```

Maintain an overview file:

```text
~/jarvis_memory/work/ERNE_DOCUMENT_CONTEXT.md
```

## Download/source handling with `gog`

1. Load the `gog`/workspace skill first for CLI quirks.
2. Use the configured account, normally:

```bash
gog -a friday.uplink@gmail.com ...
```

3. In non-interactive runs, source the GOG keyring env and set HOME/XDG if needed:

```bash
set -a; source ~/.hermes/secrets/gog_keyring.env; set +a
export HOME=/home/agent
export XDG_CONFIG_HOME=/home/agent/.config
```

4. Search/list folders with JSON output and `--no-input`:

```bash
gog -a friday.uplink@gmail.com drive search "name = 'ERNE' and mimeType = 'application/vnd.google-apps.folder' and trashed = false" --json --no-input
gog -a friday.uplink@gmail.com drive ls --parent <folder_id> --json --no-input
```

5. Download office/PDF/text files to a local cache such as:

```text
~/jarvis_memory/work/_drive_sources/ERNE/...
```

6. Export Google-native documents explicitly:

| Google MIME | Export |
|---|---|
| Docs | `--format docx` |
| Sheets | `--format xlsx` |
| Slides | `--format pptx` |
| Other Google drawing-like files | `--format pdf` |

7. Keep large audio/video meeting recordings as linked source files unless the user explicitly wants transcription. Do not spend bulk-ingest time downloading/transcribing every MP4. They belong in the manifest/document index with `media_link_only` or equivalent status.

## Text extraction

Create search-friendly extracts:

- PDF → `pdftotext -layout`
- DOCX → `python-docx`, paragraphs + tables
- XLSX → `openpyxl` with `data_only=True`
- PPTX → `python-pptx`, slide text
- TXT/MD/CSV/JSON → copy or normalize as plain text

Unsupported binaries/ZIPs can stay indexed without text extraction.

## Document typing heuristics

Classify documents in `README.md` / `document_index.csv` by path/name heuristics:

| Type | Typical markers |
|---|---|
| Werkvertrag/Vertrag | `werkvertrag`, `vertrag`, `AVB`, `Beilage` |
| Terminplan | `termin`, `bauprogramm`, `meilenstein` |
| QS/PQM/Risiko | `PQM`, `QS`, `Risiko`, `Chance`, `Qualität` |
| Protokoll/Sitzung | `protokoll`, `sitzung`, `BHS`, `Jourfix`, `FPS` |
| Adressliste/Organisation | `adresse`, `organigramm`, `organisation` |
| Kosten/Nachträge | `nachtrag`, `kosten`, `zahlung`, `budget` |
| Norm/Wissen | `SIA`, `norm`, `merkblatt` |

## Project note integration

Patch/create each project file:

```text
~/jarvis_memory/work/projects/<project_slug>/project.md
```

Add a concise section:

```markdown
## Dokumentenverzeichnis / Kontextquellen

Aktueller lokaler Dokumentenindex aus Google Drive ERNE/Projekte/<project>:

- Dokumentenverzeichnis: `documents/README.md`
- Index CSV: `documents/document_index.csv`
- Originaldateien als Symlinks: `documents/source_files/`
- Suchbare Textextrakte: `documents/extracted_text/`

Nutzung: Bei Sitzungs-/Protokollvorbereitung zuerst `documents/README.md` und bei Detailfragen die passenden Textextrakte/Originale prüfen. Medienaufnahmen sind nur als Quelle/Datei abgelegt und werden nicht automatisch vollständig ausgewertet.
```

## Verification checklist

Before reporting completion:

- `ERNE_DOCUMENT_CONTEXT.md` exists and lists all imported collections.
- Each project has `documents/README.md` and `documents/document_index.csv`.
- CSV line count roughly equals number of indexed docs + header.
- `extracted_text/` contains text extracts for most PDF/DOCX/XLSX/PPTX files.
- `project.md` contains the `Dokumentenverzeichnis / Kontextquellen` section.
- Report counts per collection and mention any intentionally linked-only media.

## Use during later meeting/protocol tasks

When preparing protocols, risk radars, PL coaching, or legal/contractual support:

1. Start with the project `documents/README.md` to identify relevant source documents.
2. Use extracted text for fast search and initial context.
3. Read original PDFs/DOCX/XLSX when exact wording, contract clauses, numbers, deadlines, or liability-sensitive interpretation matters.
4. Use `~/jarvis_memory/work/erne_wissen/documents/` for general SIA/QS/Nachtrag/Kennwert context, but keep project documents as the source of truth for project-specific obligations.
